File tree Expand file tree Collapse file tree 4 files changed +33
-8
lines changed Expand file tree Collapse file tree 4 files changed +33
-8
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,13 @@ public struct SetRouteAction: Action {
1212
1313 let route : Route
1414 let animated : Bool
15+ let disablePopAction : Bool
1516 public static let type = " RE_SWIFT_ROUTER_SET_ROUTE "
1617
17- public init ( _ route: Route , animated: Bool = true ) {
18+ public init ( _ route: Route , animated: Bool = true , disablePopAction : Bool = false ) {
1819 self . route = route
1920 self . animated = animated
21+ self . disablePopAction = disablePopAction
2022 }
2123
2224}
@@ -30,3 +32,5 @@ public struct SetRouteSpecificData: Action {
3032 self . data = data
3133 }
3234}
35+
36+ public struct EnablePopAction : Action { }
Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ public struct NavigationReducer {
2424 return setRoute ( state, setRouteAction: action)
2525 case let action as SetRouteSpecificData :
2626 return setRouteSpecificData ( state, route: action. route, data: action. data)
27+ case let action as EnablePopAction :
28+ return enablePopAction ( state)
2729 default :
2830 break
2931 }
@@ -36,6 +38,7 @@ public struct NavigationReducer {
3638
3739 state. route = setRouteAction. route
3840 state. changeRouteAnimated = setRouteAction. animated
41+ state. disablePopAction = setRouteAction. disablePopAction
3942
4043 return state
4144 }
@@ -52,5 +55,13 @@ public struct NavigationReducer {
5255
5356 return state
5457 }
58+
59+ static func enablePopAction( _ state: NavigationState ) -> NavigationState {
60+ var state = state;
61+
62+ state. disablePopAction = false
63+
64+ return state
65+ }
5566
5667}
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ public struct NavigationState {
3535 public var route : Route = [ ]
3636 public var routeSpecificState : [ RouteHash : Any ] = [ : ]
3737 var changeRouteAnimated : Bool = true
38+ var disablePopAction : Bool = false
3839}
3940
4041extension NavigationState {
Original file line number Diff line number Diff line change @@ -42,13 +42,17 @@ open class Router<State: StateType>: StoreSubscriber {
4242
4343 case let . pop( responsibleRoutableIndex, elementToBePopped) :
4444 DispatchQueue . main. async {
45- self . routables [ responsibleRoutableIndex]
46- . pop (
47- elementToBePopped,
48- animated: state. changeRouteAnimated) {
49- semaphore. signal ( )
45+ if !state. disablePopAction {
46+ self . routables [ responsibleRoutableIndex]
47+ . pop (
48+ elementToBePopped,
49+ animated: state. changeRouteAnimated) {
50+ semaphore. signal ( )
51+ }
52+ } else {
53+ semaphore. signal ( )
5054 }
51-
55+
5256 self . routables. remove ( at: responsibleRoutableIndex + 1 )
5357 }
5458
@@ -92,8 +96,13 @@ open class Router<State: StateType>: StoreSubscriber {
9296 }
9397
9498 }
95-
99+
96100 lastNavigationState = state
101+
102+ if ( state. disablePopAction) {
103+ store. dispatch ( EnablePopAction ( ) )
104+ }
105+
97106 }
98107
99108 // MARK: Route Transformation Logic
You can’t perform that action at this time.
0 commit comments