将屏幕重置为默认的本机导航

时间:2019-08-31 23:23:31

标签: react-native react-native-navigation wix-react-native-navigation

我将此库与底部标签一起使用: https://github.com/wix/react-native-navigation

对于导航,我在底部有3个标签,其中一个用于首页,问题是我从主屏幕移到另一个添加到堆栈的屏幕,我希望每当我可以重置堆栈再次点击底部标签上的主页图标。

对于route.js来说,它位于bottomTab的主页图标是这样的:

stack: {
  children: [
    {
      component: {
        name: home,
      }
    },
  ],
  options: {
    bottomTab: {
      iconInsets: {top: 6, left: 0, bottom: -6, right: 0},
      titleDisplayMode: 'alwaysHide',
      icon: require('../assets/images/home.png'),
      selectedIconColor: colors.primary,
    }

2 个答案:

答案 0 :(得分:1)

不确定从您发布的摘录中获得什么,但我认为您正在尝试使底部的选项卡起作用。这是不完整的,但希望它能使您步入正轨。

const AppTabs = createBottomTabNavigator({
  App: AppStack, // stack navigator
  Contacts: ContactsStack, // stack navigator
  Settings: {
    screen: SettingsScreen, // single component import
    navigationOptions: {
      tabBarLabel: 'Settings',
      tabBarIcon: ({ focused }) => (
        <Ionicons
          size={26}
          name={Platform.OS === 'ios' ? 'ios-settings' : 'settings'}
          style={{ marginBottom: -3 }}
          color={focused ? "red" : "gray"}
        />
      ),
    }
  },
}, {
  initialRouteName: 'App',
  tabBarPosition: 'bottom',
  swipeEnabled: true,
  tabBarOptions: {
    activeTintColor: 'green',
    inactiveTintColor: 'gray',
    labelStyle: {
      fontSize: 16,
    },
    tabStyle: { marginBottom: -10 }
  }
});

export default createAppContainer(createSwitchNavigator({
  AuthLoading: AuthLoadingScreen,
  App: AppTabs,
  Auth: AuthStack,
}, {
  initialRouteName: 'AuthLoading',
}));

答案 1 :(得分:1)

首先,如果用户单击底部的选项卡,则必须添加侦听器。在registerbottomtabselectedlistener的帮助下,您可以实现这一目标。您可以使用popToRoot将用户发送到堆栈的根目录

// Subscribe
const bottomTabEventListener = Navigation.events().registerBottomTabSelectedListener(({ selectedTabIndex, unselectedTabIndex }) => {
   Navigation.popTo(componentId);  // check selectedTabIndex and send to home
});
...
// Unsubscribe
bottomTabEventListener.remove();