823f3bbf1205db776671d8155aee0267.json
11.5 KB
{"ast":null,"code":"var _interopRequireDefault=require(\"@babel/runtime/helpers/interopRequireDefault\");Object.defineProperty(exports,\"__esModule\",{value:true});exports.default=void 0;var _objectSpread2=_interopRequireDefault(require(\"@babel/runtime/helpers/objectSpread\"));var _getChildEventSubscriber=_interopRequireDefault(require(\"./getChildEventSubscriber\"));var _getChildRouter=_interopRequireDefault(require(\"./getChildRouter\"));var _getNavigationActionCreators=_interopRequireDefault(require(\"./routers/getNavigationActionCreators\"));var _getChildrenNavigationCache=_interopRequireDefault(require(\"./getChildrenNavigationCache\"));var createParamGetter=function createParamGetter(route){return function(paramName,defaultValue){var params=route.params;if(params&¶mName in params){return params[paramName];}return defaultValue;};};function _getChildNavigation(navigation,childKey,getCurrentParentNavigation){var children=(0,_getChildrenNavigationCache.default)(navigation);var childRoute=navigation.state.routes.find(function(r){return r.key===childKey;});if(!childRoute){return null;}if(children[childKey]&&children[childKey].state===childRoute){return children[childKey];}var childRouter=(0,_getChildRouter.default)(navigation.router,childRoute.routeName);var focusedGrandChildRoute=childRoute.routes&&typeof childRoute.index==='number'?childRoute.routes[childRoute.index]:null;var actionCreators=(0,_objectSpread2.default)({},navigation.actions,navigation.router.getActionCreators(childRoute,navigation.state.key),childRouter?childRouter.getActionCreators(focusedGrandChildRoute,childRoute.key):{},(0,_getNavigationActionCreators.default)(childRoute));var actionHelpers={};Object.keys(actionCreators).forEach(function(actionName){actionHelpers[actionName]=function(){var actionCreator=actionCreators[actionName];var action=actionCreator.apply(void 0,arguments);return navigation.dispatch(action);};});var _isFirstRouteInParent=true;var parentNavigation=getCurrentParentNavigation();if(parentNavigation){_isFirstRouteInParent=parentNavigation.state.routes.indexOf(childRoute)===0;}if(children[childKey]&&children[childKey].isFirstRouteInParent()===_isFirstRouteInParent){children[childKey]=(0,_objectSpread2.default)({},children[childKey],actionHelpers,{state:childRoute,router:childRouter,actions:actionCreators,getParam:createParamGetter(childRoute)});return children[childKey];}else{var childSubscriber=(0,_getChildEventSubscriber.default)(navigation.addListener,childKey);children[childKey]=(0,_objectSpread2.default)({},actionHelpers,{state:childRoute,router:childRouter,actions:actionCreators,getParam:createParamGetter(childRoute),getChildNavigation:function getChildNavigation(grandChildKey){return _getChildNavigation(children[childKey],grandChildKey,function(){var nav=getCurrentParentNavigation();return nav&&nav.getChildNavigation(childKey);});},isFocused:function isFocused(){var currentNavigation=getCurrentParentNavigation();if(!currentNavigation){return false;}var _currentNavigation$st=currentNavigation.state,routes=_currentNavigation$st.routes,index=_currentNavigation$st.index;if(!currentNavigation.isFocused()){return false;}if(routes[index].key===childKey){return true;}return false;},isFirstRouteInParent:function isFirstRouteInParent(){return _isFirstRouteInParent;},dispatch:navigation.dispatch,getScreenProps:navigation.getScreenProps,dangerouslyGetParent:getCurrentParentNavigation,addListener:childSubscriber.addListener,emit:childSubscriber.emit});return children[childKey];}}var _default=_getChildNavigation;exports.default=_default;","map":{"version":3,"sources":["getChildNavigation.js"],"names":["createParamGetter","params","route","paramName","children","getChildrenNavigationCache","childRoute","navigation","r","childRouter","getChildRouter","focusedGrandChildRoute","actionCreators","getNavigationActionCreators","actionHelpers","Object","actionCreator","action","isFirstRouteInParent","parentNavigation","getCurrentParentNavigation","state","router","actions","getParam","childSubscriber","getChildEventSubscriber","getChildNavigation","nav","isFocused","currentNavigation","routes","index","dispatch","getScreenProps","dangerouslyGetParent","addListener","emit"],"mappings":"6PAAA,0FACA,wEACA,0GACA,gGAEA,GAAMA,CAAAA,iBAAiB,CAAjBA,QAAAA,CAAAA,iBAAAA,CAAoB,KAApBA,CAAyB,CAAA,MAAI,UAAA,SAAA,CAAA,YAAA,CAA6B,CAC9D,GAAMC,CAAAA,MAAM,CAAGC,KAAK,CAApB,MAAA,CAEA,GAAID,MAAM,EAAIE,SAAS,GAAvB,CAAA,MAAA,CAAmC,CACjC,MAAOF,CAAAA,MAAM,CAAb,SAAa,CAAb,CAGF,OAAA,CAAA,YAAA,CAP6B,CAAA,CAA/B,C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Subscriber';\nimport getChildRouter from './getChildRouter';\nimport getNavigationActionCreators from './routers/getNavigationActionCreators';\nimport getChildrenNavigationCache from './getChildrenNavigationCache';\n\nconst createParamGetter = route => (paramName, defaultValue) => {\n const params = route.params;\n\n if (params && paramName in params) {\n return params[paramName];\n }\n\n return defaultValue;\n};\n\nfunction getChildNavigation(navigation, childKey, getCurrentParentNavigation) {\n const children = getChildrenNavigationCache(navigation);\n const childRoute = navigation.state.routes.find(r => r.key === childKey);\n\n if (!childRoute) {\n return null;\n }\n\n if (children[childKey] && children[childKey].state === childRoute) {\n return children[childKey];\n }\n\n const childRouter = getChildRouter(navigation.router, childRoute.routeName);\n\n // If the route has children, we'll use this to pass in to the action creators\n // for the childRouter so that any action that depends on the active route will\n // behave as expected. We don't explicitly require that routers implement routes\n // and index properties, but if we did then we would put an invariant here to\n // ensure that a focusedGrandChildRoute exists if childRouter is defined.\n const focusedGrandChildRoute =\n childRoute.routes && typeof childRoute.index === 'number'\n ? childRoute.routes[childRoute.index]\n : null;\n\n const actionCreators = {\n ...navigation.actions,\n ...navigation.router.getActionCreators(childRoute, navigation.state.key),\n ...(childRouter\n ? childRouter.getActionCreators(focusedGrandChildRoute, childRoute.key)\n : {}),\n ...getNavigationActionCreators(childRoute),\n };\n\n const actionHelpers = {};\n Object.keys(actionCreators).forEach(actionName => {\n actionHelpers[actionName] = (...args) => {\n const actionCreator = actionCreators[actionName];\n const action = actionCreator(...args);\n return navigation.dispatch(action);\n };\n });\n\n let isFirstRouteInParent = true;\n\n const parentNavigation = getCurrentParentNavigation();\n\n if (parentNavigation) {\n isFirstRouteInParent =\n parentNavigation.state.routes.indexOf(childRoute) === 0;\n }\n\n if (\n children[childKey] &&\n children[childKey].isFirstRouteInParent() === isFirstRouteInParent\n ) {\n children[childKey] = {\n ...children[childKey],\n ...actionHelpers,\n state: childRoute,\n router: childRouter,\n actions: actionCreators,\n getParam: createParamGetter(childRoute),\n };\n return children[childKey];\n } else {\n const childSubscriber = getChildEventSubscriber(\n navigation.addListener,\n childKey\n );\n\n children[childKey] = {\n ...actionHelpers,\n\n state: childRoute,\n router: childRouter,\n actions: actionCreators,\n getParam: createParamGetter(childRoute),\n\n getChildNavigation: grandChildKey =>\n getChildNavigation(children[childKey], grandChildKey, () => {\n const nav = getCurrentParentNavigation();\n return nav && nav.getChildNavigation(childKey);\n }),\n\n isFocused: () => {\n const currentNavigation = getCurrentParentNavigation();\n if (!currentNavigation) {\n return false;\n }\n const { routes, index } = currentNavigation.state;\n if (!currentNavigation.isFocused()) {\n return false;\n }\n if (routes[index].key === childKey) {\n return true;\n }\n return false;\n },\n isFirstRouteInParent: () => isFirstRouteInParent,\n dispatch: navigation.dispatch,\n getScreenProps: navigation.getScreenProps,\n dangerouslyGetParent: getCurrentParentNavigation,\n addListener: childSubscriber.addListener,\n emit: childSubscriber.emit,\n };\n return children[childKey];\n }\n}\n\nexport default getChildNavigation;\n"]},"metadata":{},"sourceType":"script"}