UNPKG

6.75 kBSource Map (JSON)View Raw
1{"version":3,"names":["SceneView","screen","route","navigation","routeState","getState","setState","options","clearOptions","navigatorKeyRef","React","useRef","getKey","useCallback","current","addOptionsGetter","useOptionsGetters","key","setKey","getCurrentState","state","currentRoute","routes","find","r","undefined","setCurrentState","child","map","isInitialRef","useEffect","getIsInitial","context","useMemo","ScreenComponent","getComponent","component","name","children"],"sources":["SceneView.tsx"],"sourcesContent":["import type {\n NavigationState,\n ParamListBase,\n PartialState,\n Route,\n} from '@react-navigation/routers';\nimport * as React from 'react';\n\nimport EnsureSingleNavigator from './EnsureSingleNavigator';\nimport NavigationStateContext from './NavigationStateContext';\nimport StaticContainer from './StaticContainer';\nimport type { NavigationProp, RouteConfigComponent } from './types';\nimport useOptionsGetters from './useOptionsGetters';\n\ntype Props<State extends NavigationState, ScreenOptions extends {}> = {\n screen: RouteConfigComponent<ParamListBase, string> & { name: string };\n navigation: NavigationProp<\n ParamListBase,\n string,\n string | undefined,\n State,\n ScreenOptions\n >;\n route: Route<string>;\n routeState: NavigationState | PartialState<NavigationState> | undefined;\n getState: () => State;\n setState: (state: State) => void;\n options: object;\n clearOptions: () => void;\n};\n\n/**\n * Component which takes care of rendering the screen for a route.\n * It provides all required contexts and applies optimizations when applicable.\n */\nexport default function SceneView<\n State extends NavigationState,\n ScreenOptions extends {}\n>({\n screen,\n route,\n navigation,\n routeState,\n getState,\n setState,\n options,\n clearOptions,\n}: Props<State, ScreenOptions>) {\n const navigatorKeyRef = React.useRef<string | undefined>();\n const getKey = React.useCallback(() => navigatorKeyRef.current, []);\n\n const { addOptionsGetter } = useOptionsGetters({\n key: route.key,\n options,\n navigation,\n });\n\n const setKey = React.useCallback((key: string) => {\n navigatorKeyRef.current = key;\n }, []);\n\n const getCurrentState = React.useCallback(() => {\n const state = getState();\n const currentRoute = state.routes.find((r) => r.key === route.key);\n\n return currentRoute ? currentRoute.state : undefined;\n }, [getState, route.key]);\n\n const setCurrentState = React.useCallback(\n (child: NavigationState | PartialState<NavigationState> | undefined) => {\n const state = getState();\n\n setState({\n ...state,\n routes: state.routes.map((r) =>\n r.key === route.key ? { ...r, state: child } : r\n ),\n });\n },\n [getState, route.key, setState]\n );\n\n const isInitialRef = React.useRef(true);\n\n React.useEffect(() => {\n isInitialRef.current = false;\n });\n\n // Clear options set by this screen when it is unmounted\n React.useEffect(() => {\n return clearOptions;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n const getIsInitial = React.useCallback(() => isInitialRef.current, []);\n\n const context = React.useMemo(\n () => ({\n state: routeState,\n getState: getCurrentState,\n setState: setCurrentState,\n getKey,\n setKey,\n getIsInitial,\n addOptionsGetter,\n }),\n [\n routeState,\n getCurrentState,\n setCurrentState,\n getKey,\n setKey,\n getIsInitial,\n addOptionsGetter,\n ]\n );\n\n const ScreenComponent = screen.getComponent\n ? screen.getComponent()\n : screen.component;\n\n return (\n <NavigationStateContext.Provider value={context}>\n <EnsureSingleNavigator>\n <StaticContainer\n name={screen.name}\n render={ScreenComponent || screen.children}\n navigation={navigation}\n route={route}\n >\n {ScreenComponent !== undefined ? (\n <ScreenComponent navigation={navigation} route={route} />\n ) : screen.children !== undefined ? (\n screen.children({ navigation, route })\n ) : null}\n </StaticContainer>\n </EnsureSingleNavigator>\n </NavigationStateContext.Provider>\n );\n}\n"],"mappings":";;;;;;;AAMA;;AAEA;;AACA;;AACA;;AAEA;;;;;;;;AAmBA;AACA;AACA;AACA;AACe,SAASA,SAAT,OAYiB;EAAA,IAT9B;IACAC,MADA;IAEAC,KAFA;IAGAC,UAHA;IAIAC,UAJA;IAKAC,QALA;IAMAC,QANA;IAOAC,OAPA;IAQAC;EARA,CAS8B;EAC9B,MAAMC,eAAe,GAAGC,KAAK,CAACC,MAAN,EAAxB;EACA,MAAMC,MAAM,GAAGF,KAAK,CAACG,WAAN,CAAkB,MAAMJ,eAAe,CAACK,OAAxC,EAAiD,EAAjD,CAAf;EAEA,MAAM;IAAEC;EAAF,IAAuB,IAAAC,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