Using the React Navigation tab navigator https://reactnavigation.org/docs/navigators/tab how do I make one of the tab buttons push the screen up as a full screen modal? I see the stack navigator has a mode=modal
option. how do I get that mode to be used when clicking on the TakePhoto
tab button? Clicking on it currently still shows the tab bar on the bottom.
const MyApp = TabNavigator({
Home: {
screen: MyHomeScreen,
},
TakePhoto: {
screen: PhotoPickerScreen, // how can I have this screen show up as a full screen modal?
},
});
Actually, there is no support in react-navigation to change the way of presentation on the fly from
default
tomodal
(see the discussion about this here). I ran into the same issue and solved it by using a very topStackNavigator
withheaderMode
set tonone
andmode
set tomodal
:This allows me to do the following (using redux) in
Tab1Screen
andTab2Screen
to bring up the modal view from wherever I want:react-navigation
's bottomTabNavigator has atabBarOnPress
navigation option you can use to override tab presses:https://reactnavigation.org/docs/en/bottom-tab-navigator.html#tabbaronpress
If you nest your tab navigator within a stack navigator with a modal, you can open this when the tab bar button is pressed. Since the modal was opened and not the tab, when the modal is closed the app returns to the screen that was visible before the modal tab was pressed.
One way to make the tab bar go away is to hide the tabBar with
visible: false
:However, that does not seem to trigger any transition to fullscreen, which I guess is desired?
Another option could be to wrap
PhotoPickerScreen
inside a new StackNavigator and set that navigator to mode='modal'.You might have to trigger the navigation to that modal from onPress on the tabItem somehow (eg.
navigation.navigate('TakePhoto')
.)Note, I'm trying to wrap my head around how best to structure navigation myself, so …
Third option, implementing a StackNavigator as parent, then adding the
MyApp
TabNavigator as the first route inside of it, could be the most flexible solution. Then the TakePhoto screen would be on the same level as the TabNavigator, allowing you to route to it from wherever.Interested to hear what you come up with!
Not sure if this is still relevant for you, but i've managed to find away to achieve this.
So i've managed to get it working by using the tabBarComponent inside the tabNavigatorConifg, you can stop the tab navigation from navigating depending on the index.
Once you've done this, my method of showing the view modally on top of the tab views was to put the tabnavigator inside of a stacknavigatior and then just navigate to a new screen inside of the stacknavigator.
Docs are patchy in some areas, but here it is: