Skip to content

Commit 03272ae

Browse files
committed
Optional disable of pop action on setting route
1 parent 5231c3e commit 03272ae

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

ReSwiftRouter/NavigationActions.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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 {}

ReSwiftRouter/NavigationReducer.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

ReSwiftRouter/NavigationState.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

4041
extension NavigationState {

ReSwiftRouter/Router.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)