From e3cef0bcc776589fb70b334fa036c43fc16a5a00 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Sat, 27 Apr 2024 19:53:46 +0200 Subject: [PATCH] fix: issues with presenting owned modals from foreign ones (#2113) ## Description Basically this is another edition of the issue #1829 (handled by #1912). The issue comes down to the fact, that our `ScreenStack` is not aware of all modal view controllers being in presentation, but this time it is not aware of third-party modal view controllers (I've named them "foreign" modals in opposite to "owned" modals). This PR is not a comprehensive solution but rather just a patch aiming at fixing one particular interaction reported in #2048. I've left verbose code comments explaining the issue and suggesting solution in the source code, including: ``` // TODO: Find general way to manage owned and foreign modal view controllers and refactor this code. Consider building // model first (data structue, attempting to be aware of all modals in presentation and some text-like algorithm for // computing required operations). ``` Closes #2048 Closes #2085 ## Changes Trigger dissmisal of foreign modal if it is presented above `changeRoot` modal (last modal that is to stay on stack after the updates). ## Test code and steps to reproduce `Test2048` in `TestsExample` & `FabricTestExample`. ## Checklist - [x] Included code example that can be used to test this change - [x] Ensured that CI passes --- FabricTestExample/App.js | 1 + FabricTestExample/src/Test2048.tsx | 85 ++++++++++++++++++++++++++++++ TestsExample/App.js | 1 + TestsExample/src/Test2048.tsx | 85 ++++++++++++++++++++++++++++++ ios/RNSScreenStack.mm | 30 +++++++++-- 5 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 FabricTestExample/src/Test2048.tsx create mode 100644 TestsExample/src/Test2048.tsx diff --git a/FabricTestExample/App.js b/FabricTestExample/App.js index 1b50c3eff6..2aea269a4d 100644 --- a/FabricTestExample/App.js +++ b/FabricTestExample/App.js @@ -94,6 +94,7 @@ import TestScreenAnimation from './src/TestScreenAnimation'; import Test1981 from './src/Test1981'; import Test2008 from './src/Test2008'; import Test2028 from './src/Test2028'; +import Test2048 from './src/Test2048'; import Test2069 from './src/Test2069'; enableFreeze(true); diff --git a/FabricTestExample/src/Test2048.tsx b/FabricTestExample/src/Test2048.tsx new file mode 100644 index 0000000000..e4efdcaf3b --- /dev/null +++ b/FabricTestExample/src/Test2048.tsx @@ -0,0 +1,85 @@ +import React from 'react'; +import { View, Modal, Button, TouchableWithoutFeedback } from 'react-native'; +import { useState } from 'react'; + +import { NavigationContainer, useNavigation } from '@react-navigation/native'; +import { createNativeStackNavigator } from '@react-navigation/native-stack'; + +type AppStackPages = { + Home: undefined; + Modal: undefined; +}; + +function HomeScreen() { + const navigation = useNavigation(); + const [visible, setVisible] = useState(false); + + return ( + +