在底部选项卡导航器中卸载不活动的屏幕(重置堆栈)

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

我正在使用react-navigation v3,是否有选项可以使非活动的选项卡屏幕像unmountInactiveRoutes:一样在DrawerNavigator中卸载?我找不到类似于BottomTabNavigator的unmountInactiveRoutes的东西。

我在BottomTabNavigator内有两个stacknavigator,我想自动卸载它们或只重置它们。

我的导航员:

  • BottomTabNavigator
    • stackNavigator
    • stackNavigator
javascript reactjs react-native react-navigation
1个回答
0
投票

您可以使用useIsFocused挂钩解决您的问题。因此,当屏幕聚焦时,您将显示所需的屏幕,否则只需返回null。

import { useIsFocused } from '@react-navigation/native';

const isFocused = useIsFocused();

if(isFocused) return(/*your screen*/)

else if(!isFocused) return null
© www.soinside.com 2019 - 2024. All rights reserved.