-
-
Notifications
You must be signed in to change notification settings - Fork 612
feat(ios): add RNSLifecycleListenerProtocol for screen lifecycle events #3527
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
feat(ios): add RNSLifecycleListenerProtocol for screen lifecycle events #3527
Conversation
- Add RNSLifecycleListenerProtocol for external view controllers to receive screen lifecycle events - Notify conforming presented view controllers in notifyWillDisappear - Preserve controller reference before invalidation to ensure notifications work during unmount - Pass isPresenterUnmounting flag to help external modals handle dismissal correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, wouldn't it be sensible to implement mountingTransactionWillMount and observe for mutation that you're potentially interested in?
If that would be too late in case of e.g. native back button dismissal, you can observe the emitted event here via eventDispatcher from react core. ComponentDescriptor has access to event dispatcher and therefore your components can have it through state you receive in updateState:oldState: from RCTComponentProtocol, see similar setup here with image loader.
Another solution to consider is to have a module that accesses Scheduler (haven't verified whether it's possible, should be) and add a listener for an event there.
For similar reasons that I've pointed out here I'd like to avoid adding component-specific integrations for our lib, especially that we plan on sunsetting this implementation.
|
Thanks for your suggestions, @kkafar. I'll try it out. My initial issue was that the But I'll let you know, maybe this is not needed after all 🙏 |
|
Hopefully, if you use |
- Pass EventDispatcher from ComponentDescriptor through State to native view - Listen for topWillDisappear events to detect when presenter screen unmounts - Capture presenter screen tag and controller at presentation time - Distinguish navigation pop from modal dismiss by checking nav stack - Dismiss sheet when its presenter screen is being popped This replaces RNSLifecycleListenerProtocol per react-native-screens feedback. See: software-mansion/react-native-screens#3527
|
@kkafar it was a bit hacky but the I'll do some more test on our app to see if it doesn't break anything, will close this by then. Thank you! |
* feat(ios): detect screen unmount via C++ EventDispatcher - Pass EventDispatcher from ComponentDescriptor through State to native view - Listen for topWillDisappear events to detect when presenter screen unmounts - Capture presenter screen tag and controller at presentation time - Distinguish navigation pop from modal dismiss by checking nav stack - Dismiss sheet when its presenter screen is being popped This replaces RNSLifecycleListenerProtocol per react-native-screens feedback. See: software-mansion/react-native-screens#3527 * refactor(ios): extract RNScreensEventObserver from TrueSheetView * refactor(ios): remove RNSLifecycleListenerProtocol dependency * fix(ios): dismiss sheet when pushing screen in modal nav stack * refactor(ios): simplify RNScreensEventObserver modal detection * chore(example): add test screen to root navigator * docs(changelog): add PR #410 entry * docs(navigation): remove PR #3527 reference
|
Closing. Thanks again for the guidance @kkafar! |
|
Sure! Glad you managed to get it working |
Description
Add
RNSLifecycleListenerProtocolto allow external view controllers (such as third-party bottom sheets) to receive screen lifecycle events when a screen in the presenting hierarchy is about to disappear.This is useful for external modal implementations that need to know when the presenting screen is being unmounted (e.g., when navigating back) so they can dismiss themselves appropriately.
Changes
RNSLifecycleListenerProtocolinios/integrations/RNSScreen.mm:_controllerBeforeInvalidateivar to preserve controller reference before invalidationnotifyWillDisappearto notify conforming presented view controllersinvalidateImplto store controller before nullingscreenWillDisappear:isPresenterUnmounting:provides:Before & after - visual documentation
Before
before.mov
After
after.mov
Test plan
RNSLifecycleListenerProtocolscreenWillDisappear:isPresenterUnmounting:callbackExample conformance:
Checklist