我对这段代码有点困惑,我有两个屏幕,MainScreen
在FeedScreen
里面NativeStackNavigator
,initialScreenName
(将首先路由/渲染的屏幕)在哪里MainScreen
。
我有一个嵌套在里面的MainScreen
模态,在模态里面有一个按钮可以导航到FeedScreen
,在导航到 时FeedScreen
,Modal
是可见的,但在返回时MainScreen
,Modal
不再可见,甚至在单击“显示模态”按钮后无法打开...
可见Modal
性由state
变量控制,这也是正确的,但仍然Modal
不可见......
请指出这里发生了什么,因为根据我的说法,从...Modal
回来时应该是开放的MainScreen
FeedScreen
这是代码...
function MainScreen({navigation}){
const [modalVisibility, setModalVisibility] = useState(false)
return <View>
<Text style={{ fontSize: 25 }}>I'm Main Screen...</Text>
<Text>{String(modalVisibility)}</Text>
<Button title='Show Modal' onPress={()=>setModalVisibility(true)} ></Button>
<Modal visible={modalVisibility} onRequestClose={()=>setModalVisibility(false)}>
<Text>I'm modal with visiblility {String(modalVisibility)}</Text>
<Button title='Go to Feed' onPress={()=>navigation.navigate('FeedScreen')}/>
</Modal>
</View>
}
function FeedScreen({navigation}) {
return <View>
<Button title='Go to Main' onPress={()=>navigation.navigate("MainScreen")}></Button>
</View>
}
function RootStackScreen() {
return (
<NavigationContainer>
<RootStack.Navigator initialRouteName='MainScreen'>
<RootStack.Screen name="MainScreen" component={MainScreen}/>
<RootStack.Screen name="FeedScreen" component={FeedScreen}/>
</RootStack.Navigator>
</NavigationContainer>