@react-navigation/core 6.0.3 → 6.2.0
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/BaseNavigationContainer.js +13 -9
- package/lib/commonjs/BaseNavigationContainer.js.map +1 -1
- package/lib/commonjs/CurrentRenderContext.js.map +1 -1
- package/lib/commonjs/EnsureSingleNavigator.js +5 -4
- package/lib/commonjs/EnsureSingleNavigator.js.map +1 -1
- package/lib/commonjs/NavigationContainerRefContext.js.map +1 -1
- package/lib/commonjs/NavigationContext.js.map +1 -1
- package/lib/commonjs/NavigationHelpersContext.js.map +1 -1
- package/lib/commonjs/NavigationRouteContext.js.map +1 -1
- package/lib/commonjs/SceneView.js +11 -10
- package/lib/commonjs/SceneView.js.map +1 -1
- package/lib/commonjs/UnhandledActionContext.js.map +1 -1
- package/lib/commonjs/createNavigationContainerRef.js +11 -6
- package/lib/commonjs/createNavigationContainerRef.js.map +1 -1
- package/lib/commonjs/fromEntries.js +3 -1
- package/lib/commonjs/fromEntries.js.map +1 -1
- package/lib/commonjs/getActionFromState.js +2 -1
- package/lib/commonjs/getActionFromState.js.map +1 -1
- package/lib/commonjs/getPathFromState.js +13 -3
- package/lib/commonjs/getPathFromState.js.map +1 -1
- package/lib/commonjs/getStateFromPath.js +12 -2
- package/lib/commonjs/getStateFromPath.js.map +1 -1
- package/lib/commonjs/index.js +24 -24
- package/lib/commonjs/isArrayEqual.js +9 -1
- package/lib/commonjs/isArrayEqual.js.map +1 -1
- package/lib/commonjs/isRecordEqual.js +25 -0
- package/lib/commonjs/isRecordEqual.js.map +1 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/useChildListeners.js.map +1 -1
- package/lib/commonjs/useCurrentRender.js +6 -5
- package/lib/commonjs/useCurrentRender.js.map +1 -1
- package/lib/commonjs/useDescriptors.js +18 -17
- package/lib/commonjs/useDescriptors.js.map +1 -1
- package/lib/commonjs/useEventEmitter.js +7 -6
- package/lib/commonjs/useEventEmitter.js.map +1 -1
- package/lib/commonjs/useFocusEvents.js +5 -4
- package/lib/commonjs/useFocusEvents.js.map +1 -1
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js +5 -4
- package/lib/commonjs/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/commonjs/useKeyedChildListeners.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +52 -20
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/commonjs/useNavigationCache.js +26 -10
- package/lib/commonjs/useNavigationCache.js.map +1 -1
- package/lib/commonjs/useNavigationHelpers.js +32 -10
- package/lib/commonjs/useNavigationHelpers.js.map +1 -1
- package/lib/commonjs/useOnAction.js +13 -11
- package/lib/commonjs/useOnAction.js.map +1 -1
- package/lib/commonjs/useOnGetState.js +5 -4
- package/lib/commonjs/useOnGetState.js.map +1 -1
- package/lib/commonjs/useOnPreventRemove.js +6 -5
- package/lib/commonjs/useOnPreventRemove.js.map +1 -1
- package/lib/commonjs/useOnRouteFocus.js +7 -6
- package/lib/commonjs/useOnRouteFocus.js.map +1 -1
- package/lib/commonjs/useOptionsGetters.js +6 -5
- package/lib/commonjs/useOptionsGetters.js.map +1 -1
- package/lib/commonjs/useRouteCache.js +1 -1
- package/lib/commonjs/useScheduleUpdate.js +1 -1
- package/lib/commonjs/validatePathConfig.js +5 -2
- package/lib/commonjs/validatePathConfig.js.map +1 -1
- package/lib/module/BaseNavigationContainer.js +13 -9
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/CurrentRenderContext.js.map +1 -1
- package/lib/module/EnsureSingleNavigator.js +4 -3
- package/lib/module/EnsureSingleNavigator.js.map +1 -1
- package/lib/module/NavigationContainerRefContext.js.map +1 -1
- package/lib/module/NavigationContext.js.map +1 -1
- package/lib/module/NavigationHelpersContext.js.map +1 -1
- package/lib/module/NavigationRouteContext.js.map +1 -1
- package/lib/module/SceneView.js +11 -10
- package/lib/module/SceneView.js.map +1 -1
- package/lib/module/UnhandledActionContext.js.map +1 -1
- package/lib/module/createNavigationContainerRef.js +10 -5
- package/lib/module/createNavigationContainerRef.js.map +1 -1
- package/lib/module/fromEntries.js +3 -1
- package/lib/module/fromEntries.js.map +1 -1
- package/lib/module/getActionFromState.js +2 -1
- package/lib/module/getActionFromState.js.map +1 -1
- package/lib/module/getPathFromState.js +13 -3
- package/lib/module/getPathFromState.js.map +1 -1
- package/lib/module/getStateFromPath.js +12 -2
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/isArrayEqual.js +9 -1
- package/lib/module/isArrayEqual.js.map +1 -1
- package/lib/module/isRecordEqual.js +18 -0
- package/lib/module/isRecordEqual.js.map +1 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/useChildListeners.js.map +1 -1
- package/lib/module/useCurrentRender.js +6 -5
- package/lib/module/useCurrentRender.js.map +1 -1
- package/lib/module/useDescriptors.js +18 -17
- package/lib/module/useDescriptors.js.map +1 -1
- package/lib/module/useEventEmitter.js +7 -6
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEvents.js +5 -4
- package/lib/module/useFocusEvents.js.map +1 -1
- package/lib/module/useFocusedListenersChildrenAdapter.js +5 -4
- package/lib/module/useFocusedListenersChildrenAdapter.js.map +1 -1
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +51 -20
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/useNavigationCache.js +26 -10
- package/lib/module/useNavigationCache.js.map +1 -1
- package/lib/module/useNavigationHelpers.js +32 -10
- package/lib/module/useNavigationHelpers.js.map +1 -1
- package/lib/module/useOnAction.js +13 -11
- package/lib/module/useOnAction.js.map +1 -1
- package/lib/module/useOnGetState.js +5 -4
- package/lib/module/useOnGetState.js.map +1 -1
- package/lib/module/useOnPreventRemove.js +6 -5
- package/lib/module/useOnPreventRemove.js.map +1 -1
- package/lib/module/useOnRouteFocus.js +7 -6
- package/lib/module/useOnRouteFocus.js.map +1 -1
- package/lib/module/useOptionsGetters.js +6 -5
- package/lib/module/useOptionsGetters.js.map +1 -1
- package/lib/module/validatePathConfig.js +5 -2
- package/lib/module/validatePathConfig.js.map +1 -1
- package/lib/typescript/src/NavigationContext.d.ts +1 -1
- package/lib/typescript/src/SceneView.d.ts +1 -1
- package/lib/typescript/src/isRecordEqual.d.ts +4 -0
- package/lib/typescript/src/types.d.ts +50 -18
- package/lib/typescript/src/useDescriptors.d.ts +13 -10
- 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 +5 -5
- package/src/CurrentRenderContext.tsx +3 -2
- package/src/EnsureSingleNavigator.tsx +7 -8
- package/src/NavigationContainerRefContext.tsx +3 -4
- package/src/NavigationContext.tsx +3 -2
- package/src/NavigationHelpersContext.tsx +3 -2
- package/src/NavigationRouteContext.tsx +3 -2
- package/src/SceneView.tsx +7 -1
- package/src/UnhandledActionContext.tsx +3 -4
- package/src/createNavigationContainerRef.tsx +3 -1
- package/src/isArrayEqual.tsx +9 -1
- package/src/isRecordEqual.tsx +20 -0
- package/src/types.tsx +70 -21
- package/src/useChildListeners.tsx +3 -5
- package/src/useDescriptors.tsx +16 -8
- package/src/useKeyedChildListeners.tsx +6 -8
- package/src/useNavigationBuilder.tsx +90 -27
- package/src/useNavigationCache.tsx +17 -1
- package/src/useNavigationHelpers.tsx +39 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["isArrayEqual.tsx"],"names":["isArrayEqual","a","b","length","every","it","index"],"mappings":"AAAA;AACA;AACA;AACA;AACA,eAAe,SAASA,YAAT,CAAsBC,CAAtB,EAAgCC,CAAhC,EAA0C;AACvD,
|
|
1
|
+
{"version":3,"sources":["isArrayEqual.tsx"],"names":["isArrayEqual","a","b","length","every","it","index"],"mappings":"AAAA;AACA;AACA;AACA;AACA,eAAe,SAASA,YAAT,CAAsBC,CAAtB,EAAgCC,CAAhC,EAA0C;AACvD,MAAID,CAAC,KAAKC,CAAV,EAAa;AACX,WAAO,IAAP;AACD;;AAED,MAAID,CAAC,CAACE,MAAF,KAAaD,CAAC,CAACC,MAAnB,EAA2B;AACzB,WAAO,KAAP;AACD;;AAED,SAAOF,CAAC,CAACG,KAAF,CAAQ,CAACC,EAAD,EAAKC,KAAL,KAAeD,EAAE,KAAKH,CAAC,CAACI,KAAD,CAA/B,CAAP;AACD","sourcesContent":["/**\n * Compare two arrays with primitive values as the content.\n * We need to make sure that both values and order match.\n */\nexport default function isArrayEqual(a: any[], b: any[]) {\n if (a === b) {\n return true;\n }\n\n if (a.length !== b.length) {\n return false;\n }\n\n return a.every((it, index) => it === b[index]);\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compare two records with primitive values as the content.
|
|
3
|
+
*/
|
|
4
|
+
export default function isRecordEqual(a, b) {
|
|
5
|
+
if (a === b) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const aKeys = Object.keys(a);
|
|
10
|
+
const bKeys = Object.keys(b);
|
|
11
|
+
|
|
12
|
+
if (aKeys.length !== bKeys.length) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return aKeys.every(key => a[key] === b[key]);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=isRecordEqual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["isRecordEqual.tsx"],"names":["isRecordEqual","a","b","aKeys","Object","keys","bKeys","length","every","key"],"mappings":"AAAA;AACA;AACA;AACA,eAAe,SAASA,aAAT,CACbC,CADa,EAEbC,CAFa,EAGb;AACA,MAAID,CAAC,KAAKC,CAAV,EAAa;AACX,WAAO,IAAP;AACD;;AAED,QAAMC,KAAK,GAAGC,MAAM,CAACC,IAAP,CAAYJ,CAAZ,CAAd;AACA,QAAMK,KAAK,GAAGF,MAAM,CAACC,IAAP,CAAYH,CAAZ,CAAd;;AAEA,MAAIC,KAAK,CAACI,MAAN,KAAiBD,KAAK,CAACC,MAA3B,EAAmC;AACjC,WAAO,KAAP;AACD;;AAED,SAAOJ,KAAK,CAACK,KAAN,CAAaC,GAAD,IAASR,CAAC,CAACQ,GAAD,CAAD,KAAWP,CAAC,CAACO,GAAD,CAAjC,CAAP;AACD","sourcesContent":["/**\n * Compare two records with primitive values as the content.\n */\nexport default function isRecordEqual(\n a: Record<string, any>,\n b: Record<string, any>\n) {\n if (a === b) {\n return true;\n }\n\n const aKeys = Object.keys(a);\n const bKeys = Object.keys(b);\n\n if (aKeys.length !== bKeys.length) {\n return false;\n }\n\n return aKeys.every((key) => a[key] === b[key]);\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 {\n [EventName in keyof (EventMap &\n EventMapCore<State>)]: EventListenerCallback<EventMap, 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 * 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 * 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"]}
|
|
@@ -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,
|
|
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;AAClE;AACAP,IAAAA,SAAS,CAACM,IAAD,CAAT,CAAgBE,IAAhB,CAAqBD,QAArB;AAEA,WAAO,MAAM;AACX;AACA,YAAME,KAAK,GAAGT,SAAS,CAACM,IAAD,CAAT,CAAgBI,OAAhB,CAAwBH,QAAxB,CAAd;AAEAP,MAAAA,SAAS,CAACM,IAAD,CAAT,CAAgBK,MAAhB,CAAuBF,KAAvB,EAA8B,CAA9B;AACD,KALD;AAMD,GAXiB,EAYlB,CAACT,SAAD,CAZkB,CAApB;AAeA,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 // @ts-expect-error: listener should be correct type according to `type`\n listeners[type].push(listener);\n\n return () => {\n // @ts-expect-error: listener should be correct type according to `type`\n const index = listeners[type].indexOf(listener);\n\n listeners[type].splice(index, 1);\n };\n },\n [listeners]\n );\n\n return {\n listeners,\n addListener,\n };\n}\n"]}
|
|
@@ -5,11 +5,12 @@ import CurrentRenderContext from './CurrentRenderContext';
|
|
|
5
5
|
* Write the current options, so that server renderer can get current values
|
|
6
6
|
* Mutating values like this is not safe in async mode, but it doesn't apply to SSR
|
|
7
7
|
*/
|
|
8
|
-
export default function useCurrentRender({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export default function useCurrentRender(_ref) {
|
|
9
|
+
let {
|
|
10
|
+
state,
|
|
11
|
+
navigation,
|
|
12
|
+
descriptors
|
|
13
|
+
} = _ref;
|
|
13
14
|
const current = React.useContext(CurrentRenderContext);
|
|
14
15
|
|
|
15
16
|
if (current && navigation.isFocused()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useCurrentRender.tsx"],"names":["React","CurrentRenderContext","useCurrentRender","state","navigation","descriptors","current","useContext","isFocused","options","routes","index","key"],"mappings":"AACA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,oBAAP,MAAiC,wBAAjC;;AAiBA;AACA;AACA;AACA;AACA,eAAe,SAASC,gBAAT,
|
|
1
|
+
{"version":3,"sources":["useCurrentRender.tsx"],"names":["React","CurrentRenderContext","useCurrentRender","state","navigation","descriptors","current","useContext","isFocused","options","routes","index","key"],"mappings":"AACA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,oBAAP,MAAiC,wBAAjC;;AAiBA;AACA;AACA;AACA;AACA,eAAe,SAASC,gBAAT,OAIH;AAAA,MAJ6B;AACvCC,IAAAA,KADuC;AAEvCC,IAAAA,UAFuC;AAGvCC,IAAAA;AAHuC,GAI7B;AACV,QAAMC,OAAO,GAAGN,KAAK,CAACO,UAAN,CAAiBN,oBAAjB,CAAhB;;AAEA,MAAIK,OAAO,IAAIF,UAAU,CAACI,SAAX,EAAf,EAAuC;AACrCF,IAAAA,OAAO,CAACG,OAAR,GAAkBJ,WAAW,CAACF,KAAK,CAACO,MAAN,CAAaP,KAAK,CAACQ,KAAnB,EAA0BC,GAA3B,CAAX,CAA2CH,OAA7D;AACD;AACF","sourcesContent":["import type { NavigationState, ParamListBase } from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport CurrentRenderContext from './CurrentRenderContext';\nimport type {\n Descriptor,\n NavigationHelpers,\n NavigationProp,\n RouteProp,\n} from './types';\n\ntype Options = {\n state: NavigationState;\n navigation: NavigationHelpers<ParamListBase>;\n descriptors: Record<\n string,\n Descriptor<object, NavigationProp<ParamListBase>, RouteProp<ParamListBase>>\n >;\n};\n\n/**\n * Write the current options, so that server renderer can get current values\n * Mutating values like this is not safe in async mode, but it doesn't apply to SSR\n */\nexport default function useCurrentRender({\n state,\n navigation,\n descriptors,\n}: Options) {\n const current = React.useContext(CurrentRenderContext);\n\n if (current && navigation.isFocused()) {\n current.options = descriptors[state.routes[state.index].key].options;\n }\n}\n"]}
|
|
@@ -14,21 +14,22 @@ import useRouteCache from './useRouteCache';
|
|
|
14
14
|
* - Options specified by the screen for the navigator
|
|
15
15
|
* - Navigation object intended for the route
|
|
16
16
|
*/
|
|
17
|
-
export default function useDescriptors({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
export default function useDescriptors(_ref) {
|
|
18
|
+
let {
|
|
19
|
+
state,
|
|
20
|
+
screens,
|
|
21
|
+
navigation,
|
|
22
|
+
screenOptions,
|
|
23
|
+
defaultScreenOptions,
|
|
24
|
+
onAction,
|
|
25
|
+
getState,
|
|
26
|
+
setState,
|
|
27
|
+
addListener,
|
|
28
|
+
addKeyedListener,
|
|
29
|
+
onRouteFocus,
|
|
30
|
+
router,
|
|
31
|
+
emitter
|
|
32
|
+
} = _ref;
|
|
32
33
|
const [options, setOptions] = React.useState({});
|
|
33
34
|
const {
|
|
34
35
|
onDispatchAction,
|
|
@@ -56,11 +57,11 @@ export default function useDescriptors({
|
|
|
56
57
|
const routes = useRouteCache(state.routes);
|
|
57
58
|
return routes.reduce((acc, route, i) => {
|
|
58
59
|
const config = screens[route.name];
|
|
59
|
-
const screen = config
|
|
60
|
+
const screen = config.props;
|
|
60
61
|
const navigation = navigations[route.key];
|
|
61
62
|
const optionsList = [// The default `screenOptions` passed to the navigator
|
|
62
63
|
screenOptions, // The `screenOptions` props passed to `Group` elements
|
|
63
|
-
...(config
|
|
64
|
+
...(config.options ? config.options.filter(Boolean) : []), // The `options` prop passed to `Screen` elements,
|
|
64
65
|
screen.options, // The options set via `navigation.setOptions`
|
|
65
66
|
options[route.key]];
|
|
66
67
|
const customOptions = optionsList.reduce((acc, curr) => Object.assign(acc, typeof curr !== 'function' ? curr : curr({
|
|
@@ -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","key","optionsList","filter","Boolean","customOptions","curr","Object","assign","mergedOptions","clearOptions","o","_","rest","render"],"mappings":"AAMA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,wB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,CAAD,IAAO;AAChB,UAAIf,KAAK,CAACK,GAAN,IAAaU,CAAjB,EAAoB;AAClB;AACA,cAAM;AAAE,WAACf,KAAK,CAACK,GAAP,GAAaW,CAAf;AAAkB,aAAGC;AAArB,YAA8BF,CAApC;AACA,eAAOE,IAAP;AACD;;AAED,aAAOF,CAAP;AACD,KARS,CADZ;;AAWAhB,IAAAA,GAAG,CAACC,KAAK,CAACK,GAAP,CAAH,GAAiB;AACfL,MAAAA,KADe;AAEf;AACAxB,MAAAA,UAHe;;AAIf0C,MAAAA,MAAM,GAAG;AACP,4BACE,oBAAC,wBAAD,CAA0B,QAA1B;AAAmC,UAAA,GAAG,EAAElB,KAAK,CAACK,GAA9C;AAAmD,UAAA,KAAK,EAAEX;AAA1D,wBACE,oBAAC,iBAAD,CAAmB,QAAnB;AAA4B,UAAA,KAAK,EAAElB;AAAnC,wBACE,oBAAC,sBAAD,CAAwB,QAAxB;AAAiC,UAAA,KAAK,EAAEwB;AAAxC,wBACE,oBAAC,SAAD;AACE,UAAA,UAAU,EAAExB,UADd;AAEE,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,EAAEgC,aAPX;AAQE,UAAA,YAAY,EAAEC;AARhB,UADF,CADF,CADF,CADF;AAkBD,OAvBc;;AAwBf3B,MAAAA,OAAO,EAAE0B;AAxBM,KAAjB;AA2BA,WAAOd,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 (ScreenOptionsOrCallback<ScreenOptions> | undefined)[] | undefined,\n 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[1];\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[0]\n ? config[0].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;AA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AAC,iBAAD,CAAmB,QAAnB;AAA4B,UAAA,KAAK,EAAElB;AAAnC,wBACE,oBAAC,sBAAD,CAAwB,QAAxB;AAAiC,UAAA,KAAK,EAAEwB;AAAxC,wBACE,oBAAC,SAAD;AACE,UAAA,UAAU,EAAExB,UADd;AAEE,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,GA/FM,EA+FJ,EA/FI,CAAP;AAgGD","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<\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"]}
|
|
@@ -33,14 +33,15 @@ export default function useEventEmitter(listen) {
|
|
|
33
33
|
removeListener
|
|
34
34
|
};
|
|
35
35
|
}, []);
|
|
36
|
-
const emit = React.useCallback(
|
|
37
|
-
type,
|
|
38
|
-
data,
|
|
39
|
-
target,
|
|
40
|
-
canPreventDefault
|
|
41
|
-
}) => {
|
|
36
|
+
const emit = React.useCallback(_ref => {
|
|
42
37
|
var _items$target, _listenRef$current;
|
|
43
38
|
|
|
39
|
+
let {
|
|
40
|
+
type,
|
|
41
|
+
data,
|
|
42
|
+
target,
|
|
43
|
+
canPreventDefault
|
|
44
|
+
} = _ref;
|
|
44
45
|
const items = listeners.current[type] || {}; // Copy the current list of callbacks in case they are mutated during execution
|
|
45
46
|
|
|
46
47
|
const callbacks = target !== undefined ? (_items$target = items[target]) === null || _items$target === void 0 ? void 0 : _items$target.slice() : [].concat(...Object.keys(items).map(t => items[t])).filter((cb, i, self) => self.lastIndexOf(cb) === i);
|
|
@@ -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;AAEAC,MAAAA,SAAS,CAACI,MAAV,CAAiBF,KAAjB,EAAwB,CAAxB;AACD,KAZD;;AAcA,UAAMG,WAAW,GAAG,CAACP,IAAD,EAAeC,QAAf,KAAiD;AACnEN,MAAAA,SAAS,CAACD,OAAV,CAAkBM,IAAlB,IAA0BL,SAAS,CAACD,OAAV,CAAkBM,IAAlB,KAA2B,EAArD;AACAL,MAAAA,SAAS,CAACD,OAAV,CAAkBM,IAAlB,EAAwBF,MAAxB,IAAkCH,SAAS,CAACD,OAAV,CAAkBM,IAAlB,EAAwBF,MAAxB,KAAmC,EAArE;AACAH,MAAAA,SAAS,CAACD,OAAV,CAAkBM,IAAlB,EAAwBF,MAAxB,EAAgCU,IAAhC,CAAqCP,QAArC;AAEA,aAAO,MAAMF,cAAc,CAACC,IAAD,EAAOC,QAAP,CAA3B;AACD,KAND;;AAQA,WAAO;AACLM,MAAAA,WADK;AAELR,MAAAA;AAFK,KAAP;AAID,GA3Bc,EA2BZ,EA3BY,CAAf;AA6BA,QAAMU,IAAI,GAAGrB,KAAK,CAACS,WAAN,CACX,
|
|
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,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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,0BAAArC,SAAS,CAACG,OAAV,+EAAAH,SAAS,EAAWiC,KAAX,CAAT;AAEAtB,IAAAA,SAAS,SAAT,IAAAA,SAAS,WAAT,YAAAA,SAAS,CAAE8B,OAAX,CAAoBZ,EAAD,IAAQA,EAAE,CAACI,KAAD,CAA7B;AAEA,WAAOA,KAAP;AACD,GAtEU,EAuEX,EAvEW,CAAb;AA0EA,SAAOpC,KAAK,CAAC6C,OAAN,CAAc,OAAO;AAAErC,IAAAA,MAAF;AAAUa,IAAAA;AAAV,GAAP,CAAd,EAAwC,CAACb,MAAD,EAASa,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 callbacks.splice(index, 1);\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 return () => removeListener(type, callback);\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"]}
|
|
@@ -4,10 +4,11 @@ import NavigationContext from './NavigationContext';
|
|
|
4
4
|
/**
|
|
5
5
|
* Hook to take care of emitting `focus` and `blur` events.
|
|
6
6
|
*/
|
|
7
|
-
export default function useFocusEvents({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export default function useFocusEvents(_ref) {
|
|
8
|
+
let {
|
|
9
|
+
state,
|
|
10
|
+
emitter
|
|
11
|
+
} = _ref;
|
|
11
12
|
const navigation = React.useContext(NavigationContext);
|
|
12
13
|
const lastFocusedKeyRef = React.useRef();
|
|
13
14
|
const currentFocusedKey = state.routes[state.index].key; // When the parent screen changes its focus state, we also need to change child's focus
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useFocusEvents.tsx"],"names":["React","NavigationContext","useFocusEvents","state","emitter","navigation","useContext","lastFocusedKeyRef","useRef","currentFocusedKey","routes","index","key","useEffect","addListener","current","emit","type","target","undefined","lastFocusedKey","isFocused"],"mappings":"AACA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,iBAAP,MAA8B,qBAA9B;;AASA;AACA;AACA;AACA,eAAe,SAASC,cAAT,
|
|
1
|
+
{"version":3,"sources":["useFocusEvents.tsx"],"names":["React","NavigationContext","useFocusEvents","state","emitter","navigation","useContext","lastFocusedKeyRef","useRef","currentFocusedKey","routes","index","key","useEffect","addListener","current","emit","type","target","undefined","lastFocusedKey","isFocused"],"mappings":"AACA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,iBAAP,MAA8B,qBAA9B;;AASA;AACA;AACA;AACA,eAAe,SAASC,cAAT,OAGI;AAAA,MAHmD;AACpEC,IAAAA,KADoE;AAEpEC,IAAAA;AAFoE,GAGnD;AACjB,QAAMC,UAAU,GAAGL,KAAK,CAACM,UAAN,CAAiBL,iBAAjB,CAAnB;AACA,QAAMM,iBAAiB,GAAGP,KAAK,CAACQ,MAAN,EAA1B;AAEA,QAAMC,iBAAiB,GAAGN,KAAK,CAACO,MAAN,CAAaP,KAAK,CAACQ,KAAnB,EAA0BC,GAApD,CAJiB,CAMjB;AACA;;AACAZ,EAAAA,KAAK,CAACa,SAAN,CACE,MACER,UADF,aACEA,UADF,uBACEA,UAAU,CAAES,WAAZ,CAAwB,OAAxB,EAAiC,MAAM;AACrCP,IAAAA,iBAAiB,CAACQ,OAAlB,GAA4BN,iBAA5B;AACAL,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AI,EAAE,OAAR;AAAiBC,MAAAA,MAAM,EAAET;AAAzB,KAAb;AACD,GA3BD,EA2BG,CAACA,iBAAD,EAAoBL,OAApB,EAA6BC,UAA7B,CA3BH;AA4BD","sourcesContent":["import type { NavigationState } from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationContext from './NavigationContext';\nimport type { EventMapCore } from './types';\nimport type { NavigationEventEmitter } from './useEventEmitter';\n\ntype Options<State extends NavigationState> = {\n state: State;\n emitter: NavigationEventEmitter<EventMapCore<State>>;\n};\n\n/**\n * Hook to take care of emitting `focus` and `blur` events.\n */\nexport default function useFocusEvents<State extends NavigationState>({\n state,\n emitter,\n}: Options<State>) {\n const navigation = React.useContext(NavigationContext);\n const lastFocusedKeyRef = React.useRef<string | undefined>();\n\n const currentFocusedKey = state.routes[state.index].key;\n\n // When the parent screen changes its focus state, we also need to change child's focus\n // Coz the child screen can't be focused if the parent screen is out of focus\n React.useEffect(\n () =>\n navigation?.addListener('focus', () => {\n lastFocusedKeyRef.current = currentFocusedKey;\n emitter.emit({ type: 'focus', target: currentFocusedKey });\n }),\n [currentFocusedKey, emitter, navigation]\n );\n\n React.useEffect(\n () =>\n navigation?.addListener('blur', () => {\n lastFocusedKeyRef.current = undefined;\n emitter.emit({ type: 'blur', target: currentFocusedKey });\n }),\n [currentFocusedKey, emitter, navigation]\n );\n\n React.useEffect(() => {\n const lastFocusedKey = lastFocusedKeyRef.current;\n\n lastFocusedKeyRef.current = currentFocusedKey;\n\n // We wouldn't have `lastFocusedKey` on initial mount\n // Fire focus event for the current route on mount if there's no parent navigator\n if (lastFocusedKey === undefined && !navigation) {\n emitter.emit({ type: 'focus', target: currentFocusedKey });\n }\n\n // We should only emit events when the focused key changed and navigator is focused\n // When navigator is not focused, screens inside shouldn't receive focused status either\n if (\n lastFocusedKey === currentFocusedKey ||\n !(navigation ? navigation.isFocused() : true)\n ) {\n return;\n }\n\n if (lastFocusedKey === undefined) {\n // Only fire events after initial mount\n return;\n }\n\n emitter.emit({ type: 'blur', target: lastFocusedKey });\n emitter.emit({ type: 'focus', target: currentFocusedKey });\n }, [currentFocusedKey, emitter, navigation]);\n}\n"]}
|
|
@@ -4,10 +4,11 @@ import NavigationBuilderContext from './NavigationBuilderContext';
|
|
|
4
4
|
/**
|
|
5
5
|
* Hook for passing focus callback to children
|
|
6
6
|
*/
|
|
7
|
-
export default function useFocusedListenersChildrenAdapter({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export default function useFocusedListenersChildrenAdapter(_ref) {
|
|
8
|
+
let {
|
|
9
|
+
navigation,
|
|
10
|
+
focusedListeners
|
|
11
|
+
} = _ref;
|
|
11
12
|
const {
|
|
12
13
|
addListener
|
|
13
14
|
} = React.useContext(NavigationBuilderContext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useFocusedListenersChildrenAdapter.tsx"],"names":["React","NavigationBuilderContext","useFocusedListenersChildrenAdapter","navigation","focusedListeners","addListener","useContext","listener","useCallback","callback","isFocused","handled","result","useEffect"],"mappings":"AACA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,wBAAP,MAGO,4BAHP;;AAWA;AACA;AACA;AACA,eAAe,SAASC,kCAAT,
|
|
1
|
+
{"version":3,"sources":["useFocusedListenersChildrenAdapter.tsx"],"names":["React","NavigationBuilderContext","useFocusedListenersChildrenAdapter","navigation","focusedListeners","addListener","useContext","listener","useCallback","callback","isFocused","handled","result","useEffect"],"mappings":"AACA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAEA,OAAOC,wBAAP,MAGO,4BAHP;;AAWA;AACA;AACA;AACA,eAAe,SAASC,kCAAT,OAGH;AAAA,MAH+C;AACzDC,IAAAA,UADyD;AAEzDC,IAAAA;AAFyD,GAG/C;AACV,QAAM;AAAEC,IAAAA;AAAF,MAAkBL,KAAK,CAACM,UAAN,CAAiBL,wBAAjB,CAAxB;AAEA,QAAMM,QAAQ,GAAGP,KAAK,CAACQ,WAAN,CACdC,QAAD,IAA8C;AAC5C,QAAIN,UAAU,CAACO,SAAX,EAAJ,EAA4B;AAC1B,WAAK,MAAMH,QAAX,IAAuBH,gBAAvB,EAAyC;AACvC,cAAM;AAAEO,UAAAA,OAAF;AAAWC,UAAAA;AAAX,YAAsBL,QAAQ,CAACE,QAAD,CAApC;;AAEA,YAAIE,OAAJ,EAAa;AACX,iBAAO;AAAEA,YAAAA,OAAF;AAAWC,YAAAA;AAAX,WAAP;AACD;AACF;;AAED,aAAO;AAAED,QAAAA,OAAO,EAAE,IAAX;AAAiBC,QAAAA,MAAM,EAAEH,QAAQ,CAACN,UAAD;AAAjC,OAAP;AACD,KAVD,MAUO;AACL,aAAO;AAAEQ,QAAAA,OAAO,EAAE,KAAX;AAAkBC,QAAAA,MAAM,EAAE;AAA1B,OAAP;AACD;AACF,GAfc,EAgBf,CAACR,gBAAD,EAAmBD,UAAnB,CAhBe,CAAjB;AAmBAH,EAAAA,KAAK,CAACa,SAAN,CACE,MAAMR,WAAN,aAAMA,WAAN,uBAAMA,WAAW,CAAG,OAAH,EAAYE,QAAZ,CADnB,EAEE,CAACF,WAAD,EAAcE,QAAd,CAFF;AAID","sourcesContent":["import type { ParamListBase } from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport NavigationBuilderContext, {\n FocusedNavigationCallback,\n FocusedNavigationListener,\n} from './NavigationBuilderContext';\nimport type { NavigationHelpers } from './types';\n\ntype Options = {\n navigation: NavigationHelpers<ParamListBase>;\n focusedListeners: FocusedNavigationListener[];\n};\n\n/**\n * Hook for passing focus callback to children\n */\nexport default function useFocusedListenersChildrenAdapter({\n navigation,\n focusedListeners,\n}: Options) {\n const { addListener } = React.useContext(NavigationBuilderContext);\n\n const listener = React.useCallback(\n (callback: FocusedNavigationCallback<any>) => {\n if (navigation.isFocused()) {\n for (const listener of focusedListeners) {\n const { handled, result } = listener(callback);\n\n if (handled) {\n return { handled, result };\n }\n }\n\n return { handled: true, result: callback(navigation) };\n } else {\n return { handled: false, result: null };\n }\n },\n [focusedListeners, navigation]\n );\n\n React.useEffect(\n () => addListener?.('focus', listener),\n [addListener, listener]\n );\n}\n"]}
|
|
@@ -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,
|
|
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;AACHR,IAAAA,cAAc,CAACM,IAAD,CAAd,CAAqBC,GAArB,IAA4BC,QAA5B;AAEA,WAAO,MAAM;AACXR,MAAAA,cAAc,CAACM,IAAD,CAAd,CAAqBC,GAArB,IAA4BE,SAA5B;AACD,KAFD;AAGD,GAXsB,EAYvB,CAACT,cAAD,CAZuB,CAAzB;AAeA,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 keyedListeners[type][key] = listener;\n\n return () => {\n keyedListeners[type][key] = undefined;\n };\n },\n [keyedListeners]\n );\n\n return {\n keyedListeners,\n addKeyedListener,\n };\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import { isValidElementType } from 'react-is';
|
|
4
4
|
import Group from './Group';
|
|
5
5
|
import isArrayEqual from './isArrayEqual';
|
|
6
|
+
import isRecordEqual from './isRecordEqual';
|
|
6
7
|
import NavigationHelpersContext from './NavigationHelpersContext';
|
|
7
8
|
import NavigationRouteContext from './NavigationRouteContext';
|
|
8
9
|
import NavigationStateContext from './NavigationStateContext';
|
|
@@ -26,12 +27,15 @@ import useScheduleUpdate from './useScheduleUpdate'; // This is to make TypeScri
|
|
|
26
27
|
|
|
27
28
|
PrivateValueStore;
|
|
28
29
|
|
|
30
|
+
const isValidKey = key => key === undefined || typeof key === 'string' && key !== '';
|
|
29
31
|
/**
|
|
30
32
|
* Extract route config object from React children elements.
|
|
31
33
|
*
|
|
32
34
|
* @param children React Elements to extract the config from.
|
|
33
35
|
*/
|
|
34
|
-
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
const getRouteConfigsFromChildren = (children, groupKey, groupOptions) => {
|
|
35
39
|
const configs = React.Children.toArray(children).reduce((acc, child) => {
|
|
36
40
|
var _child$type, _child$props;
|
|
37
41
|
|
|
@@ -39,14 +43,26 @@ const getRouteConfigsFromChildren = (children, options) => {
|
|
|
39
43
|
if (child.type === Screen) {
|
|
40
44
|
// We can only extract the config from `Screen` elements
|
|
41
45
|
// If something else was rendered, it's probably a bug
|
|
42
|
-
|
|
46
|
+
if (!isValidKey(child.props.navigationKey)) {
|
|
47
|
+
throw new Error(`Got an invalid 'navigationKey' prop (${JSON.stringify(child.props.navigationKey)}) for the screen '${child.props.name}'. It must be a non-empty string or 'undefined'.`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
acc.push({
|
|
51
|
+
keys: [groupKey, child.props.navigationKey],
|
|
52
|
+
options: groupOptions,
|
|
53
|
+
props: child.props
|
|
54
|
+
});
|
|
43
55
|
return acc;
|
|
44
56
|
}
|
|
45
57
|
|
|
46
58
|
if (child.type === React.Fragment || child.type === Group) {
|
|
47
|
-
|
|
59
|
+
if (!isValidKey(child.props.navigationKey)) {
|
|
60
|
+
throw new Error(`Got an invalid 'navigationKey' prop (${JSON.stringify(child.props.navigationKey)}) for the group. It must be a non-empty string or 'undefined'.`);
|
|
61
|
+
} // When we encounter a fragment or group, we need to dive into its children to extract the configs
|
|
48
62
|
// This is handy to conditionally define a group of screens
|
|
49
|
-
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
acc.push(...getRouteConfigsFromChildren(child.props.children, child.props.navigationKey, child.type !== Group ? groupOptions : groupOptions != null ? [...groupOptions, child.props.screenOptions] : [child.props.screenOptions]));
|
|
50
66
|
return acc;
|
|
51
67
|
}
|
|
52
68
|
}
|
|
@@ -61,7 +77,7 @@ const getRouteConfigsFromChildren = (children, options) => {
|
|
|
61
77
|
children,
|
|
62
78
|
component,
|
|
63
79
|
getComponent
|
|
64
|
-
} = config
|
|
80
|
+
} = config.props;
|
|
65
81
|
|
|
66
82
|
if (typeof name !== 'string' || !name) {
|
|
67
83
|
throw new Error(`Got an invalid name (${JSON.stringify(name)}) for the screen. It must be a non-empty string.`);
|
|
@@ -92,11 +108,15 @@ const getRouteConfigsFromChildren = (children, options) => {
|
|
|
92
108
|
throw new Error(`Got an invalid value for 'getComponent' prop for the screen '${name}'. It must be a function returning a React Component.`);
|
|
93
109
|
}
|
|
94
110
|
|
|
95
|
-
if (typeof component === 'function'
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
111
|
+
if (typeof component === 'function') {
|
|
112
|
+
if (component.name === 'component') {
|
|
113
|
+
// Inline anonymous functions passed in the `component` prop will have the name of the prop
|
|
114
|
+
// It's relatively safe to assume that it's not a component since it should also have PascalCase name
|
|
115
|
+
// We won't catch all scenarios here, but this should catch a good chunk of incorrect use.
|
|
116
|
+
console.warn(`Looks like you're passing an inline function for 'component' prop for the screen '${name}' (e.g. component={() => <SomeComponent />}). Passing an inline function will cause the component state to be lost on re-render and cause perf issues since it's re-created every render. You can pass the function as children to 'Screen' instead to achieve the desired behaviour.`);
|
|
117
|
+
} else if (/^[a-z]/.test(component.name)) {
|
|
118
|
+
console.warn(`Got a component with the name '${component.name}' for the screen '${name}'. React Components must start with an uppercase letter. If you're passing a regular function and not a component, pass it as children to 'Screen' instead. Otherwise capitalize your component's name.`);
|
|
119
|
+
}
|
|
100
120
|
}
|
|
101
121
|
} else {
|
|
102
122
|
throw new Error(`Couldn't find a 'component', 'getComponent' or 'children' prop for the screen '${name}'. This can happen if you passed 'undefined'. You likely forgot to export your component from the file it's defined in, or mixed up default import and named import when importing.`);
|
|
@@ -132,23 +152,27 @@ export default function useNavigationBuilder(createRouter, options) {
|
|
|
132
152
|
}));
|
|
133
153
|
const routeConfigs = getRouteConfigsFromChildren(children);
|
|
134
154
|
const screens = routeConfigs.reduce((acc, config) => {
|
|
135
|
-
if (config
|
|
136
|
-
throw new Error(`A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${config
|
|
155
|
+
if (config.props.name in acc) {
|
|
156
|
+
throw new Error(`A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${config.props.name}')`);
|
|
137
157
|
}
|
|
138
158
|
|
|
139
|
-
acc[config
|
|
159
|
+
acc[config.props.name] = config;
|
|
160
|
+
return acc;
|
|
161
|
+
}, {});
|
|
162
|
+
const routeNames = routeConfigs.map(config => config.props.name);
|
|
163
|
+
const routeKeyList = routeNames.reduce((acc, curr) => {
|
|
164
|
+
acc[curr] = screens[curr].keys.map(key => key !== null && key !== void 0 ? key : '').join(':');
|
|
140
165
|
return acc;
|
|
141
166
|
}, {});
|
|
142
|
-
const routeNames = routeConfigs.map(config => config[1].name);
|
|
143
167
|
const routeParamList = routeNames.reduce((acc, curr) => {
|
|
144
168
|
const {
|
|
145
169
|
initialParams
|
|
146
|
-
} = screens[curr]
|
|
170
|
+
} = screens[curr].props;
|
|
147
171
|
acc[curr] = initialParams;
|
|
148
172
|
return acc;
|
|
149
173
|
}, {});
|
|
150
174
|
const routeGetIdList = routeNames.reduce((acc, curr) => Object.assign(acc, {
|
|
151
|
-
[curr]: screens[curr]
|
|
175
|
+
[curr]: screens[curr].props.getId
|
|
152
176
|
}), {});
|
|
153
177
|
|
|
154
178
|
if (!routeNames.length) {
|
|
@@ -188,7 +212,7 @@ export default function useNavigationBuilder(createRouter, options) {
|
|
|
188
212
|
|
|
189
213
|
const {
|
|
190
214
|
initialParams
|
|
191
|
-
} = screens[curr]
|
|
215
|
+
} = screens[curr].props;
|
|
192
216
|
const initialParamsFromParams = (route === null || route === void 0 ? void 0 : (_route$params = route.params) === null || _route$params === void 0 ? void 0 : _route$params.state) == null && (route === null || route === void 0 ? void 0 : (_route$params2 = route.params) === null || _route$params2 === void 0 ? void 0 : _route$params2.initial) !== false && (route === null || route === void 0 ? void 0 : (_route$params3 = route.params) === null || _route$params3 === void 0 ? void 0 : _route$params3.screen) === curr ? route.params.params : undefined;
|
|
193
217
|
acc[curr] = initialParams !== undefined || initialParamsFromParams !== undefined ? { ...initialParams,
|
|
194
218
|
...initialParamsFromParams
|
|
@@ -221,18 +245,24 @@ export default function useNavigationBuilder(createRouter, options) {
|
|
|
221
245
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
222
246
|
|
|
223
247
|
}, [currentState, router, isStateValid]);
|
|
248
|
+
const previousRouteKeyListRef = React.useRef(routeKeyList);
|
|
249
|
+
React.useEffect(() => {
|
|
250
|
+
previousRouteKeyListRef.current = routeKeyList;
|
|
251
|
+
});
|
|
252
|
+
const previousRouteKeyList = previousRouteKeyListRef.current;
|
|
224
253
|
let state = // If the state isn't initialized, or stale, use the state we initialized instead
|
|
225
254
|
// The state won't update until there's a change needed in the state we have initalized locally
|
|
226
255
|
// So it'll be `undefined` or stale until the first navigation event happens
|
|
227
256
|
isStateInitialized(currentState) ? currentState : initializedState;
|
|
228
257
|
let nextState = state;
|
|
229
258
|
|
|
230
|
-
if (!isArrayEqual(state.routeNames, routeNames)) {
|
|
259
|
+
if (!isArrayEqual(state.routeNames, routeNames) || !isRecordEqual(routeKeyList, previousRouteKeyList)) {
|
|
231
260
|
// When the list of route names change, the router should handle it to remove invalid routes
|
|
232
261
|
nextState = router.getStateForRouteNamesChange(state, {
|
|
233
262
|
routeNames,
|
|
234
263
|
routeParamList,
|
|
235
|
-
routeGetIdList
|
|
264
|
+
routeGetIdList,
|
|
265
|
+
routeKeyChanges: Object.keys(routeKeyList).filter(name => previousRouteKeyList.hasOwnProperty(name) && routeKeyList[name] !== previousRouteKeyList[name])
|
|
236
266
|
});
|
|
237
267
|
}
|
|
238
268
|
|
|
@@ -342,7 +372,7 @@ export default function useNavigationBuilder(createRouter, options) {
|
|
|
342
372
|
...[screenListeners, ...routeNames.map(name => {
|
|
343
373
|
const {
|
|
344
374
|
listeners
|
|
345
|
-
} = screens[name]
|
|
375
|
+
} = screens[name].props;
|
|
346
376
|
return listeners;
|
|
347
377
|
})].map(listeners => {
|
|
348
378
|
const map = typeof listeners === 'function' ? listeners({
|
|
@@ -396,6 +426,7 @@ export default function useNavigationBuilder(createRouter, options) {
|
|
|
396
426
|
setState
|
|
397
427
|
});
|
|
398
428
|
const navigation = useNavigationHelpers({
|
|
429
|
+
id: options.id,
|
|
399
430
|
onAction,
|
|
400
431
|
getState,
|
|
401
432
|
emitter,
|