react-nativereact-native-tab-view

how can I hide some tabs on react native tab view?


I used tab view react native on my app and I want to hide some tabs by changing settings but I don't know how can I do that. For now, I have 3 tabs: personal, company and material, in settings I can check the tabs, for example when company is not checked should not appears on tab view

constructor(props) {
    super(props);
    this.state = {
      index: 0,
      routes: [
        { key: 'personal', title: 'personal' },
        { key: 'company', title: 'company' },
        { key: 'material', title: 'material' }
      ],
    };
  }
_renderTabBar = props => {
    return (
      <View>
        <TabBar
          {...props}
          indicatorStyle={{backgroundColor: 'white'}}
          renderIcon={
            props => this._getTabBarIcon(props)
          }
          onTabPress={ tab => this.changeTabs(tab)}
          style={{backgroundColor: "#5243af"}}
          tabStyle={styles.tabStyle}
          labelStyle={{fontSize: Fonts.moderateScale(15), marginBottom: 10}}
          contentContainerStyle={{height: Metrics.HEIGHT * 0.1, elevation: 0}}
        />
      </View>
    );
  };
<TabView style={{ backgroundColor: 'white'}}
                navigationState={this.state}
                renderTabBar={ this._renderTabBar}
                onIndexChange={index => this.setState({ index })}
                initialLayout={{ width: Dimensions.get('window').width}}
                renderScene={this._renderScene} />

Solution

  • You should make custom own tabbar and manage the tab visibility according to condition , for more understanding follow this link

    Hide TabBar item in TabNavigator

    it will help you