From 88d9794330b30004b8e8fc9e99844958c9f111ef Mon Sep 17 00:00:00 2001 From: Hirbod <504909+hirbod@users.noreply.github.com> Date: Mon, 28 Oct 2024 17:39:38 +0100 Subject: [PATCH] fix(Paper,iOS): dismiss all attached view controllers correctly on reload (#2175) ## 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](https://github.com/software-mansion/react-native-screens/pull/2113). The issue originally started [here](https://github.com/lodev09/react-native-true-sheet/issues/34). 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 Test2175 ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes --------- Co-authored-by: Kacper Kafara Co-authored-by: adrianryt --- apps/src/tests/Test2175.tsx | 151 ++++++++++++++++++++++++++++++++++++ apps/src/tests/index.ts | 1 + ios/RNSScreenStack.mm | 19 ++++- src/components/Screen.tsx | 11 +-- 4 files changed, 172 insertions(+), 10 deletions(-) create mode 100644 apps/src/tests/Test2175.tsx diff --git a/apps/src/tests/Test2175.tsx b/apps/src/tests/Test2175.tsx new file mode 100644 index 0000000000..dbab010c24 --- /dev/null +++ b/apps/src/tests/Test2175.tsx @@ -0,0 +1,151 @@ +import React from 'react'; +import { Button, Modal, SafeAreaView, Text, View } from 'react-native'; + +import { createNativeStackNavigator } from '@react-navigation/native-stack'; +import { NavigationContainer } from '@react-navigation/native'; +import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; + +const Stack = createNativeStackNavigator(); +const Tabs = createBottomTabNavigator(); + + +function TabScreens({ navigation }): React.JSX.Element { + return ( + + + + + ); +} + +function TabHomeScreen({ navigation }): React.JSX.Element { + return ( + + Where do you where do you go, my lovely, oh oh oh oh +