how to use tabBarOnPress in tabnavigator react native

前端 未结 3 1732
心在旅途
心在旅途 2021-02-14 19:32

i am stuck in big problem that is i wants onPress event when i clicked on tab. my code is here:-

static navigationOptions = ({navigation, screenProps}) => {
          


        
3条回答
  •  你的背包
    2021-02-14 19:56

    This is my approach. It works for the version 5.x.x of react-navigation:

    const BottomTab = createBottomTabNavigator();
    const Tabs = props => (
       {
              // e.preventDefault(); // Use this to navigate somewhere else
              console.log("Foo tab bar button pressed")
            },
          }}
        />
      
    );
    

    Read more about listeners.


    For version 3.x.x and I hope for the 4th as well please use this one.

    let Tabs = createBottomTabNavigator(
      {
        FooTab: Foo,
      },
      {
        initialRouteName: "FooTab",
        defaultNavigationOptions: ({ navigation }) => ({
          tabBarOnPress: ({ navigation, defaultHandler }) => {
            console.log('onPress:', navigation.state.routeName);
            defaultHandler()
          },
        }),
      }
    );
    

    For version 2.x.x please use navigationOptions instead of the defaultNavigationOptions.

提交回复
热议问题