简体   繁体   中英

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.

<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. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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