如何在我的底部选项卡导航器上使用backBehavior:'history'

问题描述 投票:0回答:1

我在Expo应用程序中有一个BottomTabNavigator作为初始页面。每当我导航到另一个屏幕并返回时,我想打开tabnavigator上的最后一个打开的选项卡。我已经读过:'backBehavior:'history'就是这样,但它对我不起作用,而是转到初始选项卡。这是我的Tabnavigator代码:

class MainTabNavigator extends React.Component {

const DiscoverStack = createStackNavigator(
    {
        Discover: DiscoverScreen
    },
    { backBehavior: 'history' }
);

DiscoverStack.navigationOptions = {
    tabBarLabel: 'Ontdek',
    backBehavior: 'history',
    tabBarIcon: ({ focused }) => (
        <TabBarIcon
            focused={focused}
            name={`${focused ? 'md-bulb' : 'ios-bulb'}`}
        />
    )
};

const TodoStack = createStackNavigator(
    {
        Todo: TodoScreen
    },
    { backBehavior: 'history' }
);

TodoStack.navigationOptions = {
    tabBarLabel: 'Wat te doen',
    backBehavior: 'history',
    tabBarIcon: ({ focused }) => (
        <TabBarIcon focused={focused} name={'md-calendar'} />
    )
};

const ShopStack = createStackNavigator(
    {
        Shop: ShopScreen
    },
    { backBehavior: 'history' }
);

ShopStack.navigationOptions = {
    tabBarLabel: 'Shop',
    backBehavior: 'history',
    tabBarIcon: ({ focused }) => (
        <TabBarIcon focused={focused} name={'md-cart'} />
    )
};

const WinStack = createStackNavigator(
    {
        Win: WinScreen
    },
    { backBehavior: 'history' }
);

WinStack.navigationOptions = {
    tabBarLabel: 'Win',
    backBehavior: 'history',
    tabBarIcon: ({ focused }) => (
        <Icon2
            focused={focused}
            size={26}
            style={{ marginBottom: -3 }}
            color={focused ? Colors.tabIconSelected : Colors.tabIconDefault}
            name={'ticket'}
        />
    )
};

const UserStack = createStackNavigator(
    {
        User: UserScreen
    },
    { backBehavior: 'history' }
);

UserStack.navigationOptions = {
    tabBarLabel: 'Account',
    backBehavior: 'history',
    tabBarIcon: ({ focused }) => (
        <TabBarIcon focused={focused} name={'md-person'} />
    )
};

export default createBottomTabNavigator(
    {
        DiscoverStack,
        TodoStack,
        ShopStack,
        WinStack,
        UserStack
    },
    { backBehavior: 'history' }
);
reactjs react-native react-navigation expo
1个回答
0
投票

使用createAppContainer作为下面的代码。

代替

example.js:

const defaultNavigationOptions = {
  headerTintColor: "color",
  headerStyle: {
    backgroundColor: "color"
  },
  headerTitleStyle: {
    fontWeight: "your select weight",
    fontSize: "select size"
  },
};

const DiscoverStack = createStackNavigator(
    {
        Discover: DiscoverScreen
    },
    {
    defaultNavigationOptions,
  }
);

const AppNavigator = createBottomTabNavigator(
  {
   dis : DiscoverStack,
   ...
  },
 backBehavior: 'history'
);

const AppContainer = createAppContainer(AppNavigator);

export default AppContainer;

© www.soinside.com 2019 - 2024. All rights reserved.