Skip to content
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

Hide TabBar #136

Closed
microwavesafe opened this issue Feb 1, 2017 · 27 comments
Closed

Hide TabBar #136

microwavesafe opened this issue Feb 1, 2017 · 27 comments

Comments

@microwavesafe
Copy link

With DrawerNavigation we get two nice routes

this.props.navigation.navigate('DrawerOpen'); // open drawer
this.props.navigation.navigate('DrawerClose'); // close drawer

In my app I would like to hide the TabBar while the keyboard is shown and the above functionality would be very useful. Is it something you would consider a pull request for, or is there a better way of doing it that I haven't spotted?

@ericvicenti
Copy link
Contributor

We currently have a header.visible navigation option for the StackNavigator.

I think it would make sense to add a tabBar.visible option for the TabNavigator. A PR would be accepted for that.

@satya164

@satya164
Copy link
Member

satya164 commented Feb 1, 2017

@ericvicenti am I right when I say that tabBar.visible won't be animated?

@microwavesafe
Copy link
Author

In my particular case I don't need the tabBar to animate.

@ericvicenti
Copy link
Contributor

Yeah I think we can skip the animation for it. Maybe somebody will want it one day, but I think we can help @microwavesafe's use case pretty easily

@satya164
Copy link
Member

satya164 commented Feb 1, 2017

Adding good first task label then. Should be easy to implement.

@microwavesafe
Copy link
Author

@satya164 @ericvicenti

I've got this roughly working, I've implemented the visible check in the render function of TabView.js.

  render() {
    const {
      navigation,
      tabBarComponent,
      tabBarPosition,
      animationEnabled,
      lazyLoad,
    } = this.props;

    let renderHeader;
    let renderFooter;

    const { state } = this.props.navigation;
    const tabBar = this.props.router.getScreenConfig(this.props.childNavigationProps[state.routes[state.index].routeName], 'tabBar');

    if ((typeof tabBarComponent !== 'undefined') && (tabBar.visible !== false)) {
      if (tabBarPosition === 'bottom') {
        renderFooter = this._renderTabBar;
      } else {
        renderHeader = this._renderTabBar;
      }
    }

    let configureTransition;

    if (animationEnabled === false) {
      configureTransition = this._configureTransition;
    }

    return (
      <TabViewAnimated
        style={styles.container}
        navigationState={navigation.state}
        lazy={lazyLoad}
        renderHeader={renderHeader}
        renderFooter={renderFooter}
        renderScene={this._renderScene}
        renderPager={this._renderPager}
        configureTransition={configureTransition}
        onRequestChangeTab={this._handlePageChanged}
      />
    );
  }
}

I'm not convinced that's the easiest way to get the tabBar through getScreenConfig, but I can't find an easier way.

Also at the moment, this is leaving the rest of the page still sitting above a now empty tab bar. So not sure this is really how I should be doing it.

@satya164
Copy link
Member

satya164 commented Feb 1, 2017

Can you show a screenshot of page showing empty bar? Is this iOS or Android or both?

@microwavesafe
Copy link
Author

Actually it looks like it's the page contents fault. If I use the above code to turn off the tabBar and this code in page render

<View style={{flex: 1}}>
    <View><Text>Top Text</Text></View>
    <View style={{position: 'absolute', left: 0, right: 0, bottom: 0}}><Text>Bottom Text</Text></View>
</View>

It works fine and the "Bottom Text" shifts to sit at the bottom of the screen when the tabBar is turned off.

Do you want me to create a pull request with the above changes?

@satya164
Copy link
Member

satya164 commented Feb 2, 2017

Nice. Yeah, send a PR!

@microwavesafe
Copy link
Author

Pull request submitted #152. Unfortunately I can't programmatically turn the tabBar on or off until SetParams works in TabNavigator. I have a pull request for implementing it #132 and it looks like #134 also addresses params issues with TabNavigator. Do you know if you'll be able to merge either of these?

@satya164
Copy link
Member

satya164 commented Feb 2, 2017

Cool. Will check both tonight.

@natashache
Copy link

@microwavesafe I added your changes you committed for hiding tab bar and it works great! Thank you so much for adding this very useful option!

@microwavesafe
Copy link
Author

#152 fixes this, but still need to merge #132 to be able to turn it on and off.

@ryannewton
Copy link

I would like to do the same thing. How do I hide the TabBar when the keyboard is active?

@PolGuixe
Copy link

@ryannewton have you found any way?

@ryannewton
Copy link

ryannewton commented Jun 25, 2017

@PolGuixe We ended up putting the tab bar on the bottom for iOS and Android so the keyboard naturally covers up the tab bar.

For those looking to do this, add tabBarPosition: 'bottom' to the TabNavigator options.

@alinz
Copy link

alinz commented Jul 12, 2017

if tabBarPosition sets to bottom for android, it doesn't cover by keyboard and it moves along with it. Has any one encounter this?

@philsam
Copy link

philsam commented Jul 12, 2017

Yes. I encountered this issue as well

@PolGuixe
Copy link

I am experiencing the same as @alinz. @ryannewton is it different for you?

@alinz
Copy link

alinz commented Jul 13, 2017

would be nice to get some insight from @satya164 and @ericvicenti if they know any possible solutions.

@ryannewton
Copy link

@PolGuixe It stays at the bottom for me. We're on 1.0.0-beta.11.

Did it ever get covered up for you?

@PolGuixe
Copy link

@ryannewton no. It has always been pushed by the keyboard.

@microwavesafe
Copy link
Author

I believe this has to do with the introduction of this line

android:windowSoftInputMode="adjustResize"

in the AndroidManifest.xml file.

https://github.com/facebook/react-native/releases/tag/v0.42.3

If you have the line, the tabbar will avoid the keyboard by itself, if you don't have the line it will be covered. At least in my experience.

@alinz
Copy link

alinz commented Jul 14, 2017

@microwavesafe thanks, that was it. it fixes my problem.

@AaronVasquez
Copy link

Any plans to support animation?

@rumbogs
Copy link

rumbogs commented Aug 2, 2018

I’m also looking for a solution to animate the tab between screens that show or hide it. I get some ugly content jumping otherwise. Do you have plans on supporting it, or a workaround until then?

@tonmanayo
Copy link

Is there a way we can animate the tabBar when hiding yet? or hide the tabBar on a screens componentDidMount?

satya164 added a commit that referenced this issue Feb 7, 2020
I can't think of a scenario a screen would unmount when opening.
So it's probably a safe-bet to always call onClose.

Fixes #136
joshuapinter pushed a commit to cntral/react-navigation that referenced this issue Sep 29, 2021
I can't think of a scenario a screen would unmount when opening.
So it's probably a safe-bet to always call onClose.

Fixes react-navigation#136
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests