fix implicit poptotop in drawer
This commit is contained in:
@@ -160,7 +160,7 @@ let DrawerContent = ({}: React.PropsWithoutRef<{}>): React.ReactNode => {
|
||||
// =
|
||||
|
||||
const onPressTab = React.useCallback(
|
||||
(tab: string) => {
|
||||
(tab: 'Home' | 'Search' | 'Messages' | 'Notifications' | 'MyProfile') => {
|
||||
const state = navigation.getState()
|
||||
setDrawerOpen(false)
|
||||
if (isWeb) {
|
||||
@@ -168,7 +168,7 @@ let DrawerContent = ({}: React.PropsWithoutRef<{}>): React.ReactNode => {
|
||||
if (tab === 'MyProfile') {
|
||||
navigation.navigate('Profile', {name: currentAccount!.handle})
|
||||
} else {
|
||||
// @ts-ignore must be Home, Search, Notifications, or MyProfile
|
||||
// @ts-expect-error struggles with string unions, apparently
|
||||
navigation.navigate(tab)
|
||||
}
|
||||
} else {
|
||||
@@ -176,9 +176,23 @@ let DrawerContent = ({}: React.PropsWithoutRef<{}>): React.ReactNode => {
|
||||
if (tabState === TabState.InsideAtRoot) {
|
||||
emitSoftReset()
|
||||
} else if (tabState === TabState.Inside) {
|
||||
navigation.dispatch(StackActions.popToTop())
|
||||
// find the correct navigator in which to pop-to-top
|
||||
const target = state.routes.find(route => route.name === `${tab}Tab`)
|
||||
?.state?.key
|
||||
if (target) {
|
||||
// if we found it, trigger pop-to-top
|
||||
navigation.dispatch({
|
||||
...StackActions.popToTop(),
|
||||
target,
|
||||
})
|
||||
} else {
|
||||
// fallback: reset navigation
|
||||
navigation.reset({
|
||||
index: 0,
|
||||
routes: [{name: `${tab}Tab`}],
|
||||
})
|
||||
}
|
||||
} else {
|
||||
// @ts-ignore must be Home, Search, Notifications, or MyProfile
|
||||
navigation.navigate(`${tab}Tab`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user