Zhuinden / simple-stack

[ACTIVE] Simple Stack, a backstack library / navigation framework for simpler navigation and state management (for fragments, views, or whatevers).
Apache License 2.0
1.36k stars 76 forks source link

Support dispatching back across the current active scope chain #206

Closed Zhuinden closed 4 years ago

Zhuinden commented 4 years ago

I actually had a similar setup in service-tree ages ago, but this time there's a chance it'll actually make sense :wink:

Currently to dispatch back event to your current active view, you generally select the current active view through the view hierarchy, by defining a custom boolean onBackPressed() that is delegated down to the current active-most view, which is actually quite tricky if you have a multi-step flow or a ViewPager.

Clearly, it is not even the responsibility of the View layer to know who's supposed to handle back presses. It should be the responsibility of the "active ViewModel" (or something similar). Therefore, the "active ViewModel" that can handle back should be found by simple-stack and should handle back if necessary, and only goBack() when no services in the active chain have handled back.

The question however is whether this should be a new behavior of backstack.goBack() (as the behavior is opt-in, because you need to implement an interface, it would not be breaking), or if it should be a separate method such as backstack.dispatchBack() that would be wrapped in Navigator/BackstackDelegate. :thinking:

Zhuinden commented 4 years ago

I should most likely not introduce a new method, and add this behavior to goBack(). That's where one would expect it to go, anyway. :thinking: