Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a option to disable tabbar buttons

In my react native app, I have a router component which uses react-navigation-material-bottom-tabs.

In that component I have created it like this.

const tabNavigator = createMaterialBottomTabNavigator({
  home: {
    screen: Home,
    navigationOptions: ({ navigation }) => ({
        title: ''
    })
  },
  createCampaign: {
    screen: CreateCampaign,
    navigationOptions: ({ navigation }) => ({
        title: '',
        tabBarVisible: false
    })
  },
  settings: {
    screen: AllSettings,
    navigationOptions: ({ navigation }) => ({
        title: ''
    })
  }
});

This is working fine. But I want to disable some tabs of this bar under some conditions. As example, if the profile hasn't been approved, disable the tab to settings. Is there any way to do this in my screens?(Better if it's not in the router because I can't send a API request in router). How can I access tabBar options in screens? How to disable tabs? Please help.

like image 844
Buwaneka Sudheera Avatar asked Mar 12 '20 08:03

Buwaneka Sudheera


1 Answers

For Version 5.x there's a new way to do it.

<Tabs.Screen
  name="Chat"
  component={Chat}
  listeners={{
    tabPress: e => {
      // Prevent default action
      e.preventDefault();
    },
  }}
/>

Here's the reference link to the docs: https://reactnavigation.org/docs/navigation-events/

like image 119
Franco Petra Avatar answered Oct 17 '22 08:10

Franco Petra