Fix popToTop dev warning

This commit is contained in:
xmflsct 2023-01-16 22:36:49 +01:00
parent adb7a765b4
commit c2a180f4f5
4 changed files with 10 additions and 7 deletions

View File

@ -8,7 +8,7 @@ import Root from './Root'
const Stack = createNativeStackNavigator<TabLocalStackParamList>()
const TabLocal: React.FC = () => {
usePopToTop()
usePopToTop('Tab-Local-Root')
return (
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
<Stack.Screen name='Tab-Local-Root' component={Root} />

View File

@ -44,7 +44,7 @@ const Root: React.FC<
}
const TabNotifications: React.FC = () => {
usePopToTop()
usePopToTop('Tab-Notifications-Root')
return (
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>

View File

@ -8,7 +8,7 @@ import Root from './Root'
const Stack = createNativeStackNavigator<TabPublicStackParamList>()
const TabPublic: React.FC = () => {
usePopToTop()
usePopToTop('Tab-Public-Root')
return (
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
<Stack.Screen name='Tab-Public-Root' component={Root} />

View File

@ -1,15 +1,18 @@
import { StackActions, useFocusEffect, useNavigation } from '@react-navigation/native'
import { StackActions } from '@react-navigation/native'
import { useGlobalStorage } from '@utils/storage/actions'
import { useEffect } from 'react'
import navigationRef from './navigationRef'
// Mostly used when switching account and sub pages were still querying the old instance
const usePopToTop = () => {
const navigation = useNavigation()
const usePopToTop = (name: string) => {
const [accountActive] = useGlobalStorage.string('account.active')
useEffect(() => {
navigation.dispatch(StackActions.popToTop())
const currentRoute = navigationRef.getCurrentRoute()
if (currentRoute && currentRoute.name !== name) {
navigationRef.dispatch(StackActions.popToTop())
}
}, [accountActive])
}