react-native-screens
react-native-screens copied to clipboard
fix(iOS): dismiss all attached view controllers correctly on reload
Description
This PR addresses an issue with react-native-screens where modals were not being dismissed correctly during app reloads when combined with foreign view controllers. The fix involves enhancing the invalidate method to recursively dismiss all presented view controllers, ensuring a clean state on reload.
This is not a development-only problem; this fix also addresses reloads from OTA updates.
Changes
- Enhanced invalidate method in RNSScreenStack.mm to recursively dismiss all presented view controllers.
- Ensured _presentedModals is cleared and _controller is detached from its parent during invalidation.
- Added a helper method dismissAllPresentedViewControllersFrom to handle recursive dismissal logic.
Screenshots / GIFs
Before | After |
---|---|
The red background is from a transparentModal
by RNS, the sheet is a foreign view controller. Before the change, react-native-screens
would break on reload if a foreign view controller was mounted on top. I came to the solution after finding this PR. The issue originally started here. After my changes, RNS works correctly on reload with third-party controllers.
I have no experience with Fabric, so I can't help with that. Feel free to update the solution for Fabric if needed.
Test code and steps to reproduce
Checklist
- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Updated documentation:
- [ ] https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md
- [ ] https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md
- [ ] https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx
- [ ] https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx
- [ ] Ensured that CI passes
Positive side effect: Fixes #2125