how to use tabBarOnPress in tabnavigator react native

前端 未结 3 1718
心在旅途
心在旅途 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:51

    I used stack navigator

    const Stack = createStackNavigator({
        ScreenA: {
            screen:ScreenA ,
            navigationOptions: () => ({
                header: null
            }),
        },
        ScreenB: {
            screen:ScreenB ,
            navigationOptions: () => ({
                header: null
            }),
        },
    });
    

    //Added tabBarOnPress

    https://reactnavigation.org/docs/en/stack-actions.html the popToTop action takes you back to the first screen in the stack, dismissing all the others. It's functionally identical to StackActions.pop({n: currentIndex}).

    import { StackActions } from 'react-navigation';
    let Tabs = createBottomTabNavigator(
      {
        FooTab: Foo,
      },
      {
        initialRouteName: "FooTab",
        defaultNavigationOptions: ({ navigation }) => ({
        tabBarOnPress: ({ navigation, defaultHandler }) => {
          // to navigate to the top of stack whenever tab changes
          navigation.dispatch(StackActions.popToTop());
          defaultHandler();
          ]},
        }),
      }
    );
    

提交回复
热议问题