简体   繁体   English

反应本机导航单一模式,导航到不同的内容

[英]React native navigation single modal, navigate to different content

I am looking for a way to have multiple screens with a presentation mode of 'modal' but not have 2 modals pop up when navigation.navigate is called on them.我正在寻找一种方法来让多个屏幕的演示模式为“模态”,但在调用 navigation.navigate 时不会弹出 2 个模态。

<Stack.Screen name="Results" component={ResultsScreen} options={{ presentation:'modal'}} />
<Stack.Screen name="Viewer" component={ViewerScreen} options={{presentation:'modal'}} />

The default functionality seems to be to open 2 separate modal windows on top of each other.默认功能似乎是在彼此之上打开 2 个单独的模式窗口。 I would like to have a single modal open and the content of the modal change.我想打开一个单一的模态并改变模态的内容。 Is this possible?这可能吗?

You can try using a nested stack navigator您可以尝试使用嵌套堆栈导航器

const ModalStackView = () => (
  <ModalStack.Navigator
   screenOptions={{
   headerShown: true,
  }}>
    <ModalStack.Screen
     name="modalCard1"
     component={ModalView}
     options={{presentation: 'modal'}}
    />
    <ModalStack.Screen
     name="modalCard2"
     component={CardView}
     options={{presentation: 'card'}}
    />
  </ModalStack.Navigator>
)


<RootStack.Group screenOptions={{ presentation: 'modal' }}>
    <RootStack.Screen name="MyModal" component={ModalStackView} />
</RootStack.Group>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM