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

handlePopBack is not called when 2 coordinators share the same rootViewController #30

Open
krin-san opened this issue May 15, 2019 · 3 comments
Labels

Comments

@krin-san
Copy link
Contributor

Improvements in 09b040f broke the following use case:

  • App has a single UINavigationController shared between home and account navigation coordinators
  • home coordinator shows the initial screens
  • account coordinator gets control over home.rootViewController when home creates and starts the account on user event (imagine showing an Account screen over the main app screen)
  • User uses the swipe-to-pop to close controller shown by account coordinator

Context before popping:

(lldb) po home.viewControllers
[HomeViewController]

(lldb) po account.viewControllers
[AccountViewController]

(lldb) po navigationController.viewControllers
[HomeViewController, AccountViewController]

When user performs swipe-to-pop gesture, didShowController gets called on account coordinator, but it returns on the check if lastIndex <= index { return } and therefore it:

  • don't remove AccountViewController from viewControllers
  • don't call handlePopBack(to:)
  • don't call parent?.coordinatorDidFinish(...)
@krin-san
Copy link
Contributor Author

Test case added in a branch https://github.com/krin-san/Coordinator/tree/bugfix/pop_back_child reproduces this issue.

@radianttap
Copy link
Owner

This is nice catch. I'll look into this as soon as I have time.

@radianttap radianttap added the bug label May 17, 2019
@radianttap
Copy link
Owner

Thinking out-loud...it seems to me in all these cases where I just return from the didShowController(_), I should actually call parent?.coordinatorDidFinish(self, completion: {})

guard let index = viewControllers.firstIndex(of: viewController) else {
	parent?.coordinatorDidFinish(self, completion: {})
	return
}
...
if lastIndex <= index {
	parent?.coordinatorDidFinish(self, completion: {})
	return
}

In the first case, shown VC is not in this Coordinator's domain, thus most likely this Coordinator is not active anymore. In the exit, it's the same thing.

Thus parent Coordinator should then figure out which Coordinator should be re-instated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants