@react-navigation/core 6.2.2 → 6.4.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/README.md +17 -11
- package/lib/commonjs/BaseNavigationContainer.js.map +1 -1
- package/lib/commonjs/PreventRemoveContext.js +17 -0
- package/lib/commonjs/PreventRemoveContext.js.map +1 -0
- package/lib/commonjs/PreventRemoveProvider.js +114 -0
- package/lib/commonjs/PreventRemoveProvider.js.map +1 -0
- package/lib/commonjs/getStateFromPath.js +1 -1
- package/lib/commonjs/getStateFromPath.js.map +1 -1
- package/lib/commonjs/index.js +36 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/useComponent.js +22 -12
- package/lib/commonjs/useComponent.js.map +1 -1
- package/lib/commonjs/useEventEmitter.js +1 -1
- package/lib/commonjs/useEventEmitter.js.map +1 -1
- package/lib/commonjs/useFocusEffect.js +1 -1
- package/lib/commonjs/useFocusEffect.js.map +1 -1
- package/lib/commonjs/useKeyedChildListeners.js +2 -2
- package/lib/commonjs/useKeyedChildListeners.js.map +1 -1
- package/lib/commonjs/useNavigationBuilder.js +4 -2
- package/lib/commonjs/useNavigationBuilder.js.map +1 -1
- package/lib/commonjs/usePreventRemove.js +59 -0
- package/lib/commonjs/usePreventRemove.js.map +1 -0
- package/lib/commonjs/usePreventRemoveContext.js +27 -0
- package/lib/commonjs/usePreventRemoveContext.js.map +1 -0
- package/lib/module/BaseNavigationContainer.js.map +1 -1
- package/lib/module/PreventRemoveContext.js +9 -0
- package/lib/module/PreventRemoveContext.js.map +1 -0
- package/lib/module/PreventRemoveProvider.js +96 -0
- package/lib/module/PreventRemoveProvider.js.map +1 -0
- package/lib/module/getStateFromPath.js +1 -1
- package/lib/module/getStateFromPath.js.map +1 -1
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/useComponent.js +23 -12
- package/lib/module/useComponent.js.map +1 -1
- package/lib/module/useEventEmitter.js +1 -1
- package/lib/module/useEventEmitter.js.map +1 -1
- package/lib/module/useFocusEffect.js +1 -1
- package/lib/module/useFocusEffect.js.map +1 -1
- package/lib/module/useKeyedChildListeners.js +2 -2
- package/lib/module/useKeyedChildListeners.js.map +1 -1
- package/lib/module/useNavigationBuilder.js +3 -2
- package/lib/module/useNavigationBuilder.js.map +1 -1
- package/lib/module/usePreventRemove.js +41 -0
- package/lib/module/usePreventRemove.js.map +1 -0
- package/lib/module/usePreventRemoveContext.js +12 -0
- package/lib/module/usePreventRemoveContext.js.map +1 -0
- package/lib/typescript/src/PreventRemoveContext.d.ts +13 -0
- package/lib/typescript/src/PreventRemoveProvider.d.ts +9 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/types.d.ts +10 -6
- package/lib/typescript/src/useComponent.d.ts +5 -1
- package/lib/typescript/src/useDescriptors.d.ts +3 -3
- package/lib/typescript/src/useNavigationBuilder.d.ts +9 -7
- package/lib/typescript/src/useNavigationHelpers.d.ts +3 -3
- package/lib/typescript/src/usePreventRemove.d.ts +12 -0
- package/lib/typescript/src/usePreventRemoveContext.d.ts +4 -0
- package/package.json +10 -8
- package/src/BaseNavigationContainer.tsx +1 -1
- package/src/PreventRemoveContext.tsx +21 -0
- package/src/PreventRemoveProvider.tsx +126 -0
- package/src/getStateFromPath.tsx +4 -1
- package/src/index.tsx +4 -0
- package/src/types.tsx +39 -14
- package/src/useComponent.tsx +19 -12
- package/src/useEventEmitter.tsx +3 -1
- package/src/useFocusEffect.tsx +1 -1
- package/src/useKeyedChildListeners.tsx +6 -4
- package/src/useNavigationBuilder.tsx +9 -5
- package/src/usePreventRemove.tsx +51 -0
- package/src/usePreventRemoveContext.tsx +15 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["types.tsx"],"names":["PrivateValueStore"],"mappings":";;;;;;;;;AA+JO,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
|
+
{"version":3,"sources":["types.tsx"],"names":["PrivateValueStore"],"mappings":";;;;;;;;;AA+JO,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: // this first condition allows us to iterate over a union type\n // This is to avoid getting a union of all the params from `ParamList[RouteName]`,\n // which will get our types all mixed up if a union RouteName is passed in.\n RouteName extends unknown\n ? // This condition checks if the params are optional,\n // which means it's either undefined or a union with undefined\n undefined extends ParamList[RouteName]\n ?\n | [screen: RouteName] // if the params are optional, we don't have to provide it\n | [screen: RouteName, params: ParamList[RouteName]]\n : [screen: RouteName, params: ParamList[RouteName]]\n : never\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: RouteName extends unknown\n ?\n | { key: string; params?: ParamList[RouteName]; merge?: boolean }\n | {\n name: RouteName;\n key?: string;\n params: ParamList[RouteName];\n merge?: boolean;\n }\n : never\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(\n params: ParamList[RouteName] extends undefined\n ? undefined\n : Partial<ParamList[RouteName]>\n ): 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\ntype ScreenComponentType<\n ParamList extends ParamListBase,\n RouteName extends keyof ParamList\n> =\n | React.ComponentType<{\n route: RouteProp<ParamList, RouteName>;\n navigation: any;\n }>\n | React.ComponentType<{}>;\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: ScreenComponentType<ParamList, RouteName>;\n getComponent?: never;\n children?: never;\n }\n | {\n /**\n * Lazily get a React component to render for this screen.\n */\n getComponent: () => ScreenComponentType<ParamList, RouteName>;\n component?: never;\n children?: never;\n }\n | {\n /**\n * Render callback to render content of this screen.\n */\n children: (props: {\n route: RouteProp<ParamList, RouteName>;\n navigation: any;\n }) => React.ReactNode;\n component?: never;\n getComponent?: never;\n };\n\nexport type RouteConfig<\n ParamList extends ParamListBase,\n RouteName extends keyof ParamList,\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n> = {\n /**\n * Optional key for this screen. This doesn't need to be unique.\n * If the key changes, existing screens with this name will be removed or reset.\n * Useful when we have some common screens and have conditional rendering.\n */\n navigationKey?: string;\n\n /**\n * Route name of this screen.\n */\n name: RouteName;\n\n /**\n * Navigator options for this screen.\n */\n options?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamList, RouteName>;\n navigation: any;\n }) => ScreenOptions);\n\n /**\n * Event listeners for this screen.\n */\n listeners?:\n | ScreenListeners<State, EventMap>\n | ((props: {\n route: RouteProp<ParamList, RouteName>;\n navigation: any;\n }) => ScreenListeners<State, EventMap>);\n\n /**\n * Function to return an unique ID for this screen.\n * Receives an object with the route params.\n * For a given screen name, there will always be only one screen corresponding to an ID.\n * If `undefined` is returned, it acts same as no `getId` being specified.\n */\n getId?: ({ params }: { params: ParamList[RouteName] }) => string | undefined;\n\n /**\n * Initial params object for the route.\n */\n initialParams?: Partial<ParamList[RouteName]>;\n} & RouteConfigComponent<ParamList, RouteName>;\n\nexport type RouteGroupConfig<\n ParamList extends ParamListBase,\n ScreenOptions extends {}\n> = {\n /**\n * Optional key for the screens in this group.\n * If the key changes, all existing screens in this group will be removed or reset.\n */\n navigationKey?: string;\n\n /**\n * Navigator options for this screen.\n */\n screenOptions?:\n | ScreenOptions\n | ((props: {\n route: RouteProp<ParamList, keyof ParamList>;\n navigation: any;\n }) => ScreenOptions);\n /**\n * Children React Elements to extract the route configuration from.\n * Only `Screen`, `Group` and `React.Fragment` are supported as children.\n */\n children: React.ReactNode;\n};\n\nexport type NavigationContainerEventMap = {\n /**\n * Event which fires when the navigation state changes.\n */\n state: {\n data: {\n /**\n * The updated state object after the state change.\n */\n state: NavigationState | PartialState<NavigationState> | undefined;\n };\n };\n /**\n * Event which fires when current options changes.\n */\n options: { data: { options: object } };\n /**\n * Event which fires when an action is dispatched.\n * Only intended for debugging purposes, don't use it for app logic.\n * This event will be emitted before state changes have been applied.\n */\n __unsafe_action__: {\n data: {\n /**\n * The action object which was dispatched.\n */\n action: NavigationAction;\n /**\n * Whether the action was a no-op, i.e. resulted any state changes.\n */\n noop: boolean;\n /**\n * Stack trace of the action, this will only be available during development.\n */\n stack: string | undefined;\n };\n };\n};\n\nexport type NavigationContainerRef<ParamList extends {}> =\n NavigationHelpers<ParamList> &\n EventConsumer<NavigationContainerEventMap> & {\n /**\n * Reset the navigation state of the root navigator to the provided state.\n *\n * @param state Navigation state object.\n */\n resetRoot(state?: PartialState<NavigationState> | NavigationState): void;\n /**\n * Get the rehydrated navigation state of the navigation tree.\n */\n getRootState(): NavigationState;\n /**\n * Get the currently focused navigation route.\n */\n getCurrentRoute(): Route<string> | undefined;\n /**\n * Get the currently focused route's options.\n */\n getCurrentOptions(): object | undefined;\n /**\n * Whether the navigation container is ready to handle actions.\n */\n isReady(): boolean;\n };\n\nexport type NavigationContainerRefWithCurrent<ParamList extends {}> =\n NavigationContainerRef<ParamList> & {\n current: NavigationContainerRef<ParamList> | null;\n };\n\nexport type TypedNavigator<\n ParamList extends ParamListBase,\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase,\n Navigator extends React.ComponentType<any>\n> = {\n /**\n * Navigator component which manages the child screens.\n */\n Navigator: React.ComponentType<\n Omit<\n React.ComponentProps<Navigator>,\n keyof DefaultNavigatorOptions<any, any, any, any>\n > &\n DefaultNavigatorOptions<ParamList, State, ScreenOptions, EventMap>\n >;\n /**\n * Component used for grouping multiple route configuration.\n */\n Group: React.ComponentType<RouteGroupConfig<ParamList, ScreenOptions>>;\n /**\n * Component used for specifying route configuration.\n */\n Screen: <RouteName extends keyof ParamList>(\n _: RouteConfig<ParamList, RouteName, State, ScreenOptions, EventMap>\n ) => null;\n};\n\nexport type NavigatorScreenParams<\n ParamList,\n State extends NavigationState = NavigationState\n> =\n | {\n screen?: never;\n params?: never;\n initial?: never;\n path?: string;\n state: PartialState<State> | State | undefined;\n }\n | {\n [RouteName in keyof ParamList]: undefined extends ParamList[RouteName]\n ? {\n screen: RouteName;\n params?: ParamList[RouteName];\n initial?: boolean;\n path?: string;\n state?: never;\n }\n : {\n screen: RouteName;\n params: ParamList[RouteName];\n initial?: boolean;\n path?: string;\n state?: never;\n };\n }[keyof ParamList];\n\nexport type PathConfig<ParamList extends {}> = {\n path?: string;\n exact?: boolean;\n parse?: Record<string, (value: string) => any>;\n stringify?: Record<string, (value: any) => string>;\n screens?: PathConfigMap<ParamList>;\n initialRouteName?: keyof ParamList;\n};\n\nexport type PathConfigMap<ParamList extends {}> = {\n [RouteName in keyof ParamList]?: NonNullable<\n ParamList[RouteName]\n > extends NavigatorScreenParams<infer T, any>\n ? string | PathConfig<T>\n : string | Omit<PathConfig<{}>, 'screens' | 'initialRouteName'>;\n};\n"]}
|
|
@@ -11,26 +11,36 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const NavigationContent = _ref => {
|
|
15
|
+
let {
|
|
16
|
+
render,
|
|
17
|
+
children
|
|
18
|
+
} = _ref;
|
|
19
|
+
return render(children);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function useComponent(render) {
|
|
23
|
+
const renderRef = React.useRef(render); // Normally refs shouldn't be mutated in render
|
|
18
24
|
// But we return a component which will be rendered
|
|
19
25
|
// So it's just for immediate consumption
|
|
20
26
|
|
|
21
|
-
|
|
27
|
+
renderRef.current = render;
|
|
22
28
|
React.useEffect(() => {
|
|
23
|
-
|
|
29
|
+
renderRef.current = null;
|
|
24
30
|
});
|
|
25
|
-
return React.useRef(
|
|
26
|
-
|
|
31
|
+
return React.useRef(_ref2 => {
|
|
32
|
+
let {
|
|
33
|
+
children
|
|
34
|
+
} = _ref2;
|
|
35
|
+
const render = renderRef.current;
|
|
27
36
|
|
|
28
|
-
if (
|
|
37
|
+
if (render === null) {
|
|
29
38
|
throw new Error('The returned component must be rendered in the same render phase as the hook.');
|
|
30
|
-
}
|
|
31
|
-
|
|
39
|
+
}
|
|
32
40
|
|
|
33
|
-
return /*#__PURE__*/React.createElement(
|
|
41
|
+
return /*#__PURE__*/React.createElement(NavigationContent, {
|
|
42
|
+
render: render
|
|
43
|
+
}, children);
|
|
34
44
|
}).current;
|
|
35
45
|
}
|
|
36
46
|
//# sourceMappingURL=useComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useComponent.tsx"],"names":["
|
|
1
|
+
{"version":3,"sources":["useComponent.tsx"],"names":["NavigationContent","render","children","useComponent","renderRef","React","useRef","current","useEffect","Error"],"mappings":";;;;;;;AAAA;;;;;;AASA,MAAMA,iBAAiB,GAAG,QAAiC;AAAA,MAAhC;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAAgC;AACzD,SAAOD,MAAM,CAACC,QAAD,CAAb;AACD,CAFD;;AAIe,SAASC,YAAT,CAAsBF,MAAtB,EAAsC;AACnD,QAAMG,SAAS,GAAGC,KAAK,CAACC,MAAN,CAA4BL,MAA5B,CAAlB,CADmD,CAGnD;AACA;AACA;;AACAG,EAAAA,SAAS,CAACG,OAAV,GAAoBN,MAApB;AAEAI,EAAAA,KAAK,CAACG,SAAN,CAAgB,MAAM;AACpBJ,IAAAA,SAAS,CAACG,OAAV,GAAoB,IAApB;AACD,GAFD;AAIA,SAAOF,KAAK,CAACC,MAAN,CAAa,SAAiD;AAAA,QAAhD;AAAEJ,MAAAA;AAAF,KAAgD;AACnE,UAAMD,MAAM,GAAGG,SAAS,CAACG,OAAzB;;AAEA,QAAIN,MAAM,KAAK,IAAf,EAAqB;AACnB,YAAM,IAAIQ,KAAJ,CACJ,+EADI,CAAN;AAGD;;AAED,wBAAO,oBAAC,iBAAD;AAAmB,MAAA,MAAM,EAAER;AAA3B,OAAoCC,QAApC,CAAP;AACD,GAVM,EAUJK,OAVH;AAWD","sourcesContent":["import * as React from 'react';\n\ntype Render = (children: React.ReactNode) => JSX.Element;\n\ntype Props = {\n render: Render;\n children: React.ReactNode;\n};\n\nconst NavigationContent = ({ render, children }: Props) => {\n return render(children);\n};\n\nexport default function useComponent(render: Render) {\n const renderRef = React.useRef<Render | null>(render);\n\n // Normally refs shouldn't be mutated in render\n // But we return a component which will be rendered\n // So it's just for immediate consumption\n renderRef.current = render;\n\n React.useEffect(() => {\n renderRef.current = null;\n });\n\n return React.useRef(({ children }: { children: React.ReactNode }) => {\n const render = renderRef.current;\n\n if (render === null) {\n throw new Error(\n 'The returned component must be rendered in the same render phase as the hook.'\n );\n }\n\n return <NavigationContent render={render}>{children}</NavigationContent>;\n }).current;\n}\n"]}
|
|
@@ -19,7 +19,7 @@ function useEventEmitter(listen) {
|
|
|
19
19
|
React.useEffect(() => {
|
|
20
20
|
listenRef.current = listen;
|
|
21
21
|
});
|
|
22
|
-
const listeners = React.useRef(
|
|
22
|
+
const listeners = React.useRef(Object.create(null));
|
|
23
23
|
const create = React.useCallback(target => {
|
|
24
24
|
const removeListener = (type, callback) => {
|
|
25
25
|
const callbacks = listeners.current[type] ? listeners.current[type][target] : undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useEventEmitter.tsx"],"names":["useEventEmitter","listen","listenRef","React","useRef","useEffect","current","listeners","create","useCallback","target","removeListener","type","callback","callbacks","undefined","index","indexOf","splice","addListener","push","removed","emit","data","canPreventDefault","items","slice","concat","
|
|
1
|
+
{"version":3,"sources":["useEventEmitter.tsx"],"names":["useEventEmitter","listen","listenRef","React","useRef","useEffect","current","listeners","Object","create","useCallback","target","removeListener","type","callback","callbacks","undefined","index","indexOf","splice","addListener","push","removed","emit","data","canPreventDefault","items","slice","concat","keys","map","t","filter","cb","i","self","lastIndexOf","event","defineProperty","enumerable","get","defaultPrevented","defineProperties","preventDefault","value","forEach","useMemo"],"mappings":";;;;;;;AAAA;;;;;;AAWA;AACA;AACA;AACe,SAASA,eAAT,CACbC,MADa,EAEc;AAC3B,QAAMC,SAAS,GAAGC,KAAK,CAACC,MAAN,CAAaH,MAAb,CAAlB;AAEAE,EAAAA,KAAK,CAACE,SAAN,CAAgB,MAAM;AACpBH,IAAAA,SAAS,CAACI,OAAV,GAAoBL,MAApB;AACD,GAFD;AAIA,QAAMM,SAAS,GAAGJ,KAAK,CAACC,MAAN,CAChBI,MAAM,CAACC,MAAP,CAAc,IAAd,CADgB,CAAlB;AAIA,QAAMA,MAAM,GAAGN,KAAK,CAACO,WAAN,CAAmBC,MAAD,IAAoB;AACnD,UAAMC,cAAc,GAAG,CAACC,IAAD,EAAeC,QAAf,KAAiD;AACtE,YAAMC,SAAS,GAAGR,SAAS,CAACD,OAAV,CAAkBO,IAAlB,IACdN,SAAS,CAACD,OAAV,CAAkBO,IAAlB,EAAwBF,MAAxB,CADc,GAEdK,SAFJ;;AAIA,UAAI,CAACD,SAAL,EAAgB;AACd;AACD;;AAED,YAAME,KAAK,GAAGF,SAAS,CAACG,OAAV,CAAkBJ,QAAlB,CAAd;;AAEA,UAAIG,KAAK,GAAG,CAAC,CAAb,EAAgB;AACdF,QAAAA,SAAS,CAACI,MAAV,CAAiBF,KAAjB,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GAtEU,EAuEX,EAvEW,CAAb;AA0EA,SAAOlC,KAAK,CAAC2C,OAAN,CAAc,OAAO;AAAErC,IAAAA,MAAF;AAAUc,IAAAA;AAAV,GAAP,CAAd,EAAwC,CAACd,MAAD,EAASc,IAAT,CAAxC,CAAP;AACD","sourcesContent":["import * as React from 'react';\n\nimport type { EventArg, EventConsumer, EventEmitter } from './types';\n\nexport type NavigationEventEmitter<T extends Record<string, any>> =\n EventEmitter<T> & {\n create: (target: string) => EventConsumer<T>;\n };\n\ntype Listeners = ((e: any) => void)[];\n\n/**\n * Hook to manage the event system used by the navigator to notify screens of various events.\n */\nexport default function useEventEmitter<T extends Record<string, any>>(\n listen?: (e: any) => void\n): NavigationEventEmitter<T> {\n const listenRef = React.useRef(listen);\n\n React.useEffect(() => {\n listenRef.current = listen;\n });\n\n const listeners = React.useRef<Record<string, Record<string, Listeners>>>(\n Object.create(null)\n );\n\n const create = React.useCallback((target: string) => {\n const removeListener = (type: string, callback: (data: any) => void) => {\n const callbacks = listeners.current[type]\n ? listeners.current[type][target]\n : undefined;\n\n if (!callbacks) {\n return;\n }\n\n const index = callbacks.indexOf(callback);\n\n if (index > -1) {\n callbacks.splice(index, 1);\n }\n };\n\n const addListener = (type: string, callback: (data: any) => void) => {\n listeners.current[type] = listeners.current[type] || {};\n listeners.current[type][target] = listeners.current[type][target] || [];\n listeners.current[type][target].push(callback);\n\n let removed = false;\n return () => {\n // Prevent removing other listeners when unsubscribing same listener multiple times\n if (!removed) {\n removed = true;\n removeListener(type, callback);\n }\n };\n };\n\n return {\n addListener,\n removeListener,\n };\n }, []);\n\n const emit = React.useCallback(\n ({\n type,\n data,\n target,\n canPreventDefault,\n }: {\n type: string;\n data?: any;\n target?: string;\n canPreventDefault?: boolean;\n }) => {\n const items = listeners.current[type] || {};\n\n // Copy the current list of callbacks in case they are mutated during execution\n const callbacks =\n target !== undefined\n ? items[target]?.slice()\n : ([] as Listeners)\n .concat(...Object.keys(items).map((t) => items[t]))\n .filter((cb, i, self) => self.lastIndexOf(cb) === i);\n\n const event: EventArg<any, any, any> = {\n get type() {\n return type;\n },\n };\n\n if (target !== undefined) {\n Object.defineProperty(event, 'target', {\n enumerable: true,\n get() {\n return target;\n },\n });\n }\n\n if (data !== undefined) {\n Object.defineProperty(event, 'data', {\n enumerable: true,\n get() {\n return data;\n },\n });\n }\n\n if (canPreventDefault) {\n let defaultPrevented = false;\n\n Object.defineProperties(event, {\n defaultPrevented: {\n enumerable: true,\n get() {\n return defaultPrevented;\n },\n },\n preventDefault: {\n enumerable: true,\n value() {\n defaultPrevented = true;\n },\n },\n });\n }\n\n listenRef.current?.(event);\n\n callbacks?.forEach((cb) => cb(event));\n\n return event as any;\n },\n []\n );\n\n return React.useMemo(() => ({ create, emit }), [create, emit]);\n}\n"]}
|
|
@@ -47,7 +47,7 @@ function useFocusEffect(effect) {
|
|
|
47
47
|
if (destroy === null) {
|
|
48
48
|
message += " You returned 'null'. If your effect does not require clean-up, return 'undefined' (or nothing).";
|
|
49
49
|
} else if (typeof destroy.then === 'function') {
|
|
50
|
-
message += "\n\nIt looks like you wrote 'useFocusEffect(async () => ...)' or returned a Promise. " + 'Instead, write the async function inside your effect ' + 'and call it immediately:\n\n' + 'useFocusEffect(\n' + ' React.useCallback() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n\n' + ' fetchData();\n' + ' }, [someId])\n' + ');\n\n' + 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';
|
|
50
|
+
message += "\n\nIt looks like you wrote 'useFocusEffect(async () => ...)' or returned a Promise. " + 'Instead, write the async function inside your effect ' + 'and call it immediately:\n\n' + 'useFocusEffect(\n' + ' React.useCallback(() => {\n' + ' async function fetchData() {\n' + ' // You can await here\n' + ' const response = await MyAPI.getData(someId);\n' + ' // ...\n' + ' }\n\n' + ' fetchData();\n' + ' }, [someId])\n' + ');\n\n' + 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';
|
|
51
51
|
} else {
|
|
52
52
|
message += ` You returned '${JSON.stringify(destroy)}'.`;
|
|
53
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useFocusEffect.tsx"],"names":["useFocusEffect","effect","navigation","arguments","undefined","message","console","error","React","useEffect","isFocused","cleanup","callback","destroy","process","env","NODE_ENV","then","JSON","stringify","unsubscribeFocus","addListener","unsubscribeBlur"],"mappings":";;;;;;;AAAA;;AAEA;;;;;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAwBC,MAAxB,EAAgD;AAC7D,QAAMC,UAAU,GAAG,6BAAnB;;AAEA,MAAIC,SAAS,CAAC,CAAD,CAAT,KAAiBC,SAArB,EAAgC;AAC9B,UAAMC,OAAO,GACX,yFACA,8EADA,GAEA,mBAFA,GAGA,+BAHA,GAIA,yBAJA,GAKA,sBALA,GAMA,QANA,GAOA,oEARF;AAUAC,IAAAA,OAAO,CAACC,KAAR,CAAcF,OAAd;AACD;;AAEDG,EAAAA,KAAK,CAACC,SAAN,CAAgB,MAAM;AACpB,QAAIC,SAAS,GAAG,KAAhB;AACA,QAAIC,OAAJ;;AAEA,UAAMC,QAAQ,GAAG,MAAM;AACrB,YAAMC,OAAO,GAAGZ,MAAM,EAAtB;;AAEA,UAAIY,OAAO,KAAKT,SAAZ,IAAyB,OAAOS,OAAP,KAAmB,UAAhD,EAA4D;AAC1D,eAAOA,OAAP;AACD;;AAED,UAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,YAAIX,OAAO,GACT,6FADF;;AAGA,YAAIQ,OAAO,KAAK,IAAhB,EAAsB;AACpBR,UAAAA,OAAO,IACL,kGADF;AAED,SAHD,MAGO,IAAI,OAAQQ,OAAD,CAAiBI,IAAxB,KAAiC,UAArC,EAAiD;AACtDZ,UAAAA,OAAO,IACL,0FACA,uDADA,GAEA,8BAFA,GAGA,mBAHA,GAIA,
|
|
1
|
+
{"version":3,"sources":["useFocusEffect.tsx"],"names":["useFocusEffect","effect","navigation","arguments","undefined","message","console","error","React","useEffect","isFocused","cleanup","callback","destroy","process","env","NODE_ENV","then","JSON","stringify","unsubscribeFocus","addListener","unsubscribeBlur"],"mappings":";;;;;;;AAAA;;AAEA;;;;;;;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAwBC,MAAxB,EAAgD;AAC7D,QAAMC,UAAU,GAAG,6BAAnB;;AAEA,MAAIC,SAAS,CAAC,CAAD,CAAT,KAAiBC,SAArB,EAAgC;AAC9B,UAAMC,OAAO,GACX,yFACA,8EADA,GAEA,mBAFA,GAGA,+BAHA,GAIA,yBAJA,GAKA,sBALA,GAMA,QANA,GAOA,oEARF;AAUAC,IAAAA,OAAO,CAACC,KAAR,CAAcF,OAAd;AACD;;AAEDG,EAAAA,KAAK,CAACC,SAAN,CAAgB,MAAM;AACpB,QAAIC,SAAS,GAAG,KAAhB;AACA,QAAIC,OAAJ;;AAEA,UAAMC,QAAQ,GAAG,MAAM;AACrB,YAAMC,OAAO,GAAGZ,MAAM,EAAtB;;AAEA,UAAIY,OAAO,KAAKT,SAAZ,IAAyB,OAAOS,OAAP,KAAmB,UAAhD,EAA4D;AAC1D,eAAOA,OAAP;AACD;;AAED,UAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,YAAIX,OAAO,GACT,6FADF;;AAGA,YAAIQ,OAAO,KAAK,IAAhB,EAAsB;AACpBR,UAAAA,OAAO,IACL,kGADF;AAED,SAHD,MAGO,IAAI,OAAQQ,OAAD,CAAiBI,IAAxB,KAAiC,UAArC,EAAiD;AACtDZ,UAAAA,OAAO,IACL,0FACA,uDADA,GAEA,8BAFA,GAGA,mBAHA,GAIA,+BAJA,GAKA,oCALA,GAMA,+BANA,GAOA,uDAPA,GAQA,gBARA,GASA,WATA,GAUA,oBAVA,GAWA,kBAXA,GAYA,QAZA,GAaA,oEAdF;AAeD,SAhBM,MAgBA;AACLA,UAAAA,OAAO,IAAK,kBAAiBa,IAAI,CAACC,SAAL,CAAeN,OAAf,CAAwB,IAArD;AACD;;AAEDP,QAAAA,OAAO,CAACC,KAAR,CAAcF,OAAd;AACD;AACF,KApCD,CAJoB,CA0CpB;;;AACA,QAAIH,UAAU,CAACQ,SAAX,EAAJ,EAA4B;AAC1BC,MAAAA,OAAO,GAAGC,QAAQ,EAAlB;AACAF,MAAAA,SAAS,GAAG,IAAZ;AACD;;AAED,UAAMU,gBAAgB,GAAGlB,UAAU,CAACmB,WAAX,CAAuB,OAAvB,EAAgC,MAAM;AAC7D;AACA;AACA,UAAIX,SAAJ,EAAe;AACb;AACD;;AAED,UAAIC,OAAO,KAAKP,SAAhB,EAA2B;AACzBO,QAAAA,OAAO;AACR;;AAEDA,MAAAA,OAAO,GAAGC,QAAQ,EAAlB;AACAF,MAAAA,SAAS,GAAG,IAAZ;AACD,KAbwB,CAAzB;AAeA,UAAMY,eAAe,GAAGpB,UAAU,CAACmB,WAAX,CAAuB,MAAvB,EAA+B,MAAM;AAC3D,UAAIV,OAAO,KAAKP,SAAhB,EAA2B;AACzBO,QAAAA,OAAO;AACR;;AAEDA,MAAAA,OAAO,GAAGP,SAAV;AACAM,MAAAA,SAAS,GAAG,KAAZ;AACD,KAPuB,CAAxB;AASA,WAAO,MAAM;AACX,UAAIC,OAAO,KAAKP,SAAhB,EAA2B;AACzBO,QAAAA,OAAO;AACR;;AAEDS,MAAAA,gBAAgB;AAChBE,MAAAA,eAAe;AAChB,KAPD;AAQD,GAhFD,EAgFG,CAACrB,MAAD,EAASC,UAAT,CAhFH;AAiFD","sourcesContent":["import * as React from 'react';\n\nimport useNavigation from './useNavigation';\n\ntype EffectCallback = () => undefined | void | (() => void);\n\n/**\n * Hook to run an effect in a focused screen, similar to `React.useEffect`.\n * This can be used to perform side-effects such as fetching data or subscribing to events.\n * The passed callback should be wrapped in `React.useCallback` to avoid running the effect too often.\n *\n * @param callback Memoized callback containing the effect, should optionally return a cleanup function.\n */\nexport default function useFocusEffect(effect: EffectCallback) {\n const navigation = useNavigation();\n\n if (arguments[1] !== undefined) {\n const message =\n \"You passed a second argument to 'useFocusEffect', but it only accepts one argument. \" +\n \"If you want to pass a dependency array, you can use 'React.useCallback':\\n\\n\" +\n 'useFocusEffect(\\n' +\n ' React.useCallback(() => {\\n' +\n ' // Your code here\\n' +\n ' }, [depA, depB])\\n' +\n ');\\n\\n' +\n 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';\n\n console.error(message);\n }\n\n React.useEffect(() => {\n let isFocused = false;\n let cleanup: undefined | void | (() => void);\n\n const callback = () => {\n const destroy = effect();\n\n if (destroy === undefined || typeof destroy === 'function') {\n return destroy;\n }\n\n if (process.env.NODE_ENV !== 'production') {\n let message =\n 'An effect function must not return anything besides a function, which is used for clean-up.';\n\n if (destroy === null) {\n message +=\n \" You returned 'null'. If your effect does not require clean-up, return 'undefined' (or nothing).\";\n } else if (typeof (destroy as any).then === 'function') {\n message +=\n \"\\n\\nIt looks like you wrote 'useFocusEffect(async () => ...)' or returned a Promise. \" +\n 'Instead, write the async function inside your effect ' +\n 'and call it immediately:\\n\\n' +\n 'useFocusEffect(\\n' +\n ' React.useCallback(() => {\\n' +\n ' async function fetchData() {\\n' +\n ' // You can await here\\n' +\n ' const response = await MyAPI.getData(someId);\\n' +\n ' // ...\\n' +\n ' }\\n\\n' +\n ' fetchData();\\n' +\n ' }, [someId])\\n' +\n ');\\n\\n' +\n 'See usage guide: https://reactnavigation.org/docs/use-focus-effect';\n } else {\n message += ` You returned '${JSON.stringify(destroy)}'.`;\n }\n\n console.error(message);\n }\n };\n\n // We need to run the effect on intial render/dep changes if the screen is focused\n if (navigation.isFocused()) {\n cleanup = callback();\n isFocused = true;\n }\n\n const unsubscribeFocus = navigation.addListener('focus', () => {\n // If callback was already called for focus, avoid calling it again\n // The focus event may also fire on intial render, so we guard against runing the effect twice\n if (isFocused) {\n return;\n }\n\n if (cleanup !== undefined) {\n cleanup();\n }\n\n cleanup = callback();\n isFocused = true;\n });\n\n const unsubscribeBlur = navigation.addListener('blur', () => {\n if (cleanup !== undefined) {\n cleanup();\n }\n\n cleanup = undefined;\n isFocused = false;\n });\n\n return () => {\n if (cleanup !== undefined) {\n cleanup();\n }\n\n unsubscribeFocus();\n unsubscribeBlur();\n };\n }, [effect, navigation]);\n}\n"]}
|
|
@@ -17,10 +17,10 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
17
17
|
function useKeyedChildListeners() {
|
|
18
18
|
const {
|
|
19
19
|
current: keyedListeners
|
|
20
|
-
} = React.useRef({
|
|
20
|
+
} = React.useRef(Object.assign(Object.create(null), {
|
|
21
21
|
getState: {},
|
|
22
22
|
beforeRemove: {}
|
|
23
|
-
});
|
|
23
|
+
}));
|
|
24
24
|
const addKeyedListener = React.useCallback((type, key, listener) => {
|
|
25
25
|
// @ts-expect-error: according to ref stated above you can use `key` to index type
|
|
26
26
|
keyedListeners[type][key] = listener;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useKeyedChildListeners.tsx"],"names":["useKeyedChildListeners","current","keyedListeners","React","useRef","getState","beforeRemove","addKeyedListener","useCallback","type","key","listener","undefined"],"mappings":";;;;;;;AAAA;;;;;;AAIA;AACA;AACA;AACe,SAASA,sBAAT,GAAkC;AAC/C,QAAM;AAAEC,IAAAA,OAAO,EAAEC;AAAX,MAA8BC,KAAK,CAACC,MAAN,
|
|
1
|
+
{"version":3,"sources":["useKeyedChildListeners.tsx"],"names":["useKeyedChildListeners","current","keyedListeners","React","useRef","Object","assign","create","getState","beforeRemove","addKeyedListener","useCallback","type","key","listener","undefined"],"mappings":";;;;;;;AAAA;;;;;;AAIA;AACA;AACA;AACe,SAASA,sBAAT,GAAkC;AAC/C,QAAM;AAAEC,IAAAA,OAAO,EAAEC;AAAX,MAA8BC,KAAK,CAACC,MAAN,CAMlCC,MAAM,CAACC,MAAP,CAAcD,MAAM,CAACE,MAAP,CAAc,IAAd,CAAd,EAAmC;AACjCC,IAAAA,QAAQ,EAAE,EADuB;AAEjCC,IAAAA,YAAY,EAAE;AAFmB,GAAnC,CANkC,CAApC;AAYA,QAAMC,gBAAgB,GAAGP,KAAK,CAACQ,WAAN,CACvB,CACEC,IADF,EAEEC,GAFF,EAGEC,QAHF,KAIK;AACH;AACAZ,IAAAA,cAAc,CAACU,IAAD,CAAd,CAAqBC,GAArB,IAA4BC,QAA5B;AAEA,WAAO,MAAM;AACX;AACAZ,MAAAA,cAAc,CAACU,IAAD,CAAd,CAAqBC,GAArB,IAA4BE,SAA5B;AACD,KAHD;AAID,GAbsB,EAcvB,CAACb,cAAD,CAduB,CAAzB;AAiBA,SAAO;AACLA,IAAAA,cADK;AAELQ,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 Object.assign(Object.create(null), {\n getState: {},\n beforeRemove: {},\n })\n );\n\n const addKeyedListener = React.useCallback(\n <T extends keyof KeyedListenerMap>(\n type: T,\n key: string,\n listener: KeyedListenerMap[T]\n ) => {\n // @ts-expect-error: according to ref stated above you can use `key` to index type\n keyedListeners[type][key] = listener;\n\n return () => {\n // @ts-expect-error: according to ref stated above you can use `key` to index type\n keyedListeners[type][key] = undefined;\n };\n },\n [keyedListeners]\n );\n\n return {\n keyedListeners,\n addKeyedListener,\n };\n}\n"]}
|
|
@@ -23,6 +23,8 @@ var _NavigationRouteContext = _interopRequireDefault(require("./NavigationRouteC
|
|
|
23
23
|
|
|
24
24
|
var _NavigationStateContext = _interopRequireDefault(require("./NavigationStateContext"));
|
|
25
25
|
|
|
26
|
+
var _PreventRemoveProvider = _interopRequireDefault(require("./PreventRemoveProvider"));
|
|
27
|
+
|
|
26
28
|
var _Screen = _interopRequireDefault(require("./Screen"));
|
|
27
29
|
|
|
28
30
|
var _types = require("./types");
|
|
@@ -499,9 +501,9 @@ function useNavigationBuilder(createRouter, options) {
|
|
|
499
501
|
navigation,
|
|
500
502
|
descriptors
|
|
501
503
|
});
|
|
502
|
-
const NavigationContent = (0, _useComponent.default)(_NavigationHelpersContext.default.Provider, {
|
|
504
|
+
const NavigationContent = (0, _useComponent.default)(children => /*#__PURE__*/React.createElement(_NavigationHelpersContext.default.Provider, {
|
|
503
505
|
value: navigation
|
|
504
|
-
});
|
|
506
|
+
}, /*#__PURE__*/React.createElement(_PreventRemoveProvider.default, null, children)));
|
|
505
507
|
return {
|
|
506
508
|
state,
|
|
507
509
|
navigation,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useNavigationBuilder.tsx"],"names":["PrivateValueStore","isValidKey","key","undefined","getRouteConfigsFromChildren","children","groupKey","groupOptions","configs","React","Children","toArray","reduce","acc","child","isValidElement","type","Screen","props","navigationKey","Error","JSON","stringify","name","push","keys","options","Fragment","Group","screenOptions","String","process","env","NODE_ENV","forEach","config","component","getComponent","console","warn","test","useNavigationBuilder","createRouter","navigatorKey","route","useContext","NavigationRouteContext","screenListeners","rest","current","router","useRef","params","state","initial","screen","initialRouteName","routeConfigs","screens","routeNames","map","routeKeyList","curr","join","routeParamList","initialParams","routeGetIdList","Object","assign","getId","length","isStateValid","useCallback","isStateInitialized","stale","currentState","getState","getCurrentState","setState","setCurrentState","setKey","getKey","getIsInitial","NavigationStateContext","stateCleanedUp","cleanUpState","initializedState","isFirstStateInitialization","useMemo","initialRouteParamList","initialParamsFromParams","getInitialState","getRehydratedState","previousRouteKeyListRef","useEffect","previousRouteKeyList","nextState","getStateForRouteNamesChange","routeKeyChanges","filter","hasOwnProperty","previousNestedParamsRef","previousParams","action","CommonActions","reset","navigate","path","updatedState","getStateForAction","shouldUpdate","setTimeout","initializedStateRef","emitter","e","target","routes","find","index","navigation","descriptors","listeners","concat","cb","i","self","lastIndexOf","listener","emit","data","childListeners","addListener","keyedListeners","addKeyedListener","onAction","actionListeners","beforeRemoveListeners","beforeRemove","routerConfigOptions","onRouteFocus","id","focusedListeners","focus","getStateListeners","defaultScreenOptions","NavigationContent","NavigationHelpersContext","Provider","value"],"mappings":";;;;;;;AAAA;;AAYA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA;AACA;AACAA;;AAOA,MAAMC,UAAU,GAAIC,GAAD,IACjBA,GAAG,KAAKC,SAAR,IAAsB,OAAOD,GAAP,KAAe,QAAf,IAA2BA,GAAG,KAAK,EAD3D;AAGA;AACA;AACA;AACA;AACA;;;AACA,MAAME,2BAA2B,GAAG,CAKlCC,QALkC,EAMlCC,QANkC,EAOlCC,YAPkC,KAY/B;AACH,QAAMC,OAAO,GAAGC,KAAK,CAACC,QAAN,CAAeC,OAAf,CAAuBN,QAAvB,EAAiCO,MAAjC,CAEd,CAACC,GAAD,EAAMC,KAAN,KAAgB;AAAA;;AAChB,sBAAIL,KAAK,CAACM,cAAN,CAAqBD,KAArB,CAAJ,EAAiC;AAC/B,UAAIA,KAAK,CAACE,IAAN,KAAeC,eAAnB,EAA2B;AACzB;AACA;AAEA,YAAI,CAAChB,UAAU,CAACa,KAAK,CAACI,KAAN,CAAYC,aAAb,CAAf,EAA4C;AAC1C,gBAAM,IAAIC,KAAJ,CACH,wCAAuCC,IAAI,CAACC,SAAL,CACtCR,KAAK,CAACI,KAAN,CAAYC,aAD0B,CAEtC,qBACAL,KAAK,CAACI,KAAN,CAAYK,IACb,kDALG,CAAN;AAOD;;AAEDV,QAAAA,GAAG,CAACW,IAAJ,CAAS;AACPC,UAAAA,IAAI,EAAE,CAACnB,QAAD,EAAWQ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CAACkH,EADZ;AAEAN,IAAAA,QAFA;AAGA1D,IAAAA,QAHA;AAIAqC,IAAAA,OAJA;AAKA/D,IAAAA;AALA,GALiB,CAAnB;AAaA,mDAAmC;AACjCqE,IAAAA,UADiC;AAEjCsB,IAAAA,gBAAgB,EAAEX,cAAc,CAACY;AAFA,GAAnC;AAKA,8BAAc;AACZlE,IAAAA,QADY;AAEZmE,IAAAA,iBAAiB,EAAEX,cAAc,CAACxD;AAFtB,GAAd;AAKA,QAAM4C,WAAW,GAAG,6BAKlB;AACAnE,IAAAA,KADA;AAEAK,IAAAA,OAFA;AAGA6D,IAAAA,UAHA;AAIA1F,IAAAA,aAAa,EAAEH,OAAO,CAACG,aAJvB;AAKAmH,IAAAA,oBAAoB,EAAEtH,OAAO,CAACsH,oBAL9B;AAMAV,IAAAA,QANA;AAOA1D,IAAAA,QAPA;AAQAE,IAAAA,QARA;AASA6D,IAAAA,YATA;AAUAR,IAAAA,WAVA;AAWAE,IAAAA,gBAXA;AAYAnF,IAAAA,MAZA;AAaA;AACA+D,IAAAA;AAdA,GALkB,CAApB;AAsBA,iCAAiB;AACf5D,IAAAA,KADe;AAEfkE,IAAAA,UAFe;AAGfC,IAAAA;AAHe,GAAjB;AAMA,QAAMyB,iBAAiB,GAAG,2BAAaC,kCAAyBC,QAAtC,EAAgD;AACxEC,IAAAA,KAAK,EAAE7B;AADiE,GAAhD,CAA1B;AAIA,SAAO;AACLlE,IAAAA,KADK;AAELkE,IAAAA,UAFK;AAGLC,IAAAA,WAHK;AAILyB,IAAAA;AAJK,GAAP;AAMD","sourcesContent":["import {\n CommonActions,\n DefaultRouterOptions,\n NavigationAction,\n NavigationState,\n ParamListBase,\n PartialState,\n Route,\n Router,\n RouterConfigOptions,\n RouterFactory,\n} from '@react-navigation/routers';\nimport * as React from 'react';\nimport { isValidElementType } from 'react-is';\n\nimport Group from './Group';\nimport isArrayEqual from './isArrayEqual';\nimport isRecordEqual from './isRecordEqual';\nimport NavigationHelpersContext from './NavigationHelpersContext';\nimport NavigationRouteContext from './NavigationRouteContext';\nimport NavigationStateContext from './NavigationStateContext';\nimport Screen from './Screen';\nimport {\n DefaultNavigatorOptions,\n EventMapBase,\n EventMapCore,\n NavigatorScreenParams,\n PrivateValueStore,\n RouteConfig,\n} from './types';\nimport useChildListeners from './useChildListeners';\nimport useComponent from './useComponent';\nimport useCurrentRender from './useCurrentRender';\nimport useDescriptors, { ScreenConfigWithParent } from './useDescriptors';\nimport useEventEmitter from './useEventEmitter';\nimport useFocusedListenersChildrenAdapter from './useFocusedListenersChildrenAdapter';\nimport useFocusEvents from './useFocusEvents';\nimport useKeyedChildListeners from './useKeyedChildListeners';\nimport useNavigationHelpers from './useNavigationHelpers';\nimport useOnAction from './useOnAction';\nimport useOnGetState from './useOnGetState';\nimport useOnRouteFocus from './useOnRouteFocus';\nimport useRegisterNavigator from './useRegisterNavigator';\nimport useScheduleUpdate from './useScheduleUpdate';\n\n// This is to make TypeScript compiler happy\n// eslint-disable-next-line babel/no-unused-expressions\nPrivateValueStore;\n\ntype NavigatorRoute<State extends NavigationState> = {\n key: string;\n params?: NavigatorScreenParams<ParamListBase, State>;\n};\n\nconst isValidKey = (key: unknown) =>\n key === undefined || (typeof key === 'string' && key !== '');\n\n/**\n * Extract route config object from React children elements.\n *\n * @param children React Elements to extract the config from.\n */\nconst getRouteConfigsFromChildren = <\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n>(\n children: React.ReactNode,\n groupKey?: string,\n groupOptions?: ScreenConfigWithParent<\n State,\n ScreenOptions,\n EventMap\n >['options']\n) => {\n const configs = React.Children.toArray(children).reduce<\n ScreenConfigWithParent<State, ScreenOptions, EventMap>[]\n >((acc, child) => {\n if (React.isValidElement(child)) {\n if (child.type === Screen) {\n // We can only extract the config from `Screen` elements\n // If something else was rendered, it's probably a bug\n\n if (!isValidKey(child.props.navigationKey)) {\n throw new Error(\n `Got an invalid 'navigationKey' prop (${JSON.stringify(\n child.props.navigationKey\n )}) for the screen '${\n child.props.name\n }'. It must be a non-empty string or 'undefined'.`\n );\n }\n\n acc.push({\n keys: [groupKey, child.props.navigationKey],\n options: groupOptions,\n props: child.props as RouteConfig<\n ParamListBase,\n string,\n State,\n ScreenOptions,\n EventMap\n >,\n });\n return acc;\n }\n\n if (child.type === React.Fragment || child.type === Group) {\n if (!isValidKey(child.props.navigationKey)) {\n throw new Error(\n `Got an invalid 'navigationKey' prop (${JSON.stringify(\n child.props.navigationKey\n )}) for the group. It must be a non-empty string or 'undefined'.`\n );\n }\n\n // When we encounter a fragment or group, we need to dive into its children to extract the configs\n // This is handy to conditionally define a group of screens\n acc.push(\n ...getRouteConfigsFromChildren<State, ScreenOptions, EventMap>(\n child.props.children,\n child.props.navigationKey,\n child.type !== Group\n ? groupOptions\n : groupOptions != null\n ? [...groupOptions, child.props.screenOptions]\n : [child.props.screenOptions]\n )\n );\n return acc;\n }\n }\n\n throw new Error(\n `A navigator can only contain 'Screen', 'Group' or 'React.Fragment' as its direct children (found ${\n React.isValidElement(child)\n ? `'${\n typeof child.type === 'string' ? child.type : child.type?.name\n }'${\n child.props?.name ? ` for the screen '${child.props.name}'` : ''\n }`\n : typeof child === 'object'\n ? JSON.stringify(child)\n : `'${String(child)}'`\n }). To render this component in the navigator, pass it in the 'component' prop to 'Screen'.`\n );\n }, []);\n\n if (process.env.NODE_ENV !== 'production') {\n configs.forEach((config) => {\n const { name, children, component, getComponent } = config.props;\n\n if (typeof name !== 'string' || !name) {\n throw new Error(\n `Got an invalid name (${JSON.stringify(\n name\n )}) for the screen. It must be a non-empty string.`\n );\n }\n\n if (\n children != null ||\n component !== undefined ||\n getComponent !== undefined\n ) {\n if (children != null && component !== undefined) {\n throw new Error(\n `Got both 'component' and 'children' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (children != null && getComponent !== undefined) {\n throw new Error(\n `Got both 'getComponent' and 'children' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (component !== undefined && getComponent !== undefined) {\n throw new Error(\n `Got both 'component' and 'getComponent' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (children != null && typeof children !== 'function') {\n throw new Error(\n `Got an invalid value for 'children' prop for the screen '${name}'. It must be a function returning a React Element.`\n );\n }\n\n if (component !== undefined && !isValidElementType(component)) {\n throw new Error(\n `Got an invalid value for 'component' prop for the screen '${name}'. It must be a valid React Component.`\n );\n }\n\n if (getComponent !== undefined && typeof getComponent !== 'function') {\n throw new Error(\n `Got an invalid value for 'getComponent' prop for the screen '${name}'. It must be a function returning a React Component.`\n );\n }\n\n if (typeof component === 'function') {\n if (component.name === 'component') {\n // Inline anonymous functions passed in the `component` prop will have the name of the prop\n // It's relatively safe to assume that it's not a component since it should also have PascalCase name\n // We won't catch all scenarios here, but this should catch a good chunk of incorrect use.\n console.warn(\n `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.`\n );\n } else if (/^[a-z]/.test(component.name)) {\n console.warn(\n `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.`\n );\n }\n }\n } else {\n throw new Error(\n `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.`\n );\n }\n });\n }\n\n return configs;\n};\n\n/**\n * Hook for building navigators.\n *\n * @param createRouter Factory method which returns router object.\n * @param options Options object containing `children` and additional options for the router.\n * @returns An object containing `state`, `navigation`, `descriptors` objects.\n */\nexport default function useNavigationBuilder<\n State extends NavigationState,\n RouterOptions extends DefaultRouterOptions,\n ActionHelpers extends Record<string, () => void>,\n ScreenOptions extends {},\n EventMap extends Record<string, any>\n>(\n createRouter: RouterFactory<State, any, RouterOptions>,\n options: DefaultNavigatorOptions<\n ParamListBase,\n State,\n ScreenOptions,\n EventMap\n > &\n RouterOptions\n) {\n const navigatorKey = useRegisterNavigator();\n\n const route = React.useContext(NavigationRouteContext) as\n | NavigatorRoute<State>\n | undefined;\n\n const { children, screenListeners, ...rest } = options;\n const { current: router } = React.useRef<Router<State, any>>(\n createRouter({\n ...(rest as unknown as RouterOptions),\n ...(route?.params &&\n route.params.state == null &&\n route.params.initial !== false &&\n typeof route.params.screen === 'string'\n ? { initialRouteName: route.params.screen }\n : null),\n })\n );\n\n const routeConfigs = getRouteConfigsFromChildren<\n State,\n ScreenOptions,\n EventMap\n >(children);\n\n const screens = routeConfigs.reduce<\n Record<string, ScreenConfigWithParent<State, ScreenOptions, EventMap>>\n >((acc, config) => {\n if (config.props.name in acc) {\n throw new Error(\n `A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${config.props.name}')`\n );\n }\n\n acc[config.props.name] = config;\n return acc;\n }, {});\n\n const routeNames = routeConfigs.map((config) => config.props.name);\n const routeKeyList = routeNames.reduce<Record<string, React.Key | undefined>>(\n (acc, curr) => {\n acc[curr] = screens[curr].keys.map((key) => key ?? '').join(':');\n return acc;\n },\n {}\n );\n const routeParamList = routeNames.reduce<Record<string, object | undefined>>(\n (acc, curr) => {\n const { initialParams } = screens[curr].props;\n acc[curr] = initialParams;\n return acc;\n },\n {}\n );\n const routeGetIdList = routeNames.reduce<\n RouterConfigOptions['routeGetIdList']\n >(\n (acc, curr) =>\n Object.assign(acc, {\n [curr]: screens[curr].props.getId,\n }),\n {}\n );\n\n if (!routeNames.length) {\n throw new Error(\n \"Couldn't find any screens for the navigator. Have you defined any screens as its children?\"\n );\n }\n\n const isStateValid = React.useCallback(\n (state) => state.type === undefined || state.type === router.type,\n [router.type]\n );\n\n const isStateInitialized = React.useCallback(\n (state) =>\n state !== undefined && state.stale === false && isStateValid(state),\n [isStateValid]\n );\n\n const {\n state: currentState,\n getState: getCurrentState,\n setState: setCurrentState,\n setKey,\n getKey,\n getIsInitial,\n } = React.useContext(NavigationStateContext);\n\n const stateCleanedUp = React.useRef(false);\n\n const cleanUpState = React.useCallback(() => {\n setCurrentState(undefined);\n stateCleanedUp.current = true;\n }, [setCurrentState]);\n\n const setState = React.useCallback(\n (state: NavigationState | PartialState<NavigationState> | undefined) => {\n if (stateCleanedUp.current) {\n // State might have been already cleaned up due to unmount\n // We do not want to expose API allowing to override this\n // This would lead to old data preservation on main navigator unmount\n return;\n }\n setCurrentState(state);\n },\n [setCurrentState]\n );\n\n const [initializedState, isFirstStateInitialization] = React.useMemo(() => {\n const initialRouteParamList = routeNames.reduce<\n Record<string, object | undefined>\n >((acc, curr) => {\n const { initialParams } = screens[curr].props;\n const initialParamsFromParams =\n route?.params?.state == null &&\n route?.params?.initial !== false &&\n route?.params?.screen === curr\n ? route.params.params\n : undefined;\n\n acc[curr] =\n initialParams !== undefined || initialParamsFromParams !== undefined\n ? {\n ...initialParams,\n ...initialParamsFromParams,\n }\n : undefined;\n\n return acc;\n }, {});\n\n // If the current state isn't initialized on first render, we initialize it\n // We also need to re-initialize it if the state passed from parent was changed (maybe due to reset)\n // Otherwise assume that the state was provided as initial state\n // So we need to rehydrate it to make it usable\n if (\n (currentState === undefined || !isStateValid(currentState)) &&\n route?.params?.state == null\n ) {\n return [\n router.getInitialState({\n routeNames,\n routeParamList: initialRouteParamList,\n routeGetIdList,\n }),\n true,\n ];\n } else {\n return [\n router.getRehydratedState(\n route?.params?.state ?? (currentState as PartialState<State>),\n {\n routeNames,\n routeParamList: initialRouteParamList,\n routeGetIdList,\n }\n ),\n false,\n ];\n }\n // We explicitly don't include routeNames, route.params etc. in the dep list\n // below. We want to avoid forcing a new state to be calculated in those cases\n // Instead, we handle changes to these in the nextState code below. Note\n // that some changes to routeConfigs are explicitly ignored, such as changes\n // to initialParams\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [currentState, router, isStateValid]);\n\n const previousRouteKeyListRef = React.useRef(routeKeyList);\n\n React.useEffect(() => {\n previousRouteKeyListRef.current = routeKeyList;\n });\n\n const previousRouteKeyList = previousRouteKeyListRef.current;\n\n let state =\n // If the state isn't initialized, or stale, use the state we initialized instead\n // The state won't update until there's a change needed in the state we have initalized locally\n // So it'll be `undefined` or stale until the first navigation event happens\n isStateInitialized(currentState)\n ? (currentState as State)\n : (initializedState as State);\n\n let nextState: State = state;\n\n if (\n !isArrayEqual(state.routeNames, routeNames) ||\n !isRecordEqual(routeKeyList, previousRouteKeyList)\n ) {\n // When the list of route names change, the router should handle it to remove invalid routes\n nextState = router.getStateForRouteNamesChange(state, {\n routeNames,\n routeParamList,\n routeGetIdList,\n routeKeyChanges: Object.keys(routeKeyList).filter(\n (name) =>\n previousRouteKeyList.hasOwnProperty(name) &&\n routeKeyList[name] !== previousRouteKeyList[name]\n ),\n });\n }\n\n const previousNestedParamsRef = React.useRef(route?.params);\n\n React.useEffect(() => {\n previousNestedParamsRef.current = route?.params;\n }, [route?.params]);\n\n if (route?.params) {\n const previousParams = previousNestedParamsRef.current;\n\n let action: CommonActions.Action | undefined;\n\n if (\n typeof route.params.state === 'object' &&\n route.params.state != null &&\n route.params !== previousParams\n ) {\n // If the route was updated with new state, we should reset to it\n action = CommonActions.reset(route.params.state);\n } else if (\n typeof route.params.screen === 'string' &&\n ((route.params.initial === false && isFirstStateInitialization) ||\n route.params !== previousParams)\n ) {\n // If the route was updated with new screen name and/or params, we should navigate there\n action = CommonActions.navigate({\n name: route.params.screen,\n params: route.params.params,\n path: route.params.path,\n });\n }\n\n // The update should be limited to current navigator only, so we call the router manually\n const updatedState = action\n ? router.getStateForAction(nextState, action, {\n routeNames,\n routeParamList,\n routeGetIdList,\n })\n : null;\n\n nextState =\n updatedState !== null\n ? router.getRehydratedState(updatedState, {\n routeNames,\n routeParamList,\n routeGetIdList,\n })\n : nextState;\n }\n\n const shouldUpdate = state !== nextState;\n\n useScheduleUpdate(() => {\n if (shouldUpdate) {\n // If the state needs to be updated, we'll schedule an update\n setState(nextState);\n }\n });\n\n // The up-to-date state will come in next render, but we don't need to wait for it\n // We can't use the outdated state since the screens have changed, which will cause error due to mismatched config\n // So we override the state object we return to use the latest state as soon as possible\n state = nextState;\n\n React.useEffect(() => {\n setKey(navigatorKey);\n\n if (!getIsInitial()) {\n // If it's not initial render, we need to update the state\n // This will make sure that our container gets notifier of state changes due to new mounts\n // This is necessary for proper screen tracking, URL updates etc.\n setState(nextState);\n }\n\n return () => {\n // We need to clean up state for this navigator on unmount\n // We do it in a timeout because we need to detect if another navigator mounted in the meantime\n // For example, if another navigator has started rendering, we should skip cleanup\n // Otherwise, our cleanup step will cleanup state for the other navigator and re-initialize it\n setTimeout(() => {\n if (getCurrentState() !== undefined && getKey() === navigatorKey) {\n cleanUpState();\n }\n }, 0);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // We initialize this ref here to avoid a new getState getting initialized\n // whenever initializedState changes. We want getState to have access to the\n // latest initializedState, but don't need it to change when that happens\n const initializedStateRef = React.useRef<State>();\n initializedStateRef.current = initializedState;\n\n const getState = React.useCallback((): State => {\n const currentState = getCurrentState();\n\n return isStateInitialized(currentState)\n ? (currentState as State)\n : (initializedStateRef.current as State);\n }, [getCurrentState, isStateInitialized]);\n\n const emitter = useEventEmitter<EventMapCore<State>>((e) => {\n let routeNames = [];\n\n let route: Route<string> | undefined;\n\n if (e.target) {\n route = state.routes.find((route) => route.key === e.target);\n\n if (route?.name) {\n routeNames.push(route.name);\n }\n } else {\n route = state.routes[state.index];\n routeNames.push(\n ...Object.keys(screens).filter((name) => route?.name === name)\n );\n }\n\n if (route == null) {\n return;\n }\n\n const navigation = descriptors[route.key].navigation;\n\n const listeners = ([] as (((e: any) => void) | undefined)[])\n .concat(\n // Get an array of listeners for all screens + common listeners on navigator\n ...[\n screenListeners,\n ...routeNames.map((name) => {\n const { listeners } = screens[name].props;\n return listeners;\n }),\n ].map((listeners) => {\n const map =\n typeof listeners === 'function'\n ? listeners({ route: route as any, navigation })\n : listeners;\n\n return map\n ? Object.keys(map)\n .filter((type) => type === e.type)\n .map((type) => map?.[type])\n : undefined;\n })\n )\n // We don't want same listener to be called multiple times for same event\n // So we remove any duplicate functions from the array\n .filter((cb, i, self) => cb && self.lastIndexOf(cb) === i);\n\n listeners.forEach((listener) => listener?.(e));\n });\n\n useFocusEvents({ state, emitter });\n\n React.useEffect(() => {\n emitter.emit({ type: 'state', data: { state } });\n }, [emitter, state]);\n\n const { listeners: childListeners, addListener } = useChildListeners();\n\n const { keyedListeners, addKeyedListener } = useKeyedChildListeners();\n\n const onAction = useOnAction({\n router,\n getState,\n setState,\n key: route?.key,\n actionListeners: childListeners.action,\n beforeRemoveListeners: keyedListeners.beforeRemove,\n routerConfigOptions: {\n routeNames,\n routeParamList,\n routeGetIdList,\n },\n emitter,\n });\n\n const onRouteFocus = useOnRouteFocus({\n router,\n key: route?.key,\n getState,\n setState,\n });\n\n const navigation = useNavigationHelpers<\n State,\n ActionHelpers,\n NavigationAction,\n EventMap\n >({\n id: options.id,\n onAction,\n getState,\n emitter,\n router,\n });\n\n useFocusedListenersChildrenAdapter({\n navigation,\n focusedListeners: childListeners.focus,\n });\n\n useOnGetState({\n getState,\n getStateListeners: keyedListeners.getState,\n });\n\n const descriptors = useDescriptors<\n State,\n ActionHelpers,\n ScreenOptions,\n EventMap\n >({\n state,\n screens,\n navigation,\n screenOptions: options.screenOptions,\n defaultScreenOptions: options.defaultScreenOptions,\n onAction,\n getState,\n setState,\n onRouteFocus,\n addListener,\n addKeyedListener,\n router,\n // @ts-expect-error: this should have both core and custom events, but too much work right now\n emitter,\n });\n\n useCurrentRender({\n state,\n navigation,\n descriptors,\n });\n\n const NavigationContent = useComponent(NavigationHelpersContext.Provider, {\n value: navigation,\n });\n\n return {\n state,\n navigation,\n descriptors,\n NavigationContent,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["useNavigationBuilder.tsx"],"names":["PrivateValueStore","isValidKey","key","undefined","getRouteConfigsFromChildren","children","groupKey","groupOptions","configs","React","Children","toArray","reduce","acc","child","isValidElement","type","Screen","props","navigationKey","Error","JSON","stringify","name","push","keys","options","Fragment","Group","screenOptions","String","process","env","NODE_ENV","forEach","config","component","getComponent","console","warn","test","useNavigationBuilder","createRouter","navigatorKey","route","useContext","NavigationRouteContext","screenListeners","rest","current","router","useRef","params","state","initial","screen","initialRouteName","routeConfigs","screens","routeNames","map","routeKeyList","curr","join","routeParamList","initialParams","routeGetIdList","Object","assign","getId","length","isStateValid","useCallback","isStateInitialized","stale","currentState","getState","getCurrentState","setState","setCurrentState","setKey","getKey","getIsInitial","NavigationStateContext","stateCleanedUp","cleanUpState","initializedState","isFirstStateInitialization","useMemo","initialRouteParamList","initialParamsFromParams","getInitialState","getRehydratedState","previousRouteKeyListRef","useEffect","previousRouteKeyList","nextState","getStateForRouteNamesChange","routeKeyChanges","filter","hasOwnProperty","previousNestedParamsRef","previousParams","action","CommonActions","reset","navigate","path","updatedState","getStateForAction","shouldUpdate","setTimeout","initializedStateRef","emitter","e","target","routes","find","index","navigation","descriptors","listeners","concat","cb","i","self","lastIndexOf","listener","emit","data","childListeners","addListener","keyedListeners","addKeyedListener","onAction","actionListeners","beforeRemoveListeners","beforeRemove","routerConfigOptions","onRouteFocus","id","focusedListeners","focus","getStateListeners","defaultScreenOptions","NavigationContent"],"mappings":";;;;;;;AAAA;;AAYA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAQA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA;AACA;AACAA;;AAOA,MAAMC,UAAU,GAAIC,GAAD,IACjBA,GAAG,KAAKC,SAAR,IAAsB,OAAOD,GAAP,KAAe,QAAf,IAA2BA,GAAG,KAAK,EAD3D;AAGA;AACA;AACA;AACA;AACA;;;AACA,MAAME,2BAA2B,GAAG,CAKlCC,QALkC,EAMlCC,QANkC,EAOlCC,YAPkC,KAY/B;AACH,QAAMC,OAAO,GA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CAApB;AAsBA,iCAAiB;AACf5D,IAAAA,KADe;AAEfkE,IAAAA,UAFe;AAGfC,IAAAA;AAHe,GAAjB;AAMA,QAAMyB,iBAAiB,GAAG,2BAAc5I,QAAD,iBACrC,oBAAC,iCAAD,CAA0B,QAA1B;AAAmC,IAAA,KAAK,EAAEkH;AAA1C,kBACE,oBAAC,8BAAD,QAAwBlH,QAAxB,CADF,CADwB,CAA1B;AAMA,SAAO;AACLgD,IAAAA,KADK;AAELkE,IAAAA,UAFK;AAGLC,IAAAA,WAHK;AAILyB,IAAAA;AAJK,GAAP;AAMD","sourcesContent":["import {\n CommonActions,\n DefaultRouterOptions,\n NavigationAction,\n NavigationState,\n ParamListBase,\n PartialState,\n Route,\n Router,\n RouterConfigOptions,\n RouterFactory,\n} from '@react-navigation/routers';\nimport * as React from 'react';\nimport { isValidElementType } from 'react-is';\n\nimport Group from './Group';\nimport isArrayEqual from './isArrayEqual';\nimport isRecordEqual from './isRecordEqual';\nimport NavigationHelpersContext from './NavigationHelpersContext';\nimport NavigationRouteContext from './NavigationRouteContext';\nimport NavigationStateContext from './NavigationStateContext';\nimport PreventRemoveProvider from './PreventRemoveProvider';\nimport Screen from './Screen';\nimport {\n DefaultNavigatorOptions,\n EventMapBase,\n EventMapCore,\n NavigatorScreenParams,\n PrivateValueStore,\n RouteConfig,\n} from './types';\nimport useChildListeners from './useChildListeners';\nimport useComponent from './useComponent';\nimport useCurrentRender from './useCurrentRender';\nimport useDescriptors, { ScreenConfigWithParent } from './useDescriptors';\nimport useEventEmitter from './useEventEmitter';\nimport useFocusedListenersChildrenAdapter from './useFocusedListenersChildrenAdapter';\nimport useFocusEvents from './useFocusEvents';\nimport useKeyedChildListeners from './useKeyedChildListeners';\nimport useNavigationHelpers from './useNavigationHelpers';\nimport useOnAction from './useOnAction';\nimport useOnGetState from './useOnGetState';\nimport useOnRouteFocus from './useOnRouteFocus';\nimport useRegisterNavigator from './useRegisterNavigator';\nimport useScheduleUpdate from './useScheduleUpdate';\n\n// This is to make TypeScript compiler happy\n// eslint-disable-next-line babel/no-unused-expressions\nPrivateValueStore;\n\ntype NavigatorRoute<State extends NavigationState> = {\n key: string;\n params?: NavigatorScreenParams<ParamListBase, State>;\n};\n\nconst isValidKey = (key: unknown) =>\n key === undefined || (typeof key === 'string' && key !== '');\n\n/**\n * Extract route config object from React children elements.\n *\n * @param children React Elements to extract the config from.\n */\nconst getRouteConfigsFromChildren = <\n State extends NavigationState,\n ScreenOptions extends {},\n EventMap extends EventMapBase\n>(\n children: React.ReactNode,\n groupKey?: string,\n groupOptions?: ScreenConfigWithParent<\n State,\n ScreenOptions,\n EventMap\n >['options']\n) => {\n const configs = React.Children.toArray(children).reduce<\n ScreenConfigWithParent<State, ScreenOptions, EventMap>[]\n >((acc, child) => {\n if (React.isValidElement(child)) {\n if (child.type === Screen) {\n // We can only extract the config from `Screen` elements\n // If something else was rendered, it's probably a bug\n\n if (!isValidKey(child.props.navigationKey)) {\n throw new Error(\n `Got an invalid 'navigationKey' prop (${JSON.stringify(\n child.props.navigationKey\n )}) for the screen '${\n child.props.name\n }'. It must be a non-empty string or 'undefined'.`\n );\n }\n\n acc.push({\n keys: [groupKey, child.props.navigationKey],\n options: groupOptions,\n props: child.props as RouteConfig<\n ParamListBase,\n string,\n State,\n ScreenOptions,\n EventMap\n >,\n });\n return acc;\n }\n\n if (child.type === React.Fragment || child.type === Group) {\n if (!isValidKey(child.props.navigationKey)) {\n throw new Error(\n `Got an invalid 'navigationKey' prop (${JSON.stringify(\n child.props.navigationKey\n )}) for the group. It must be a non-empty string or 'undefined'.`\n );\n }\n\n // When we encounter a fragment or group, we need to dive into its children to extract the configs\n // This is handy to conditionally define a group of screens\n acc.push(\n ...getRouteConfigsFromChildren<State, ScreenOptions, EventMap>(\n child.props.children,\n child.props.navigationKey,\n child.type !== Group\n ? groupOptions\n : groupOptions != null\n ? [...groupOptions, child.props.screenOptions]\n : [child.props.screenOptions]\n )\n );\n return acc;\n }\n }\n\n throw new Error(\n `A navigator can only contain 'Screen', 'Group' or 'React.Fragment' as its direct children (found ${\n React.isValidElement(child)\n ? `'${\n typeof child.type === 'string' ? child.type : child.type?.name\n }'${\n child.props?.name ? ` for the screen '${child.props.name}'` : ''\n }`\n : typeof child === 'object'\n ? JSON.stringify(child)\n : `'${String(child)}'`\n }). To render this component in the navigator, pass it in the 'component' prop to 'Screen'.`\n );\n }, []);\n\n if (process.env.NODE_ENV !== 'production') {\n configs.forEach((config) => {\n const { name, children, component, getComponent } = config.props;\n\n if (typeof name !== 'string' || !name) {\n throw new Error(\n `Got an invalid name (${JSON.stringify(\n name\n )}) for the screen. It must be a non-empty string.`\n );\n }\n\n if (\n children != null ||\n component !== undefined ||\n getComponent !== undefined\n ) {\n if (children != null && component !== undefined) {\n throw new Error(\n `Got both 'component' and 'children' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (children != null && getComponent !== undefined) {\n throw new Error(\n `Got both 'getComponent' and 'children' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (component !== undefined && getComponent !== undefined) {\n throw new Error(\n `Got both 'component' and 'getComponent' props for the screen '${name}'. You must pass only one of them.`\n );\n }\n\n if (children != null && typeof children !== 'function') {\n throw new Error(\n `Got an invalid value for 'children' prop for the screen '${name}'. It must be a function returning a React Element.`\n );\n }\n\n if (component !== undefined && !isValidElementType(component)) {\n throw new Error(\n `Got an invalid value for 'component' prop for the screen '${name}'. It must be a valid React Component.`\n );\n }\n\n if (getComponent !== undefined && typeof getComponent !== 'function') {\n throw new Error(\n `Got an invalid value for 'getComponent' prop for the screen '${name}'. It must be a function returning a React Component.`\n );\n }\n\n if (typeof component === 'function') {\n if (component.name === 'component') {\n // Inline anonymous functions passed in the `component` prop will have the name of the prop\n // It's relatively safe to assume that it's not a component since it should also have PascalCase name\n // We won't catch all scenarios here, but this should catch a good chunk of incorrect use.\n console.warn(\n `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.`\n );\n } else if (/^[a-z]/.test(component.name)) {\n console.warn(\n `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.`\n );\n }\n }\n } else {\n throw new Error(\n `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.`\n );\n }\n });\n }\n\n return configs;\n};\n\n/**\n * Hook for building navigators.\n *\n * @param createRouter Factory method which returns router object.\n * @param options Options object containing `children` and additional options for the router.\n * @returns An object containing `state`, `navigation`, `descriptors` objects.\n */\nexport default function useNavigationBuilder<\n State extends NavigationState,\n RouterOptions extends DefaultRouterOptions,\n ActionHelpers extends Record<string, () => void>,\n ScreenOptions extends {},\n EventMap extends Record<string, any>\n>(\n createRouter: RouterFactory<State, any, RouterOptions>,\n options: DefaultNavigatorOptions<\n ParamListBase,\n State,\n ScreenOptions,\n EventMap\n > &\n RouterOptions\n) {\n const navigatorKey = useRegisterNavigator();\n\n const route = React.useContext(NavigationRouteContext) as\n | NavigatorRoute<State>\n | undefined;\n\n const { children, screenListeners, ...rest } = options;\n const { current: router } = React.useRef<Router<State, any>>(\n createRouter({\n ...(rest as unknown as RouterOptions),\n ...(route?.params &&\n route.params.state == null &&\n route.params.initial !== false &&\n typeof route.params.screen === 'string'\n ? { initialRouteName: route.params.screen }\n : null),\n })\n );\n\n const routeConfigs = getRouteConfigsFromChildren<\n State,\n ScreenOptions,\n EventMap\n >(children);\n\n const screens = routeConfigs.reduce<\n Record<string, ScreenConfigWithParent<State, ScreenOptions, EventMap>>\n >((acc, config) => {\n if (config.props.name in acc) {\n throw new Error(\n `A navigator cannot contain multiple 'Screen' components with the same name (found duplicate screen named '${config.props.name}')`\n );\n }\n\n acc[config.props.name] = config;\n return acc;\n }, {});\n\n const routeNames = routeConfigs.map((config) => config.props.name);\n const routeKeyList = routeNames.reduce<Record<string, React.Key | undefined>>(\n (acc, curr) => {\n acc[curr] = screens[curr].keys.map((key) => key ?? '').join(':');\n return acc;\n },\n {}\n );\n const routeParamList = routeNames.reduce<Record<string, object | undefined>>(\n (acc, curr) => {\n const { initialParams } = screens[curr].props;\n acc[curr] = initialParams;\n return acc;\n },\n {}\n );\n const routeGetIdList = routeNames.reduce<\n RouterConfigOptions['routeGetIdList']\n >(\n (acc, curr) =>\n Object.assign(acc, {\n [curr]: screens[curr].props.getId,\n }),\n {}\n );\n\n if (!routeNames.length) {\n throw new Error(\n \"Couldn't find any screens for the navigator. Have you defined any screens as its children?\"\n );\n }\n\n const isStateValid = React.useCallback(\n (state: NavigationState | PartialState<NavigationState>) =>\n state.type === undefined || state.type === router.type,\n [router.type]\n );\n\n const isStateInitialized = React.useCallback(\n (state: NavigationState | PartialState<NavigationState> | undefined) =>\n state !== undefined && state.stale === false && isStateValid(state),\n [isStateValid]\n );\n\n const {\n state: currentState,\n getState: getCurrentState,\n setState: setCurrentState,\n setKey,\n getKey,\n getIsInitial,\n } = React.useContext(NavigationStateContext);\n\n const stateCleanedUp = React.useRef(false);\n\n const cleanUpState = React.useCallback(() => {\n setCurrentState(undefined);\n stateCleanedUp.current = true;\n }, [setCurrentState]);\n\n const setState = React.useCallback(\n (state: NavigationState | PartialState<NavigationState> | undefined) => {\n if (stateCleanedUp.current) {\n // State might have been already cleaned up due to unmount\n // We do not want to expose API allowing to override this\n // This would lead to old data preservation on main navigator unmount\n return;\n }\n setCurrentState(state);\n },\n [setCurrentState]\n );\n\n const [initializedState, isFirstStateInitialization] = React.useMemo(() => {\n const initialRouteParamList = routeNames.reduce<\n Record<string, object | undefined>\n >((acc, curr) => {\n const { initialParams } = screens[curr].props;\n const initialParamsFromParams =\n route?.params?.state == null &&\n route?.params?.initial !== false &&\n route?.params?.screen === curr\n ? route.params.params\n : undefined;\n\n acc[curr] =\n initialParams !== undefined || initialParamsFromParams !== undefined\n ? {\n ...initialParams,\n ...initialParamsFromParams,\n }\n : undefined;\n\n return acc;\n }, {});\n\n // If the current state isn't initialized on first render, we initialize it\n // We also need to re-initialize it if the state passed from parent was changed (maybe due to reset)\n // Otherwise assume that the state was provided as initial state\n // So we need to rehydrate it to make it usable\n if (\n (currentState === undefined || !isStateValid(currentState)) &&\n route?.params?.state == null\n ) {\n return [\n router.getInitialState({\n routeNames,\n routeParamList: initialRouteParamList,\n routeGetIdList,\n }),\n true,\n ];\n } else {\n return [\n router.getRehydratedState(\n route?.params?.state ?? (currentState as PartialState<State>),\n {\n routeNames,\n routeParamList: initialRouteParamList,\n routeGetIdList,\n }\n ),\n false,\n ];\n }\n // We explicitly don't include routeNames, route.params etc. in the dep list\n // below. We want to avoid forcing a new state to be calculated in those cases\n // Instead, we handle changes to these in the nextState code below. Note\n // that some changes to routeConfigs are explicitly ignored, such as changes\n // to initialParams\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [currentState, router, isStateValid]);\n\n const previousRouteKeyListRef = React.useRef(routeKeyList);\n\n React.useEffect(() => {\n previousRouteKeyListRef.current = routeKeyList;\n });\n\n const previousRouteKeyList = previousRouteKeyListRef.current;\n\n let state =\n // If the state isn't initialized, or stale, use the state we initialized instead\n // The state won't update until there's a change needed in the state we have initalized locally\n // So it'll be `undefined` or stale until the first navigation event happens\n isStateInitialized(currentState)\n ? (currentState as State)\n : (initializedState as State);\n\n let nextState: State = state;\n\n if (\n !isArrayEqual(state.routeNames, routeNames) ||\n !isRecordEqual(routeKeyList, previousRouteKeyList)\n ) {\n // When the list of route names change, the router should handle it to remove invalid routes\n nextState = router.getStateForRouteNamesChange(state, {\n routeNames,\n routeParamList,\n routeGetIdList,\n routeKeyChanges: Object.keys(routeKeyList).filter(\n (name) =>\n previousRouteKeyList.hasOwnProperty(name) &&\n routeKeyList[name] !== previousRouteKeyList[name]\n ),\n });\n }\n\n const previousNestedParamsRef = React.useRef(route?.params);\n\n React.useEffect(() => {\n previousNestedParamsRef.current = route?.params;\n }, [route?.params]);\n\n if (route?.params) {\n const previousParams = previousNestedParamsRef.current;\n\n let action: CommonActions.Action | undefined;\n\n if (\n typeof route.params.state === 'object' &&\n route.params.state != null &&\n route.params !== previousParams\n ) {\n // If the route was updated with new state, we should reset to it\n action = CommonActions.reset(route.params.state);\n } else if (\n typeof route.params.screen === 'string' &&\n ((route.params.initial === false && isFirstStateInitialization) ||\n route.params !== previousParams)\n ) {\n // If the route was updated with new screen name and/or params, we should navigate there\n action = CommonActions.navigate({\n name: route.params.screen,\n params: route.params.params,\n path: route.params.path,\n });\n }\n\n // The update should be limited to current navigator only, so we call the router manually\n const updatedState = action\n ? router.getStateForAction(nextState, action, {\n routeNames,\n routeParamList,\n routeGetIdList,\n })\n : null;\n\n nextState =\n updatedState !== null\n ? router.getRehydratedState(updatedState, {\n routeNames,\n routeParamList,\n routeGetIdList,\n })\n : nextState;\n }\n\n const shouldUpdate = state !== nextState;\n\n useScheduleUpdate(() => {\n if (shouldUpdate) {\n // If the state needs to be updated, we'll schedule an update\n setState(nextState);\n }\n });\n\n // The up-to-date state will come in next render, but we don't need to wait for it\n // We can't use the outdated state since the screens have changed, which will cause error due to mismatched config\n // So we override the state object we return to use the latest state as soon as possible\n state = nextState;\n\n React.useEffect(() => {\n setKey(navigatorKey);\n\n if (!getIsInitial()) {\n // If it's not initial render, we need to update the state\n // This will make sure that our container gets notifier of state changes due to new mounts\n // This is necessary for proper screen tracking, URL updates etc.\n setState(nextState);\n }\n\n return () => {\n // We need to clean up state for this navigator on unmount\n // We do it in a timeout because we need to detect if another navigator mounted in the meantime\n // For example, if another navigator has started rendering, we should skip cleanup\n // Otherwise, our cleanup step will cleanup state for the other navigator and re-initialize it\n setTimeout(() => {\n if (getCurrentState() !== undefined && getKey() === navigatorKey) {\n cleanUpState();\n }\n }, 0);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // We initialize this ref here to avoid a new getState getting initialized\n // whenever initializedState changes. We want getState to have access to the\n // latest initializedState, but don't need it to change when that happens\n const initializedStateRef = React.useRef<State>();\n initializedStateRef.current = initializedState;\n\n const getState = React.useCallback((): State => {\n const currentState = getCurrentState();\n\n return isStateInitialized(currentState)\n ? (currentState as State)\n : (initializedStateRef.current as State);\n }, [getCurrentState, isStateInitialized]);\n\n const emitter = useEventEmitter<EventMapCore<State>>((e) => {\n let routeNames = [];\n\n let route: Route<string> | undefined;\n\n if (e.target) {\n route = state.routes.find((route) => route.key === e.target);\n\n if (route?.name) {\n routeNames.push(route.name);\n }\n } else {\n route = state.routes[state.index];\n routeNames.push(\n ...Object.keys(screens).filter((name) => route?.name === name)\n );\n }\n\n if (route == null) {\n return;\n }\n\n const navigation = descriptors[route.key].navigation;\n\n const listeners = ([] as (((e: any) => void) | undefined)[])\n .concat(\n // Get an array of listeners for all screens + common listeners on navigator\n ...[\n screenListeners,\n ...routeNames.map((name) => {\n const { listeners } = screens[name].props;\n return listeners;\n }),\n ].map((listeners) => {\n const map =\n typeof listeners === 'function'\n ? listeners({ route: route as any, navigation })\n : listeners;\n\n return map\n ? Object.keys(map)\n .filter((type) => type === e.type)\n .map((type) => map?.[type])\n : undefined;\n })\n )\n // We don't want same listener to be called multiple times for same event\n // So we remove any duplicate functions from the array\n .filter((cb, i, self) => cb && self.lastIndexOf(cb) === i);\n\n listeners.forEach((listener) => listener?.(e));\n });\n\n useFocusEvents({ state, emitter });\n\n React.useEffect(() => {\n emitter.emit({ type: 'state', data: { state } });\n }, [emitter, state]);\n\n const { listeners: childListeners, addListener } = useChildListeners();\n\n const { keyedListeners, addKeyedListener } = useKeyedChildListeners();\n\n const onAction = useOnAction({\n router,\n getState,\n setState,\n key: route?.key,\n actionListeners: childListeners.action,\n beforeRemoveListeners: keyedListeners.beforeRemove,\n routerConfigOptions: {\n routeNames,\n routeParamList,\n routeGetIdList,\n },\n emitter,\n });\n\n const onRouteFocus = useOnRouteFocus({\n router,\n key: route?.key,\n getState,\n setState,\n });\n\n const navigation = useNavigationHelpers<\n State,\n ActionHelpers,\n NavigationAction,\n EventMap\n >({\n id: options.id,\n onAction,\n getState,\n emitter,\n router,\n });\n\n useFocusedListenersChildrenAdapter({\n navigation,\n focusedListeners: childListeners.focus,\n });\n\n useOnGetState({\n getState,\n getStateListeners: keyedListeners.getState,\n });\n\n const descriptors = useDescriptors<\n State,\n ActionHelpers,\n ScreenOptions,\n EventMap\n >({\n state,\n screens,\n navigation,\n screenOptions: options.screenOptions,\n defaultScreenOptions: options.defaultScreenOptions,\n onAction,\n getState,\n setState,\n onRouteFocus,\n addListener,\n addKeyedListener,\n router,\n // @ts-expect-error: this should have both core and custom events, but too much work right now\n emitter,\n });\n\n useCurrentRender({\n state,\n navigation,\n descriptors,\n });\n\n const NavigationContent = useComponent((children: React.ReactNode) => (\n <NavigationHelpersContext.Provider value={navigation}>\n <PreventRemoveProvider>{children}</PreventRemoveProvider>\n </NavigationHelpersContext.Provider>\n ));\n\n return {\n state,\n navigation,\n descriptors,\n NavigationContent,\n };\n}\n"]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = usePreventRemove;
|
|
7
|
+
|
|
8
|
+
var _nonSecure = require("nanoid/non-secure");
|
|
9
|
+
|
|
10
|
+
var React = _interopRequireWildcard(require("react"));
|
|
11
|
+
|
|
12
|
+
var _useLatestCallback = _interopRequireDefault(require("use-latest-callback"));
|
|
13
|
+
|
|
14
|
+
var _useNavigation = _interopRequireDefault(require("./useNavigation"));
|
|
15
|
+
|
|
16
|
+
var _usePreventRemoveContext = _interopRequireDefault(require("./usePreventRemoveContext"));
|
|
17
|
+
|
|
18
|
+
var _useRoute = _interopRequireDefault(require("./useRoute"));
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
+
|
|
24
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Hook to prevent screen from being removed. Can be used to prevent users from leaving the screen.
|
|
28
|
+
*
|
|
29
|
+
* @param preventRemove Boolean indicating whether to prevent screen from being removed.
|
|
30
|
+
* @param callback Function which is executed when screen was prevented from being removed.
|
|
31
|
+
*/
|
|
32
|
+
function usePreventRemove(preventRemove, callback) {
|
|
33
|
+
const [id] = React.useState(() => (0, _nonSecure.nanoid)());
|
|
34
|
+
const navigation = (0, _useNavigation.default)();
|
|
35
|
+
const {
|
|
36
|
+
key: routeKey
|
|
37
|
+
} = (0, _useRoute.default)();
|
|
38
|
+
const {
|
|
39
|
+
setPreventRemove
|
|
40
|
+
} = (0, _usePreventRemoveContext.default)();
|
|
41
|
+
React.useEffect(() => {
|
|
42
|
+
setPreventRemove(id, routeKey, preventRemove);
|
|
43
|
+
return () => {
|
|
44
|
+
setPreventRemove(id, routeKey, false);
|
|
45
|
+
};
|
|
46
|
+
}, [setPreventRemove, id, routeKey, preventRemove]);
|
|
47
|
+
const beforeRemoveListener = (0, _useLatestCallback.default)(e => {
|
|
48
|
+
if (!preventRemove) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
callback({
|
|
54
|
+
data: e.data
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
React.useEffect(() => navigation === null || navigation === void 0 ? void 0 : navigation.addListener('beforeRemove', beforeRemoveListener), [navigation, beforeRemoveListener]);
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=usePreventRemove.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["usePreventRemove.tsx"],"names":["usePreventRemove","preventRemove","callback","id","React","useState","navigation","key","routeKey","setPreventRemove","useEffect","beforeRemoveListener","e","preventDefault","data","addListener"],"mappings":";;;;;;;AACA;;AACA;;AACA;;AAGA;;AACA;;AACA;;;;;;;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,gBAAT,CACbC,aADa,EAEbC,QAFa,EAGb;AACA,QAAM,CAACC,EAAD,IAAOC,KAAK,CAACC,QAAN,CAAe,MAAM,wBAArB,CAAb;AAEA,QAAMC,UAAU,GAAG,6BAAnB;AACA,QAAM;AAAEC,IAAAA,GAAG,EAAEC;AAAP,MAAoB,wBAA1B;AAEA,QAAM;AAAEC,IAAAA;AAAF,MAAuB,uCAA7B;AAEAL,EAAAA,KAAK,CAACM,SAAN,CAAgB,MAAM;AACpBD,IAAAA,gBAAgB,CAACN,EAAD,EAAKK,QAAL,EAAeP,aAAf,CAAhB;AACA,WAAO,MAAM;AACXQ,MAAAA,gBAAgB,CAACN,EAAD,EAAKK,QAAL,EAAe,KAAf,CAAhB;AACD,KAFD;AAGD,GALD,EAKG,CAACC,gBAAD,EAAmBN,EAAnB,EAAuBK,QAAvB,EAAiCP,aAAjC,CALH;AAOA,QAAMU,oBAAoB,GAAG,gCAE1BC,CAAD,IAAO;AACP,QAAI,CAACX,aAAL,EAAoB;AAClB;AACD;;AAEDW,IAAAA,CAAC,CAACC,cAAF;AAEAX,IAAAA,QAAQ,CAAC;AAAEY,MAAAA,IAAI,EAAEF,CAAC,CAACE;AAAV,KAAD,CAAR;AACD,GAV4B,CAA7B;AAYAV,EAAAA,KAAK,CAACM,SAAN,CACE,MAAMJ,UAAN,aAAMA,UAAN,uBAAMA,UAAU,CAAES,WAAZ,CAAwB,cAAxB,EAAwCJ,oBAAxC,CADR,EAEE,CAACL,UAAD,EAAaK,oBAAb,CAFF;AAID","sourcesContent":["import type { NavigationAction } from '@react-navigation/routers';\nimport { nanoid } from 'nanoid/non-secure';\nimport * as React from 'react';\nimport useLatestCallback from 'use-latest-callback';\n\nimport type { EventListenerCallback, EventMapCore } from './types';\nimport useNavigation from './useNavigation';\nimport usePreventRemoveContext from './usePreventRemoveContext';\nimport useRoute from './useRoute';\n\n/**\n * Hook to prevent screen from being removed. Can be used to prevent users from leaving the screen.\n *\n * @param preventRemove Boolean indicating whether to prevent screen from being removed.\n * @param callback Function which is executed when screen was prevented from being removed.\n */\nexport default function usePreventRemove(\n preventRemove: boolean,\n callback: (options: { data: { action: NavigationAction } }) => void\n) {\n const [id] = React.useState(() => nanoid());\n\n const navigation = useNavigation();\n const { key: routeKey } = useRoute();\n\n const { setPreventRemove } = usePreventRemoveContext();\n\n React.useEffect(() => {\n setPreventRemove(id, routeKey, preventRemove);\n return () => {\n setPreventRemove(id, routeKey, false);\n };\n }, [setPreventRemove, id, routeKey, preventRemove]);\n\n const beforeRemoveListener = useLatestCallback<\n EventListenerCallback<EventMapCore<any>, 'beforeRemove'>\n >((e) => {\n if (!preventRemove) {\n return;\n }\n\n e.preventDefault();\n\n callback({ data: e.data });\n });\n\n React.useEffect(\n () => navigation?.addListener('beforeRemove', beforeRemoveListener),\n [navigation, beforeRemoveListener]\n );\n}\n"]}
|