- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
How can I selectively hide Tabs with nested StackNavigators on certain screens? #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The tabs:
A child stack nav:
|
In order to hide a tabBar on one of the tabs, you can set this option to true. It's been recently documented. Is that something you were looking for? |
@grabbou but how would you put the tabBar navigation option on a screen that is a part of the stacknavigator. the stack nav is a child of the tabnavigators. that's why i was trying to find a round-about way to reach the "grandparent" navigator. |
and i cant make the profile screen part of the tabnavigator because that would make it a tab. not really what i want. let me know if my question is too confusing, and i'll try to add more code. |
I think I know what's the issue. I have one idea I'll try to send you tomorrow morning, maybe it works. |
ok thanks |
@grabbou does it involve redux? |
@KabirKang, to do this you have to have the Parent navigation as the StackNavigation, and then have your TabNavigation as one of the Stack screens. Then by turning on/off the
|
@dbhowell In your example you wrote header: {visible: true}. Did you mean tabBar? and would that work for tabbar? |
Note that Edit: I meant that |
@dbhowell So would the structure you suggest allow you to visit more screens within each tab or would each tab still need to have a nested stack navigator in each? Also what does this do to the back button? If you were to switch tabs, and then click the Android back button, would it go back to the previous tab? |
It does get confusing, so the best thing is to try it out and see what the result is. |
@dbhowell that works fine with headers (if
I'm also interested in how to do this, as a typical use case for us would be to hide the tab bar on the second level navigation throughout the app. Would be willing to help out implementing it, but need a few pointers on how to go about it. @grabbou, any ideas you have would be highly appreciated! |
@grabbou any update on this one? |
I think there should be an API which we can configure - This could update the global state of the navbar where it's configured - E.g inside a stack navigator: static tabbarOptions = {
hide: true,
...Otheroptions
} However I'm not sure how react-navigation is setup internally. |
I faced this problem too today. I need to hide the tabBar in the second level of navigation in one tab. I have a Is it possible right now with a certain config? |
Create separate tab navigators with the config you want and use them. |
Do you have an example? I can't figure out how to do this.
I want to hide the tabBar on the |
Hi, I found a simple solution. if we take @Kerumen config, we can add a per tab
The main thing there is that the tabBar option is a function that take 2 parameters : state and acc, acc is the And for example in SubScreen2 you can have this :
Hope it helps ;-) |
Hi, ` export const MainStack = StackNavigator({ export const MainTabs = TabNavigator( I tried putting this in the code of my "AdventureArticle" screen (in my stackNavigator): Is there a simple and straightforward way of handling this? |
Your config in AdventureArticle is overridden by the navigationOptions of the TabNavigator. Try this :
|
@adogor This kinda worked to just hide the tabbar, but the user is still able to swipe left or right to go to the other scenes in my tabbar. Is there a way to lock it on a particular screen? |
@bramvbilsen You can add |
@Kerumen But how would I do it for a single page that is a child of a StackNavigator? |
The way we did it was:
This works fine! We then store the top level E.g |
You can bind the tabBarVisible to a params, and on the screens that you want to hide the tab bar, fire a NavigationActions.setParams action to set the value of the parameter to the specific tab route. |
I have this working as follows:
npm versions:
|
@twairball confirmed, that works! |
@twairball That works dude. Thanks ! |
I'd be happy to make a PR to docs for this example. Where should I put this? Now, if only anyone can show me how to hide tabs dynamically :) |
nice @twairball ! I noticed one detail: the StackNavigator component must be the tab itself. If you have anything inbetween like a container component, this will not work. |
I have this root navigator: import HomeNavigator from './HomeNavigator';
export default {
Splash: { screen: SplashContainer },
Activation: { screen: ActivationContainer },
Login: { screen: LoginContainer },
ForgotPassword: { screen: ForgotPasswordContainer },
Register: { screen: RegisterContainer },
HomeScreen: { screen: HomeNavigator },
}; HomeNavigator: @connect(store => ({ authentication: store.authentication }))
class HomeNavigator extends Component {
getRoutesConfig = () => {
const tabToComponentMap = {
Screen1: Screen1Navigator,
Screen2: Screen2Navigator,
...
};
const config = {};
const { tabs = [] } = this.props.authentication.loginDetails;
tabs.forEach(tab => (config[tab] = { screen: tabToComponentMap[tab] }));
return config;
};
render() {
const config = this.getRoutesConfig();
const Navigator = Platform.select({
ios: () => TabNavigator(config),
android: () => DrawerNavigator(config),
})();
return <Navigator />;
}
} Every screen in the Tab/Drawer navigator is in turn a StackNavigator (Screen1Navigator, etc.). On some of those screens inside that StackNavigator i need to hide the tab bar. Currently i'm achieving the behaviour i need by passing down functions as screenProps from Screen1Navigator to its screens to alter the navigationOptions on Screen1Navigator itself, through Also to add a button in the header to toggle the Drawer for Android, i'm having to pass down another function from Screen1Navigator that dispatches |
As @EdmundMai mentioned:
Setting
TabView does not re-render when navigators are wrapped components. |
@aroth - Thanks for that tip. Was def. scratching my head for a while. |
Hi! In an effort to get the hundreds of issues on this repo under control I'm closing issues tagged as questions. Please don't take this personally - it's simply something we need to do to get the issues to a manageable point. If you still have a question I encourage you to re-read the docs, ask on StackOverflow, or ask on the #react-navigation Reactiflux channel. Thank you! |
Hi, I got the same issue, setting
|
@aroth Is there a solution to that? |
@amitava82 @rvlewerissa @aroth I was able to get this working with a redux container by wrapping the navigation view with redux instead of the actual navigator. I copied most of the config from https://github.com/react-community/react-navigation/blob/master/src/navigators/StackNavigator.js AccountNavigator.js
|
@SimonVuong and you're using the |
@rvlewerissa |
The same question, I want to hide the tab bar by click a buttom dynamicly.
I reference @weili1977 soulution, #464 This is my code structure (not exact).
|
It seems the
I can't set a first screen shown tabBar in this config. |
projeect url navigationChat |
@EdmundMai and anybody else trying to use The following appears to work (modified from @twairball's example) using the comment at the bottom of this page in the docs: https://reactnavigation.org/docs/intro/nesting The most important difference is to explicitly pass the navigation prop through the wrapper into the nested navigator, and to manually assign
|
I love @twairball solution but what if i have the following structure ? class JournalNavigation extends React.Component {
static navigationOptions = nav => {
return {
title: i18n.t('navigation.journal').toUpperCase(),
tabBarIcon: ({ focused }) => (
<TabBarIcon icon="journal" focused={focused} />
),
tabBarVisible: true // I want to change the value here thanks to my JournalOnboardingNavigation currentScreen option value.
}
}
static propTypes = {
hasCompleteOnboarding: PropTypes.bool.isRequired
}
render() {
return this.props.hasCompleteOnboarding ? (
<JournalReadyNavigation />
) : (
<JournalOnboardingNavigation />
)
}
}
const mapStateToProps = state => ({
hasCompleteOnboarding: hasCompleteOnboarding(state)
})
export default connect(mapStateToProps)(JournalNavigation) const JournalOnboardingNavigation = StackNavigator(
{
JournalOnboarding: { screen: JournalOnboarding },
TrackersSelectionScreen: {screen: TrackersSelectionScreen}
},
{
cardStyle: {
// StackNavigator seems to add a black background behind
backgroundColor: 'white'
}
}
) I've no idea how i can propagate to the third level.... Any idea ? Best regards |
If you need to hide the parent TabBar in a specific StackNavigator Screen then this would work:
|
It seems like this functionality was removed in v2-rc1 |
Hi there! I found answer here: https://reactnavigation.org/docs/en/navigation-options-resolution.html
|
I solved this by simply doing . . .
and in the child route
Nothing else is needed |
@Kerumen Hi, i want to hide TabBar when right bar button(like cart screen which is common for every tab) on navigation bar clicked.tabBarVisible = true is not working for this case |
For bottom tab navigators, I made a npm package for that, check : |
The downsides of this https://reactnavigation.org/docs/en/navigation-options-resolution.html#a-tab-navigator-contains-a-stack-and-you-want-to-hide-the-tab-bar-on-specific-screens is not smooth transition animation when you hide/show TabBar. To make the animations look smoother you need to make TabNavigator a child of StackNavigator and then screens from Stack will render above the TabBar. A good idea would be to animate the TabBar as well to make it look fine, but I haven't implemented that. |
I have a TabNavigator with three TabView children. Each TabView has a stacknavigator as a child so that the user can visit detail views, etc. I want to hide the tabs on one of the detail views. I have tried registering each navigator in a high level context and then accessing the tab navigator from the screen and doing setParams on it, but it doesn't seem that setParams is doing anything.
What is the best way to selectively hide the tabs?
The text was updated successfully, but these errors were encountered: