React Navigation,通过单击抽屉项目关闭抽屉导航内的堆栈导航
我在反应导航 v6 方面遇到了小问题...
抽屉导航:
<Drawer.Navigator drawerContent={(props) => <CustomDrawer {...props} />} >
<Drawer.Screen name="Search" component={MainStackNavigator} />
<Drawer.Screen name="Contact" component={ContactScreen} />
</Drawer.Navigator>
堆栈导航:
const MainStackNavigator = () => {
return (
<Stack.Navigator initialRouteName="OffersList">
<Stack.Screen name="OffersList" component={OffersList} />
<Stack.Screen name="OfferDetails" component={OfferDetails} />
</Stack.Navigator>
);
};
现在,当我单击抽屉导航中的元素 Search 时,会显示 OffersList
页面。接下来,在 OffersList
上,当我单击任何优惠链接时,我会看到 OfferDetails
视图(堆栈导航) - 一切正常。然后,当我单击抽屉导航中的联系人,然后再次单击搜索时,我会看到上次打开的 OfferDetails 而不是 OfferList
。当我通过抽屉导航时如何重置此堆栈导航?
I have small issue with react navigation v6...
Drawer Navigation:
<Drawer.Navigator drawerContent={(props) => <CustomDrawer {...props} />} >
<Drawer.Screen name="Search" component={MainStackNavigator} />
<Drawer.Screen name="Contact" component={ContactScreen} />
</Drawer.Navigator>
Stack navigation:
const MainStackNavigator = () => {
return (
<Stack.Navigator initialRouteName="OffersList">
<Stack.Screen name="OffersList" component={OffersList} />
<Stack.Screen name="OfferDetails" component={OfferDetails} />
</Stack.Navigator>
);
};
and now, when I click on the element Search in drawer navigation then OffersList
page is displayed. Next, on the OffersList
, when I click on any offer link, then I see OfferDetails
view (Stack Navigation) - every thing is ok. Then, when I click on the Contact in drawer nav, and again on Search then I see last opened OfferDetails instead of OfferList
. How can I reset this stack navigation when i navigate by drawer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用户并不期望堆栈重置,但您认为这可以改善应用体验,只需在抽屉的
screenOptions
上传递unmountOnBlur: true
即可。您的代码将如下所示:您可以在世博会小吃上看到完整的示例代码。 https://snack.expo.dev/@marcelofreires/stackoverflow-questions-71548781< /a>
The user doesn't expect a stack reset, but you think it improves the app experience, just pass
unmountOnBlur: true
onscreenOptions
for the Drawer. Your code will be like this:You can see the complete example code on an Expo snack. https://snack.expo.dev/@marcelofreires/stackoverflow-questions-71548781
我有相同的要求,并且在堆栈内的所有屏幕中使用 useIsFocused 挂钩除了初始屏幕之外,我使用 useEffect 来检查 isFocused 是否为 false,然后弹出屏幕。这是示例代码。
I have the same requirement and I use the useIsFocused hook, in all screens inside the stack except the initial screen I use useEffect to check if
isFocused
is false then pop the screen out. Here is the example code.