在选项卡导航上添加抽屉,所有选项卡都在抽屉中
我是 React Native 的新手,在复制之前我尝试过各种解决方案,例如 如何从React Native 中的抽屉导航到底部选项卡栏导航? 和 在 React Native 上使用 DrawerNavigator 和堆栈导航 但没有一个适合我的情况。
我想要实现的是,有 2 个屏幕堆栈,即登录屏幕和主屏幕。 我只需要主屏幕中的抽屉,而不是登录屏幕中的抽屉。 在主屏幕上有一个底部选项卡导航器。 我希望主屏幕中的抽屉包含所有选项卡,而且当选择抽屉中的屏幕时,它应该在底部选项卡导航中显示屏幕。 即使是一个基本的例子就足够了。
这是我的代码
const Tabs = () => {
return (
<Tab.Navigator
screenOptions={{
headerShown: false,
tabBarShowLabel: false,
tabBarHideOnKeyboard: true,
}}
barStyle={{ backgroundColor: "white" }}
>
<Tab.Screen
name="Trade"
component={Trade}
options={{
tabBarIcon: ({ focused }) => (
<TabBarIcon icon="eye" label="Trade" focused={focused} />
),
}}
/>
<Tab.Screen
name="MyOrders"
component={MyOrders}
options={{
tabBarIcon: ({ focused }) => (
<TabBarIcon
icon="shopping-bag"
label="My Orders"
focused={focused}
/>
),
}}
/>
<Tab.Screen
name="Transport"
component={Trade}
options={{
tabBarIcon: ({ focused }) => (
<TabBarIcon icon="truck" label="Transport" focused={focused} />
),
}}
/>
<Tab.Screen
name="Transaction"
component={Trade}
options={{
tabBarIcon: ({ focused }) => (
<TabBarIcon icon="wallet" label="Transaction" focused={focused} />
),
}}
/>
<Tab.Screen
name="Profile"
component={Trade}
options={{
tabBarIcon: ({ focused }) => (
<TabBarIcon icon="user" label="Profile" focused={focused} />
),
}}
/>
</Tab.Navigator>
);
};
const DrawerStack = () => {
return (
<Drawer.Navigator screenOptions={{ headerShown: false }}>
{/* <Drawer.Screen name="Trade" component={Trade}></Drawer.Screen>
<Drawer.Screen name="MyOrders" component={MyOrders}></Drawer.Screen> */}
<Drawer.Screen name="Tabs" component={Tabs}></Drawer.Screen>
</Drawer.Navigator>
);
};
const AppStack = () => {
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="App" component={LoginStack}></Stack.Screen>
<Stack.Screen name="HomeScreen" component={DrawerStack}></Stack.Screen>
</Stack.Navigator>
);
};
export default AppStack;
I'm new to React native, Before duplicating i've tried various solutions such as
How to Navigate from DRAWER NAVIGATION to BOTTOM TAB BAR NAVIGATION in react native? and
Using DrawerNavigator alongside stack navigation on react native
but none worked for my case.
What i want to achieve is, There are 2 screen stacks ie Login and Home screen.
I need the drawer only in home screen and not the login screen.
And in home screen there is a bottom tab navigator.
I want the drawer in home screen with all the tabs also when the screen in drawer is selected it should show the screen in bottom tab navigation.
Even a basic example will suffice.
Here's my code
const Tabs = () => {
return (
<Tab.Navigator
screenOptions={{
headerShown: false,
tabBarShowLabel: false,
tabBarHideOnKeyboard: true,
}}
barStyle={{ backgroundColor: "white" }}
>
<Tab.Screen
name="Trade"
component={Trade}
options={{
tabBarIcon: ({ focused }) => (
<TabBarIcon icon="eye" label="Trade" focused={focused} />
),
}}
/>
<Tab.Screen
name="MyOrders"
component={MyOrders}
options={{
tabBarIcon: ({ focused }) => (
<TabBarIcon
icon="shopping-bag"
label="My Orders"
focused={focused}
/>
),
}}
/>
<Tab.Screen
name="Transport"
component={Trade}
options={{
tabBarIcon: ({ focused }) => (
<TabBarIcon icon="truck" label="Transport" focused={focused} />
),
}}
/>
<Tab.Screen
name="Transaction"
component={Trade}
options={{
tabBarIcon: ({ focused }) => (
<TabBarIcon icon="wallet" label="Transaction" focused={focused} />
),
}}
/>
<Tab.Screen
name="Profile"
component={Trade}
options={{
tabBarIcon: ({ focused }) => (
<TabBarIcon icon="user" label="Profile" focused={focused} />
),
}}
/>
</Tab.Navigator>
);
};
const DrawerStack = () => {
return (
<Drawer.Navigator screenOptions={{ headerShown: false }}>
{/* <Drawer.Screen name="Trade" component={Trade}></Drawer.Screen>
<Drawer.Screen name="MyOrders" component={MyOrders}></Drawer.Screen> */}
<Drawer.Screen name="Tabs" component={Tabs}></Drawer.Screen>
</Drawer.Navigator>
);
};
const AppStack = () => {
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="App" component={LoginStack}></Stack.Screen>
<Stack.Screen name="HomeScreen" component={DrawerStack}></Stack.Screen>
</Stack.Navigator>
);
};
export default AppStack;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要创建一个自定义抽屉,重点关注底部选项卡项目,该项目在底部选项卡内注册,类似于您问题中的链接,即 如何从抽屉导航导航到底部选项卡栏导航在本机反应中?
You need to create a custom drawer that focuses your bottom tab items which is registered inside your bottom tabs similar to the link in your question i.e. How to Navigate from DRAWER NAVIGATION to BOTTOM TAB BAR NAVIGATION in react native?