mirror of
https://github.com/tooot-app/app
synced 2025-03-10 08:30:19 +01:00
Fix popToTop dev warning
This commit is contained in:
parent
adb7a765b4
commit
c2a180f4f5
@ -8,7 +8,7 @@ import Root from './Root'
|
|||||||
const Stack = createNativeStackNavigator<TabLocalStackParamList>()
|
const Stack = createNativeStackNavigator<TabLocalStackParamList>()
|
||||||
|
|
||||||
const TabLocal: React.FC = () => {
|
const TabLocal: React.FC = () => {
|
||||||
usePopToTop()
|
usePopToTop('Tab-Local-Root')
|
||||||
return (
|
return (
|
||||||
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
||||||
<Stack.Screen name='Tab-Local-Root' component={Root} />
|
<Stack.Screen name='Tab-Local-Root' component={Root} />
|
||||||
|
@ -44,7 +44,7 @@ const Root: React.FC<
|
|||||||
}
|
}
|
||||||
|
|
||||||
const TabNotifications: React.FC = () => {
|
const TabNotifications: React.FC = () => {
|
||||||
usePopToTop()
|
usePopToTop('Tab-Notifications-Root')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
||||||
|
@ -8,7 +8,7 @@ import Root from './Root'
|
|||||||
const Stack = createNativeStackNavigator<TabPublicStackParamList>()
|
const Stack = createNativeStackNavigator<TabPublicStackParamList>()
|
||||||
|
|
||||||
const TabPublic: React.FC = () => {
|
const TabPublic: React.FC = () => {
|
||||||
usePopToTop()
|
usePopToTop('Tab-Public-Root')
|
||||||
return (
|
return (
|
||||||
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
<Stack.Navigator screenOptions={{ headerShadowVisible: false }}>
|
||||||
<Stack.Screen name='Tab-Public-Root' component={Root} />
|
<Stack.Screen name='Tab-Public-Root' component={Root} />
|
||||||
|
@ -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 { useGlobalStorage } from '@utils/storage/actions'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
import navigationRef from './navigationRef'
|
||||||
|
|
||||||
// Mostly used when switching account and sub pages were still querying the old instance
|
// Mostly used when switching account and sub pages were still querying the old instance
|
||||||
|
|
||||||
const usePopToTop = () => {
|
const usePopToTop = (name: string) => {
|
||||||
const navigation = useNavigation()
|
|
||||||
const [accountActive] = useGlobalStorage.string('account.active')
|
const [accountActive] = useGlobalStorage.string('account.active')
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
navigation.dispatch(StackActions.popToTop())
|
const currentRoute = navigationRef.getCurrentRoute()
|
||||||
|
if (currentRoute && currentRoute.name !== name) {
|
||||||
|
navigationRef.dispatch(StackActions.popToTop())
|
||||||
|
}
|
||||||
}, [accountActive])
|
}, [accountActive])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user