Skip to content

Commit

Permalink
Merge pull request #7 from Ikloo/popToVC-Crash
Browse files Browse the repository at this point in the history
Pop style crash fix
  • Loading branch information
SpectralDragon authored Sep 29, 2017
2 parents a305bef + 239fc1f commit f6cf4ac
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion LightRoute/LightRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ public final class TransitionPromise<T> {
}
// Remove old link action then we can setup new transition action.
self.postLinkAction = nil

self.checkForPop(in: style)

// Setup new transition action from transition case.
self.postLintAction { [weak self] in
Expand Down Expand Up @@ -395,7 +397,40 @@ public final class TransitionPromise<T> {
func postLintAction( _ completion: @escaping TransitionPostLinkAction) {
self.postLinkAction = completion
}


///
/// This method check style for 'pop', if so then change destination view controller to correct from navigation stack.
/// - parameter style: Style from `TransitionStyle` class.
///
private func checkForPop(in style: TransitionStyle) {
switch style {
case .navigationController(preferredStyle: let navStyle):
switch navStyle {
case .pop:
guard let dest = self.getDestinationFromNavigationStack() else { fatalError("[LightRoute]: Destination view controller was nil (not exist in navigation stack)") }
destination = dest
default:
break
}

default:
break
}
}

///
/// This method found correct view controller from navigation stack.
/// - no parameter.
///
private func getDestinationFromNavigationStack() -> UIViewController? {
guard let navController = root.navigationController else {
print("[LightRoute]: Transition error, navigation controller was nil.")
return nil
}
let destinationId = destination?.restorationIdentifier

return navController.viewControllers.filter({ $0.restorationIdentifier == destinationId}).first
}
}


Expand Down

0 comments on commit f6cf4ac

Please sign in to comment.