Bluesky app fork with some witchin' additions 馃挮
witchsky.app
bluesky
fork
client
1import {useMemo} from 'react'
2import {useNavigation} from '@react-navigation/core'
3
4import {useDedupe} from '#/lib/hooks/useDedupe'
5import {type NavigationProp} from '#/lib/routes/types'
6
7export type DebouncedNavigationProp = Pick<
8 NavigationProp,
9 | 'popToTop'
10 | 'popTo'
11 | 'pop'
12 | 'push'
13 | 'navigate'
14 | 'canGoBack'
15 | 'replace'
16 | 'dispatch'
17 | 'goBack'
18 | 'getState'
19 | 'getParent'
20>
21
22export function useNavigationDeduped() {
23 const navigation = useNavigation<NavigationProp>()
24 const dedupe = useDedupe()
25
26 return useMemo<DebouncedNavigationProp>(
27 () => ({
28 push: (...args: Parameters<typeof navigation.push>) => {
29 dedupe(() => navigation.push(...args))
30 },
31 navigate: (...args: Parameters<typeof navigation.navigate>) => {
32 dedupe(() => navigation.navigate(...args))
33 },
34 replace: (...args: Parameters<typeof navigation.replace>) => {
35 dedupe(() => navigation.replace(...args))
36 },
37 dispatch: (...args: Parameters<typeof navigation.dispatch>) => {
38 dedupe(() => navigation.dispatch(...args))
39 },
40 popToTop: () => {
41 dedupe(() => navigation.popToTop())
42 },
43 popTo: (...args: Parameters<typeof navigation.popTo>) => {
44 dedupe(() => navigation.popTo(...args))
45 },
46 pop: (...args: Parameters<typeof navigation.pop>) => {
47 dedupe(() => navigation.pop(...args))
48 },
49 goBack: () => {
50 dedupe(() => navigation.goBack())
51 },
52 canGoBack: () => {
53 return navigation.canGoBack()
54 },
55 getState: () => {
56 return navigation.getState()
57 },
58 getParent: (...args: Parameters<typeof navigation.getParent>) => {
59 return navigation.getParent(...args)
60 },
61 }),
62 [dedupe, navigation],
63 )
64}