diff --git a/ReSwiftRouter/NavigationActions.swift b/ReSwiftRouter/NavigationActions.swift index 06e8a34..c94b2a6 100644 --- a/ReSwiftRouter/NavigationActions.swift +++ b/ReSwiftRouter/NavigationActions.swift @@ -12,11 +12,13 @@ public struct SetRouteAction: Action { let route: Route let animated: Bool + let disablePopAction: Bool public static let type = "RE_SWIFT_ROUTER_SET_ROUTE" - public init (_ route: Route, animated: Bool = true) { + public init (_ route: Route, animated: Bool = true, disablePopAction: Bool = false) { self.route = route self.animated = animated + self.disablePopAction = disablePopAction } } @@ -30,3 +32,5 @@ public struct SetRouteSpecificData: Action { self.data = data } } + +public struct EnablePopAction: Action {} diff --git a/ReSwiftRouter/NavigationReducer.swift b/ReSwiftRouter/NavigationReducer.swift index 538701a..c63a4fe 100644 --- a/ReSwiftRouter/NavigationReducer.swift +++ b/ReSwiftRouter/NavigationReducer.swift @@ -24,6 +24,8 @@ public struct NavigationReducer { return setRoute(state, setRouteAction: action) case let action as SetRouteSpecificData: return setRouteSpecificData(state, route: action.route, data: action.data) + case let action as EnablePopAction: + return enablePopAction(state) default: break } @@ -36,6 +38,7 @@ public struct NavigationReducer { state.route = setRouteAction.route state.changeRouteAnimated = setRouteAction.animated + state.disablePopAction = setRouteAction.disablePopAction return state } @@ -52,5 +55,13 @@ public struct NavigationReducer { return state } + + static func enablePopAction(_ state: NavigationState) -> NavigationState { + var state = state; + + state.disablePopAction = false + + return state + } } diff --git a/ReSwiftRouter/NavigationState.swift b/ReSwiftRouter/NavigationState.swift index 3d34bf6..804b24b 100644 --- a/ReSwiftRouter/NavigationState.swift +++ b/ReSwiftRouter/NavigationState.swift @@ -35,6 +35,7 @@ public struct NavigationState { public var route: Route = [] public var routeSpecificState: [RouteHash: Any] = [:] var changeRouteAnimated: Bool = true + var disablePopAction: Bool = false } extension NavigationState { diff --git a/ReSwiftRouter/Router.swift b/ReSwiftRouter/Router.swift index 2275aab..d22aefb 100644 --- a/ReSwiftRouter/Router.swift +++ b/ReSwiftRouter/Router.swift @@ -42,13 +42,17 @@ open class Router: StoreSubscriber { case let .pop(responsibleRoutableIndex, elementToBePopped): DispatchQueue.main.async { - self.routables[responsibleRoutableIndex] - .pop( - elementToBePopped, - animated: state.changeRouteAnimated) { - semaphore.signal() + if !state.disablePopAction { + self.routables[responsibleRoutableIndex] + .pop( + elementToBePopped, + animated: state.changeRouteAnimated) { + semaphore.signal() + } + } else { + semaphore.signal() } - + self.routables.remove(at: responsibleRoutableIndex + 1) } @@ -92,8 +96,13 @@ open class Router: StoreSubscriber { } } - + lastNavigationState = state + + if (state.disablePopAction) { + store.dispatch(EnablePopAction()) + } + } // MARK: Route Transformation Logic