@react-navigation/core 6.1.1 → 6.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/useChildListeners.js +6 -3
- package/lib/commonjs/useChildListeners.js.map +1 -1
- package/lib/commonjs/useDescriptors.js.map +1 -1
- package/lib/commonjs/useEventEmitter.js +12 -2
- package/lib/commonjs/useEventEmitter.js.map +1 -1
- package/lib/commonjs/useKeyedChildListeners.js +2 -0
- package/lib/commonjs/useKeyedChildListeners.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +1 -0
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/commonjs/useNavigationCache.js +9 -0
- package/lib/commonjs/useNavigationCache.js.map +1 -1
- package/lib/commonjs/useNavigationHelpers.js +18 -3
- package/lib/commonjs/useNavigationHelpers.js.map +1 -1
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useChildListeners.js +6 -3
- package/lib/module/useChildListeners.js.map +1 -1
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +12 -2
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useKeyedChildListeners.js +2 -0
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +1 -0
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +9 -0
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +18 -3
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/typescript/src/NavigationBuilderContext.d.ts +1 -1
- package/lib/typescript/src/NavigationContext.d.ts +1 -1
- package/lib/typescript/src/SceneView.d.ts +1 -1
- package/lib/typescript/src/types.d.ts +39 -18
- package/lib/typescript/src/useDescriptors.d.ts +8 -6
- package/lib/typescript/src/useNavigationBuilder.d.ts +12 -73
- package/lib/typescript/src/useNavigationCache.d.ts +1 -1
- package/lib/typescript/src/useNavigationHelpers.d.ts +7 -69
- package/package.json +7 -8
- package/src/SceneView.tsx +7 -1
- package/src/types.tsx +51 -15
- package/src/useChildListeners.tsx +5 -3
- package/src/useDescriptors.tsx +8 -1
- package/src/useEventEmitter.tsx +11 -2
- package/src/useKeyedChildListeners.tsx +2 -0
- package/src/useNavigationBuilder.tsx +1 -0
- package/src/useNavigationCache.tsx +17 -1
- package/src/useNavigationHelpers.tsx +33 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useNavigationCache.tsx"],"names":["useNavigationCache","state","getState","navigation","setOptions","router","emitter","stackRef","React","useContext","NavigationBuilderContext","cache","useMemo","current","actions","actionCreators","CommonActions","routes","reduce","acc","route","previous","key","emit","rest","dispatch","thunk","action","source","withStack","callback","isStackSet","process","env","NODE_ENV","Error","stack","undefined","helpers","Object","keys","name","args","create","options","o","isFocused","index"],"mappings":";;;;;;;AAAA;;AAOA;;AAEA;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["useNavigationCache.tsx"],"names":["useNavigationCache","state","getState","navigation","setOptions","router","emitter","stackRef","React","useContext","NavigationBuilderContext","cache","useMemo","current","actions","actionCreators","CommonActions","routes","reduce","acc","route","previous","key","emit","rest","dispatch","thunk","action","source","withStack","callback","isStackSet","process","env","NODE_ENV","Error","stack","undefined","helpers","Object","keys","name","args","create","getParent","id","getId","options","o","isFocused","index"],"mappings":";;;;;;;AAAA;;AAOA;;AAEA;;;;;;;;AAmCA;AACA;AACA;AACA;AACA;AACe,SAASA,kBAAT,OAWc;AAAA,MAP3B;AACAC,IAAAA,KADA;AAEAC,IAAAA,QAFA;AAGAC,IAAAA,UAHA;AAIAC,IAAAA,UAJA;AAKAC,IAAAA,MALA;AAMAC,IAAAA;AANA,GAO2B;AAC3B,QAAM;AAAEC,IAAAA;AAAF,MAAeC,KAAK,CAACC,UAAN,CAAiBC,iCAA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ACjB,GAAGA,CADc;AAEjB,WAAC5B,KAAK,CAACE,GAAP,GAAa,EAAE,GAAG0B,CAAC,CAAC5B,KAAK,CAACE,GAAP,CAAN;AAAmB,eAAGyB;AAAtB;AAFI,SAAR,CAAD,CAhBG;AAoBfE,QAAAA,SAAS,EAAE,MAAM;AACf,gBAAMhD,KAAK,GAAGC,QAAQ,EAAtB;;AAEA,cAAID,KAAK,CAACgB,MAAN,CAAahB,KAAK,CAACiD,KAAnB,EAA0B5B,GAA1B,KAAkCF,KAAK,CAACE,GAA5C,EAAiD;AAC/C,mBAAO,KAAP;AACD,WALc,CAOf;AACA;;;AACA,iBAAOnB,UAAU,GAAGA,UAAU,CAAC8C,SAAX,EAAH,GAA4B,IAA7C;AACD;AA9Bc,OAAjB;AAgCD;;AAED,WAAO9B,GAAP;AACD,GA9Fe,EA8Fb,EA9Fa,CAAhB;AAgGA,SAAOR,KAAK,CAACE,OAAb;AACD","sourcesContent":["import {\n CommonActions,\n NavigationAction,\n NavigationState,\n ParamListBase,\n Router,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationBuilderContext from './NavigationBuilderContext';\nimport type { NavigationHelpers, NavigationProp } from './types';\nimport type { NavigationEventEmitter } from './useEventEmitter';\n\ntype Options<\n State extends NavigationState,\n EventMap extends Record<string, any>\n> = {\n state: State;\n getState: () => State;\n navigation: NavigationHelpers<ParamListBase> &\n Partial<NavigationProp<ParamListBase, string, any, any, any>>;\n setOptions: (\n cb: (options: Record<string, object>) => Record<string, object>\n ) => void;\n router: Router<State, NavigationAction>;\n emitter: NavigationEventEmitter<EventMap>;\n};\n\ntype NavigationCache<\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends Record<string, any>\n> = Record<\n string,\n NavigationProp<\n ParamListBase,\n string,\n string | undefined,\n State,\n ScreenOptions,\n EventMap\n >\n>;\n\n/**\n * Hook to cache navigation objects for each screen in the navigator.\n * It's important to cache them to make sure navigation objects don't change between renders.\n * This lets us apply optimizations like `React.memo` to minimize re-rendering screens.\n */\nexport default function useNavigationCache<\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends Record<string, any>\n>({\n state,\n getState,\n navigation,\n setOptions,\n router,\n emitter,\n}: Options<State, EventMap>) {\n const { stackRef } = React.useContext(NavigationBuilderContext);\n\n // Cache object which holds navigation objects for each screen\n // We use `React.useMemo` instead of `React.useRef` coz we want to invalidate it when deps change\n // In reality, these deps will rarely change, if ever\n const cache = React.useMemo(\n () => ({ current: {} as NavigationCache<State, ScreenOptions, EventMap> }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [getState, navigation, setOptions, router, emitter]\n );\n\n const actions = {\n ...router.actionCreators,\n ...CommonActions,\n };\n\n cache.current = state.routes.reduce<\n NavigationCache<State, ScreenOptions, EventMap>\n >((acc, route) => {\n const previous = cache.current[route.key];\n\n type Thunk =\n | NavigationAction\n | ((state: State) => NavigationAction | null | undefined);\n\n if (previous) {\n // If a cached navigation object already exists, reuse it\n acc[route.key] = previous;\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { emit, ...rest } = navigation;\n\n const dispatch = (thunk: Thunk) => {\n const action = typeof thunk === 'function' ? thunk(getState()) : thunk;\n\n if (action != null) {\n navigation.dispatch({ source: route.key, ...action });\n }\n };\n\n const withStack = (callback: () => void) => {\n let isStackSet = false;\n\n try {\n if (\n process.env.NODE_ENV !== 'production' &&\n stackRef &&\n !stackRef.current\n ) {\n // Capture the stack trace for devtools\n stackRef.current = new Error().stack;\n isStackSet = true;\n }\n\n callback();\n } finally {\n if (isStackSet && stackRef) {\n stackRef.current = undefined;\n }\n }\n };\n\n const helpers = Object.keys(actions).reduce<Record<string, () => void>>(\n (acc, name) => {\n acc[name] = (...args: any) =>\n withStack(() =>\n // @ts-expect-error: name is a valid key, but TypeScript is dumb\n dispatch(actions[name](...args))\n );\n\n return acc;\n },\n {}\n );\n\n acc[route.key] = {\n ...rest,\n ...helpers,\n // FIXME: too much work to fix the types for now\n ...(emitter.create(route.key) as any),\n dispatch: (thunk: Thunk) => withStack(() => dispatch(thunk)),\n getParent: (id?: string) => {\n if (id !== undefined && id === rest.getId()) {\n // If the passed id is the same as the current navigation id,\n // we return the cached navigation object for the relevant route\n return acc[route.key];\n }\n\n return rest.getParent(id);\n },\n setOptions: (options: object) =>\n setOptions((o) => ({\n ...o,\n [route.key]: { ...o[route.key], ...options },\n })),\n isFocused: () => {\n const state = getState();\n\n if (state.routes[state.index].key !== route.key) {\n return false;\n }\n\n // If the current screen is focused, we also need to check if parent navigator is focused\n // This makes sure that we return the focus state in the whole tree, not just this navigator\n return navigation ? navigation.isFocused() : true;\n },\n };\n }\n\n return acc;\n }, {});\n\n return cache.current;\n}\n"]}
|
|
@@ -31,6 +31,7 @@ _types.PrivateValueStore;
|
|
|
31
31
|
*/
|
|
32
32
|
function useNavigationHelpers(_ref) {
|
|
33
33
|
let {
|
|
34
|
+
id: navigatorId,
|
|
34
35
|
onAction,
|
|
35
36
|
getState,
|
|
36
37
|
emitter,
|
|
@@ -59,7 +60,7 @@ function useNavigationHelpers(_ref) {
|
|
|
59
60
|
|
|
60
61
|
return acc;
|
|
61
62
|
}, {});
|
|
62
|
-
|
|
63
|
+
const navigationHelpers = { ...parentNavigationHelpers,
|
|
63
64
|
...helpers,
|
|
64
65
|
dispatch,
|
|
65
66
|
emit: emitter.emit,
|
|
@@ -72,9 +73,23 @@ function useNavigationHelpers(_ref) {
|
|
|
72
73
|
routeGetIdList: {}
|
|
73
74
|
}) !== null || (parentNavigationHelpers === null || parentNavigationHelpers === void 0 ? void 0 : parentNavigationHelpers.canGoBack()) || false;
|
|
74
75
|
},
|
|
75
|
-
|
|
76
|
+
getId: () => navigatorId,
|
|
77
|
+
getParent: id => {
|
|
78
|
+
if (id !== undefined) {
|
|
79
|
+
let current = navigationHelpers;
|
|
80
|
+
|
|
81
|
+
while (current && id !== current.getId()) {
|
|
82
|
+
current = current.getParent();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return current;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return parentNavigationHelpers;
|
|
89
|
+
},
|
|
76
90
|
getState
|
|
77
91
|
};
|
|
78
|
-
|
|
92
|
+
return navigationHelpers;
|
|
93
|
+
}, [navigatorId, emitter.emit, getState, onAction, onUnhandledAction, parentNavigationHelpers, router]);
|
|
79
94
|
}
|
|
80
95
|
//# sourceMappingURL=useNavigationHelpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useNavigationHelpers.tsx"],"names":["PrivateValueStore","useNavigationHelpers","onAction","getState","emitter","router","onUnhandledAction","React","useContext","UnhandledActionContext","parentNavigationHelpers","NavigationContext","useMemo","dispatch","op","action","handled","actions","actionCreators","CommonActions","helpers","Object","keys","reduce","acc","name","emit","isFocused","canGoBack","state","getStateForAction","goBack","routeNames","routeParamList","routeGetIdList","getParent"],"mappings":";;;;;;;AAAA;;AAOA;;AAEA;;AACA;;AACA;;;;;;;;AAGA;AACA;AACAA;;
|
|
1
|
+
{"version":3,"sources":["useNavigationHelpers.tsx"],"names":["PrivateValueStore","useNavigationHelpers","id","navigatorId","onAction","getState","emitter","router","onUnhandledAction","React","useContext","UnhandledActionContext","parentNavigationHelpers","NavigationContext","useMemo","dispatch","op","action","handled","actions","actionCreators","CommonActions","helpers","Object","keys","reduce","acc","name","navigationHelpers","emit","isFocused","canGoBack","state","getStateForAction","goBack","routeNames","routeParamList","routeGetIdList","getId","getParent","undefined","current"],"mappings":";;;;;;;AAAA;;AAOA;;AAEA;;AACA;;AACA;;;;;;;;AAGA;AACA;AACAA;;AAUA;AACA;AACA;AACA;AACe,SAASC,oBAAT,OAWY;AAAA,MANzB;AACAC,IAAAA,EAAE,EAAEC,WADJ;AAEAC,IAAAA,QAFA;AAGAC,IAAAA,QAHA;AAIAC,IAAAA,OAJA;AAKAC,IAAAA;AALA,GAMyB;AACzB,QAAMC,iBAAiB,GAAGC,KAAK,CAACC,UAAN,CAAiBC,+BAAjB,CAA1B;AACA,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AU,EAAEH,KAAK,CAACG,UAD8C;AAEhEC,UAAAA,cAAc,EAAE,EAFgD;AAGhEC,UAAAA,cAAc,EAAE;AAHgD,SAAlE,MAIO,IAJP,KAKAzB,uBALA,aAKAA,uBALA,uBAKAA,uBAAuB,CAAEmB,SAAzB,EALA,KAMA,KAPF;AASD,OApBuB;AAqBxBO,MAAAA,KAAK,EAAE,MAAMnC,WArBW;AAsBxBoC,MAAAA,SAAS,EAAGrC,EAAD,IAAiB;AAC1B,YAAIA,EAAE,KAAKsC,SAAX,EAAsB;AACpB,cAAIC,OAAO,GAAGb,iBAAd;;AAEA,iBAAOa,OAAO,IAAIvC,EAAE,KAAKuC,OAAO,CAACH,KAAR,EAAzB,EAA0C;AACxCG,YAAAA,OAAO,GAAGA,OAAO,CAACF,SAAR,EAAV;AACD;;AAED,iBAAOE,OAAP;AACD;;AAED,eAAO7B,uBAAP;AACD,OAlCuB;AAmCxBP,MAAAA;AAnCwB,KAA1B;AAsCA,WAAOuB,iBAAP;AACD,GA7DM,EA6DJ,CACDzB,WADC,EAEDG,OAAO,CAACuB,IAFP,EAGDxB,QAHC,EAIDD,QAJC,EAKDI,iBALC,EAMDI,uBANC,EAODL,MAPC,CA7DI,CAAP;AAsED","sourcesContent":["import {\n CommonActions,\n NavigationAction,\n NavigationState,\n ParamListBase,\n Router,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationContext from './NavigationContext';\nimport { NavigationHelpers, PrivateValueStore } from './types';\nimport UnhandledActionContext from './UnhandledActionContext';\nimport type { NavigationEventEmitter } from './useEventEmitter';\n\n// This is to make TypeScript compiler happy\n// eslint-disable-next-line babel/no-unused-expressions\nPrivateValueStore;\n\ntype Options<State extends NavigationState, Action extends NavigationAction> = {\n id: string | undefined;\n onAction: (action: NavigationAction) => boolean;\n getState: () => State;\n emitter: NavigationEventEmitter<any>;\n router: Router<State, Action>;\n};\n\n/**\n * Navigation object with helper methods to be used by a navigator.\n * This object includes methods for common actions as well as methods the parent screen's navigation object.\n */\nexport default function useNavigationHelpers<\n State extends NavigationState,\n ActionHelpers extends Record<string, () => void>,\n Action extends NavigationAction,\n EventMap extends Record<string, any>\n>({\n id: navigatorId,\n onAction,\n getState,\n emitter,\n router,\n}: Options<State, Action>) {\n const onUnhandledAction = React.useContext(UnhandledActionContext);\n const parentNavigationHelpers = React.useContext(NavigationContext);\n\n return React.useMemo(() => {\n const dispatch = (op: Action | ((state: State) => Action)) => {\n const action = typeof op === 'function' ? op(getState()) : op;\n\n const handled = onAction(action);\n\n if (!handled) {\n onUnhandledAction?.(action);\n }\n };\n\n const actions = {\n ...router.actionCreators,\n ...CommonActions,\n };\n\n const helpers = Object.keys(actions).reduce((acc, name) => {\n // @ts-expect-error: name is a valid key, but TypeScript is dumb\n acc[name] = (...args: any) => dispatch(actions[name](...args));\n return acc;\n }, {} as ActionHelpers);\n\n const navigationHelpers = {\n ...parentNavigationHelpers,\n ...helpers,\n dispatch,\n emit: emitter.emit,\n isFocused: parentNavigationHelpers\n ? parentNavigationHelpers.isFocused\n : () => true,\n canGoBack: () => {\n const state = getState();\n\n return (\n router.getStateForAction(state, CommonActions.goBack() as Action, {\n routeNames: state.routeNames,\n routeParamList: {},\n routeGetIdList: {},\n }) !== null ||\n parentNavigationHelpers?.canGoBack() ||\n false\n );\n },\n getId: () => navigatorId,\n getParent: (id?: string) => {\n if (id !== undefined) {\n let current = navigationHelpers;\n\n while (current && id !== current.getId()) {\n current = current.getParent();\n }\n\n return current;\n }\n\n return parentNavigationHelpers;\n },\n getState,\n } as NavigationHelpers<ParamListBase, EventMap> & ActionHelpers;\n\n return navigationHelpers;\n }, [\n navigatorId,\n emitter.emit,\n getState,\n onAction,\n onUnhandledAction,\n parentNavigationHelpers,\n router,\n ]);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["SceneView.tsx"],"names":["React","EnsureSingleNavigator","NavigationStateContext","StaticContainer","useOptionsGetters","SceneView","screen","route","navigation","routeState","getState","setState","options","clearOptions","navigatorKeyRef","useRef","getKey","useCallback","current","addOptionsGetter","key","setKey","getCurrentState","state","currentRoute","routes","find","r","undefined","setCurrentState","child","map","isInitialRef","useEffect","getIsInitial","context","useMemo","ScreenComponent","getComponent","component","name","children"],"mappings":"AAMA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,qBAAP,MAAkC,yBAAlC;AACA,OAAOC,sBAAP,MAAmC,0BAAnC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AAEA,OAAOC,iBAAP,MAA8B,qBAA9B;;
|
|
1
|
+
{"version":3,"sources":["SceneView.tsx"],"names":["React","EnsureSingleNavigator","NavigationStateContext","StaticContainer","useOptionsGetters","SceneView","screen","route","navigation","routeState","getState","setState","options","clearOptions","navigatorKeyRef","useRef","getKey","useCallback","current","addOptionsGetter","key","setKey","getCurrentState","state","currentRoute","routes","find","r","undefined","setCurrentState","child","map","isInitialRef","useEffect","getIsInitial","context","useMemo","ScreenComponent","getComponent","component","name","children"],"mappings":"AAMA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,qBAAP,MAAkC,yBAAlC;AACA,OAAOC,sBAAP,MAAmC,0BAAnC;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AAEA,OAAOC,iBAAP,MAA8B,qBAA9B;;AAmBA;AACA;AACA;AACA;AACA,eAAe,SAASC,SAAT,OAYiB;AAAA,MAT9B;AACAC,IAAAA,MADA;AAEAC,IAAAA,KAFA;AAGAC,IAAAA,UAHA;AAIAC,IAAAA,UAJA;AAKAC,IAAAA,QALA;AAMAC,IAAAA,QANA;AAOAC,IAAAA,OAPA;AAQAC,IAAAA;AARA,GAS8B;AAC9B,QAAMC,eAAe,GAAGd,KAAK,CAACe,MAAN,EAAxB;AACA,QAAMC,MAAM,GAAGhB,KAAK,CAACiB,WAAN,CAAkB,MAAMH,eAAe,CAACI,OAAxC,EAAiD,EAAjD,CAAf;AAEA,QAAM;AAAEC,IAAAA;AAAF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UAAF;AAAcD,IAAAA;AAAd,GAAhB,CADE,GAEA,IAVN,CADF,CADF,CADF;AAkBD","sourcesContent":["import type {\n NavigationState,\n ParamListBase,\n PartialState,\n Route,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport EnsureSingleNavigator from './EnsureSingleNavigator';\nimport NavigationStateContext from './NavigationStateContext';\nimport StaticContainer from './StaticContainer';\nimport type { NavigationProp, RouteConfigComponent } from './types';\nimport useOptionsGetters from './useOptionsGetters';\n\ntype Props<State extends NavigationState, ScreenOptions extends {}> = {\n screen: RouteConfigComponent<ParamListBase, string> & { name: string };\n navigation: NavigationProp<\n ParamListBase,\n string,\n string | undefined,\n State,\n ScreenOptions\n >;\n route: Route<string>;\n routeState: NavigationState | PartialState<NavigationState> | undefined;\n getState: () => State;\n setState: (state: State) => void;\n options: object;\n clearOptions: () => void;\n};\n\n/**\n * Component which takes care of rendering the screen for a route.\n * It provides all required contexts and applies optimizations when applicable.\n */\nexport default function SceneView<\n State extends NavigationState,\n ScreenOptions extends {}\n>({\n screen,\n route,\n navigation,\n routeState,\n getState,\n setState,\n options,\n clearOptions,\n}: Props<State, ScreenOptions>) {\n const navigatorKeyRef = React.useRef<string | undefined>();\n const getKey = React.useCallback(() => navigatorKeyRef.current, []);\n\n const { addOptionsGetter } = useOptionsGetters({\n key: route.key,\n options,\n navigation,\n });\n\n const setKey = React.useCallback((key: string) => {\n navigatorKeyRef.current = key;\n }, []);\n\n const getCurrentState = React.useCallback(() => {\n const state = getState();\n const currentRoute = state.routes.find((r) => r.key === route.key);\n\n return currentRoute ? currentRoute.state : undefined;\n }, [getState, route.key]);\n\n const setCurrentState = React.useCallback(\n (child: NavigationState | PartialState<NavigationState> | undefined) => {\n const state = getState();\n\n setState({\n ...state,\n routes: state.routes.map((r) =>\n r.key === route.key ? { ...r, state: child } : r\n ),\n });\n },\n [getState, route.key, setState]\n );\n\n const isInitialRef = React.useRef(true);\n\n React.useEffect(() => {\n isInitialRef.current = false;\n });\n\n // Clear options set by this screen when it is unmounted\n React.useEffect(() => {\n return clearOptions;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const getIsInitial = React.useCallback(() => isInitialRef.current, []);\n\n const context = React.useMemo(\n () => ({\n state: routeState,\n getState: getCurrentState,\n setState: setCurrentState,\n getKey,\n setKey,\n getIsInitial,\n addOptionsGetter,\n }),\n [\n routeState,\n getCurrentState,\n setCurrentState,\n getKey,\n setKey,\n getIsInitial,\n addOptionsGetter,\n ]\n );\n\n const ScreenComponent = screen.getComponent\n ? screen.getComponent()\n : screen.component;\n\n return (\n <NavigationStateContext.Provider value={context}>\n <EnsureSingleNavigator>\n <StaticContainer\n name={screen.name}\n render={ScreenComponent || screen.children}\n navigation={navigation}\n route={route}\n >\n {ScreenComponent !== undefined ? (\n <ScreenComponent navigation={navigation} route={route} />\n ) : screen.children !== undefined ? (\n screen.children({ navigation, route })\n ) : null}\n </StaticContainer>\n </EnsureSingleNavigator>\n </NavigationStateContext.Provider>\n );\n}\n"]}
|
package/lib/module/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["types.tsx"],"names":["PrivateValueStore"],"mappings":";;AA2JA,OAAO,MAAMA,iBAAN,CAAiC;AAAA;AAAA,0BAW5B,EAX4B;AAAA;;AAAA","sourcesContent":["import type {\n DefaultRouterOptions,\n InitialState,\n NavigationAction,\n NavigationState,\n ParamListBase,\n PartialState,\n Route,\n} from '@react-navigation/routers';\nimport type * as React from 'react';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace ReactNavigation {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface RootParamList {}\n }\n}\n\ntype Keyof<T extends {}> = Extract<keyof T, string>;\n\nexport type DefaultNavigatorOptions<\n ParamList extends ParamListBase,\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n> = DefaultRouterOptions<Keyof<ParamList>> & {\n /**\n * Children React Elements to extract the route configuration from.\n * Only `Screen`, `Group` and `React.Fragment` are supported as children.\n */\n children: React.ReactNode;\n /**\n * Event listeners for all the screens in the navigator.\n */\n screenListeners?:\n | ScreenListeners<State, EventMap>\n | ((props: {\n route: RouteProp<ParamList>;\n navigation: any;\n }) => ScreenListeners<State, EventMap>);\n /**\n * Default options for all screens under this navigator.\n */\n screenOptions?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamList>;\n navigation: any;\n }) => ScreenOptions);\n /**\n * Default options specified by the navigator.\n * It receives the custom options in the arguments if a function is specified.\n */\n defaultScreenOptions?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamList>;\n navigation: any;\n options: ScreenOptions;\n }) => ScreenOptions);\n};\n\nexport type EventMapBase = Record<\n string,\n { data?: any; canPreventDefault?: boolean }\n>;\n\nexport type EventMapCore<State extends NavigationState> = {\n focus: { data: undefined };\n blur: { data: undefined };\n state: { data: { state: State } };\n beforeRemove: { data: { action: NavigationAction }; canPreventDefault: true };\n};\n\nexport type EventArg<\n EventName extends string,\n CanPreventDefault extends boolean | undefined = false,\n Data = undefined\n> = {\n /**\n * Type of the event (e.g. `focus`, `blur`)\n */\n readonly type: EventName;\n readonly target?: string;\n} & (CanPreventDefault extends true\n ? {\n /**\n * Whether `event.preventDefault()` was called on this event object.\n */\n readonly defaultPrevented: boolean;\n /**\n * Prevent the default action which happens on this event.\n */\n preventDefault(): void;\n }\n : {}) &\n (undefined extends Data\n ? { readonly data?: Readonly<Data> }\n : { readonly data: Readonly<Data> });\n\nexport type EventListenerCallback<\n EventMap extends EventMapBase,\n EventName extends keyof EventMap\n> = (\n e: EventArg<\n Extract<EventName, string>,\n EventMap[EventName]['canPreventDefault'],\n EventMap[EventName]['data']\n >\n) => void;\n\nexport type EventConsumer<EventMap extends EventMapBase> = {\n /**\n * Subscribe to events from the parent navigator.\n *\n * @param type Type of the event (e.g. `focus`, `blur`)\n * @param callback Callback listener which is executed upon receiving the event.\n */\n addListener<EventName extends Keyof<EventMap>>(\n type: EventName,\n callback: EventListenerCallback<EventMap, EventName>\n ): () => void;\n removeListener<EventName extends Keyof<EventMap>>(\n type: EventName,\n callback: EventListenerCallback<EventMap, EventName>\n ): void;\n};\n\nexport type EventEmitter<EventMap extends EventMapBase> = {\n /**\n * Emit an event to child screens.\n *\n * @param options.type Type of the event (e.g. `focus`, `blur`)\n * @param [options.data] Optional information regarding the event.\n * @param [options.target] Key of the target route which should receive the event.\n * If not specified, all routes receive the event.\n */\n emit<EventName extends Keyof<EventMap>>(\n options: {\n type: EventName;\n target?: string;\n } & (EventMap[EventName]['canPreventDefault'] extends true\n ? { canPreventDefault: true }\n : {}) &\n (undefined extends EventMap[EventName]['data']\n ? { data?: EventMap[EventName]['data'] }\n : { data: EventMap[EventName]['data'] })\n ): EventArg<\n EventName,\n EventMap[EventName]['canPreventDefault'],\n EventMap[EventName]['data']\n >;\n};\n\nexport class PrivateValueStore<A, B, C> {\n /**\n * UGLY HACK! DO NOT USE THE TYPE!!!\n *\n * TypeScript requires a type to be used to be able to infer it.\n * The type should exist as its own without any operations such as union.\n * So we need to figure out a way to store this type in a property.\n * The problem with a normal property is that it shows up in intelliSense.\n * Adding private keyword works, but the annotation is stripped away in declaration.\n * Turns out if we use an empty string, it doesn't show up in intelliSense.\n */\n protected ''?: { a: A; b: B; c: C };\n}\n\ntype NavigationHelpersCommon<\n ParamList extends ParamListBase,\n State extends NavigationState = NavigationState\n> = {\n /**\n * Dispatch an action or an update function to the router.\n * The update function will receive the current state,\n *\n * @param action Action object or update function.\n */\n dispatch(\n action: NavigationAction | ((state: State) => NavigationAction)\n ): void;\n\n /**\n * Navigate to a route in current navigation tree.\n *\n * @param name Name of the route to navigate to.\n * @param [params] Params object for the route.\n */\n navigate<RouteName extends keyof ParamList>(\n ...args: undefined extends ParamList[RouteName]\n ? [screen: RouteName] | [screen: RouteName, params: ParamList[RouteName]]\n : [screen: RouteName, params: ParamList[RouteName]]\n ): void;\n\n /**\n * Navigate to a route in current navigation tree.\n *\n * @param route Object with `key` or `name` for the route to navigate to, and a `params` object.\n */\n navigate<RouteName extends keyof ParamList>(\n options:\n | { key: string; params?: ParamList[RouteName]; merge?: boolean }\n | {\n name: RouteName;\n key?: string;\n params: ParamList[RouteName];\n merge?: boolean;\n }\n ): void;\n\n /**\n * Reset the navigation state to the provided state.\n *\n * @param state Navigation state object.\n */\n reset(state: PartialState<State> | State): void;\n\n /**\n * Go back to the previous route in history.\n */\n goBack(): void;\n\n /**\n * Check if the screen is focused. The method returns `true` if focused, `false` otherwise.\n * Note that this method doesn't re-render screen when the focus changes. So don't use it in `render`.\n * To get notified of focus changes, use `addListener('focus', cb)` and `addListener('blur', cb)`.\n * To conditionally render content based on focus state, use the `useIsFocused` hook.\n */\n isFocused(): boolean;\n\n /**\n * Check if dispatching back action will be handled by navigation.\n * Note that this method doesn't re-render screen when the result changes. So don't use it in `render`.\n */\n canGoBack(): boolean;\n\n /**\n * Returns the navigation prop from the parent navigator,\n */\n getParent<T = NavigationProp<ParamListBase> | undefined>(): T;\n\n /**\n * Returns the navigator's state.\n * Note that this method doesn't re-render screen when the result changes. So don't use it in `render`.\n */\n getState(): State;\n} & PrivateValueStore<ParamList, keyof ParamList, {}>;\n\nexport type NavigationHelpers<\n ParamList extends ParamListBase,\n EventMap extends EventMapBase = {}\n> = NavigationHelpersCommon<ParamList> &\n EventEmitter<EventMap> & {\n /**\n * Update the param object for the route.\n * The new params will be shallow merged with the old one.\n *\n * @param params Params object for the current route.\n */\n setParams<RouteName extends keyof ParamList>(\n params: Partial<ParamList[RouteName]>\n ): void;\n };\n\nexport type NavigationContainerProps = {\n /**\n * Initial navigation state for the child navigators.\n */\n initialState?: InitialState;\n /**\n * Callback which is called with the latest navigation state when it changes.\n */\n onStateChange?: (state: NavigationState | undefined) => void;\n /**\n * Callback which is called when an action is not handled.\n */\n onUnhandledAction?: (action: NavigationAction) => void;\n /**\n * Whether this navigation container should be independent of parent containers.\n * If this is not set to `true`, this container cannot be nested inside another container.\n * Setting it to `true` disconnects any children navigators from parent container.\n */\n independent?: boolean;\n /**\n * Children elements to render.\n */\n children: React.ReactNode;\n};\n\nexport type NavigationProp<\n ParamList extends {},\n RouteName extends keyof ParamList = Keyof<ParamList>,\n State extends NavigationState = NavigationState<ParamList>,\n ScreenOptions extends {} = {},\n EventMap extends EventMapBase = {}\n> = NavigationHelpersCommon<ParamList, State> & {\n /**\n * Update the param object for the route.\n * The new params will be shallow merged with the old one.\n *\n * @param params Params object for the current route.\n */\n setParams(params: Partial<ParamList[RouteName]>): void;\n\n /**\n * Update the options for the route.\n * The options object will be shallow merged with default options object.\n *\n * @param options Options object for the route.\n */\n setOptions(options: Partial<ScreenOptions>): void;\n} & EventConsumer<EventMap & EventMapCore<State>> &\n PrivateValueStore<ParamList, RouteName, EventMap>;\n\nexport type RouteProp<\n ParamList extends ParamListBase,\n RouteName extends keyof ParamList = Keyof<ParamList>\n> = Route<Extract<RouteName, string>, ParamList[RouteName]>;\n\nexport type CompositeNavigationProp<\n A extends NavigationProp<ParamListBase, string, any, any>,\n B extends NavigationHelpersCommon<ParamListBase, any>\n> = Omit<A & B, keyof NavigationProp<any>> &\n NavigationProp<\n /**\n * Param list from both navigation objects needs to be combined\n * For example, we should be able to navigate to screens in both A and B\n */\n (A extends NavigationHelpersCommon<infer T> ? T : never) &\n (B extends NavigationHelpersCommon<infer U> ? U : never),\n /**\n * The route name should refer to the route name specified in the first type\n * Ideally it should work for any of them, but it's not possible to infer that way\n */\n A extends NavigationProp<any, infer R> ? R : string,\n /**\n * The type of state should refer to the state specified in the first type\n */\n A extends NavigationProp<any, any, infer S> ? S : NavigationState,\n /**\n * Screen options from both navigation objects needs to be combined\n * This allows typechecking `setOptions`\n */\n (A extends NavigationProp<any, any, any, infer O> ? O : {}) &\n (B extends NavigationProp<any, any, any, infer P> ? P : {}),\n /**\n * Event consumer config should refer to the config specified in the first type\n * This allows typechecking `addListener`/`removeListener`\n */\n A extends NavigationProp<any, any, any, any, infer E> ? E : {}\n >;\n\nexport type CompositeScreenProps<\n A extends {\n navigation: NavigationProp<ParamListBase, string, any, any>;\n route: RouteProp<ParamListBase>;\n },\n B extends {\n navigation: NavigationHelpersCommon<ParamListBase, any>;\n }\n> = {\n navigation: CompositeNavigationProp<A['navigation'], B['navigation']>;\n route: A['route'];\n};\n\nexport type Descriptor<\n ScreenOptions extends {},\n Navigation extends NavigationProp<any, any, any, any, any>,\n Route extends RouteProp<any, any>\n> = {\n /**\n * Render the component associated with this route.\n */\n render(): JSX.Element;\n\n /**\n * Options for the route.\n */\n options: ScreenOptions;\n\n /**\n * Route object for the screen\n */\n route: Route;\n\n /**\n * Navigation object for the screen\n */\n navigation: Navigation;\n};\n\nexport type ScreenListeners<\n State extends NavigationState,\n EventMap extends EventMapBase\n> = Partial<{\n [EventName in keyof (EventMap & EventMapCore<State>)]: EventListenerCallback<\n EventMap,\n EventName\n >;\n}>;\n\nexport type RouteConfigComponent<\n ParamList extends ParamListBase,\n RouteName extends keyof ParamList\n> =\n | {\n /**\n * React component to render for this screen.\n */\n component: React.ComponentType<any>;\n getComponent?: never;\n children?: never;\n }\n | {\n /**\n * Lazily get a React component to render for this screen.\n */\n getComponent: () => React.ComponentType<any>;\n component?: never;\n children?: never;\n }\n | {\n /**\n * Render callback to render content of this screen.\n */\n children: (props: {\n route: RouteProp<ParamList, RouteName>;\n navigation: any;\n }) => React.ReactNode;\n component?: never;\n getComponent?: never;\n };\n\nexport type RouteConfig<\n ParamList extends ParamListBase,\n RouteName extends keyof ParamList,\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n> = {\n /**\n * Optional key for this screen. This doesn't need to be unique.\n * If the key changes, existing screens with this name will be removed or reset.\n * Useful when we have some common screens and have conditional rendering.\n */\n navigationKey?: string;\n\n /**\n * Route name of this screen.\n */\n name: RouteName;\n\n /**\n * Navigator options for this screen.\n */\n options?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamList, RouteName>;\n navigation: any;\n }) => ScreenOptions);\n\n /**\n * Event listeners for this screen.\n */\n listeners?:\n | ScreenListeners<State, EventMap>\n | ((props: {\n route: RouteProp<ParamList, RouteName>;\n navigation: any;\n }) => ScreenListeners<State, EventMap>);\n\n /**\n * Function to return an unique ID for this screen.\n * Receives an object with the route params.\n * For a given screen name, there will always be only one screen corresponding to an ID.\n * If `undefined` is returned, it acts same as no `getId` being specified.\n */\n getId?: ({ params }: { params: ParamList[RouteName] }) => string | undefined;\n\n /**\n * Initial params object for the route.\n */\n initialParams?: Partial<ParamList[RouteName]>;\n} & RouteConfigComponent<ParamList, RouteName>;\n\nexport type RouteGroupConfig<\n ParamList extends ParamListBase,\n ScreenOptions extends {}\n> = {\n /**\n * Optional key for the screens in this group.\n * If the key changes, all existing screens in this group will be removed or reset.\n */\n navigationKey?: string;\n\n /**\n * Navigator options for this screen.\n */\n screenOptions?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamList, keyof ParamList>;\n navigation: any;\n }) => ScreenOptions);\n /**\n * Children React Elements to extract the route configuration from.\n * Only `Screen`, `Group` and `React.Fragment` are supported as children.\n */\n children: React.ReactNode;\n};\n\nexport type NavigationContainerEventMap = {\n /**\n * Event which fires when the navigation state changes.\n */\n state: {\n data: {\n /**\n * The updated state object after the state change.\n */\n state: NavigationState | PartialState<NavigationState> | undefined;\n };\n };\n /**\n * Event which fires when current options changes.\n */\n options: { data: { options: object } };\n /**\n * Event which fires when an action is dispatched.\n * Only intended for debugging purposes, don't use it for app logic.\n * This event will be emitted before state changes have been applied.\n */\n __unsafe_action__: {\n data: {\n /**\n * The action object which was dispatched.\n */\n action: NavigationAction;\n /**\n * Whether the action was a no-op, i.e. resulted any state changes.\n */\n noop: boolean;\n /**\n * Stack trace of the action, this will only be available during development.\n */\n stack: string | undefined;\n };\n };\n};\n\nexport type NavigationContainerRef<ParamList extends {}> =\n NavigationHelpers<ParamList> &\n EventConsumer<NavigationContainerEventMap> & {\n /**\n * Reset the navigation state of the root navigator to the provided state.\n *\n * @param state Navigation state object.\n */\n resetRoot(state?: PartialState<NavigationState> | NavigationState): void;\n /**\n * Get the rehydrated navigation state of the navigation tree.\n */\n getRootState(): NavigationState;\n /**\n * Get the currently focused navigation route.\n */\n getCurrentRoute(): Route<string> | undefined;\n /**\n * Get the currently focused route's options.\n */\n getCurrentOptions(): object | undefined;\n /**\n * Whether the navigation container is ready to handle actions.\n */\n isReady(): boolean;\n };\n\nexport type NavigationContainerRefWithCurrent<ParamList extends {}> =\n NavigationContainerRef<ParamList> & {\n current: NavigationContainerRef<ParamList> | null;\n };\n\nexport type TypedNavigator<\n ParamList extends ParamListBase,\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase,\n Navigator extends React.ComponentType<any>\n> = {\n /**\n * Navigator component which manages the child screens.\n */\n Navigator: React.ComponentType<\n Omit<\n React.ComponentProps<Navigator>,\n keyof DefaultNavigatorOptions<any, any, any, any>\n > &\n DefaultNavigatorOptions<ParamList, State, ScreenOptions, EventMap>\n >;\n /**\n * Component used for grouping multiple route configuration.\n */\n Group: React.ComponentType<RouteGroupConfig<ParamList, ScreenOptions>>;\n /**\n * Component used for specifying route configuration.\n */\n Screen: <RouteName extends keyof ParamList>(\n _: RouteConfig<ParamList, RouteName, State, ScreenOptions, EventMap>\n ) => null;\n};\n\nexport type NavigatorScreenParams<\n ParamList,\n State extends NavigationState = NavigationState\n> =\n | {\n screen?: never;\n params?: never;\n initial?: never;\n path?: string;\n state: PartialState<State> | State | undefined;\n }\n | {\n [RouteName in keyof ParamList]: undefined extends ParamList[RouteName]\n ? {\n screen: RouteName;\n params?: ParamList[RouteName];\n initial?: boolean;\n path?: string;\n state?: never;\n }\n : {\n screen: RouteName;\n params: ParamList[RouteName];\n initial?: boolean;\n path?: string;\n state?: never;\n };\n }[keyof ParamList];\n\nexport type PathConfig<ParamList extends {}> = {\n path?: string;\n exact?: boolean;\n parse?: Record<string, (value: string) => any>;\n stringify?: Record<string, (value: any) => string>;\n screens?: PathConfigMap<ParamList>;\n initialRouteName?: keyof ParamList;\n};\n\nexport type PathConfigMap<ParamList extends {}> = {\n [RouteName in keyof ParamList]?: NonNullable<\n ParamList[RouteName]\n > extends NavigatorScreenParams<infer T, any>\n ? string | PathConfig<T>\n : string | Omit<PathConfig<{}>, 'screens' | 'initialRouteName'>;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["types.tsx"],"names":["PrivateValueStore"],"mappings":";;AA+JA,OAAO,MAAMA,iBAAN,CAAmD;AAAA;AAAA,0BAW9C,EAX8C;AAAA;;AAAA","sourcesContent":["import type {\n DefaultRouterOptions,\n InitialState,\n NavigationAction,\n NavigationState,\n ParamListBase,\n PartialState,\n Route,\n} from '@react-navigation/routers';\nimport type * as React from 'react';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace ReactNavigation {\n // eslint-disable-next-line @typescript-eslint/no-empty-interface\n interface RootParamList {}\n }\n}\n\ntype Keyof<T extends {}> = Extract<keyof T, string>;\n\nexport type DefaultNavigatorOptions<\n ParamList extends ParamListBase,\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n> = DefaultRouterOptions<Keyof<ParamList>> & {\n /**\n * Optional ID for the navigator. Can be used with `navigation.getParent(id)` to refer to a parent.\n */\n id?: string;\n /**\n * Children React Elements to extract the route configuration from.\n * Only `Screen`, `Group` and `React.Fragment` are supported as children.\n */\n children: React.ReactNode;\n /**\n * Event listeners for all the screens in the navigator.\n */\n screenListeners?:\n | ScreenListeners<State, EventMap>\n | ((props: {\n route: RouteProp<ParamList>;\n navigation: any;\n }) => ScreenListeners<State, EventMap>);\n /**\n * Default options for all screens under this navigator.\n */\n screenOptions?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamList>;\n navigation: any;\n }) => ScreenOptions);\n /**\n * Default options specified by the navigator.\n * It receives the custom options in the arguments if a function is specified.\n */\n defaultScreenOptions?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamList>;\n navigation: any;\n options: ScreenOptions;\n }) => ScreenOptions);\n};\n\nexport type EventMapBase = Record<\n string,\n { data?: any; canPreventDefault?: boolean }\n>;\n\nexport type EventMapCore<State extends NavigationState> = {\n focus: { data: undefined };\n blur: { data: undefined };\n state: { data: { state: State } };\n beforeRemove: { data: { action: NavigationAction }; canPreventDefault: true };\n};\n\nexport type EventArg<\n EventName extends string,\n CanPreventDefault extends boolean | undefined = false,\n Data = undefined\n> = {\n /**\n * Type of the event (e.g. `focus`, `blur`)\n */\n readonly type: EventName;\n readonly target?: string;\n} & (CanPreventDefault extends true\n ? {\n /**\n * Whether `event.preventDefault()` was called on this event object.\n */\n readonly defaultPrevented: boolean;\n /**\n * Prevent the default action which happens on this event.\n */\n preventDefault(): void;\n }\n : {}) &\n (undefined extends Data\n ? { readonly data?: Readonly<Data> }\n : { readonly data: Readonly<Data> });\n\nexport type EventListenerCallback<\n EventMap extends EventMapBase,\n EventName extends keyof EventMap\n> = (\n e: EventArg<\n Extract<EventName, string>,\n EventMap[EventName]['canPreventDefault'],\n EventMap[EventName]['data']\n >\n) => void;\n\nexport type EventConsumer<EventMap extends EventMapBase> = {\n /**\n * Subscribe to events from the parent navigator.\n *\n * @param type Type of the event (e.g. `focus`, `blur`)\n * @param callback Callback listener which is executed upon receiving the event.\n */\n addListener<EventName extends Keyof<EventMap>>(\n type: EventName,\n callback: EventListenerCallback<EventMap, EventName>\n ): () => void;\n removeListener<EventName extends Keyof<EventMap>>(\n type: EventName,\n callback: EventListenerCallback<EventMap, EventName>\n ): void;\n};\n\nexport type EventEmitter<EventMap extends EventMapBase> = {\n /**\n * Emit an event to child screens.\n *\n * @param options.type Type of the event (e.g. `focus`, `blur`)\n * @param [options.data] Optional information regarding the event.\n * @param [options.target] Key of the target route which should receive the event.\n * If not specified, all routes receive the event.\n */\n emit<EventName extends Keyof<EventMap>>(\n options: {\n type: EventName;\n target?: string;\n } & (EventMap[EventName]['canPreventDefault'] extends true\n ? { canPreventDefault: true }\n : {}) &\n (undefined extends EventMap[EventName]['data']\n ? { data?: EventMap[EventName]['data'] }\n : { data: EventMap[EventName]['data'] })\n ): EventArg<\n EventName,\n EventMap[EventName]['canPreventDefault'],\n EventMap[EventName]['data']\n >;\n};\n\nexport class PrivateValueStore<T extends [any, any, any]> {\n /**\n * UGLY HACK! DO NOT USE THE TYPE!!!\n *\n * TypeScript requires a type to be used to be able to infer it.\n * The type should exist as its own without any operations such as union.\n * So we need to figure out a way to store this type in a property.\n * The problem with a normal property is that it shows up in intelliSense.\n * Adding private keyword works, but the annotation is stripped away in declaration.\n * Turns out if we use an empty string, it doesn't show up in intelliSense.\n */\n protected ''?: T;\n}\n\ntype NavigationHelpersCommon<\n ParamList extends ParamListBase,\n State extends NavigationState = NavigationState\n> = {\n /**\n * Dispatch an action or an update function to the router.\n * The update function will receive the current state,\n *\n * @param action Action object or update function.\n */\n dispatch(\n action: NavigationAction | ((state: State) => NavigationAction)\n ): void;\n\n /**\n * Navigate to a route in current navigation tree.\n *\n * @param name Name of the route to navigate to.\n * @param [params] Params object for the route.\n */\n navigate<RouteName extends keyof ParamList>(\n ...args: undefined extends ParamList[RouteName]\n ? [screen: RouteName] | [screen: RouteName, params: ParamList[RouteName]]\n : [screen: RouteName, params: ParamList[RouteName]]\n ): void;\n\n /**\n * Navigate to a route in current navigation tree.\n *\n * @param route Object with `key` or `name` for the route to navigate to, and a `params` object.\n */\n navigate<RouteName extends keyof ParamList>(\n options:\n | { key: string; params?: ParamList[RouteName]; merge?: boolean }\n | {\n name: RouteName;\n key?: string;\n params: ParamList[RouteName];\n merge?: boolean;\n }\n ): void;\n\n /**\n * Reset the navigation state to the provided state.\n *\n * @param state Navigation state object.\n */\n reset(state: PartialState<State> | State): void;\n\n /**\n * Go back to the previous route in history.\n */\n goBack(): void;\n\n /**\n * Check if the screen is focused. The method returns `true` if focused, `false` otherwise.\n * Note that this method doesn't re-render screen when the focus changes. So don't use it in `render`.\n * To get notified of focus changes, use `addListener('focus', cb)` and `addListener('blur', cb)`.\n * To conditionally render content based on focus state, use the `useIsFocused` hook.\n */\n isFocused(): boolean;\n\n /**\n * Check if dispatching back action will be handled by navigation.\n * Note that this method doesn't re-render screen when the result changes. So don't use it in `render`.\n */\n canGoBack(): boolean;\n\n /**\n * Returns the name of the navigator specified in the `name` prop.\n * If no name is specified, returns `undefined`.\n */\n getId(): string | undefined;\n\n /**\n * Returns the navigation helpers from a parent navigator based on the ID.\n * If an ID is provided, the navigation helper from the parent navigator with matching ID (including current) will be returned.\n * If no ID is provided, the navigation helper from the immediate parent navigator will be returned.\n *\n * @param id Optional ID of a parent navigator.\n */\n getParent<T = NavigationHelpers<ParamListBase> | undefined>(id?: string): T;\n\n /**\n * Returns the navigator's state.\n * Note that this method doesn't re-render screen when the result changes. So don't use it in `render`.\n */\n getState(): State;\n} & PrivateValueStore<[ParamList, unknown, unknown]>;\n\nexport type NavigationHelpers<\n ParamList extends ParamListBase,\n EventMap extends EventMapBase = {}\n> = NavigationHelpersCommon<ParamList> &\n EventEmitter<EventMap> & {\n /**\n * Update the param object for the route.\n * The new params will be shallow merged with the old one.\n *\n * @param params Params object for the current route.\n */\n setParams<RouteName extends keyof ParamList>(\n params: Partial<ParamList[RouteName]>\n ): void;\n };\n\nexport type NavigationContainerProps = {\n /**\n * Initial navigation state for the child navigators.\n */\n initialState?: InitialState;\n /**\n * Callback which is called with the latest navigation state when it changes.\n */\n onStateChange?: (state: NavigationState | undefined) => void;\n /**\n * Callback which is called when an action is not handled.\n */\n onUnhandledAction?: (action: NavigationAction) => void;\n /**\n * Whether this navigation container should be independent of parent containers.\n * If this is not set to `true`, this container cannot be nested inside another container.\n * Setting it to `true` disconnects any children navigators from parent container.\n */\n independent?: boolean;\n /**\n * Children elements to render.\n */\n children: React.ReactNode;\n};\n\nexport type NavigationProp<\n ParamList extends {},\n RouteName extends keyof ParamList = Keyof<ParamList>,\n NavigatorID extends string | undefined = undefined,\n State extends NavigationState = NavigationState<ParamList>,\n ScreenOptions extends {} = {},\n EventMap extends EventMapBase = {}\n> = Omit<NavigationHelpersCommon<ParamList, State>, 'getParent'> & {\n /**\n * Returns the navigation prop from a parent navigator based on the ID.\n * If an ID is provided, the navigation prop from the parent navigator with matching ID (including current) will be returned.\n * If no ID is provided, the navigation prop from the immediate parent navigator will be returned.\n *\n * @param id Optional ID of a parent navigator.\n */\n getParent<T = NavigationProp<ParamListBase> | undefined>(id?: NavigatorID): T;\n\n /**\n * Update the param object for the route.\n * The new params will be shallow merged with the old one.\n *\n * @param params Params object for the current route.\n */\n setParams(params: Partial<ParamList[RouteName]>): void;\n\n /**\n * Update the options for the route.\n * The options object will be shallow merged with default options object.\n *\n * @param options Options object for the route.\n */\n setOptions(options: Partial<ScreenOptions>): void;\n} & EventConsumer<EventMap & EventMapCore<State>> &\n PrivateValueStore<[ParamList, RouteName, EventMap]>;\n\nexport type RouteProp<\n ParamList extends ParamListBase,\n RouteName extends keyof ParamList = Keyof<ParamList>\n> = Route<Extract<RouteName, string>, ParamList[RouteName]>;\n\nexport type CompositeNavigationProp<\n A extends NavigationProp<ParamListBase, string, any, any, any>,\n B extends NavigationHelpersCommon<ParamListBase, any>\n> = Omit<A & B, keyof NavigationProp<any>> &\n NavigationProp<\n /**\n * Param list from both navigation objects needs to be combined\n * For example, we should be able to navigate to screens in both A and B\n */\n (A extends NavigationHelpersCommon<infer T> ? T : never) &\n (B extends NavigationHelpersCommon<infer U> ? U : never),\n /**\n * The route name should refer to the route name specified in the first type\n * Ideally it should work for any of them, but it's not possible to infer that way\n */\n A extends NavigationProp<any, infer R> ? R : string,\n /**\n * ID from both navigation objects needs to be combined for `getParent`\n */\n | (A extends NavigationProp<any, any, infer I> ? I : never)\n | (B extends NavigationProp<any, any, infer J> ? J : never),\n /**\n * The type of state should refer to the state specified in the first type\n */\n A extends NavigationProp<any, any, any, infer S> ? S : NavigationState,\n /**\n * Screen options from both navigation objects needs to be combined\n * This allows typechecking `setOptions`\n */\n (A extends NavigationProp<any, any, any, any, infer O> ? O : {}) &\n (B extends NavigationProp<any, any, any, any, infer P> ? P : {}),\n /**\n * Event consumer config should refer to the config specified in the first type\n * This allows typechecking `addListener`/`removeListener`\n */\n A extends NavigationProp<any, any, any, any, any, infer E> ? E : {}\n >;\n\nexport type CompositeScreenProps<\n A extends {\n navigation: NavigationProp<\n ParamListBase,\n string,\n string | undefined,\n any,\n any,\n any\n >;\n route: RouteProp<ParamListBase>;\n },\n B extends {\n navigation: NavigationHelpersCommon<any, any>;\n }\n> = {\n navigation: CompositeNavigationProp<A['navigation'], B['navigation']>;\n route: A['route'];\n};\n\nexport type Descriptor<\n ScreenOptions extends {},\n Navigation extends NavigationProp<any, any, any, any, any, any>,\n Route extends RouteProp<any, any>\n> = {\n /**\n * Render the component associated with this route.\n */\n render(): JSX.Element;\n\n /**\n * Options for the route.\n */\n options: ScreenOptions;\n\n /**\n * Route object for the screen\n */\n route: Route;\n\n /**\n * Navigation object for the screen\n */\n navigation: Navigation;\n};\n\nexport type ScreenListeners<\n State extends NavigationState,\n EventMap extends EventMapBase\n> = Partial<{\n [EventName in keyof (EventMap & EventMapCore<State>)]: EventListenerCallback<\n EventMap,\n EventName\n >;\n}>;\n\nexport type RouteConfigComponent<\n ParamList extends ParamListBase,\n RouteName extends keyof ParamList\n> =\n | {\n /**\n * React component to render for this screen.\n */\n component: React.ComponentType<any>;\n getComponent?: never;\n children?: never;\n }\n | {\n /**\n * Lazily get a React component to render for this screen.\n */\n getComponent: () => React.ComponentType<any>;\n component?: never;\n children?: never;\n }\n | {\n /**\n * Render callback to render content of this screen.\n */\n children: (props: {\n route: RouteProp<ParamList, RouteName>;\n navigation: any;\n }) => React.ReactNode;\n component?: never;\n getComponent?: never;\n };\n\nexport type RouteConfig<\n ParamList extends ParamListBase,\n RouteName extends keyof ParamList,\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n> = {\n /**\n * Optional key for this screen. This doesn't need to be unique.\n * If the key changes, existing screens with this name will be removed or reset.\n * Useful when we have some common screens and have conditional rendering.\n */\n navigationKey?: string;\n\n /**\n * Route name of this screen.\n */\n name: RouteName;\n\n /**\n * Navigator options for this screen.\n */\n options?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamList, RouteName>;\n navigation: any;\n }) => ScreenOptions);\n\n /**\n * Event listeners for this screen.\n */\n listeners?:\n | ScreenListeners<State, EventMap>\n | ((props: {\n route: RouteProp<ParamList, RouteName>;\n navigation: any;\n }) => ScreenListeners<State, EventMap>);\n\n /**\n * Function to return an unique ID for this screen.\n * Receives an object with the route params.\n * For a given screen name, there will always be only one screen corresponding to an ID.\n * If `undefined` is returned, it acts same as no `getId` being specified.\n */\n getId?: ({ params }: { params: ParamList[RouteName] }) => string | undefined;\n\n /**\n * Initial params object for the route.\n */\n initialParams?: Partial<ParamList[RouteName]>;\n} & RouteConfigComponent<ParamList, RouteName>;\n\nexport type RouteGroupConfig<\n ParamList extends ParamListBase,\n ScreenOptions extends {}\n> = {\n /**\n * Optional key for the screens in this group.\n * If the key changes, all existing screens in this group will be removed or reset.\n */\n navigationKey?: string;\n\n /**\n * Navigator options for this screen.\n */\n screenOptions?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamList, keyof ParamList>;\n navigation: any;\n }) => ScreenOptions);\n /**\n * Children React Elements to extract the route configuration from.\n * Only `Screen`, `Group` and `React.Fragment` are supported as children.\n */\n children: React.ReactNode;\n};\n\nexport type NavigationContainerEventMap = {\n /**\n * Event which fires when the navigation state changes.\n */\n state: {\n data: {\n /**\n * The updated state object after the state change.\n */\n state: NavigationState | PartialState<NavigationState> | undefined;\n };\n };\n /**\n * Event which fires when current options changes.\n */\n options: { data: { options: object } };\n /**\n * Event which fires when an action is dispatched.\n * Only intended for debugging purposes, don't use it for app logic.\n * This event will be emitted before state changes have been applied.\n */\n __unsafe_action__: {\n data: {\n /**\n * The action object which was dispatched.\n */\n action: NavigationAction;\n /**\n * Whether the action was a no-op, i.e. resulted any state changes.\n */\n noop: boolean;\n /**\n * Stack trace of the action, this will only be available during development.\n */\n stack: string | undefined;\n };\n };\n};\n\nexport type NavigationContainerRef<ParamList extends {}> =\n NavigationHelpers<ParamList> &\n EventConsumer<NavigationContainerEventMap> & {\n /**\n * Reset the navigation state of the root navigator to the provided state.\n *\n * @param state Navigation state object.\n */\n resetRoot(state?: PartialState<NavigationState> | NavigationState): void;\n /**\n * Get the rehydrated navigation state of the navigation tree.\n */\n getRootState(): NavigationState;\n /**\n * Get the currently focused navigation route.\n */\n getCurrentRoute(): Route<string> | undefined;\n /**\n * Get the currently focused route's options.\n */\n getCurrentOptions(): object | undefined;\n /**\n * Whether the navigation container is ready to handle actions.\n */\n isReady(): boolean;\n };\n\nexport type NavigationContainerRefWithCurrent<ParamList extends {}> =\n NavigationContainerRef<ParamList> & {\n current: NavigationContainerRef<ParamList> | null;\n };\n\nexport type TypedNavigator<\n ParamList extends ParamListBase,\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase,\n Navigator extends React.ComponentType<any>\n> = {\n /**\n * Navigator component which manages the child screens.\n */\n Navigator: React.ComponentType<\n Omit<\n React.ComponentProps<Navigator>,\n keyof DefaultNavigatorOptions<any, any, any, any>\n > &\n DefaultNavigatorOptions<ParamList, State, ScreenOptions, EventMap>\n >;\n /**\n * Component used for grouping multiple route configuration.\n */\n Group: React.ComponentType<RouteGroupConfig<ParamList, ScreenOptions>>;\n /**\n * Component used for specifying route configuration.\n */\n Screen: <RouteName extends keyof ParamList>(\n _: RouteConfig<ParamList, RouteName, State, ScreenOptions, EventMap>\n ) => null;\n};\n\nexport type NavigatorScreenParams<\n ParamList,\n State extends NavigationState = NavigationState\n> =\n | {\n screen?: never;\n params?: never;\n initial?: never;\n path?: string;\n state: PartialState<State> | State | undefined;\n }\n | {\n [RouteName in keyof ParamList]: undefined extends ParamList[RouteName]\n ? {\n screen: RouteName;\n params?: ParamList[RouteName];\n initial?: boolean;\n path?: string;\n state?: never;\n }\n : {\n screen: RouteName;\n params: ParamList[RouteName];\n initial?: boolean;\n path?: string;\n state?: never;\n };\n }[keyof ParamList];\n\nexport type PathConfig<ParamList extends {}> = {\n path?: string;\n exact?: boolean;\n parse?: Record<string, (value: string) => any>;\n stringify?: Record<string, (value: any) => string>;\n screens?: PathConfigMap<ParamList>;\n initialRouteName?: keyof ParamList;\n};\n\nexport type PathConfigMap<ParamList extends {}> = {\n [RouteName in keyof ParamList]?: NonNullable<\n ParamList[RouteName]\n > extends NavigatorScreenParams<infer T, any>\n ? string | PathConfig<T>\n : string | Omit<PathConfig<{}>, 'screens' | 'initialRouteName'>;\n};\n"]}
|
|
@@ -11,12 +11,15 @@ export default function useChildListeners() {
|
|
|
11
11
|
focus: []
|
|
12
12
|
});
|
|
13
13
|
const addListener = React.useCallback((type, listener) => {
|
|
14
|
-
// @ts-expect-error: listener should be correct type according to `type`
|
|
15
14
|
listeners[type].push(listener);
|
|
15
|
+
let removed = false;
|
|
16
16
|
return () => {
|
|
17
|
-
// @ts-expect-error: listener should be correct type according to `type`
|
|
18
17
|
const index = listeners[type].indexOf(listener);
|
|
19
|
-
|
|
18
|
+
|
|
19
|
+
if (!removed && index > -1) {
|
|
20
|
+
removed = true;
|
|
21
|
+
listeners[type].splice(index, 1);
|
|
22
|
+
}
|
|
20
23
|
};
|
|
21
24
|
}, [listeners]);
|
|
22
25
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useChildListeners.tsx"],"names":["React","useChildListeners","current","listeners","useRef","action","focus","addListener","useCallback","type","listener","push","index","indexOf","splice"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAIA;AACA;AACA;AACA,eAAe,SAASC,iBAAT,GAA6B;AAC1C,QAAM;AAAEC,IAAAA,OAAO,EAAEC;AAAX,MAAyBH,KAAK,CAACI,MAAN,CAE5B;AACDC,IAAAA,MAAM,EAAE,EADP;AAEDC,IAAAA,KAAK,EAAE;AAFN,GAF4B,CAA/B;AAOA,QAAMC,WAAW,GAAGP,KAAK,CAACQ,WAAN,CAClB,CAA8BC,IAA9B,EAAuCC,QAAvC,KAAoE;
|
|
1
|
+
{"version":3,"sources":["useChildListeners.tsx"],"names":["React","useChildListeners","current","listeners","useRef","action","focus","addListener","useCallback","type","listener","push","removed","index","indexOf","splice"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAIA;AACA;AACA;AACA,eAAe,SAASC,iBAAT,GAA6B;AAC1C,QAAM;AAAEC,IAAAA,OAAO,EAAEC;AAAX,MAAyBH,KAAK,CAACI,MAAN,CAE5B;AACDC,IAAAA,MAAM,EAAE,EADP;AAEDC,IAAAA,KAAK,EAAE;AAFN,GAF4B,CAA/B;AAOA,QAAMC,WAAW,GAAGP,KAAK,CAACQ,WAAN,CAClB,CAA8BC,IAA9B,EAAuCC,QAAvC,KAAoE;AAClEP,IAAAA,SAAS,CAACM,IAAD,CAAT,CAAgBE,IAAhB,CAAqBD,QAArB;AAEA,QAAIE,OAAO,GAAG,KAAd;AACA,WAAO,MAAM;AACX,YAAMC,KAAK,GAAGV,SAAS,CAACM,IAAD,CAAT,CAAgBK,OAAhB,CAAwBJ,QAAxB,CAAd;;AAEA,UAAI,CAACE,OAAD,IAAYC,KAAK,GAAG,CAAC,CAAzB,EAA4B;AAC1BD,QAAAA,OAAO,GAAG,IAAV;AACAT,QAAAA,SAAS,CAACM,IAAD,CAAT,CAAgBM,MAAhB,CAAuBF,KAAvB,EAA8B,CAA9B;AACD;AACF,KAPD;AAQD,GAbiB,EAclB,CAACV,SAAD,CAdkB,CAApB;AAiBA,SAAO;AACLA,IAAAA,SADK;AAELI,IAAAA;AAFK,GAAP;AAID","sourcesContent":["import * as React from 'react';\n\nimport type { ListenerMap } from './NavigationBuilderContext';\n\n/**\n * Hook which lets child navigators add action listeners.\n */\nexport default function useChildListeners() {\n const { current: listeners } = React.useRef<{\n [K in keyof ListenerMap]: ListenerMap[K][];\n }>({\n action: [],\n focus: [],\n });\n\n const addListener = React.useCallback(\n <T extends keyof ListenerMap>(type: T, listener: ListenerMap[T]) => {\n listeners[type].push(listener);\n\n let removed = false;\n return () => {\n const index = listeners[type].indexOf(listener);\n\n if (!removed && index > -1) {\n removed = true;\n listeners[type].splice(index, 1);\n }\n };\n },\n [listeners]\n );\n\n return {\n listeners,\n addListener,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useDescriptors.tsx"],"names":["React","NavigationBuilderContext","NavigationContext","NavigationRouteContext","SceneView","useNavigationCache","useRouteCache","useDescriptors","state","screens","navigation","screenOptions","defaultScreenOptions","onAction","getState","setState","addListener","addKeyedListener","onRouteFocus","router","emitter","options","setOptions","useState","onDispatchAction","onOptionsChange","stackRef","useContext","context","useMemo","navigations","routes","reduce","acc","route","i","config","name","screen","props","key","optionsList","filter","Boolean","customOptions","curr","Object","assign","mergedOptions","clearOptions","o","_","rest","render"],"mappings":"AAMA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,wBAAP,MAGO,4BAHP;AAIA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,sBAAP,MAAmC,0BAAnC;AACA,OAAOC,SAAP,MAAsB,aAAtB;AAUA,OAAOC,kBAAP,MAA+B,sBAA/B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;;AAgDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,cAAT,OAmB6B;AAAA,MAd1C;AACAC,IAAAA,KADA;AAEAC,IAAAA,OAFA;AAGAC,IAAAA,UAHA;AAIAC,IAAAA,aAJA;AAKAC,IAAAA,oBALA;AAMAC,IAAAA,QANA;AAOAC,IAAAA,QAPA;AAQAC,IAAAA,QARA;AASAC,IAAAA,WATA;AAUAC,IAAAA,gBAVA;AAWAC,IAAAA,YAXA;AAYAC,IAAAA,MAZA;AAaAC,IAAAA;AAbA,GAc0C;AAC1C,QAAM,CAACC,OAAD,EAAUC,UAAV,IAAwBtB,KAAK,CAACuB,QAAN,CAAuC,EAAvC,CAA9B;AACA,QAAM;AAAEC,IAAAA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EE,UAAA,KAAK,EAAEwB,KAFT;AAGE,UAAA,MAAM,EAAEI,MAHV;AAIE,UAAA,UAAU,EAAE9B,KAAK,CAACuB,MAAN,CAAaI,CAAb,EAAgB3B,KAJ9B;AAKE,UAAA,QAAQ,EAAEM,QALZ;AAME,UAAA,QAAQ,EAAEC,QANZ;AAOE,UAAA,OAAO,EAAEiC,aAPX;AAQE,UAAA,YAAY,EAAEC;AARhB,UADF,CADF,CADF,CADF;AAkBD,OAvBc;;AAwBf5B,MAAAA,OAAO,EAAE2B;AAxBM,KAAjB;AA2BA,WAAOf,GAAP;AACD,GAxFM,EAwFJ,EAxFI,CAAP;AAyFD","sourcesContent":["import type {\n NavigationAction,\n NavigationState,\n ParamListBase,\n Router,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationBuilderContext, {\n AddKeyedListener,\n AddListener,\n} from './NavigationBuilderContext';\nimport NavigationContext from './NavigationContext';\nimport NavigationRouteContext from './NavigationRouteContext';\nimport SceneView from './SceneView';\nimport type {\n Descriptor,\n EventMapBase,\n NavigationHelpers,\n NavigationProp,\n RouteConfig,\n RouteProp,\n} from './types';\nimport type { NavigationEventEmitter } from './useEventEmitter';\nimport useNavigationCache from './useNavigationCache';\nimport useRouteCache from './useRouteCache';\n\nexport type ScreenConfigWithParent<\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n> = {\n keys: (string | undefined)[];\n options: (ScreenOptionsOrCallback<ScreenOptions> | undefined)[] | undefined;\n props: RouteConfig<ParamListBase, string, State, ScreenOptions, EventMap>;\n};\n\ntype ScreenOptionsOrCallback<ScreenOptions extends {}> =\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamListBase, string>;\n navigation: any;\n }) => ScreenOptions);\n\ntype Options<\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n> = {\n state: State;\n screens: Record<\n string,\n ScreenConfigWithParent<State, ScreenOptions, EventMap>\n >;\n navigation: NavigationHelpers<ParamListBase>;\n screenOptions?: ScreenOptionsOrCallback<ScreenOptions>;\n defaultScreenOptions?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamListBase>;\n navigation: any;\n options: ScreenOptions;\n }) => ScreenOptions);\n onAction: (action: NavigationAction) => boolean;\n getState: () => State;\n setState: (state: State) => void;\n addListener: AddListener;\n addKeyedListener: AddKeyedListener;\n onRouteFocus: (key: string) => void;\n router: Router<State, NavigationAction>;\n emitter: NavigationEventEmitter<EventMap>;\n};\n\n/**\n * Hook to create descriptor objects for the child routes.\n *\n * A descriptor object provides 3 things:\n * - Helper method to render a screen\n * - Options specified by the screen for the navigator\n * - Navigation object intended for the route\n */\nexport default function useDescriptors<\n State extends NavigationState,\n ActionHelpers extends Record<string, () => void>,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n>({\n state,\n screens,\n navigation,\n screenOptions,\n defaultScreenOptions,\n onAction,\n getState,\n setState,\n addListener,\n addKeyedListener,\n onRouteFocus,\n router,\n emitter,\n}: Options<State, ScreenOptions, EventMap>) {\n const [options, setOptions] = React.useState<Record<string, object>>({});\n const { onDispatchAction, onOptionsChange, stackRef } = React.useContext(\n NavigationBuilderContext\n );\n\n const context = React.useMemo(\n () => ({\n navigation,\n onAction,\n addListener,\n addKeyedListener,\n onRouteFocus,\n onDispatchAction,\n onOptionsChange,\n stackRef,\n }),\n [\n navigation,\n onAction,\n addListener,\n addKeyedListener,\n onRouteFocus,\n onDispatchAction,\n onOptionsChange,\n stackRef,\n ]\n );\n\n const navigations = useNavigationCache<State, ScreenOptions, EventMap>({\n state,\n getState,\n navigation,\n setOptions,\n router,\n emitter,\n });\n\n const routes = useRouteCache(state.routes);\n\n return routes.reduce<\n Record<\n string,\n Descriptor<\n ScreenOptions,\n NavigationProp<ParamListBase, string, State, ScreenOptions, EventMap> &\n ActionHelpers,\n RouteProp<ParamListBase>\n >\n >\n >((acc, route, i) => {\n const config = screens[route.name];\n const screen = config.props;\n const navigation = navigations[route.key];\n\n const optionsList = [\n // The default `screenOptions` passed to the navigator\n screenOptions,\n // The `screenOptions` props passed to `Group` elements\n ...((config.options\n ? config.options.filter(Boolean)\n : []) as ScreenOptionsOrCallback<ScreenOptions>[]),\n // The `options` prop passed to `Screen` elements,\n screen.options,\n // The options set via `navigation.setOptions`\n options[route.key],\n ];\n\n const customOptions = optionsList.reduce<ScreenOptions>(\n (acc, curr) =>\n Object.assign(\n acc,\n typeof curr !== 'function' ? curr : curr({ route, navigation })\n ),\n {} as ScreenOptions\n );\n\n const mergedOptions = {\n ...(typeof defaultScreenOptions === 'function'\n ? // @ts-expect-error: ts gives incorrect error here\n defaultScreenOptions({\n route,\n navigation,\n options: customOptions,\n })\n : defaultScreenOptions),\n ...customOptions,\n };\n\n const clearOptions = () =>\n setOptions((o) => {\n if (route.key in o) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { [route.key]: _, ...rest } = o;\n return rest;\n }\n\n return o;\n });\n\n acc[route.key] = {\n route,\n // @ts-expect-error: it's missing action helpers, fix later\n navigation,\n render() {\n return (\n <NavigationBuilderContext.Provider key={route.key} value={context}>\n <NavigationContext.Provider value={navigation}>\n <NavigationRouteContext.Provider value={route}>\n <SceneView\n navigation={navigation}\n route={route}\n screen={screen}\n routeState={state.routes[i].state}\n getState={getState}\n setState={setState}\n options={mergedOptions}\n clearOptions={clearOptions}\n />\n </NavigationRouteContext.Provider>\n </NavigationContext.Provider>\n </NavigationBuilderContext.Provider>\n );\n },\n options: mergedOptions as ScreenOptions,\n };\n\n return acc;\n }, {});\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["useDescriptors.tsx"],"names":["React","NavigationBuilderContext","NavigationContext","NavigationRouteContext","SceneView","useNavigationCache","useRouteCache","useDescriptors","state","screens","navigation","screenOptions","defaultScreenOptions","onAction","getState","setState","addListener","addKeyedListener","onRouteFocus","router","emitter","options","setOptions","useState","onDispatchAction","onOptionsChange","stackRef","useContext","context","useMemo","navigations","routes","reduce","acc","route","i","config","name","screen","props","key","optionsList","filter","Boolean","customOptions","curr","Object","assign","mergedOptions","clearOptions","o","_","rest","render"],"mappings":"AAMA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,wBAAP,MAGO,4BAHP;AAIA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,sBAAP,MAAmC,0BAAnC;AACA,OAAOC,SAAP,MAAsB,aAAtB;AAUA,OAAOC,kBAAP,MAA+B,sBAA/B;AACA,OAAOC,aAAP,MAA0B,iBAA1B;;AAgDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,cAAT,OAmB6B;AAAA,MAd1C;AACAC,IAAAA,KADA;AAEAC,IAAAA,OAFA;AAGAC,IAAAA,UAHA;AAIAC,IAAAA,aAJA;AAKAC,IAAAA,oBALA;AAMAC,IAAAA,QANA;AAOAC,IAAAA,QAPA;AAQAC,IAAAA,QARA;AASAC,IAAAA,WATA;AAUAC,IAAAA,gBAVA;AAWAC,IAAAA,YAXA;AAYAC,IAAAA,MAZA;AAaAC,IAAAA;AAbA,GAc0C;AAC1C,QAAM,CAACC,OAAD,EAAUC,UAAV,IAAwBtB,KAAK,CAACuB,QAAN,CAAuC,EAAvC,CAA9B;AACA,QAAM;AAAEC,IAAAA,gBAAF;AAAoBC,IAAAA,eAApB;AAAqCC,IAAAA;AAArC,MAAkD1B,KAAK,CAAC2B,UAAN,CACtD1B,wBADsD,CAAxD;AAIA,QAAM2B,OAAO,GAAG5B,KAAK,CAAC6B,OAAN,CACd,OAAO;AACLnB,IAAAA,UADK;AAELG,IAAAA,QAFK;AAGLG,IAAAA,WAHK;AAILC,IAAAA,gBAJK;AAKLC,IAAAA,YALK;AAMLM,IAAAA,gBANK;AAOLC,IAAAA,eAPK;AAQLC,IAAAA;AARK,GAAP,CADc,EAWd,CACEhB,UADF,EAEEG,QAFF,EAGEG,WAHF,EAIEC,gBAJF,EAKEC,YALF,EAMEM,gBANF,EAOEC,eAPF,EAQEC,QARF,CAXc,CAAhB;AA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\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationBuilderContext, {\n AddKeyedListener,\n AddListener,\n} from './NavigationBuilderContext';\nimport NavigationContext from './NavigationContext';\nimport NavigationRouteContext from './NavigationRouteContext';\nimport SceneView from './SceneView';\nimport type {\n Descriptor,\n EventMapBase,\n NavigationHelpers,\n NavigationProp,\n RouteConfig,\n RouteProp,\n} from './types';\nimport type { NavigationEventEmitter } from './useEventEmitter';\nimport useNavigationCache from './useNavigationCache';\nimport useRouteCache from './useRouteCache';\n\nexport type ScreenConfigWithParent<\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n> = {\n keys: (string | undefined)[];\n options: (ScreenOptionsOrCallback<ScreenOptions> | undefined)[] | undefined;\n props: RouteConfig<ParamListBase, string, State, ScreenOptions, EventMap>;\n};\n\ntype ScreenOptionsOrCallback<ScreenOptions extends {}> =\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamListBase, string>;\n navigation: any;\n }) => ScreenOptions);\n\ntype Options<\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n> = {\n state: State;\n screens: Record<\n string,\n ScreenConfigWithParent<State, ScreenOptions, EventMap>\n >;\n navigation: NavigationHelpers<ParamListBase>;\n screenOptions?: ScreenOptionsOrCallback<ScreenOptions>;\n defaultScreenOptions?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamListBase>;\n navigation: any;\n options: ScreenOptions;\n }) => ScreenOptions);\n onAction: (action: NavigationAction) => boolean;\n getState: () => State;\n setState: (state: State) => void;\n addListener: AddListener;\n addKeyedListener: AddKeyedListener;\n onRouteFocus: (key: string) => void;\n router: Router<State, NavigationAction>;\n emitter: NavigationEventEmitter<EventMap>;\n};\n\n/**\n * Hook to create descriptor objects for the child routes.\n *\n * A descriptor object provides 3 things:\n * - Helper method to render a screen\n * - Options specified by the screen for the navigator\n * - Navigation object intended for the route\n */\nexport default function useDescriptors<\n State extends NavigationState,\n ActionHelpers extends Record<string, () => void>,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n>({\n state,\n screens,\n navigation,\n screenOptions,\n defaultScreenOptions,\n onAction,\n getState,\n setState,\n addListener,\n addKeyedListener,\n onRouteFocus,\n router,\n emitter,\n}: Options<State, ScreenOptions, EventMap>) {\n const [options, setOptions] = React.useState<Record<string, object>>({});\n const { onDispatchAction, onOptionsChange, stackRef } = React.useContext(\n NavigationBuilderContext\n );\n\n const context = React.useMemo(\n () => ({\n navigation,\n onAction,\n addListener,\n addKeyedListener,\n onRouteFocus,\n onDispatchAction,\n onOptionsChange,\n stackRef,\n }),\n [\n navigation,\n onAction,\n addListener,\n addKeyedListener,\n onRouteFocus,\n onDispatchAction,\n onOptionsChange,\n stackRef,\n ]\n );\n\n const navigations = useNavigationCache<State, ScreenOptions, EventMap>({\n state,\n getState,\n navigation,\n setOptions,\n router,\n emitter,\n });\n\n const routes = useRouteCache(state.routes);\n\n return routes.reduce<\n Record<\n string,\n Descriptor<\n ScreenOptions,\n NavigationProp<\n ParamListBase,\n string,\n string | undefined,\n State,\n ScreenOptions,\n EventMap\n > &\n ActionHelpers,\n RouteProp<ParamListBase>\n >\n >\n >((acc, route, i) => {\n const config = screens[route.name];\n const screen = config.props;\n const navigation = navigations[route.key];\n\n const optionsList = [\n // The default `screenOptions` passed to the navigator\n screenOptions,\n // The `screenOptions` props passed to `Group` elements\n ...((config.options\n ? config.options.filter(Boolean)\n : []) as ScreenOptionsOrCallback<ScreenOptions>[]),\n // The `options` prop passed to `Screen` elements,\n screen.options,\n // The options set via `navigation.setOptions`\n options[route.key],\n ];\n\n const customOptions = optionsList.reduce<ScreenOptions>(\n (acc, curr) =>\n Object.assign(\n acc,\n typeof curr !== 'function' ? curr : curr({ route, navigation })\n ),\n {} as ScreenOptions\n );\n\n const mergedOptions = {\n ...(typeof defaultScreenOptions === 'function'\n ? // @ts-expect-error: ts gives incorrect error here\n defaultScreenOptions({\n route,\n navigation,\n options: customOptions,\n })\n : defaultScreenOptions),\n ...customOptions,\n };\n\n const clearOptions = () =>\n setOptions((o) => {\n if (route.key in o) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { [route.key]: _, ...rest } = o;\n return rest;\n }\n\n return o;\n });\n\n acc[route.key] = {\n route,\n // @ts-expect-error: it's missing action helpers, fix later\n navigation,\n render() {\n return (\n <NavigationBuilderContext.Provider key={route.key} value={context}>\n <NavigationContext.Provider value={navigation}>\n <NavigationRouteContext.Provider value={route}>\n <SceneView\n navigation={navigation}\n route={route}\n screen={screen}\n routeState={state.routes[i].state}\n getState={getState}\n setState={setState}\n options={mergedOptions}\n clearOptions={clearOptions}\n />\n </NavigationRouteContext.Provider>\n </NavigationContext.Provider>\n </NavigationBuilderContext.Provider>\n );\n },\n options: mergedOptions as ScreenOptions,\n };\n\n return acc;\n }, {});\n}\n"]}
|
|
@@ -18,14 +18,24 @@ export default function useEventEmitter(listen) {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const index = callbacks.indexOf(callback);
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
if (index > -1) {
|
|
23
|
+
callbacks.splice(index, 1);
|
|
24
|
+
}
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
const addListener = (type, callback) => {
|
|
25
28
|
listeners.current[type] = listeners.current[type] || {};
|
|
26
29
|
listeners.current[type][target] = listeners.current[type][target] || [];
|
|
27
30
|
listeners.current[type][target].push(callback);
|
|
28
|
-
|
|
31
|
+
let removed = false;
|
|
32
|
+
return () => {
|
|
33
|
+
// Prevent removing other listeners when unsubscribing same listener multiple times
|
|
34
|
+
if (!removed) {
|
|
35
|
+
removed = true;
|
|
36
|
+
removeListener(type, callback);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
29
39
|
};
|
|
30
40
|
|
|
31
41
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useEventEmitter.tsx"],"names":["React","useEventEmitter","listen","listenRef","useRef","useEffect","current","listeners","create","useCallback","target","removeListener","type","callback","callbacks","undefined","index","indexOf","splice","addListener","push","emit","data","canPreventDefault","items","slice","concat","Object","keys","map","t","filter","cb","i","self","lastIndexOf","event","defineProperty","enumerable","get","defaultPrevented","defineProperties","preventDefault","value","forEach","useMemo"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAWA;AACA;AACA;AACA,eAAe,SAASC,eAAT,CACbC,MADa,EAEc;AAC3B,QAAMC,SAAS,GAAGH,KAAK,CAACI,MAAN,CAAaF,MAAb,CAAlB;AAEAF,EAAAA,KAAK,CAACK,SAAN,CAAgB,MAAM;AACpBF,IAAAA,SAAS,CAACG,OAAV,GAAoBJ,MAApB;AACD,GAFD;AAIA,QAAMK,SAAS,GAAGP,KAAK,CAACI,MAAN,CAAwD,EAAxD,CAAlB;AAEA,QAAMI,MAAM,GAAGR,KAAK,CAACS,WAAN,CAAmBC,MAAD,IAAoB;AACnD,UAAMC,cAAc,GAAG,CAACC,IAAD,EAAeC,QAAf,KAAiD;AACtE,YAAMC,SAAS,GAAGP,SAAS,CAACD,OAAV,CAAkBM,IAAlB,IACdL,SAAS,CAACD,OAAV,CAAkBM,IAAlB,EAAwBF,MAAxB,CADc,GAEdK,SAFJ;;AAIA,UAAI,CAACD,SAAL,EAAgB;AACd;AACD;;AAED,YAAME,KAAK,GAAGF,SAAS,CAACG,OAAV,CAAkBJ,QAAlB,CAAd;
|
|
1
|
+
{"version":3,"sources":["useEventEmitter.tsx"],"names":["React","useEventEmitter","listen","listenRef","useRef","useEffect","current","listeners","create","useCallback","target","removeListener","type","callback","callbacks","undefined","index","indexOf","splice","addListener","push","removed","emit","data","canPreventDefault","items","slice","concat","Object","keys","map","t","filter","cb","i","self","lastIndexOf","event","defineProperty","enumerable","get","defaultPrevented","defineProperties","preventDefault","value","forEach","useMemo"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAWA;AACA;AACA;AACA,eAAe,SAASC,eAAT,CACbC,MADa,EAEc;AAC3B,Q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AG,GAAG;AACJ,iBAAOjB,IAAP;AACD;;AAJkC,OAArC;AAMD;;AAED,QAAIC,iBAAJ,EAAuB;AACrB,UAAIiB,gBAAgB,GAAG,KAAvB;AAEAb,MAAAA,MAAM,CAACc,gBAAP,CAAwBL,KAAxB,EAA+B;AAC7BI,QAAAA,gBAAgB,EAAE;AAChBF,UAAAA,UAAU,EAAE,IADI;;AAEhBC,UAAAA,GAAG,GAAG;AACJ,mBAAOC,gBAAP;AACD;;AAJe,SADW;AAO7BE,QAAAA,cAAc,EAAE;AACdJ,UAAAA,UAAU,EAAE,IADE;;AAEdK,UAAAA,KAAK,GAAG;AACNH,YAAAA,gBAAgB,GAAG,IAAnB;AACD;;AAJa;AAPa,OAA/B;AAcD;;AAED,0BAAAtC,SAAS,CAACG,OAAV,+EAAAH,SAAS,EAAWkC,KAAX,CAAT;AAEAvB,IAAAA,SAAS,SAAT,IAAAA,SAAS,WAAT,YAAAA,SAAS,CAAE+B,OAAX,CAAoBZ,EAAD,IAAQA,EAAE,CAACI,KAAD,CAA7B;AAEA,WAAOA,KAAP;AACD,GAtEU,EAuEX,EAvEW,CAAb;AA0EA,SAAOrC,KAAK,CAAC8C,OAAN,CAAc,OAAO;AAAEtC,IAAAA,MAAF;AAAUc,IAAAA;AAAV,GAAP,CAAd,EAAwC,CAACd,MAAD,EAASc,IAAT,CAAxC,CAAP;AACD","sourcesContent":["import * as React from 'react';\n\nimport type { EventArg, EventConsumer, EventEmitter } from './types';\n\nexport type NavigationEventEmitter<T extends Record<string, any>> =\n EventEmitter<T> & {\n create: (target: string) => EventConsumer<T>;\n };\n\ntype Listeners = ((e: any) => void)[];\n\n/**\n * Hook to manage the event system used by the navigator to notify screens of various events.\n */\nexport default function useEventEmitter<T extends Record<string, any>>(\n listen?: (e: any) => void\n): NavigationEventEmitter<T> {\n const listenRef = React.useRef(listen);\n\n React.useEffect(() => {\n listenRef.current = listen;\n });\n\n const listeners = React.useRef<Record<string, Record<string, Listeners>>>({});\n\n const create = React.useCallback((target: string) => {\n const removeListener = (type: string, callback: (data: any) => void) => {\n const callbacks = listeners.current[type]\n ? listeners.current[type][target]\n : undefined;\n\n if (!callbacks) {\n return;\n }\n\n const index = callbacks.indexOf(callback);\n\n if (index > -1) {\n callbacks.splice(index, 1);\n }\n };\n\n const addListener = (type: string, callback: (data: any) => void) => {\n listeners.current[type] = listeners.current[type] || {};\n listeners.current[type][target] = listeners.current[type][target] || [];\n listeners.current[type][target].push(callback);\n\n let removed = false;\n return () => {\n // Prevent removing other listeners when unsubscribing same listener multiple times\n if (!removed) {\n removed = true;\n removeListener(type, callback);\n }\n };\n };\n\n return {\n addListener,\n removeListener,\n };\n }, []);\n\n const emit = React.useCallback(\n ({\n type,\n data,\n target,\n canPreventDefault,\n }: {\n type: string;\n data?: any;\n target?: string;\n canPreventDefault?: boolean;\n }) => {\n const items = listeners.current[type] || {};\n\n // Copy the current list of callbacks in case they are mutated during execution\n const callbacks =\n target !== undefined\n ? items[target]?.slice()\n : ([] as Listeners)\n .concat(...Object.keys(items).map((t) => items[t]))\n .filter((cb, i, self) => self.lastIndexOf(cb) === i);\n\n const event: EventArg<any, any, any> = {\n get type() {\n return type;\n },\n };\n\n if (target !== undefined) {\n Object.defineProperty(event, 'target', {\n enumerable: true,\n get() {\n return target;\n },\n });\n }\n\n if (data !== undefined) {\n Object.defineProperty(event, 'data', {\n enumerable: true,\n get() {\n return data;\n },\n });\n }\n\n if (canPreventDefault) {\n let defaultPrevented = false;\n\n Object.defineProperties(event, {\n defaultPrevented: {\n enumerable: true,\n get() {\n return defaultPrevented;\n },\n },\n preventDefault: {\n enumerable: true,\n value() {\n defaultPrevented = true;\n },\n },\n });\n }\n\n listenRef.current?.(event);\n\n callbacks?.forEach((cb) => cb(event));\n\n return event as any;\n },\n []\n );\n\n return React.useMemo(() => ({ create, emit }), [create, emit]);\n}\n"]}
|
|
@@ -11,8 +11,10 @@ export default function useKeyedChildListeners() {
|
|
|
11
11
|
beforeRemove: {}
|
|
12
12
|
});
|
|
13
13
|
const addKeyedListener = React.useCallback((type, key, listener) => {
|
|
14
|
+
// @ts-expect-error: according to ref stated above you can use `key` to index type
|
|
14
15
|
keyedListeners[type][key] = listener;
|
|
15
16
|
return () => {
|
|
17
|
+
// @ts-expect-error: according to ref stated above you can use `key` to index type
|
|
16
18
|
keyedListeners[type][key] = undefined;
|
|
17
19
|
};
|
|
18
20
|
}, [keyedListeners]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useKeyedChildListeners.tsx"],"names":["React","useKeyedChildListeners","current","keyedListeners","useRef","getState","beforeRemove","addKeyedListener","useCallback","type","key","listener","undefined"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAIA;AACA;AACA;AACA,eAAe,SAASC,sBAAT,GAAkC;AAC/C,QAAM;AAAEC,IAAAA,OAAO,EAAEC;AAAX,MAA8BH,KAAK,CAACI,MAAN,CAKjC;AACDC,IAAAA,QAAQ,EAAE,EADT;AAEDC,IAAAA,YAAY,EAAE;AAFb,GALiC,CAApC;AAUA,QAAMC,gBAAgB,GAAGP,KAAK,CAACQ,WAAN,CACvB,CACEC,IADF,EAEEC,GAFF,EAGEC,QAHF,KAIK;
|
|
1
|
+
{"version":3,"sources":["useKeyedChildListeners.tsx"],"names":["React","useKeyedChildListeners","current","keyedListeners","useRef","getState","beforeRemove","addKeyedListener","useCallback","type","key","listener","undefined"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;;AAIA;AACA;AACA;AACA,eAAe,SAASC,sBAAT,GAAkC;AAC/C,QAAM;AAAEC,IAAAA,OAAO,EAAEC;AAAX,MAA8BH,KAAK,CAACI,MAAN,CAKjC;AACDC,IAAAA,QAAQ,EAAE,EADT;AAEDC,IAAAA,YAAY,EAAE;AAFb,GALiC,CAApC;AAUA,QAAMC,gBAAgB,GAAGP,KAAK,CAACQ,WAAN,CACvB,CACEC,IADF,EAEEC,GAFF,EAGEC,QAHF,KAIK;AACH;AACAR,IAAAA,cAAc,CAACM,IAAD,CAAd,CAAqBC,GAArB,IAA4BC,QAA5B;AAEA,WAAO,MAAM;AACX;AACAR,MAAAA,cAAc,CAACM,IAAD,CAAd,CAAqBC,GAArB,IAA4BE,SAA5B;AACD,KAHD;AAID,GAbsB,EAcvB,CAACT,cAAD,CAduB,CAAzB;AAiBA,SAAO;AACLA,IAAAA,cADK;AAELI,IAAAA;AAFK,GAAP;AAID","sourcesContent":["import * as React from 'react';\n\nimport type { KeyedListenerMap } from './NavigationBuilderContext';\n\n/**\n * Hook which lets child navigators add getters to be called for obtaining rehydrated state.\n */\nexport default function useKeyedChildListeners() {\n const { current: keyedListeners } = React.useRef<{\n [K in keyof KeyedListenerMap]: Record<\n string,\n KeyedListenerMap[K] | undefined\n >;\n }>({\n getState: {},\n beforeRemove: {},\n });\n\n const addKeyedListener = React.useCallback(\n <T extends keyof KeyedListenerMap>(\n type: T,\n key: string,\n listener: KeyedListenerMap[T]\n ) => {\n // @ts-expect-error: according to ref stated above you can use `key` to index type\n keyedListeners[type][key] = listener;\n\n return () => {\n // @ts-expect-error: according to ref stated above you can use `key` to index type\n keyedListeners[type][key] = undefined;\n };\n },\n [keyedListeners]\n );\n\n return {\n keyedListeners,\n addKeyedListener,\n };\n}\n"]}
|