[英]How to unmount inactive screens in bottom tab navigator react-navigation?
[英]Unmount inactive screens (reset stacks) in bottom tab navigator
我正在使用 react-navigation v3,是否有一個選項可以讓非活動選項卡屏幕像在 DrawerNavigator 中的 unmountInactiveRoutes: true 一樣被卸載? 我無法為 BottomTabNavigator 找到類似 unmountInactiveRoutes 的內容。
我在 BottomTabNavigator 中有兩個 stacknavigator,我想自動卸載它們或只是重置它們。
我的導航器:
您可以使用useIsFocused掛鈎來解決您的問題。 因此,當屏幕聚焦時,您將顯示您想要的屏幕,否則只需返回 null。 檢查下面的代碼:
import { useIsFocused } from '@react-navigation/native';
const isFocused = useIsFocused();
if(isFocused) return(/*your screen*/)
else if(!isFocused) return null
如果您想對每個焦點進行一些獲取或更改,只需使用useFocusEffect掛鈎。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.