You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
10 KiB
1 line
10 KiB
{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/defineProperty\";\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }\nimport * as React from 'react';\nimport EnsureSingleNavigator from \"./EnsureSingleNavigator\";\nimport NavigationStateContext from \"./NavigationStateContext\";\nimport StaticContainer from \"./StaticContainer\";\nimport useOptionsGetters from \"./useOptionsGetters\";\nexport default function SceneView(_ref) {\n var screen = _ref.screen,\n route = _ref.route,\n navigation = _ref.navigation,\n routeState = _ref.routeState,\n getState = _ref.getState,\n setState = _ref.setState,\n options = _ref.options,\n clearOptions = _ref.clearOptions;\n var navigatorKeyRef = React.useRef();\n var getKey = React.useCallback(function () {\n return navigatorKeyRef.current;\n }, []);\n var _useOptionsGetters = useOptionsGetters({\n key: route.key,\n options: options,\n navigation: navigation\n }),\n addOptionsGetter = _useOptionsGetters.addOptionsGetter;\n var setKey = React.useCallback(function (key) {\n navigatorKeyRef.current = key;\n }, []);\n var getCurrentState = React.useCallback(function () {\n var state = getState();\n var currentRoute = state.routes.find(function (r) {\n return r.key === route.key;\n });\n return currentRoute ? currentRoute.state : undefined;\n }, [getState, route.key]);\n var setCurrentState = React.useCallback(function (child) {\n var state = getState();\n setState(_objectSpread(_objectSpread({}, state), {}, {\n routes: state.routes.map(function (r) {\n return r.key === route.key ? _objectSpread(_objectSpread({}, r), {}, {\n state: child\n }) : r;\n })\n }));\n }, [getState, route.key, setState]);\n var isInitialRef = React.useRef(true);\n React.useEffect(function () {\n isInitialRef.current = false;\n });\n React.useEffect(function () {\n return clearOptions;\n }, []);\n var getIsInitial = React.useCallback(function () {\n return isInitialRef.current;\n }, []);\n var context = React.useMemo(function () {\n return {\n state: routeState,\n getState: getCurrentState,\n setState: setCurrentState,\n getKey: getKey,\n setKey: setKey,\n getIsInitial: getIsInitial,\n addOptionsGetter: addOptionsGetter\n };\n }, [routeState, getCurrentState, setCurrentState, getKey, setKey, getIsInitial, addOptionsGetter]);\n var ScreenComponent = screen.getComponent ? screen.getComponent() : screen.component;\n return React.createElement(NavigationStateContext.Provider, {\n value: context\n }, React.createElement(EnsureSingleNavigator, null, React.createElement(StaticContainer, {\n name: screen.name,\n render: ScreenComponent || screen.children,\n navigation: navigation,\n route: route\n }, ScreenComponent !== undefined ? React.createElement(ScreenComponent, {\n navigation: navigation,\n route: route\n }) : screen.children !== undefined ? screen.children({\n navigation: navigation,\n route: route\n }) : null)));\n}","map":{"version":3,"sources":["SceneView.tsx"],"names":["React","EnsureSingleNavigator","NavigationStateContext","StaticContainer","useOptionsGetters","SceneView","screen","route","navigation","routeState","getState","setState","options","clearOptions","navigatorKeyRef","useRef","getKey","useCallback","current","addOptionsGetter","key","setKey","getCurrentState","state","currentRoute","routes","find","r","undefined","setCurrentState","child","map","isInitialRef","useEffect","getIsInitial","context","useMemo","ScreenComponent","getComponent","component","name","children"],"mappings":";;;AAMA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,OAAOC,qBAAqB;AAC5B,OAAOC,sBAAsB;AAC7B,OAAOC,eAAe;AAEtB,OAAOC,iBAAiB;AAuBxB,eAAe,SAASC,SAAS,CAAA,IAAA,EAYD;EAT9B,IACAC,MAAM,GAQsB,IAAA,CAR5BA,MAAM;I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,KAAK,EAAEJ;EAAQ,CAAA,EAC9C,KAAA,CAAA,aAAA,CAAC,qBAAqB,EAAA,IAAA,EACpB,KAAA,CAAA,aAAA,CAAC,eAAe,EAAA;IACd,IAAI,EAAE7B,MAAM,CAACkC,IAAK;IAClB,MAAM,EAAEH,eAAe,IAAI/B,MAAM,CAACmC,QAAS;IAC3C,UAAU,EAAEjC,UAAW;IACvB,KAAK,EAAED;EAAM,CAAA,EAEZ8B,eAAe,KAAKT,SAAS,GAC5B,KAAA,CAAA,aAAA,CAAC,eAAe,EAAA;IAAC,UAAU,EAAEpB,UAAW;IAAC,KAAK,EAAED;EAAM,CAAA,CAAG,GACvDD,MAAM,CAACmC,QAAQ,KAAKb,SAAS,GAC/BtB,MAAM,CAACmC,QAAQ,CAAC;IAAEjC,UAAU,EAAVA,UAAU;IAAED,KAAAA,EAAAA;EAAM,CAAC,CAAC,GACpC,IAAI,CACQ,CACI,CACQ;AAEtC","sourceRoot":"../../src","sourcesContent":["import * as React from 'react';\nimport EnsureSingleNavigator from './EnsureSingleNavigator';\nimport NavigationStateContext from './NavigationStateContext';\nimport StaticContainer from './StaticContainer';\nimport useOptionsGetters from './useOptionsGetters';\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(_ref) {\n let {\n screen,\n route,\n navigation,\n routeState,\n getState,\n setState,\n options,\n clearOptions\n } = _ref;\n const navigatorKeyRef = React.useRef();\n const getKey = React.useCallback(() => navigatorKeyRef.current, []);\n const {\n addOptionsGetter\n } = useOptionsGetters({\n key: route.key,\n options,\n navigation\n });\n const setKey = React.useCallback(key => {\n navigatorKeyRef.current = key;\n }, []);\n const getCurrentState = React.useCallback(() => {\n const state = getState();\n const currentRoute = state.routes.find(r => r.key === route.key);\n return currentRoute ? currentRoute.state : undefined;\n }, [getState, route.key]);\n const setCurrentState = React.useCallback(child => {\n const state = getState();\n setState({\n ...state,\n routes: state.routes.map(r => r.key === route.key ? {\n ...r,\n state: child\n } : r)\n });\n }, [getState, route.key, setState]);\n const isInitialRef = React.useRef(true);\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 const getIsInitial = React.useCallback(() => isInitialRef.current, []);\n const context = React.useMemo(() => ({\n state: routeState,\n getState: getCurrentState,\n setState: setCurrentState,\n getKey,\n setKey,\n getIsInitial,\n addOptionsGetter\n }), [routeState, getCurrentState, setCurrentState, getKey, setKey, getIsInitial, addOptionsGetter]);\n const ScreenComponent = screen.getComponent ? screen.getComponent() : screen.component;\n return /*#__PURE__*/React.createElement(NavigationStateContext.Provider, {\n value: context\n }, /*#__PURE__*/React.createElement(EnsureSingleNavigator, null, /*#__PURE__*/React.createElement(StaticContainer, {\n name: screen.name,\n render: ScreenComponent || screen.children,\n navigation: navigation,\n route: route\n }, ScreenComponent !== undefined ? /*#__PURE__*/React.createElement(ScreenComponent, {\n navigation: navigation,\n route: route\n }) : screen.children !== undefined ? screen.children({\n navigation,\n route\n }) : null)));\n}\n//# sourceMappingURL=SceneView.js.map"]},"metadata":{},"sourceType":"module"} |