Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional disable of pop action on setting route #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ReSwiftRouter/NavigationActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}
Expand All @@ -30,3 +32,5 @@ public struct SetRouteSpecificData: Action {
self.data = data
}
}

public struct EnablePopAction: Action {}
11 changes: 11 additions & 0 deletions ReSwiftRouter/NavigationReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -36,6 +38,7 @@ public struct NavigationReducer {

state.route = setRouteAction.route
state.changeRouteAnimated = setRouteAction.animated
state.disablePopAction = setRouteAction.disablePopAction

return state
}
Expand All @@ -52,5 +55,13 @@ public struct NavigationReducer {

return state
}

static func enablePopAction(_ state: NavigationState) -> NavigationState {
var state = state;

state.disablePopAction = false

return state
}

}
1 change: 1 addition & 0 deletions ReSwiftRouter/NavigationState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 16 additions & 7 deletions ReSwiftRouter/Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@ open class Router<State: StateType>: 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)
}

Expand Down Expand Up @@ -92,8 +96,13 @@ open class Router<State: StateType>: StoreSubscriber {
}

}

lastNavigationState = state

if (state.disablePopAction) {
store.dispatch(EnablePopAction())
}

}

// MARK: Route Transformation Logic
Expand Down