fix implicit poptotop in drawer
This commit is contained in:
@@ -160,7 +160,7 @@ let DrawerContent = ({}: React.PropsWithoutRef<{}>): React.ReactNode => {
|
|||||||
// =
|
// =
|
||||||
|
|
||||||
const onPressTab = React.useCallback(
|
const onPressTab = React.useCallback(
|
||||||
(tab: string) => {
|
(tab: 'Home' | 'Search' | 'Messages' | 'Notifications' | 'MyProfile') => {
|
||||||
const state = navigation.getState()
|
const state = navigation.getState()
|
||||||
setDrawerOpen(false)
|
setDrawerOpen(false)
|
||||||
if (isWeb) {
|
if (isWeb) {
|
||||||
@@ -168,7 +168,7 @@ let DrawerContent = ({}: React.PropsWithoutRef<{}>): React.ReactNode => {
|
|||||||
if (tab === 'MyProfile') {
|
if (tab === 'MyProfile') {
|
||||||
navigation.navigate('Profile', {name: currentAccount!.handle})
|
navigation.navigate('Profile', {name: currentAccount!.handle})
|
||||||
} else {
|
} else {
|
||||||
// @ts-ignore must be Home, Search, Notifications, or MyProfile
|
// @ts-expect-error struggles with string unions, apparently
|
||||||
navigation.navigate(tab)
|
navigation.navigate(tab)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -176,9 +176,23 @@ let DrawerContent = ({}: React.PropsWithoutRef<{}>): React.ReactNode => {
|
|||||||
if (tabState === TabState.InsideAtRoot) {
|
if (tabState === TabState.InsideAtRoot) {
|
||||||
emitSoftReset()
|
emitSoftReset()
|
||||||
} else if (tabState === TabState.Inside) {
|
} 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 {
|
} else {
|
||||||
// @ts-ignore must be Home, Search, Notifications, or MyProfile
|
|
||||||
navigation.navigate(`${tab}Tab`)
|
navigation.navigate(`${tab}Tab`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user