如何在React-Navigation中单击Bottom Tab Navigator打开DrawerNavigator?

时间:2018-06-16 05:34:26

标签: javascript android reactjs react-native

我正在使用react-navigation并尝试在点击BottomTabNavigator中的标签项时打开抽屉(使用DrawerNavigator)。

我目前的代码如下所示

export default createBottomTabNavigator({
  Dashboard:{
      screen:Dashboard,
      navigationOptions:{
        tabBarLabel:'Dashboard',
        tabBarIcon:({tintColor}) => (
          <Icon name ="ios-speedometer-outline" color =
            {tintColor} size = {24} />
        )
      }
  },
  Customers:{
    screen:Customers,
    navigationOptions:{
      tabBarLabel:'Customers',
      tabBarIcon:({tintColor}) => (
        <Icon name ="ios-people-outline" color =
          {tintColor} size = {24} />
      )
    }
  },
  Invoice:{
    screen:Invoice,
    navigationOptions:{
      tabBarLabel:'Invoice',
      tabBarIcon:({tintColor}) => (
        <Icon name ="ios-copy-outline" color =
          {tintColor} size = {24} />
      )
    }
  },
  TimeTracker:{
    screen:TimeTracker,
    navigationOptions:{
      tabBarLabel:'Timetracker',
      tabBarIcon:({tintColor}) => (
        <Icon name ="ios-timer-outline" color =
          {tintColor} size = {24} />
      )
    }
  },
  More:{
   screen : More,

    navigationOptions:{
      tabBarLabel:'More',
      tabBarIcon:({tintColor}) => (
        <Icon name ="ios-menu-outline" color = {tintColor} size = {24} />
      )
    }
  }
},{
  tabBarOptions:{
    activeTintColor: 'red',
    inactiveTintColor: 'grey',
    style:{
      backgroundColor: 'white',
      borderTopWidth : 0,
      shadowOffset: {width:5,height : 3},
      shadowColor: 'black',
      shadowOpacity: 0.5,
      elevation: 5
    }
  }
})

const MyApp = createDrawerNavigator({
  Home :{
    screen : HomeScreen
  },
  Settings: {
    screen:SettingScreen
  }
})

我想点击bottomTabNavigator打开drawerNavigator。即,每当按下更多标签时,drawerNavigator都会打开。

我该怎么做?

我是React-Native的新手。

1 个答案:

答案 0 :(得分:0)

您可以在导航选项中使用tabBarOnPress事件来修改标签导航,然后单击

例如。

tabBarOnPress: (tab) => {
        //your code and other stuff 
        tab.jumpToIndex(tab.scene.index)
 }
相关问题