johnpatrickmorgan / FlowStacks

FlowStacks allows you to hoist SwiftUI navigation and presentation state into a Coordinator
MIT License
783 stars 56 forks source link

Show root, go back to root only if needed #45

Closed Kondamon closed 1 year ago

Kondamon commented 1 year ago

It doesn't make sense IMO to get an assert when going back to root if the root is already presented. Or is there any other way to show the initial screen (for e.g. deeplink handling):

$routes.withDelaysIfUnsupported {
    $0.dismiss()
    $0.goBackToRoot()
}
Kondamon commented 1 year ago

Have added a convenience function to show initial root screen.

johnpatrickmorgan commented 1 year ago

Thanks @Kondamon! I completely agree, it should not assert when going back to the root if we're already on the root, it should just do nothing.

However, I'm not sure I understand the usefulness of the convenience function. It should always be sufficient to call:

$routes.withDelaysIfUnsupported {
    $0.goBackToRoot()
}

The goBack family of methods work on both pushed and presented screens, so even if the stack contains a mixture of presented and pushed screens, there should be no need to call dismiss in addition to goBackToRoot. If you're seeing different behaviour, please could you describe it, as that would be a bug. Thanks!

johnpatrickmorgan commented 1 year ago

In the meantime, I've merged your first commit and tagged a new version 0.2.4. Thanks for contributing!

Kondamon commented 1 year ago

@johnpatrickmorgan, I was initially thinking of UINavigationController behavior where you need to call popToRootViewController and dismiss any screens that are presented.

Ok, I got it! Thanks for clarification and the fast merge!