forked from software-mansion/react-native-screens
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: issues with presenting owned modals from foreign ones (software-…
…mansion#2113) ## Description Basically this is another edition of the issue software-mansion#1829 (handled by software-mansion#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 software-mansion#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 software-mansion#2048 Closes software-mansion#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
- Loading branch information
Showing
5 changed files
with
198 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> | ||
<Button | ||
title="Toggle bottom modal" | ||
onPress={() => setVisible(prev => !prev)} | ||
/> | ||
<Modal animationType="slide" visible={visible} transparent> | ||
<TouchableWithoutFeedback onPress={() => setVisible(false)}> | ||
<View style={{ flex: 1 }} /> | ||
</TouchableWithoutFeedback> | ||
<View | ||
style={{ | ||
borderTopLeftRadius: 10, | ||
borderTopRightRadius: 10, | ||
borderWidth: 2, | ||
borderColor: 'red', | ||
padding: 10, | ||
minHeight: '40%', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}}> | ||
<Button | ||
title="Open navigation modal" | ||
onPress={() => { | ||
// Issue: autohiding the Modal that serves as a bottom sheet unmounts | ||
// the anchor component for the screen that is in { presentation: "modal" } mode | ||
// Previously the anchoring component for a { presentation: "modal" }-based screen was different and it worked | ||
// The culprit is: https://github.com/software-mansion/react-native-screens/pull/1912 released in https://github.com/software-mansion/react-native-screens/releases/tag/3.29.0 | ||
// adding setTimeout does not bring any good, because | ||
// - we either don't see navigation action | ||
// - we unmount both the bottom sheet modal and the screen itself | ||
|
||
setVisible(false); | ||
|
||
navigation.navigate('Modal'); | ||
}} | ||
/> | ||
</View> | ||
</Modal> | ||
</View> | ||
); | ||
} | ||
|
||
function ModalScreen() { | ||
return <View style={{ flex: 1, backgroundColor: 'rgb(50,150,50)' }} />; | ||
} | ||
|
||
const AppStack = createNativeStackNavigator<AppStackPages>(); | ||
|
||
function Navigation() { | ||
return ( | ||
<AppStack.Navigator> | ||
<AppStack.Screen name="Home" component={HomeScreen} /> | ||
<AppStack.Screen | ||
name="Modal" | ||
component={ModalScreen} | ||
options={{ presentation: 'modal' }} | ||
/> | ||
</AppStack.Navigator> | ||
); | ||
} | ||
|
||
export default function App() { | ||
return ( | ||
<NavigationContainer> | ||
<Navigation /> | ||
</NavigationContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> | ||
<Button | ||
title="Toggle bottom modal" | ||
onPress={() => setVisible(prev => !prev)} | ||
/> | ||
<Modal animationType="slide" visible={visible} transparent> | ||
<TouchableWithoutFeedback onPress={() => setVisible(false)}> | ||
<View style={{ flex: 1 }} /> | ||
</TouchableWithoutFeedback> | ||
<View | ||
style={{ | ||
borderTopLeftRadius: 10, | ||
borderTopRightRadius: 10, | ||
borderWidth: 2, | ||
borderColor: 'red', | ||
padding: 10, | ||
minHeight: '40%', | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}}> | ||
<Button | ||
title="Open navigation modal" | ||
onPress={() => { | ||
// Issue: autohiding the Modal that serves as a bottom sheet unmounts | ||
// the anchor component for the screen that is in { presentation: "modal" } mode | ||
// Previously the anchoring component for a { presentation: "modal" }-based screen was different and it worked | ||
// The culprit is: https://github.com/software-mansion/react-native-screens/pull/1912 released in https://github.com/software-mansion/react-native-screens/releases/tag/3.29.0 | ||
// adding setTimeout does not bring any good, because | ||
// - we either don't see navigation action | ||
// - we unmount both the bottom sheet modal and the screen itself | ||
|
||
setVisible(false); | ||
|
||
navigation.navigate('Modal'); | ||
}} | ||
/> | ||
</View> | ||
</Modal> | ||
</View> | ||
); | ||
} | ||
|
||
function ModalScreen() { | ||
return <View style={{ flex: 1, backgroundColor: 'rgb(50,150,50)' }} />; | ||
} | ||
|
||
const AppStack = createNativeStackNavigator<AppStackPages>(); | ||
|
||
function Navigation() { | ||
return ( | ||
<AppStack.Navigator> | ||
<AppStack.Screen name="Home" component={HomeScreen} /> | ||
<AppStack.Screen | ||
name="Modal" | ||
component={ModalScreen} | ||
options={{ presentation: 'modal' }} | ||
/> | ||
</AppStack.Navigator> | ||
); | ||
} | ||
|
||
export default function App() { | ||
return ( | ||
<NavigationContainer> | ||
<Navigation /> | ||
</NavigationContainer> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters