我有一个应用场景,其中我有一个底部选项卡导航器作为我的基本导航器选项卡,其中主页、产品...作为我的选项卡:
<Tab.Navigator
screenOptions={{
headerShown: true,
}}
tabBarOptions={{
showLabel: false,
activeTintColor: MyColors.COLOR_ACCENT,
}}>
<Tab.Screen
name="Home"
component={HomeStack}
options={{
tabBarIcon: ({color, size}) => (
<Icon name="home" color={color} size={size} />
),
}}
/>
<Tab.Screen
name="Product"
component={ProductStack}
options={{
tabBarIcon: ({color, size}) => (
<Icon name="business-center" color={color} size={size} />
),
}}
/>
<Tab.Screen
name="Request"
component={MedRequest}
options={{
color: MyColors.COLOR_PRIMARY,
tabBarIcon: ({color, size}) => (
<Icon
name="near-me"
color={color}
size={35}
style={{transform: [{rotateZ: '20deg'}]}}
/>
),
}}
/>
<Tab.Screen
name="Reminder"
component={Reminder}
options={{
tabBarIcon: ({color, size}) => (
<Icon name="alarm" color={color} size={size} />
),
}}
/>
<Tab.Screen
name="Location"
component={LocationStack}
options={{
tabBarIcon: ({color, size}) => (
<Icon name="location-on" color={color} size={size} />
),
}}
/>
</Tab.Navigator>
让我们考虑一下底部选项卡中的前 2 个屏幕。第一个是家。它包含前 5 个热门产品的列表和一个“查看全部”链接,该链接将其导航到第二个标签产品。
每个单独列出的产品都应该导航到产品详细信息页面。由于底部选项卡导航器中未定义 productDetail 导航,因此我尝试通过 homeStack 在主页中创建一个新的 Stack 导航器来解决此问题,如下所示:
<Stack.Navigator
screenOptions={{
headerShown: false,
}}>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Notifications" component={Notifications} />
<Stack.Screen name="ProductDetail" component={ProductDetail} />
<Stack.Screen name="AuthStack" component={AuthStack} />
<Stack.Screen name="BlogStack" component={BlogStack} />
<Stack.Screen name="BlogDetail" component={BlogDetail} />
<Stack.Screen name="Cart" component={CartStack} />
</Stack.Navigator>
现在我们在处理程序中有 productDetail 导航器,我可以导航到产品详细信息。同样,产品底部选项卡在顶部有另一个堆栈导航器 ProductStack,它有助于导航到其各种链接。它是这样的:
<Stack.Navigator
screenOptions={{
headerShown: false,
}}>
<Stack.Screen name="Product" component={Product} />
<Stack.Screen name="CartStack" component={CartStack} />
<Stack.Screen name="ProductDetail" component={ProductDetail} />
</Stack.Navigator>
我在这里主要担心的是,我在不止一个地方将 ProductDetail 和 CartStack 作为导航器的元素包含在内,我觉得我做的不对。
这种多层次的导航器堆叠也会导致性能问题吗?
此外,当我从主屏幕直接导航到 productDetail 时访问的 cartStack 会导致底部选项卡消失。
我在这里处理情况完全错误吗?有没有更简单的方法可以做到这一点,我还没有想到?