tabBarOnPress停止工作反应导航3.3.2

时间:2019-03-05 05:01:08

标签: react-navigation

升级到反应导航3.3.2之后,tabBarOnPress不再触发。下面的代码段。有什么想法吗?

const Tabs = createBottomTabNavigator(
  {
    HomeStack,
    WallStack,
    MemeStack,
  },
  {
    navigationOptions: ({navigation}) => ({
      tabBarOnPress: () => {
        console.log('tab pressed');
      }
    })

  }
);

export default DrawerNav = createDrawerNavigator({
  Tabs: Tabs
},{
  drawerBackgroundColor: Colors.grayDark,
  contentComponent: Sidebar
})

1 个答案:

答案 0 :(得分:0)

tabBarOnPress正在工作,但我正在像这样使用它。您需要将其作为每个堆栈的属性传递。 (不要忘记调用defaultHandler来保持默认行为:

const DashboardStack = createStackNavigator(
  {
    Dashboard,
  }
);

DashboardStack.navigationOptions = {
  tabBarOnPress({ navigation, defaultHandler }) {
    // do something
    defaultHandler();
  },
};

const ProfileStack = createStackNavigator(
  {
    Profile,
    AccountInfo,
    Membership,
    Browser,
    ConnectedAccounts,
  }
);

ProfileStack.navigationOptions = {
  tabBarOnPress({ navigation, defaultHandler }) {
    // do something
    defaultHandler();
  },
};

const SpendingStack = createStackNavigator(
  {
    Budget,
    Transactions,
  }
);

SpendingStack.navigationOptions = {
  tabBarOnPress({ navigation, defaultHandler }) {
    // do something
    defaultHandler();
  },
};

export default createBottomTabNavigator(
  {
    SpendingStack,
    DashboardStack,
    ProfileStack,
  }
);