Fix perf issue on web - restore pop behaviour to tabs (#8620)
This commit is contained in:
@@ -192,7 +192,7 @@ export function useLink({
|
|||||||
navigation.dispatch(StackActions.replace(screen, params))
|
navigation.dispatch(StackActions.replace(screen, params))
|
||||||
} else if (action === 'navigate') {
|
} else if (action === 'navigate') {
|
||||||
// @ts-expect-error not typed
|
// @ts-expect-error not typed
|
||||||
navigation.navigate(screen, params)
|
navigation.navigate(screen, params, {pop: true})
|
||||||
} else {
|
} else {
|
||||||
throw Error('Unsupported navigator action.')
|
throw Error('Unsupported navigator action.')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,7 +156,6 @@ export function Link({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseLink
|
<BaseLink
|
||||||
action="push"
|
|
||||||
to={`/starter-pack/${handleOrDid}/${rkey}`}
|
to={`/starter-pack/${handleOrDid}/${rkey}`}
|
||||||
label={_(msg`Navigate to ${record.name}`)}
|
label={_(msg`Navigate to ${record.name}`)}
|
||||||
onPress={() => {
|
onPress={() => {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import {type NavigationProp} from '#/lib/routes/types'
|
|||||||
export type DebouncedNavigationProp = Pick<
|
export type DebouncedNavigationProp = Pick<
|
||||||
NavigationProp,
|
NavigationProp,
|
||||||
| 'popToTop'
|
| 'popToTop'
|
||||||
|
| 'popTo'
|
||||||
|
| 'pop'
|
||||||
| 'push'
|
| 'push'
|
||||||
| 'navigate'
|
| 'navigate'
|
||||||
| 'canGoBack'
|
| 'canGoBack'
|
||||||
@@ -38,6 +40,12 @@ export function useNavigationDeduped() {
|
|||||||
popToTop: () => {
|
popToTop: () => {
|
||||||
dedupe(() => navigation.popToTop())
|
dedupe(() => navigation.popToTop())
|
||||||
},
|
},
|
||||||
|
popTo: (...args: Parameters<typeof navigation.popTo>) => {
|
||||||
|
dedupe(() => navigation.popTo(...args))
|
||||||
|
},
|
||||||
|
pop: (...args: Parameters<typeof navigation.pop>) => {
|
||||||
|
dedupe(() => navigation.pop(...args))
|
||||||
|
},
|
||||||
goBack: () => {
|
goBack: () => {
|
||||||
dedupe(() => navigation.goBack())
|
dedupe(() => navigation.goBack())
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
type ViewStyle,
|
type ViewStyle,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import {sanitizeUrl} from '@braintree/sanitize-url'
|
import {sanitizeUrl} from '@braintree/sanitize-url'
|
||||||
import {StackActions} from '@react-navigation/native'
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
type DebouncedNavigationProp,
|
type DebouncedNavigationProp,
|
||||||
@@ -421,8 +420,10 @@ function onPressInner(
|
|||||||
if (tabState === TabState.InsideAtRoot) {
|
if (tabState === TabState.InsideAtRoot) {
|
||||||
emitSoftReset()
|
emitSoftReset()
|
||||||
} else {
|
} else {
|
||||||
|
// note: 'navigate' actually acts the same as 'push' nowadays
|
||||||
|
// therefore we need to add 'pop' -sfn
|
||||||
// @ts-ignore we're not able to type check on this one -prf
|
// @ts-ignore we're not able to type check on this one -prf
|
||||||
navigation.navigate(routeName, params)
|
navigation.navigate(routeName, params, {pop: true})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw Error('Unsupported navigator action.')
|
throw Error('Unsupported navigator action.')
|
||||||
|
|||||||
@@ -3,11 +3,7 @@ import {StyleSheet, View} from 'react-native'
|
|||||||
import {type AppBskyActorDefs} from '@atproto/api'
|
import {type AppBskyActorDefs} from '@atproto/api'
|
||||||
import {msg, plural, Trans} from '@lingui/macro'
|
import {msg, plural, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {
|
import {useNavigation, useNavigationState} from '@react-navigation/native'
|
||||||
useLinkTo,
|
|
||||||
useNavigation,
|
|
||||||
useNavigationState,
|
|
||||||
} from '@react-navigation/native'
|
|
||||||
|
|
||||||
import {useActorStatus} from '#/lib/actor-status'
|
import {useActorStatus} from '#/lib/actor-status'
|
||||||
import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher'
|
import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher'
|
||||||
@@ -16,7 +12,10 @@ import {usePalette} from '#/lib/hooks/usePalette'
|
|||||||
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
||||||
import {getCurrentRoute, isTab} from '#/lib/routes/helpers'
|
import {getCurrentRoute, isTab} from '#/lib/routes/helpers'
|
||||||
import {makeProfileLink} from '#/lib/routes/links'
|
import {makeProfileLink} from '#/lib/routes/links'
|
||||||
import {type CommonNavigatorParams} from '#/lib/routes/types'
|
import {
|
||||||
|
type CommonNavigatorParams,
|
||||||
|
type NavigationProp,
|
||||||
|
} from '#/lib/routes/types'
|
||||||
import {useGate} from '#/lib/statsig/statsig'
|
import {useGate} from '#/lib/statsig/statsig'
|
||||||
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||||
import {isInvalidHandle, sanitizeHandle} from '#/lib/strings/handles'
|
import {isInvalidHandle, sanitizeHandle} from '#/lib/strings/handles'
|
||||||
@@ -339,7 +338,7 @@ function NavItem({count, hasNew, href, icon, iconFilled, label}: NavItemProps) {
|
|||||||
(currentRouteInfo.params as CommonNavigatorParams['Profile']).name ===
|
(currentRouteInfo.params as CommonNavigatorParams['Profile']).name ===
|
||||||
currentAccount?.handle
|
currentAccount?.handle
|
||||||
: isTab(currentRouteInfo.name, pathName)
|
: isTab(currentRouteInfo.name, pathName)
|
||||||
const linkTo = useLinkTo()
|
const navigation = useNavigation<NavigationProp>()
|
||||||
const onPressWrapped = useCallback(
|
const onPressWrapped = useCallback(
|
||||||
(e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
|
(e: React.MouseEvent<HTMLAnchorElement, MouseEvent>) => {
|
||||||
if (e.ctrlKey || e.metaKey || e.altKey) {
|
if (e.ctrlKey || e.metaKey || e.altKey) {
|
||||||
@@ -349,10 +348,12 @@ function NavItem({count, hasNew, href, icon, iconFilled, label}: NavItemProps) {
|
|||||||
if (isCurrent) {
|
if (isCurrent) {
|
||||||
emitSoftReset()
|
emitSoftReset()
|
||||||
} else {
|
} else {
|
||||||
linkTo(href)
|
const [screen, params] = router.matchPath(href)
|
||||||
|
// @ts-expect-error TODO: type matchPath well enough that it can be plugged into navigation.navigate directly
|
||||||
|
navigation.popTo(screen, params)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[linkTo, href, isCurrent],
|
[navigation, href, isCurrent],
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user