native-navigation
native-navigation copied to clipboard
Feature request: Expose screen stack events
Use case: we intend to use stacked fragments to create a card stack. A card needs to know that it's not on the top of the stack so it can render differently (for example, change its position and size, optimize away elements which won't be rendered, etc)
I'm thinking about a NavigatorModule.addScreenStackChangedListener
or NavigatorModule.on('screenStackChanged', (name: string, props: object) => void)
method. Then all the work to keep state of which screens are being show can be done on the JS side.
If you agree with that API, I'll (try to) make the PR.
I think implementation should not be too difficult using FragmentManager.addOnBackStackChangedListener on android and UINavigationController's delegate didShowViewController
.
Or we can just emit the relevant events on the present/push/pop/dismiss native methods instead of using the FragmentManager/UINavigationController events
cc @gpeal
I like this idea and have been wanting something similar on iOS as well.
I think we should expose an event emitter interface through the NavigationCoordinator
equivalents on both iOS and Android, as well as exposing a Navigator.on(event, callback)
on the JS side.