@react-navigation/core 3.5.0-alpha.6 → 3.5.1

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.
Files changed (86) hide show
  1. package/lib/commonjs/navigators/__tests__/createSwitchnavigator-test.js +1 -1
  2. package/lib/commonjs/navigators/__tests__/createSwitchnavigator-test.js.map +1 -1
  3. package/lib/commonjs/navigators/createNavigator.js +1 -1
  4. package/lib/commonjs/navigators/createNavigator.js.map +1 -1
  5. package/lib/commonjs/routers/SwitchRouter.js +1 -1
  6. package/lib/commonjs/routers/SwitchRouter.js.map +1 -1
  7. package/lib/commonjs/routers/__tests__/PathHandling-test.js +1 -1
  8. package/lib/commonjs/routers/__tests__/PathHandling-test.js.map +1 -1
  9. package/lib/commonjs/routers/__tests__/Routers-test.js +1 -1
  10. package/lib/commonjs/routers/__tests__/Routers-test.js.map +1 -1
  11. package/lib/commonjs/routers/__tests__/StackRouter-test.js +1 -1
  12. package/lib/commonjs/routers/__tests__/StackRouter-test.js.map +1 -1
  13. package/lib/commonjs/routers/__tests__/SwitchRouter-test.js +1 -1
  14. package/lib/commonjs/routers/__tests__/SwitchRouter-test.js.map +1 -1
  15. package/lib/commonjs/routers/__tests__/TabRouter-test.js +1 -1
  16. package/lib/commonjs/routers/__tests__/TabRouter-test.js.map +1 -1
  17. package/lib/commonjs/routers/__tests__/pathUtils-test.js +1 -1
  18. package/lib/commonjs/routers/__tests__/pathUtils-test.js.map +1 -1
  19. package/lib/commonjs/routers/__tests__/validateRouteConfigMap-test.js +1 -1
  20. package/lib/commonjs/routers/__tests__/validateRouteConfigMap-test.js.map +1 -1
  21. package/lib/commonjs/routers/createConfigGetter.js +1 -1
  22. package/lib/commonjs/routers/createConfigGetter.js.map +1 -1
  23. package/lib/commonjs/routers/pathUtils.js +1 -1
  24. package/lib/commonjs/routers/pathUtils.js.map +1 -1
  25. package/lib/commonjs/useTheme.js +1 -1
  26. package/lib/commonjs/useTheme.js.map +1 -1
  27. package/lib/commonjs/utils/getActiveChildNavigationOptions.js +1 -1
  28. package/lib/commonjs/utils/getActiveChildNavigationOptions.js.map +1 -1
  29. package/lib/commonjs/views/SceneView.js +1 -1
  30. package/lib/commonjs/views/SceneView.js.map +1 -1
  31. package/lib/commonjs/views/SwitchView/SwitchView.js +1 -1
  32. package/lib/commonjs/views/SwitchView/SwitchView.js.map +1 -1
  33. package/lib/commonjs/views/__tests__/NavigationEvents-test.js +1 -1
  34. package/lib/commonjs/views/__tests__/NavigationEvents-test.js.map +1 -1
  35. package/lib/commonjs/views/withNavigation.js +1 -1
  36. package/lib/commonjs/views/withNavigation.js.map +1 -1
  37. package/lib/commonjs/views/withNavigationFocus.js +1 -1
  38. package/lib/commonjs/views/withNavigationFocus.js.map +1 -1
  39. package/lib/module/navigators/__tests__/createSwitchnavigator-test.js +1 -1
  40. package/lib/module/navigators/__tests__/createSwitchnavigator-test.js.map +1 -1
  41. package/lib/module/navigators/createNavigator.js +1 -1
  42. package/lib/module/navigators/createNavigator.js.map +1 -1
  43. package/lib/module/routers/SwitchRouter.js +1 -1
  44. package/lib/module/routers/SwitchRouter.js.map +1 -1
  45. package/lib/module/routers/__tests__/PathHandling-test.js +1 -1
  46. package/lib/module/routers/__tests__/PathHandling-test.js.map +1 -1
  47. package/lib/module/routers/__tests__/Routers-test.js +1 -1
  48. package/lib/module/routers/__tests__/Routers-test.js.map +1 -1
  49. package/lib/module/routers/__tests__/StackRouter-test.js +1 -1
  50. package/lib/module/routers/__tests__/StackRouter-test.js.map +1 -1
  51. package/lib/module/routers/__tests__/SwitchRouter-test.js +1 -1
  52. package/lib/module/routers/__tests__/SwitchRouter-test.js.map +1 -1
  53. package/lib/module/routers/__tests__/TabRouter-test.js +1 -1
  54. package/lib/module/routers/__tests__/TabRouter-test.js.map +1 -1
  55. package/lib/module/routers/__tests__/pathUtils-test.js +1 -1
  56. package/lib/module/routers/__tests__/pathUtils-test.js.map +1 -1
  57. package/lib/module/routers/__tests__/validateRouteConfigMap-test.js +1 -1
  58. package/lib/module/routers/__tests__/validateRouteConfigMap-test.js.map +1 -1
  59. package/lib/module/routers/createConfigGetter.js +1 -1
  60. package/lib/module/routers/createConfigGetter.js.map +1 -1
  61. package/lib/module/routers/pathUtils.js +1 -1
  62. package/lib/module/routers/pathUtils.js.map +1 -1
  63. package/lib/module/useTheme.js +1 -1
  64. package/lib/module/useTheme.js.map +1 -1
  65. package/lib/module/utils/getActiveChildNavigationOptions.js +1 -1
  66. package/lib/module/utils/getActiveChildNavigationOptions.js.map +1 -1
  67. package/lib/module/views/SceneView.js +1 -1
  68. package/lib/module/views/SceneView.js.map +1 -1
  69. package/lib/module/views/SwitchView/SwitchView.js +1 -1
  70. package/lib/module/views/SwitchView/SwitchView.js.map +1 -1
  71. package/lib/module/views/__tests__/NavigationEvents-test.js +1 -1
  72. package/lib/module/views/__tests__/NavigationEvents-test.js.map +1 -1
  73. package/lib/module/views/withNavigation.js +1 -1
  74. package/lib/module/views/withNavigation.js.map +1 -1
  75. package/lib/module/views/withNavigationFocus.js +1 -1
  76. package/lib/module/views/withNavigationFocus.js.map +1 -1
  77. package/lib/typescript/useTheme.d.ts +1 -1
  78. package/package.json +1 -1
  79. package/src/navigators/createNavigator.js +35 -16
  80. package/src/routers/SwitchRouter.js +13 -11
  81. package/src/routers/__tests__/pathUtils-test.js +37 -1
  82. package/src/routers/createConfigGetter.js +3 -2
  83. package/src/routers/pathUtils.js +16 -5
  84. package/src/useTheme.ts +1 -1
  85. package/src/utils/getActiveChildNavigationOptions.js +6 -2
  86. package/src/.DS_Store +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["createConfigGetter.js"],"names":["invariant","getScreenForRouteName","validateScreenOptions","applyConfig","configurer","navigationOptions","configProps","routeConfigs","navigatorScreenConfig","navigation","screenProps","state","route","routeName","Component","routeConfig","routeScreenConfig","componentScreenConfig","configOptions","outputConfig"],"mappings":"+DAAA,MAAOA,CAAAA,SAAP,KAAsB,oBAAtB,CAEA,MAAOC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wB,CAExBE,YAFwB,CAGxBD,aAHwB,CAA1B,CAKAC,YAAY,CAAGhB,WAAW,CAACa,iBAAD,CAAoBG,YAApB,CAAkCD,aAAlC,CAA1B,CAEAhB,qBAAqB,CAACiB,YAAD,CAAeP,KAAf,CAArB,CAEA,MAAOO,CAAAA,YAAP,CACD,CAjCc,EAAf","sourcesContent":["import invariant from '../utils/invariant';\n\nimport getScreenForRouteName from './getScreenForRouteName';\nimport validateScreenOptions from './validateScreenOptions';\n\nfunction applyConfig(configurer, navigationOptions, configProps) {\n if (typeof configurer === 'function') {\n return {\n ...navigationOptions,\n ...configurer({\n ...configProps,\n navigationOptions,\n }),\n };\n }\n if (typeof configurer === 'object') {\n return {\n ...navigationOptions,\n ...configurer,\n };\n }\n return navigationOptions;\n}\n\nexport default (routeConfigs, navigatorScreenConfig) => (\n navigation,\n screenProps\n) => {\n const { state } = navigation;\n const route = state;\n\n invariant(\n route.routeName && typeof route.routeName === 'string',\n 'Cannot get config because the route does not have a routeName.'\n );\n\n const Component = getScreenForRouteName(routeConfigs, route.routeName);\n\n const routeConfig = routeConfigs[route.routeName];\n\n const routeScreenConfig =\n routeConfig === Component ? null : routeConfig.navigationOptions;\n const componentScreenConfig = Component.navigationOptions;\n\n const configOptions = { navigation, screenProps: screenProps || {} };\n\n let outputConfig = applyConfig(navigatorScreenConfig, {}, configOptions);\n outputConfig = applyConfig(\n componentScreenConfig,\n outputConfig,\n configOptions\n );\n outputConfig = applyConfig(routeScreenConfig, outputConfig, configOptions);\n\n validateScreenOptions(outputConfig, route);\n\n return outputConfig;\n};\n"]}
1
+ {"version":3,"sources":["createConfigGetter.js"],"names":["invariant","getScreenForRouteName","validateScreenOptions","applyConfig","configurer","navigationOptions","configProps","routeConfigs","navigatorScreenConfig","navigation","screenProps","theme","state","route","routeName","Component","routeConfig","routeScreenConfig","componentScreenConfig","configOptions","outputConfig"],"mappings":"+DAAA,MAAOA,CAAAA,SAAP,KAAsB,oBAAtB,CAEA,MAAOC,CA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9B,CACAC,YAAY,CAAGjB,WAAW,CACxBe,qBADwB,CAExBE,YAFwB,CAGxBD,aAHwB,CAA1B,CAKAC,YAAY,CAAGjB,WAAW,CAACc,iBAAD,CAAoBG,YAApB,CAAkCD,aAAlC,CAA1B,CAEAjB,qBAAqB,CAACkB,YAAD,CAAeP,KAAf,CAArB,CAEA,MAAOO,CAAAA,YAAP,CACD,CAlCc,EAAf","sourcesContent":["import invariant from '../utils/invariant';\n\nimport getScreenForRouteName from './getScreenForRouteName';\nimport validateScreenOptions from './validateScreenOptions';\n\nfunction applyConfig(configurer, navigationOptions, configProps) {\n if (typeof configurer === 'function') {\n return {\n ...navigationOptions,\n ...configurer({\n ...configProps,\n navigationOptions,\n }),\n };\n }\n if (typeof configurer === 'object') {\n return {\n ...navigationOptions,\n ...configurer,\n };\n }\n return navigationOptions;\n}\n\nexport default (routeConfigs, navigatorScreenConfig) => (\n navigation,\n screenProps,\n theme\n) => {\n const { state } = navigation;\n const route = state;\n\n invariant(\n route.routeName && typeof route.routeName === 'string',\n 'Cannot get config because the route does not have a routeName.'\n );\n\n const Component = getScreenForRouteName(routeConfigs, route.routeName);\n\n const routeConfig = routeConfigs[route.routeName];\n\n const routeScreenConfig =\n routeConfig === Component ? null : routeConfig.navigationOptions;\n const componentScreenConfig = Component.navigationOptions;\n\n const configOptions = { navigation, screenProps: screenProps || {}, theme };\n\n let outputConfig = applyConfig(navigatorScreenConfig, {}, configOptions);\n outputConfig = applyConfig(\n componentScreenConfig,\n outputConfig,\n configOptions\n );\n outputConfig = applyConfig(routeScreenConfig, outputConfig, configOptions);\n\n validateScreenOptions(outputConfig, route);\n\n return outputConfig;\n};\n"]}
@@ -1,2 +1,2 @@
1
- import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _objectSpread from"@babel/runtime/helpers/objectSpread";import pathToRegexp,{compile}from'path-to-regexp';import*as NavigationActions from'../NavigationActions';import invariant from'../utils/invariant';var queryString=require('query-string');export var getParamsFromPath=function getParamsFromPath(inputParams,pathMatch,pathMatchKeys){var params=pathMatch.slice(1).reduce(function(paramsOut,matchResult,i){var key=pathMatchKeys[i];if(!key||key.asterisk){return paramsOut;}var paramName=key.name;var decodedMatchResult;if(matchResult){try{decodedMatchResult=decodeURIComponent(matchResult);}catch(e){}}paramsOut[paramName]=decodedMatchResult||matchResult;return paramsOut;},_objectSpread({},inputParams));return params;};var getRestOfPath=function getRestOfPath(pathMatch,pathMatchKeys){var rest=pathMatch[pathMatchKeys.findIndex(function(k){return k.asterisk;})+1];return rest;};export var urlToPathAndParams=function urlToPathAndParams(url,uriPrefix){var searchMatch=url.match(/^(.*)\?(.*)$/);var params=searchMatch?queryString.parse(searchMatch[2]):{};var urlWithoutSearch=searchMatch?searchMatch[1]:url;var delimiter=uriPrefix||'://';var path=urlWithoutSearch.split(delimiter)[1];if(path===undefined){path=urlWithoutSearch;}if(path==='/'){path='';}if(path[path.length-1]==='/'){path=path.slice(0,-1);}return{path:path,params:params};};export var createPathParser=function createPathParser(childRouters,routeConfigs,_ref){var _ref$paths=_ref.paths,pathConfigs=_ref$paths===void 0?{}:_ref$paths,disableRouteNamePaths=_ref.disableRouteNamePaths;var pathsByRouteNames={};var paths=[];Object.keys(childRouters).forEach(function(routeName){var pathPattern;if(pathConfigs[routeName]!==undefined){pathPattern=pathConfigs[routeName];}else{pathPattern=routeConfigs[routeName].path;}if(pathPattern===undefined){pathPattern=disableRouteNamePaths?null:routeName;}invariant(pathPattern===null||typeof pathPattern==='string',"Route path for "+routeName+" must be specified as a string, or null.");var isPathMatchable=pathPattern!==null;var exactReKeys=[];var exactRe=isPathMatchable?pathToRegexp(pathPattern,exactReKeys):null;var extendedPathReKeys=[];var isWildcard=pathPattern===''||!isPathMatchable;var extendedPathRe=pathToRegexp(isWildcard?'*':pathPattern+"/*",extendedPathReKeys);pathsByRouteNames[routeName]={exactRe:exactRe,exactReKeys:exactReKeys,extendedPathRe:extendedPathRe,extendedPathReKeys:extendedPathReKeys,isWildcard:isWildcard,toPath:pathPattern===null?function(){return'';}:compile(pathPattern)};});paths=Object.entries(pathsByRouteNames);var getActionForPathAndParams=function getActionForPathAndParams(){var pathToResolve=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'';var inputParams=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};for(var _iterator=paths,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]();;){var _ref4;if(_isArray){if(_i>=_iterator.length)break;_ref4=_iterator[_i++];}else{_i=_iterator.next();if(_i.done)break;_ref4=_i.value;}var _ref8=_ref4;var _ref3=_slicedToArray(_ref8,2);var _routeName2=_ref3[0];var _path2=_ref3[1];var exactRe=_path2.exactRe,exactReKeys=_path2.exactReKeys,extendedPathRe=_path2.extendedPathRe,extendedPathReKeys=_path2.extendedPathReKeys;var childRouter=childRouters[_routeName2];var exactMatch=exactRe&&exactRe.exec(pathToResolve);if(exactMatch&&exactMatch.length){var extendedMatch=extendedPathRe&&extendedPathRe.exec(pathToResolve);var childAction=null;if(extendedMatch&&childRouter){var restOfPath=getRestOfPath(extendedMatch,extendedPathReKeys);childAction=childRouter.getActionForPathAndParams(restOfPath,inputParams);}return NavigationActions.navigate({routeName:_routeName2,params:getParamsFromPath(inputParams,exactMatch,exactReKeys),action:childAction});}}for(var _iterator2=paths,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]();;){var _ref7;if(_isArray2){if(_i2>=_iterator2.length)break;_ref7=_iterator2[_i2++];}else{_i2=_iterator2.next();if(_i2.done)break;_ref7=_i2.value;}var _ref9=_ref7;var _ref6=_slicedToArray(_ref9,2);var _routeName3=_ref6[0];var _path3=_ref6[1];var _extendedPathRe=_path3.extendedPathRe,_extendedPathReKeys=_path3.extendedPathReKeys;var _childRouter=childRouters[_routeName3];var _extendedMatch=_extendedPathRe&&_extendedPathRe.exec(pathToResolve);if(_extendedMatch&&_extendedMatch.length){var _restOfPath=getRestOfPath(_extendedMatch,_extendedPathReKeys);var _childAction=null;if(_childRouter){_childAction=_childRouter.getActionForPathAndParams(_restOfPath,inputParams);}if(!_childAction){continue;}return NavigationActions.navigate({routeName:_routeName3,params:getParamsFromPath(inputParams,_extendedMatch,_extendedPathReKeys),action:_childAction});}}return null;};var getPathAndParamsForRoute=function getPathAndParamsForRoute(route){var routeName=route.routeName,params=route.params;var childRouter=childRouters[routeName];var _pathsByRouteNames$ro=pathsByRouteNames[routeName],toPath=_pathsByRouteNames$ro.toPath,exactReKeys=_pathsByRouteNames$ro.exactReKeys;var subPath=toPath(params);var nonPathParams={};if(params){Object.keys(params).filter(function(paramName){return!exactReKeys.find(function(k){return k.name===paramName;});}).forEach(function(paramName){nonPathParams[paramName]=params[paramName];});}if(childRouter){var child=childRouter.getPathAndParamsForState(route);return{path:subPath?subPath+"/"+child.path:child.path,params:child.params?_objectSpread({},nonPathParams,child.params):nonPathParams};}return{path:subPath,params:nonPathParams};};return{getActionForPathAndParams:getActionForPathAndParams,getPathAndParamsForRoute:getPathAndParamsForRoute};};
1
+ import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _objectSpread from"@babel/runtime/helpers/objectSpread";import pathToRegexp,{compile}from'path-to-regexp';import*as NavigationActions from'../NavigationActions';import invariant from'../utils/invariant';var queryString=require('query-string');export var getParamsFromPath=function getParamsFromPath(inputParams,pathMatch,pathMatchKeys){var params=pathMatch.slice(1).reduce(function(paramsOut,matchResult,i){var key=pathMatchKeys[i];if(!key||key.asterisk){return paramsOut;}var paramName=key.name;var decodedMatchResult;if(matchResult){try{decodedMatchResult=decodeURIComponent(matchResult);}catch(e){}}paramsOut[paramName]=decodedMatchResult||matchResult;return paramsOut;},_objectSpread({},inputParams));return params;};var getRestOfPath=function getRestOfPath(pathMatch,pathMatchKeys){var rest=pathMatch[pathMatchKeys.findIndex(function(k){return k.asterisk;})+1];return rest;};var determineDelimiter=function determineDelimiter(uri,uriPrefix){if(Array.isArray(uriPrefix)){if(uriPrefix.length===1)return uriPrefix[0];for(var _iterator=uriPrefix,_isArray=Array.isArray(_iterator),_i=0,_iterator=_isArray?_iterator:_iterator[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]();;){var _ref;if(_isArray){if(_i>=_iterator.length)break;_ref=_iterator[_i++];}else{_i=_iterator.next();if(_i.done)break;_ref=_i.value;}var _prefix=_ref;if(uri.startsWith(_prefix))return _prefix;}return null;}return uriPrefix;};export var urlToPathAndParams=function urlToPathAndParams(url,uriPrefix){var searchMatch=url.match(/^(.*)\?(.*)$/);var _ref2=searchMatch||[null,url,{}],_ref3=_slicedToArray(_ref2,3),urlWithoutQuery=_ref3[1],query=_ref3[2];var params=queryString.parse(query);var delimiter=determineDelimiter(urlWithoutQuery,uriPrefix)||'://';var path=urlWithoutQuery.split(delimiter)[1];if(path===undefined){path=urlWithoutQuery;}if(path==='/'){path='';}if(path[path.length-1]==='/'){path=path.slice(0,-1);}return{path:path,params:params};};export var createPathParser=function createPathParser(childRouters,routeConfigs,_ref4){var _ref4$paths=_ref4.paths,pathConfigs=_ref4$paths===void 0?{}:_ref4$paths,disableRouteNamePaths=_ref4.disableRouteNamePaths;var pathsByRouteNames={};var paths=[];Object.keys(childRouters).forEach(function(routeName){var pathPattern;if(pathConfigs[routeName]!==undefined){pathPattern=pathConfigs[routeName];}else{pathPattern=routeConfigs[routeName].path;}if(pathPattern===undefined){pathPattern=disableRouteNamePaths?null:routeName;}invariant(pathPattern===null||typeof pathPattern==='string',"Route path for "+routeName+" must be specified as a string, or null.");var isPathMatchable=pathPattern!==null;var exactReKeys=[];var exactRe=isPathMatchable?pathToRegexp(pathPattern,exactReKeys):null;var extendedPathReKeys=[];var isWildcard=pathPattern===''||!isPathMatchable;var extendedPathRe=pathToRegexp(isWildcard?'*':pathPattern+"/*",extendedPathReKeys);pathsByRouteNames[routeName]={exactRe:exactRe,exactReKeys:exactReKeys,extendedPathRe:extendedPathRe,extendedPathReKeys:extendedPathReKeys,isWildcard:isWildcard,toPath:pathPattern===null?function(){return'';}:compile(pathPattern)};});paths=Object.entries(pathsByRouteNames);var getActionForPathAndParams=function getActionForPathAndParams(){var pathToResolve=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'';var inputParams=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};for(var _iterator2=paths,_isArray2=Array.isArray(_iterator2),_i2=0,_iterator2=_isArray2?_iterator2:_iterator2[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]();;){var _ref7;if(_isArray2){if(_i2>=_iterator2.length)break;_ref7=_iterator2[_i2++];}else{_i2=_iterator2.next();if(_i2.done)break;_ref7=_i2.value;}var _ref11=_ref7;var _ref6=_slicedToArray(_ref11,2);var _routeName2=_ref6[0];var _path2=_ref6[1];var exactRe=_path2.exactRe,exactReKeys=_path2.exactReKeys,extendedPathRe=_path2.extendedPathRe,extendedPathReKeys=_path2.extendedPathReKeys;var childRouter=childRouters[_routeName2];var exactMatch=exactRe&&exactRe.exec(pathToResolve);if(exactMatch&&exactMatch.length){var extendedMatch=extendedPathRe&&extendedPathRe.exec(pathToResolve);var childAction=null;if(extendedMatch&&childRouter){var restOfPath=getRestOfPath(extendedMatch,extendedPathReKeys);childAction=childRouter.getActionForPathAndParams(restOfPath,inputParams);}return NavigationActions.navigate({routeName:_routeName2,params:getParamsFromPath(inputParams,exactMatch,exactReKeys),action:childAction});}}for(var _iterator3=paths,_isArray3=Array.isArray(_iterator3),_i3=0,_iterator3=_isArray3?_iterator3:_iterator3[typeof Symbol==="function"?Symbol.iterator:"@@iterator"]();;){var _ref10;if(_isArray3){if(_i3>=_iterator3.length)break;_ref10=_iterator3[_i3++];}else{_i3=_iterator3.next();if(_i3.done)break;_ref10=_i3.value;}var _ref12=_ref10;var _ref9=_slicedToArray(_ref12,2);var _routeName3=_ref9[0];var _path3=_ref9[1];var _extendedPathRe=_path3.extendedPathRe,_extendedPathReKeys=_path3.extendedPathReKeys;var _childRouter=childRouters[_routeName3];var _extendedMatch=_extendedPathRe&&_extendedPathRe.exec(pathToResolve);if(_extendedMatch&&_extendedMatch.length){var _restOfPath=getRestOfPath(_extendedMatch,_extendedPathReKeys);var _childAction=null;if(_childRouter){_childAction=_childRouter.getActionForPathAndParams(_restOfPath,inputParams);}if(!_childAction){continue;}return NavigationActions.navigate({routeName:_routeName3,params:getParamsFromPath(inputParams,_extendedMatch,_extendedPathReKeys),action:_childAction});}}return null;};var getPathAndParamsForRoute=function getPathAndParamsForRoute(route){var routeName=route.routeName,params=route.params;var childRouter=childRouters[routeName];var _pathsByRouteNames$ro=pathsByRouteNames[routeName],toPath=_pathsByRouteNames$ro.toPath,exactReKeys=_pathsByRouteNames$ro.exactReKeys;var subPath=toPath(params);var nonPathParams={};if(params){Object.keys(params).filter(function(paramName){return!exactReKeys.find(function(k){return k.name===paramName;});}).forEach(function(paramName){nonPathParams[paramName]=params[paramName];});}if(childRouter){var child=childRouter.getPathAndParamsForState(route);return{path:subPath?subPath+"/"+child.path:child.path,params:child.params?_objectSpread({},nonPathParams,child.params):nonPathParams};}return{path:subPath,params:nonPathParams};};return{getActionForPathAndParams:getActionForPathAndParams,getPathAndParamsForRoute:getPathAndParamsForRoute};};
2
2
  //# sourceMappingURL=pathUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["pathUtils.js"],"names":["pathToRegexp","compile","NavigationActions","invariant","queryString","require","getParamsFromPath","inputParams","pathMatch","pathMatchKeys","params","slice","reduce","paramsOut","matchResult","i","key","asterisk","paramName","name","decodedMatchResult","decodeURIComponent","e","getRestOfPath","rest","findIndex","k","urlToPathAndParams","url","uriPrefix","searchMatch","match","parse","urlWithoutSearch","delimiter","path","split","undefined","length","createPathParser","childRouters","routeConfigs","paths","pathConfigs","disableRouteNamePaths","pathsByRouteNames","Object","keys","forEach","routeName","pathPattern","isPathMatchable","exactReKeys","exactRe","extendedPathReKeys","isWildcard","extendedPathRe","toPath","entries","getActionForPathAndParams","pathToResolve","childRouter","exactMatch","exec","extendedMatch","childAction","restOfPath","navigate","action","getPathAndParamsForRoute","route","subPath","nonPathParams","filter","find","child","getPathAndParamsForState"],"mappings":"gIAEA,MAAOA,CAAAA,YAAP,EAAuBC,OAAvB,KAAsC,gBAAtC,CACA,MAAO,GAAKC,CAAAA,iBAAZ,KAAmC,sBAAnC,CACA,MAAOC,CAAAA,SAAP,KAAsB,oBAAtB,CAEA,GAAMC,CAAAA,WAAW,CAAGC,OAAO,CAAC,cAAD,CAA3B,CAEA,MAAO,IAAMC,CAAAA,iBAAiB,CAAG,QAApBA,CAAAA,iBAAoB,CAACC,WAAD,CAAcC,SAAd,CAAyBC,aAAzB,CAA2C,CAC1E,GAAMC,CAAAA,MAAM,CAAGF,SAAS,CAACG,KAAV,CAAgB,CAAhB,EAAmBC,MAAnB,CAEb,SAACC,SAAD,CAAYC,WAAZ,CAAyBC,CAAzB,CAA+B,CAC7B,GAAMC,CAAAA,GAAG,CAAGP,aAAa,CAACM,CAAD,CAAzB,CACA,GAAI,CAACC,GAAD,EAAQA,GAAG,CAACC,QAAhB,CAA0B,CACxB,MAAOJ,CAAAA,SAAP,CACD,CACD,GAAMK,CAAAA,SAAS,CAAGF,GAAG,CAACG,IAAtB,CAEA,GAAIC,CAAAA,kBAAJ,CACA,GAAIN,WAAJ,CAAiB,CACf,GAAI,CACFM,kBAAkB,CAAGC,kBAAkB,CAACP,WAAD,CAAvC,CACD,CAAC,MAAOQ,CAAP,CAAU,CAEX,CACF,CAEDT,SAAS,CAACK,SAAD,CAAT,CAAuBE,kBAAkB,EAAIN,WAA7C,CACA,MAAOD,CAAAA,SAAP,CACD,CApBY,kBAuBRN,WAvBQ,EAAf,CA0BA,MAAOG,CAAAA,MAAP,CACD,CA5BM,CA6BP,GAAMa,CAAAA,aAAa,CAAG,QAAhBA,CAAAA,aAAgB,CAACf,SAAD,CAAYC,aAAZ,CAA8B,CAClD,GAAMe,CAAAA,IAAI,CAAGhB,SAAS,CAACC,aAAa,CAACgB,SAAd,CAAw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,CAAGd,MAAM,CAAC/C,MAAD,CAAtB,CACA,GAAM8D,CAAAA,aAAa,CAAG,EAAtB,CACA,GAAI9D,MAAJ,CAAY,CACVoC,MAAM,CAACC,IAAP,CAAYrC,MAAZ,EACG+D,MADH,CACU,SAAAvD,SAAS,QAAI,CAACkC,WAAW,CAACsB,IAAZ,CAAiB,SAAAhD,CAAC,QAAIA,CAAAA,CAAC,CAACP,IAAF,GAAWD,SAAf,EAAlB,CAAL,EADnB,EAEG8B,OAFH,CAEW,SAAA9B,SAAS,CAAI,CACpBsD,aAAa,CAACtD,SAAD,CAAb,CAA2BR,MAAM,CAACQ,SAAD,CAAjC,CACD,CAJH,EAKD,CACD,GAAI2C,WAAJ,CAAiB,CAGf,GAAMc,CAAAA,KAAK,CAAGd,WAAW,CAACe,wBAAZ,CAAqCN,KAArC,CAAd,CACA,MAAO,CACLnC,IAAI,CAAEoC,OAAO,CAAMA,OAAN,KAAiBI,KAAK,CAACxC,IAAvB,CAAgCwC,KAAK,CAACxC,IAD9C,CAELzB,MAAM,CAAEiE,KAAK,CAACjE,MAAN,kBACC8D,aADD,CACmBG,KAAK,CAACjE,MADzB,EAEJ8D,aAJC,CAAP,CAMD,CACD,MAAO,CACLrC,IAAI,CAAEoC,OADD,CAEL7D,MAAM,CAAE8D,aAFH,CAAP,CAID,CA5BD,CA6BA,MAAO,CAAEb,yBAAyB,CAAzBA,yBAAF,CAA6BU,wBAAwB,CAAxBA,wBAA7B,CAAP,CACD,CAnJM","sourcesContent":["/* eslint-disable import/no-commonjs */\n\nimport pathToRegexp, { compile } from 'path-to-regexp';\nimport * as NavigationActions from '../NavigationActions';\nimport invariant from '../utils/invariant';\n\nconst queryString = require('query-string');\n\nexport const getParamsFromPath = (inputParams, pathMatch, pathMatchKeys) => {\n const params = pathMatch.slice(1).reduce(\n // iterate over matched path params\n (paramsOut, matchResult, i) => {\n const key = pathMatchKeys[i];\n if (!key || key.asterisk) {\n return paramsOut;\n }\n const paramName = key.name;\n\n let decodedMatchResult;\n if (matchResult) {\n try {\n decodedMatchResult = decodeURIComponent(matchResult);\n } catch (e) {\n // ignore `URIError: malformed URI`\n }\n }\n\n paramsOut[paramName] = decodedMatchResult || matchResult;\n return paramsOut;\n },\n {\n // start with the input(query string) params, which will get overridden by path params\n ...inputParams,\n }\n );\n return params;\n};\nconst getRestOfPath = (pathMatch, pathMatchKeys) => {\n const rest = pathMatch[pathMatchKeys.findIndex(k => k.asterisk) + 1];\n return rest;\n};\n\nexport const urlToPathAndParams = (url, uriPrefix) => {\n const searchMatch = url.match(/^(.*)\\?(.*)$/);\n const params = searchMatch ? queryString.parse(searchMatch[2]) : {};\n const urlWithoutSearch = searchMatch ? searchMatch[1] : url;\n const delimiter = uriPrefix || '://';\n let path = urlWithoutSearch.split(delimiter)[1];\n if (path === undefined) {\n path = urlWithoutSearch;\n }\n if (path === '/') {\n path = '';\n }\n if (path[path.length - 1] === '/') {\n path = path.slice(0, -1);\n }\n return {\n path,\n params,\n };\n};\n\nexport const createPathParser = (\n childRouters,\n routeConfigs,\n { paths: pathConfigs = {}, disableRouteNamePaths }\n) => {\n const pathsByRouteNames = {};\n let paths = [];\n\n // Build pathsByRouteNames, which includes a regex to match paths for each route. Keep in mind, the regex will pass for the route and all child routes. The code that uses pathsByRouteNames will need to also verify that the child router produces an action, in the case of isPathMatchable false (a null path).\n Object.keys(childRouters).forEach(routeName => {\n let pathPattern;\n\n // First check for paths on the router, then check the route config\n if (pathConfigs[routeName] !== undefined) {\n pathPattern = pathConfigs[routeName];\n } else {\n pathPattern = routeConfigs[routeName].path;\n }\n\n if (pathPattern === undefined) {\n // If the user hasn't specified a path at all nor disableRouteNamePaths, then we assume the routeName is an appropriate path\n pathPattern = disableRouteNamePaths ? null : routeName;\n }\n\n invariant(\n pathPattern === null || typeof pathPattern === 'string',\n `Route path for ${routeName} must be specified as a string, or null.`\n );\n\n // the path may be specified as null, which is similar to empty string because it allows child routers to handle the action, but it will not match empty paths\n const isPathMatchable = pathPattern !== null;\n // pathPattern is a string with inline params, such as people/:id/*foo\n const exactReKeys = [];\n const exactRe = isPathMatchable\n ? pathToRegexp(pathPattern, exactReKeys)\n : null;\n const extendedPathReKeys = [];\n const isWildcard = pathPattern === '' || !isPathMatchable;\n const extendedPathRe = pathToRegexp(\n isWildcard ? '*' : `${pathPattern}/*`,\n extendedPathReKeys\n );\n\n pathsByRouteNames[routeName] = {\n exactRe,\n exactReKeys,\n extendedPathRe,\n extendedPathReKeys,\n isWildcard,\n toPath: pathPattern === null ? () => '' : compile(pathPattern),\n };\n });\n\n paths = Object.entries(pathsByRouteNames);\n\n const getActionForPathAndParams = (pathToResolve = '', inputParams = {}) => {\n // Attempt to match `pathToResolve` with a route in this router's routeConfigs, deferring to child routers\n\n for (const [routeName, path] of paths) {\n const { exactRe, exactReKeys, extendedPathRe, extendedPathReKeys } = path;\n const childRouter = childRouters[routeName];\n\n const exactMatch = exactRe && exactRe.exec(pathToResolve);\n\n if (exactMatch && exactMatch.length) {\n const extendedMatch =\n extendedPathRe && extendedPathRe.exec(pathToResolve);\n let childAction = null;\n if (extendedMatch && childRouter) {\n const restOfPath = getRestOfPath(extendedMatch, extendedPathReKeys);\n childAction = childRouter.getActionForPathAndParams(\n restOfPath,\n inputParams\n );\n }\n\n return NavigationActions.navigate({\n routeName,\n params: getParamsFromPath(inputParams, exactMatch, exactReKeys),\n action: childAction,\n });\n }\n }\n\n for (const [routeName, path] of paths) {\n const { extendedPathRe, extendedPathReKeys } = path;\n const childRouter = childRouters[routeName];\n\n const extendedMatch =\n extendedPathRe && extendedPathRe.exec(pathToResolve);\n\n if (extendedMatch && extendedMatch.length) {\n const restOfPath = getRestOfPath(extendedMatch, extendedPathReKeys);\n let childAction = null;\n if (childRouter) {\n childAction = childRouter.getActionForPathAndParams(\n restOfPath,\n inputParams\n );\n }\n if (!childAction) {\n continue;\n }\n return NavigationActions.navigate({\n routeName,\n params: getParamsFromPath(\n inputParams,\n extendedMatch,\n extendedPathReKeys\n ),\n action: childAction,\n });\n }\n }\n\n return null;\n };\n const getPathAndParamsForRoute = route => {\n const { routeName, params } = route;\n const childRouter = childRouters[routeName];\n const { toPath, exactReKeys } = pathsByRouteNames[routeName];\n const subPath = toPath(params);\n const nonPathParams = {};\n if (params) {\n Object.keys(params)\n .filter(paramName => !exactReKeys.find(k => k.name === paramName))\n .forEach(paramName => {\n nonPathParams[paramName] = params[paramName];\n });\n }\n if (childRouter) {\n // If it has a router it's a navigator.\n // If it doesn't have router it's an ordinary React component.\n const child = childRouter.getPathAndParamsForState(route);\n return {\n path: subPath ? `${subPath}/${child.path}` : child.path,\n params: child.params\n ? { ...nonPathParams, ...child.params }\n : nonPathParams,\n };\n }\n return {\n path: subPath,\n params: nonPathParams,\n };\n };\n return { getActionForPathAndParams, getPathAndParamsForRoute };\n};\n"]}
1
+ {"version":3,"sources":["pathUtils.js"],"names":["pathToRegexp","compile","NavigationActions","invariant","queryString","require","getParamsFromPath","inputParams","pathMatch","pathMatchKeys","params","slice","reduce","paramsOut","matchResult","i","key","asterisk","paramName","name","decodedMatchResult","decodeURIComponent","e","getRestOfPath","rest","findIndex","k","determineDelimiter","uri","uriPrefix","Array","isArray","length","prefix","startsWith","urlToPathAndParams","url","searchMatch","match","urlWithoutQuery","query","parse","delimiter","path","split","undefined","createPathParser","childRouters","routeConfigs","paths","pathConfigs","disableRouteNamePaths","pathsByRouteNames","Object","keys","forEach","routeName","pathPattern","isPathMatchable","exactReKeys","exactRe","extendedPathReKeys","isWildcard","extendedPathRe","toPath","entries","getActionForPathAndParams","pathToResolve","childRouter","exactMatch","exec","extendedMatch","childAction","restOfPath","navigate","action","getPathAndParamsForRoute","route","subPath","nonPathParams","filter","find","child","getPathAndParamsForState"],"mappings":"gIAEA,MAAOA,CAAAA,YAAP,EAAuBC,OAAvB,KAAsC,gBAAtC,CACA,MAAO,GAAKC,CAAAA,iBAAZ,KAAmC,sBAAnC,CACA,MAAOC,CAAAA,SAAP,KAAsB,oBAAtB,CAEA,GAAMC,C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AM0D,CAAAA,WAAW,CAAGrB,YAAY,CAACS,SAAD,CAAhC,CAFwC,0BAGRJ,iBAAiB,CAACI,SAAD,CAHT,CAGhCQ,MAHgC,uBAGhCA,MAHgC,CAGxBL,WAHwB,uBAGxBA,WAHwB,CAIxC,GAAMmB,CAAAA,OAAO,CAAGd,MAAM,CAACtD,MAAD,CAAtB,CACA,GAAMqE,CAAAA,aAAa,CAAG,EAAtB,CACA,GAAIrE,MAAJ,CAAY,CACV2C,MAAM,CAACC,IAAP,CAAY5C,MAAZ,EACGsE,MADH,CACU,SAAA9D,SAAS,QAAI,CAACyC,WAAW,CAACsB,IAAZ,CAAiB,SAAAvD,CAAC,QAAIA,CAAAA,CAAC,CAACP,IAAF,GAAWD,SAAf,EAAlB,CAAL,EADnB,EAEGqC,OAFH,CAEW,SAAArC,SAAS,CAAI,CACpB6D,aAAa,CAAC7D,SAAD,CAAb,CAA2BR,MAAM,CAACQ,SAAD,CAAjC,CACD,CAJH,EAKD,CACD,GAAIkD,WAAJ,CAAiB,CAGf,GAAMc,CAAAA,KAAK,CAAGd,WAAW,CAACe,wBAAZ,CAAqCN,KAArC,CAAd,CACA,MAAO,CACLlC,IAAI,CAAEmC,OAAO,CAAMA,OAAN,KAAiBI,KAAK,CAACvC,IAAvB,CAAgCuC,KAAK,CAACvC,IAD9C,CAELjC,MAAM,CAAEwE,KAAK,CAACxE,MAAN,kBACCqE,aADD,CACmBG,KAAK,CAACxE,MADzB,EAEJqE,aAJC,CAAP,CAMD,CACD,MAAO,CACLpC,IAAI,CAAEmC,OADD,CAELpE,MAAM,CAAEqE,aAFH,CAAP,CAID,CA5BD,CA6BA,MAAO,CAAEb,yBAAyB,CAAzBA,yBAAF,CAA6BU,wBAAwB,CAAxBA,wBAA7B,CAAP,CACD,CAnJM","sourcesContent":["/* eslint-disable import/no-commonjs */\n\nimport pathToRegexp, { compile } from 'path-to-regexp';\nimport * as NavigationActions from '../NavigationActions';\nimport invariant from '../utils/invariant';\n\nconst queryString = require('query-string');\n\nexport const getParamsFromPath = (inputParams, pathMatch, pathMatchKeys) => {\n const params = pathMatch.slice(1).reduce(\n // iterate over matched path params\n (paramsOut, matchResult, i) => {\n const key = pathMatchKeys[i];\n if (!key || key.asterisk) {\n return paramsOut;\n }\n const paramName = key.name;\n\n let decodedMatchResult;\n if (matchResult) {\n try {\n decodedMatchResult = decodeURIComponent(matchResult);\n } catch (e) {\n // ignore `URIError: malformed URI`\n }\n }\n\n paramsOut[paramName] = decodedMatchResult || matchResult;\n return paramsOut;\n },\n {\n // start with the input(query string) params, which will get overridden by path params\n ...inputParams,\n }\n );\n return params;\n};\nconst getRestOfPath = (pathMatch, pathMatchKeys) => {\n const rest = pathMatch[pathMatchKeys.findIndex(k => k.asterisk) + 1];\n return rest;\n};\n\nconst determineDelimiter = (uri, uriPrefix) => {\n if (Array.isArray(uriPrefix)) {\n if (uriPrefix.length === 1) return uriPrefix[0];\n for (let prefix of uriPrefix) {\n if (uri.startsWith(prefix)) return prefix;\n }\n return null;\n }\n return uriPrefix;\n};\n\nexport const urlToPathAndParams = (url, uriPrefix) => {\n const searchMatch = url.match(/^(.*)\\?(.*)$/);\n const [, urlWithoutQuery, query] = searchMatch || [null, url, {}];\n const params = queryString.parse(query);\n const delimiter = determineDelimiter(urlWithoutQuery, uriPrefix) || '://';\n let path = urlWithoutQuery.split(delimiter)[1];\n if (path === undefined) {\n path = urlWithoutQuery;\n }\n if (path === '/') {\n path = '';\n }\n if (path[path.length - 1] === '/') {\n path = path.slice(0, -1);\n }\n return {\n path,\n params,\n };\n};\n\nexport const createPathParser = (\n childRouters,\n routeConfigs,\n { paths: pathConfigs = {}, disableRouteNamePaths }\n) => {\n const pathsByRouteNames = {};\n let paths = [];\n\n // Build pathsByRouteNames, which includes a regex to match paths for each route. Keep in mind, the regex will pass for the route and all child routes. The code that uses pathsByRouteNames will need to also verify that the child router produces an action, in the case of isPathMatchable false (a null path).\n Object.keys(childRouters).forEach(routeName => {\n let pathPattern;\n\n // First check for paths on the router, then check the route config\n if (pathConfigs[routeName] !== undefined) {\n pathPattern = pathConfigs[routeName];\n } else {\n pathPattern = routeConfigs[routeName].path;\n }\n\n if (pathPattern === undefined) {\n // If the user hasn't specified a path at all nor disableRouteNamePaths, then we assume the routeName is an appropriate path\n pathPattern = disableRouteNamePaths ? null : routeName;\n }\n\n invariant(\n pathPattern === null || typeof pathPattern === 'string',\n `Route path for ${routeName} must be specified as a string, or null.`\n );\n\n // the path may be specified as null, which is similar to empty string because it allows child routers to handle the action, but it will not match empty paths\n const isPathMatchable = pathPattern !== null;\n // pathPattern is a string with inline params, such as people/:id/*foo\n const exactReKeys = [];\n const exactRe = isPathMatchable\n ? pathToRegexp(pathPattern, exactReKeys)\n : null;\n const extendedPathReKeys = [];\n const isWildcard = pathPattern === '' || !isPathMatchable;\n const extendedPathRe = pathToRegexp(\n isWildcard ? '*' : `${pathPattern}/*`,\n extendedPathReKeys\n );\n\n pathsByRouteNames[routeName] = {\n exactRe,\n exactReKeys,\n extendedPathRe,\n extendedPathReKeys,\n isWildcard,\n toPath: pathPattern === null ? () => '' : compile(pathPattern),\n };\n });\n\n paths = Object.entries(pathsByRouteNames);\n\n const getActionForPathAndParams = (pathToResolve = '', inputParams = {}) => {\n // Attempt to match `pathToResolve` with a route in this router's routeConfigs, deferring to child routers\n\n for (const [routeName, path] of paths) {\n const { exactRe, exactReKeys, extendedPathRe, extendedPathReKeys } = path;\n const childRouter = childRouters[routeName];\n\n const exactMatch = exactRe && exactRe.exec(pathToResolve);\n\n if (exactMatch && exactMatch.length) {\n const extendedMatch =\n extendedPathRe && extendedPathRe.exec(pathToResolve);\n let childAction = null;\n if (extendedMatch && childRouter) {\n const restOfPath = getRestOfPath(extendedMatch, extendedPathReKeys);\n childAction = childRouter.getActionForPathAndParams(\n restOfPath,\n inputParams\n );\n }\n\n return NavigationActions.navigate({\n routeName,\n params: getParamsFromPath(inputParams, exactMatch, exactReKeys),\n action: childAction,\n });\n }\n }\n\n for (const [routeName, path] of paths) {\n const { extendedPathRe, extendedPathReKeys } = path;\n const childRouter = childRouters[routeName];\n\n const extendedMatch =\n extendedPathRe && extendedPathRe.exec(pathToResolve);\n\n if (extendedMatch && extendedMatch.length) {\n const restOfPath = getRestOfPath(extendedMatch, extendedPathReKeys);\n let childAction = null;\n if (childRouter) {\n childAction = childRouter.getActionForPathAndParams(\n restOfPath,\n inputParams\n );\n }\n if (!childAction) {\n continue;\n }\n return NavigationActions.navigate({\n routeName,\n params: getParamsFromPath(\n inputParams,\n extendedMatch,\n extendedPathReKeys\n ),\n action: childAction,\n });\n }\n }\n\n return null;\n };\n const getPathAndParamsForRoute = route => {\n const { routeName, params } = route;\n const childRouter = childRouters[routeName];\n const { toPath, exactReKeys } = pathsByRouteNames[routeName];\n const subPath = toPath(params);\n const nonPathParams = {};\n if (params) {\n Object.keys(params)\n .filter(paramName => !exactReKeys.find(k => k.name === paramName))\n .forEach(paramName => {\n nonPathParams[paramName] = params[paramName];\n });\n }\n if (childRouter) {\n // If it has a router it's a navigator.\n // If it doesn't have router it's an ordinary React component.\n const child = childRouter.getPathAndParamsForState(route);\n return {\n path: subPath ? `${subPath}/${child.path}` : child.path,\n params: child.params\n ? { ...nonPathParams, ...child.params }\n : nonPathParams,\n };\n }\n return {\n path: subPath,\n params: nonPathParams,\n };\n };\n return { getActionForPathAndParams, getPathAndParamsForRoute };\n};\n"]}
@@ -1,2 +1,2 @@
1
- import{useContext}from'react';import ThemeContext from'./views/ThemeContext';export default useContext(ThemeContext);
1
+ import{useContext}from'react';import ThemeContext from'./views/ThemeContext';export default(function(){return useContext(ThemeContext);});
2
2
  //# sourceMappingURL=useTheme.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useTheme.ts"],"names":["useContext","ThemeContext"],"mappings":"AAAA,OAASA,UAAT,KAA2B,OAA3B,CACA,MAAOC,CAAAA,YAAP,KAAyB,sBAAzB,CAEA,cAAeD,CAAAA,UAAU,CAACC,YAAD,CAAzB","sourcesContent":["import { useContext } from 'react';\nimport ThemeContext from './views/ThemeContext';\n\nexport default useContext(ThemeContext);\n"]}
1
+ {"version":3,"sources":["useTheme.ts"],"names":["useContext","ThemeContext"],"mappings":"AAAA,OAASA,UAAT,KAA2B,OAA3B,CACA,MAAOC,CAAAA,YAAP,KAAyB,sBAAzB,CAEA,eAAe,iBAAMD,CAAAA,UAAU,CAACC,YAAD,CAAhB,EAAf","sourcesContent":["import { useContext } from 'react';\nimport ThemeContext from './views/ThemeContext';\n\nexport default () => useContext(ThemeContext);\n"]}
@@ -1,2 +1,2 @@
1
- var getActiveChildNavigationOptions=function getActiveChildNavigationOptions(navigation,screenProps){var state=navigation.state,router=navigation.router,getChildNavigation=navigation.getChildNavigation;var activeRoute=state.routes[state.index];var activeNavigation=getChildNavigation(activeRoute.key);var options=router.getScreenOptions(activeNavigation,screenProps);return options;};export default getActiveChildNavigationOptions;
1
+ var getActiveChildNavigationOptions=function getActiveChildNavigationOptions(navigation,screenProps){var theme=arguments.length>2&&arguments[2]!==undefined?arguments[2]:'light';var state=navigation.state,router=navigation.router,getChildNavigation=navigation.getChildNavigation;var activeRoute=state.routes[state.index];var activeNavigation=getChildNavigation(activeRoute.key);var options=router.getScreenOptions(activeNavigation,screenProps,theme);return options;};export default getActiveChildNavigationOptions;
2
2
  //# sourceMappingURL=getActiveChildNavigationOptions.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["getActiveChildNavigationOptions.js"],"names":["getActiveChildNavigationOptions","navigation","screenProps","state","router","getChildNavigation","activeRoute","routes","index","activeNavigation","key","options","getScreenOptions"],"mappings":"AAAA,GAAMA,CAAAA,+BAA+B,CAAG,QAAlCA,CAAAA,+BAAkC,CAACC,UAAD,CAAaC,WAAb,CAA6B,IAC3DC,CAAAA,KAD2D,CACrBF,UADqB,CAC3DE,KAD2D,CACpDC,MADoD,CACrBH,UADqB,CACpDG,MADoD,CAC5CC,kBAD4C,CACrBJ,UADqB,CAC5CI,kBAD4C,CAEnE,GAAMC,CAAAA,WAAW,CAAGH,KAAK,CAACI,MAAN,CAAaJ,KAAK,CAACK,KAAnB,CAApB,CACA,GAAMC,CAAAA,gBAAgB,CAAGJ,kBAAkB,CAACC,WAAW,CAACI,GAAb,CAA3C,CACA,GAAMC,CAAAA,OAAO,CAAGP,MAAM,CAACQ,gBAAP,CAAwBH,gBAAxB,CAA0CP,WAA1C,CAAhB,CACA,MAAOS,CAAAA,OAAP,CACD,CAND,CAQA,cAAeX,CAAAA,+BAAf","sourcesContent":["const getActiveChildNavigationOptions = (navigation, screenProps) => {\n const { state, router, getChildNavigation } = navigation;\n const activeRoute = state.routes[state.index];\n const activeNavigation = getChildNavigation(activeRoute.key);\n const options = router.getScreenOptions(activeNavigation, screenProps);\n return options;\n};\n\nexport default getActiveChildNavigationOptions;\n"]}
1
+ {"version":3,"sources":["getActiveChildNavigationOptions.js"],"names":["getActiveChildNavigationOptions","navigation","screenProps","theme","state","router","getChildNavigation","activeRoute","routes","index","activeNavigation","key","options","getScreenOptions"],"mappings":"AAAA,GAAMA,CAAAA,+BAA+B,CAAG,QAAlCA,CAAAA,+BAAkC,CACtCC,UADsC,CAEtCC,WAFsC,CAInC,IADHC,CAAAA,KACG,2DADK,OACL,IACKC,CAAAA,KADL,CAC2CH,UAD3C,CACKG,KADL,CACYC,MADZ,CAC2CJ,UAD3C,CACYI,MADZ,CACoBC,kBADpB,CAC2CL,UAD3C,CACoBK,kBADpB,CAEH,GAAMC,CAAAA,WAAW,CAAGH,KAAK,CAACI,MAAN,CAAaJ,KAAK,CAACK,KAAnB,CAApB,CACA,GAAMC,CAAAA,gBAAgB,CAAGJ,kBAAkB,CAACC,WAAW,CAACI,GAAb,CAA3C,CACA,GAAMC,CAAAA,OAAO,CAAGP,MAAM,CAACQ,gBAAP,CAAwBH,gBAAxB,CAA0CR,WAA1C,CAAuDC,KAAvD,CAAhB,CACA,MAAOS,CAAAA,OAAP,CACD,CAVD,CAYA,cAAeZ,CAAAA,+BAAf","sourcesContent":["const getActiveChildNavigationOptions = (\n navigation,\n screenProps,\n theme = 'light'\n) => {\n const { state, router, getChildNavigation } = navigation;\n const activeRoute = state.routes[state.index];\n const activeNavigation = getChildNavigation(activeRoute.key);\n const options = router.getScreenOptions(activeNavigation, screenProps, theme);\n return options;\n};\n\nexport default getActiveChildNavigationOptions;\n"]}
@@ -1,2 +1,2 @@
1
- import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _inherits from"@babel/runtime/helpers/inherits";var _jsxFileName="/Users/brentvatne/coding/react-navigation-core/src/views/SceneView.js";import React from'react';import NavigationContext from'./NavigationContext';var SceneView=function(_React$PureComponent){_inherits(SceneView,_React$PureComponent);function SceneView(){_classCallCheck(this,SceneView);return _possibleConstructorReturn(this,_getPrototypeOf(SceneView).apply(this,arguments));}_createClass(SceneView,[{key:"render",value:function render(){var _this$props=this.props,screenProps=_this$props.screenProps,Component=_this$props.component,navigation=_this$props.navigation;return React.createElement(NavigationContext.Provider,{value:navigation,__source:{fileName:_jsxFileName,lineNumber:8}},React.createElement(Component,{screenProps:screenProps,navigation:navigation,__source:{fileName:_jsxFileName,lineNumber:9}}));}}]);return SceneView;}(React.PureComponent);export{SceneView as default};
1
+ import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _inherits from"@babel/runtime/helpers/inherits";var _jsxFileName="/Users/satya/Workspace/Callstack/react-navigation-core/src/views/SceneView.js";import React from'react';import NavigationContext from'./NavigationContext';var SceneView=function(_React$PureComponent){_inherits(SceneView,_React$PureComponent);function SceneView(){_classCallCheck(this,SceneView);return _possibleConstructorReturn(this,_getPrototypeOf(SceneView).apply(this,arguments));}_createClass(SceneView,[{key:"render",value:function render(){var _this$props=this.props,screenProps=_this$props.screenProps,Component=_this$props.component,navigation=_this$props.navigation;return React.createElement(NavigationContext.Provider,{value:navigation,__source:{fileName:_jsxFileName,lineNumber:8}},React.createElement(Component,{screenProps:screenProps,navigation:navigation,__source:{fileName:_jsxFileName,lineNumber:9}}));}}]);return SceneView;}(React.PureComponent);export{SceneView as default};
2
2
  //# sourceMappingURL=SceneView.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["SceneView.js"],"names":["React","NavigationContext","SceneView","props","screenProps","Component","component","navigation","PureComponent"],"mappings":"4aAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,MAAOC,CAAAA,iBAAP,KAA8B,qBAA9B,C,GAEqBC,CAAAA,S,sRACV,iBACmD,KAAKC,KADxD,CACCC,WADD,aACCA,WADD,CACyBC,SADzB,aACcC,SADd,CACoCC,UADpC,aACoCA,UADpC,CAEP,MACE,qBAAC,iBAAD,CAAmB,QAAnB,EAA4B,KAAK,CAAEA,UAAnC,gDACE,oBAAC,SAAD,EAAW,WAAW,CAAEH,WAAxB,CAAqC,UAAU,CAAEG,UAAjD,gDADF,CADF,CAKD,C,uBARoCP,KAAK,CAACQ,a,SAAxBN,S","sourcesContent":["import React from 'react';\nimport NavigationContext from './NavigationContext';\n\nexport default class SceneView extends React.PureComponent {\n render() {\n const { screenProps, component: Component, navigation } = this.props;\n return (\n <NavigationContext.Provider value={navigation}>\n <Component screenProps={screenProps} navigation={navigation} />\n </NavigationContext.Provider>\n );\n }\n}\n"]}
1
+ {"version":3,"sources":["SceneView.js"],"names":["React","NavigationContext","SceneView","props","screenProps","Component","component","navigation","PureComponent"],"mappings":"obAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,MAAOC,CAAAA,iBAAP,KAA8B,qBAA9B,C,GAEqBC,CAAAA,S,sRACV,iBACmD,KAAKC,KADxD,CACCC,WADD,aACCA,WADD,CACyBC,SADzB,aACcC,SADd,CACoCC,UADpC,aACoCA,UADpC,CAEP,MACE,qBAAC,iBAAD,CAAmB,QAAnB,EAA4B,KAAK,CAAEA,UAAnC,gDACE,oBAAC,SAAD,EAAW,WAAW,CAAEH,WAAxB,CAAqC,UAAU,CAAEG,UAAjD,gDADF,CADF,CAKD,C,uBARoCP,KAAK,CAACQ,a,SAAxBN,S","sourcesContent":["import React from 'react';\nimport NavigationContext from './NavigationContext';\n\nexport default class SceneView extends React.PureComponent {\n render() {\n const { screenProps, component: Component, navigation } = this.props;\n return (\n <NavigationContext.Provider value={navigation}>\n <Component screenProps={screenProps} navigation={navigation} />\n </NavigationContext.Provider>\n );\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _inherits from"@babel/runtime/helpers/inherits";var _jsxFileName="/Users/brentvatne/coding/react-navigation-core/src/views/SwitchView/SwitchView.js";import React from'react';import SceneView from'../SceneView';var SwitchView=function(_React$Component){_inherits(SwitchView,_React$Component);function SwitchView(){_classCallCheck(this,SwitchView);return _possibleConstructorReturn(this,_getPrototypeOf(SwitchView).apply(this,arguments));}_createClass(SwitchView,[{key:"render",value:function render(){var state=this.props.navigation.state;var activeKey=state.routes[state.index].key;var descriptor=this.props.descriptors[activeKey];var ChildComponent=descriptor.getComponent();return React.createElement(SceneView,{component:ChildComponent,navigation:descriptor.navigation,screenProps:this.props.screenProps,__source:{fileName:_jsxFileName,lineNumber:12}});}}]);return SwitchView;}(React.Component);export{SwitchView as default};
1
+ import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _inherits from"@babel/runtime/helpers/inherits";var _jsxFileName="/Users/satya/Workspace/Callstack/react-navigation-core/src/views/SwitchView/SwitchView.js";import React from'react';import SceneView from'../SceneView';var SwitchView=function(_React$Component){_inherits(SwitchView,_React$Component);function SwitchView(){_classCallCheck(this,SwitchView);return _possibleConstructorReturn(this,_getPrototypeOf(SwitchView).apply(this,arguments));}_createClass(SwitchView,[{key:"render",value:function render(){var state=this.props.navigation.state;var activeKey=state.routes[state.index].key;var descriptor=this.props.descriptors[activeKey];var ChildComponent=descriptor.getComponent();return React.createElement(SceneView,{component:ChildComponent,navigation:descriptor.navigation,screenProps:this.props.screenProps,__source:{fileName:_jsxFileName,lineNumber:12}});}}]);return SwitchView;}(React.Component);export{SwitchView as default};
2
2
  //# sourceMappingURL=SwitchView.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["SwitchView.js"],"names":["React","SceneView","SwitchView","state","props","navigation","activeKey","routes","index","key","descriptor","descriptors","ChildComponent","getComponent","screenProps","Component"],"mappings":"wbAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,MAAOC,CAAAA,SAAP,KAAsB,cAAtB,C,GAEqBC,CAAAA,U,mRACV,IACCC,CAAAA,KADD,CACW,KAAKC,KAAL,CAAWC,UADtB,CACCF,KADD,CAEP,GAAMG,CAAAA,SAAS,CAAGH,KAAK,CAACI,MAAN,CAAaJ,KAAK,CAACK,KAAnB,EAA0BC,GAA5C,CACA,GAAMC,CAAAA,UAAU,CAAG,KAAKN,KAAL,CAAWO,WAAX,CAAuBL,SAAvB,CAAnB,CACA,GAAMM,CAAAA,cAAc,CAAGF,UAAU,CAACG,YAAX,EAAvB,CAEA,MACE,qBAAC,SAAD,EACE,SAAS,CAAED,cADb,CAEE,UAAU,CAAEF,UAAU,CAACL,UAFzB,CAGE,WAAW,CAAE,KAAKD,KAAL,CAAWU,WAH1B,iDADF,CAOD,C,wBAdqCd,KAAK,CAACe,S,SAAzBb,U","sourcesContent":["import React from 'react';\nimport SceneView from '../SceneView';\n\nexport default class SwitchView extends React.Component {\n render() {\n const { state } = this.props.navigation;\n const activeKey = state.routes[state.index].key;\n const descriptor = this.props.descriptors[activeKey];\n const ChildComponent = descriptor.getComponent();\n\n return (\n <SceneView\n component={ChildComponent}\n navigation={descriptor.navigation}\n screenProps={this.props.screenProps}\n />\n );\n }\n}\n"]}
1
+ {"version":3,"sources":["SwitchView.js"],"names":["React","SceneView","SwitchView","state","props","navigation","activeKey","routes","index","key","descriptor","descriptors","ChildComponent","getComponent","screenProps","Component"],"mappings":"gcAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,MAAOC,CAAAA,SAAP,KAAsB,cAAtB,C,GAEqBC,CAAAA,U,mRACV,IACCC,CAAAA,KADD,CACW,KAAKC,KAAL,CAAWC,UADtB,CACCF,KADD,CAEP,GAAMG,CAAAA,SAAS,CAAGH,KAAK,CAACI,MAAN,CAAaJ,KAAK,CAACK,KAAnB,EAA0BC,GAA5C,CACA,GAAMC,CAAAA,UAAU,CAAG,KAAKN,KAAL,CAAWO,WAAX,CAAuBL,SAAvB,CAAnB,CACA,GAAMM,CAAAA,cAAc,CAAGF,UAAU,CAACG,YAAX,EAAvB,CAEA,MACE,qBAAC,SAAD,EACE,SAAS,CAAED,cADb,CAEE,UAAU,CAAEF,UAAU,CAACL,UAFzB,CAGE,WAAW,CAAE,KAAKD,KAAL,CAAWU,WAH1B,iDADF,CAOD,C,wBAdqCd,KAAK,CAACe,S,SAAzBb,U","sourcesContent":["import React from 'react';\nimport SceneView from '../SceneView';\n\nexport default class SwitchView extends React.Component {\n render() {\n const { state } = this.props.navigation;\n const activeKey = state.routes[state.index].key;\n const descriptor = this.props.descriptors[activeKey];\n const ChildComponent = descriptor.getComponent();\n\n return (\n <SceneView\n component={ChildComponent}\n navigation={descriptor.navigation}\n screenProps={this.props.screenProps}\n />\n );\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- import _extends from"@babel/runtime/helpers/extends";var _jsxFileName="/Users/brentvatne/coding/react-navigation-core/src/views/__tests__/NavigationEvents-test.js";import React from'react';import renderer from'react-test-renderer';import NavigationEvents from'../NavigationEvents';import NavigationContext from'../NavigationContext';var createPropListener=function createPropListener(){return jest.fn();};var createEventListenersProp=function createEventListenersProp(){return{onWillFocus:createPropListener(),onDidFocus:createPropListener(),onWillBlur:createPropListener(),onDidBlur:createPropListener()};};var createTestNavigationAndHelpers=function createTestNavigationAndHelpers(){var NavigationListenersAPI=function(){var listeners={willFocus:[],didFocus:[],willBlur:[],didBlur:[]};return{add:function add(eventName,handler){listeners[eventName].push(handler);},remove:function remove(eventName,handler){listeners[eventName]=listeners[eventName].filter(function(h){return h!==handler;});},get:function get(eventName){return listeners[eventName];},call:function call(eventName){listeners[eventName].forEach(function(listener){return listener();});}};}();var navigation={addListener:jest.fn(function(eventName,handler){NavigationListenersAPI.add(eventName,handler);return{remove:function remove(){return NavigationListenersAPI.remove(eventName,handler);}};})};return{navigation:navigation,NavigationListenersAPI:NavigationListenersAPI};};describe('NavigationEvents',function(){it('add all listeners on mount and remove them on unmount, even without any event prop provided (see #5058)',function(){var _createTestNavigation=createTestNavigationAndHelpers(),navigation=_createTestNavigation.navigation,NavigationListenersAPI=_createTestNavigation.NavigationListenersAPI;var component=renderer.create(React.createElement(NavigationEvents,{navigation:navigation,__source:{fileName:_jsxFileName,lineNumber:63}}));expect(NavigationListenersAPI.get('willFocus').length).toBe(1);expect(NavigationListenersAPI.get('didFocus').length).toBe(1);expect(NavigationListenersAPI.get('willBlur').length).toBe(1);expect(NavigationListenersAPI.get('didBlur').length).toBe(1);component.unmount();expect(NavigationListenersAPI.get('willFocus').length).toBe(0);expect(NavigationListenersAPI.get('didFocus').length).toBe(0);expect(NavigationListenersAPI.get('willBlur').length).toBe(0);expect(NavigationListenersAPI.get('didBlur').length).toBe(0);});it('support context-provided navigation',function(){var _createTestNavigation2=createTestNavigationAndHelpers(),navigation=_createTestNavigation2.navigation,NavigationListenersAPI=_createTestNavigation2.NavigationListenersAPI;var component=renderer.create(React.createElement(NavigationContext.Provider,{value:navigation,__source:{fileName:_jsxFileName,lineNumber:83}},React.createElement(NavigationEvents,{__source:{fileName:_jsxFileName,lineNumber:84}})));expect(NavigationListenersAPI.get('willFocus').length).toBe(1);expect(NavigationListenersAPI.get('didFocus').length).toBe(1);expect(NavigationListenersAPI.get('willBlur').length).toBe(1);expect(NavigationListenersAPI.get('didBlur').length).toBe(1);component.unmount();expect(NavigationListenersAPI.get('willFocus').length).toBe(0);expect(NavigationListenersAPI.get('didFocus').length).toBe(0);expect(NavigationListenersAPI.get('willBlur').length).toBe(0);expect(NavigationListenersAPI.get('didBlur').length).toBe(0);});it('wire props listeners to navigation listeners',function(){var _createTestNavigation3=createTestNavigationAndHelpers(),navigation=_createTestNavigation3.navigation,NavigationListenersAPI=_createTestNavigation3.NavigationListenersAPI;var eventListenerProps=createEventListenersProp();renderer.create(React.createElement(NavigationEvents,_extends({navigation:navigation},eventListenerProps,{__source:{fileName:_jsxFileName,lineNumber:108}})));var checkPropListenerIsCalled=function checkPropListenerIsCalled(eventName,propName){expect(eventListenerProps[propName]).toHaveBeenCalledTimes(0);NavigationListenersAPI.call(eventName);expect(eventListenerProps[propName]).toHaveBeenCalledTimes(1);};checkPropListenerIsCalled('willFocus','onWillFocus');checkPropListenerIsCalled('didFocus','onDidFocus');checkPropListenerIsCalled('willBlur','onWillBlur');checkPropListenerIsCalled('didBlur','onDidBlur');});it('wire latest props listener to navigation listeners on updates (support closure/arrow functions update)',function(){var _createTestNavigation4=createTestNavigationAndHelpers(),navigation=_createTestNavigation4.navigation,NavigationListenersAPI=_createTestNavigation4.NavigationListenersAPI;var component=renderer.create(React.createElement(NavigationEvents,_extends({navigation:navigation},createEventListenersProp(),{__source:{fileName:_jsxFileName,lineNumber:130}})));component.update(React.createElement(NavigationEvents,{navigation:navigation,onWillBlur:function onWillBlur(){throw new Error('should not be called');},onDidFocus:function onDidFocus(){throw new Error('should not be called');},__source:{fileName:_jsxFileName,lineNumber:137}}));component.update(React.createElement(NavigationEvents,_extends({navigation:navigation},createEventListenersProp(),{__source:{fileName:_jsxFileName,lineNumber:149}})));var latestEventListenerProps=createEventListenersProp();component.update(React.createElement(NavigationEvents,_extends({navigation:navigation},latestEventListenerProps,{__source:{fileName:_jsxFileName,lineNumber:157}})));var checkLatestPropListenerCalled=function checkLatestPropListenerCalled(eventName,propName){expect(latestEventListenerProps[propName]).toHaveBeenCalledTimes(0);NavigationListenersAPI.call(eventName);expect(latestEventListenerProps[propName]).toHaveBeenCalledTimes(1);};checkLatestPropListenerCalled('willFocus','onWillFocus');checkLatestPropListenerCalled('didFocus','onDidFocus');checkLatestPropListenerCalled('willBlur','onWillBlur');checkLatestPropListenerCalled('didBlur','onDidBlur');});});
1
+ import _extends from"@babel/runtime/helpers/extends";var _jsxFileName="/Users/satya/Workspace/Callstack/react-navigation-core/src/views/__tests__/NavigationEvents-test.js";import React from'react';import renderer from'react-test-renderer';import NavigationEvents from'../NavigationEvents';import NavigationContext from'../NavigationContext';var createPropListener=function createPropListener(){return jest.fn();};var createEventListenersProp=function createEventListenersProp(){return{onWillFocus:createPropListener(),onDidFocus:createPropListener(),onWillBlur:createPropListener(),onDidBlur:createPropListener()};};var createTestNavigationAndHelpers=function createTestNavigationAndHelpers(){var NavigationListenersAPI=function(){var listeners={willFocus:[],didFocus:[],willBlur:[],didBlur:[]};return{add:function add(eventName,handler){listeners[eventName].push(handler);},remove:function remove(eventName,handler){listeners[eventName]=listeners[eventName].filter(function(h){return h!==handler;});},get:function get(eventName){return listeners[eventName];},call:function call(eventName){listeners[eventName].forEach(function(listener){return listener();});}};}();var navigation={addListener:jest.fn(function(eventName,handler){NavigationListenersAPI.add(eventName,handler);return{remove:function remove(){return NavigationListenersAPI.remove(eventName,handler);}};})};return{navigation:navigation,NavigationListenersAPI:NavigationListenersAPI};};describe('NavigationEvents',function(){it('add all listeners on mount and remove them on unmount, even without any event prop provided (see #5058)',function(){var _createTestNavigation=createTestNavigationAndHelpers(),navigation=_createTestNavigation.navigation,NavigationListenersAPI=_createTestNavigation.NavigationListenersAPI;var component=renderer.create(React.createElement(NavigationEvents,{navigation:navigation,__source:{fileName:_jsxFileName,lineNumber:63}}));expect(NavigationListenersAPI.get('willFocus').length).toBe(1);expect(NavigationListenersAPI.get('didFocus').length).toBe(1);expect(NavigationListenersAPI.get('willBlur').length).toBe(1);expect(NavigationListenersAPI.get('didBlur').length).toBe(1);component.unmount();expect(NavigationListenersAPI.get('willFocus').length).toBe(0);expect(NavigationListenersAPI.get('didFocus').length).toBe(0);expect(NavigationListenersAPI.get('willBlur').length).toBe(0);expect(NavigationListenersAPI.get('didBlur').length).toBe(0);});it('support context-provided navigation',function(){var _createTestNavigation2=createTestNavigationAndHelpers(),navigation=_createTestNavigation2.navigation,NavigationListenersAPI=_createTestNavigation2.NavigationListenersAPI;var component=renderer.create(React.createElement(NavigationContext.Provider,{value:navigation,__source:{fileName:_jsxFileName,lineNumber:83}},React.createElement(NavigationEvents,{__source:{fileName:_jsxFileName,lineNumber:84}})));expect(NavigationListenersAPI.get('willFocus').length).toBe(1);expect(NavigationListenersAPI.get('didFocus').length).toBe(1);expect(NavigationListenersAPI.get('willBlur').length).toBe(1);expect(NavigationListenersAPI.get('didBlur').length).toBe(1);component.unmount();expect(NavigationListenersAPI.get('willFocus').length).toBe(0);expect(NavigationListenersAPI.get('didFocus').length).toBe(0);expect(NavigationListenersAPI.get('willBlur').length).toBe(0);expect(NavigationListenersAPI.get('didBlur').length).toBe(0);});it('wire props listeners to navigation listeners',function(){var _createTestNavigation3=createTestNavigationAndHelpers(),navigation=_createTestNavigation3.navigation,NavigationListenersAPI=_createTestNavigation3.NavigationListenersAPI;var eventListenerProps=createEventListenersProp();renderer.create(React.createElement(NavigationEvents,_extends({navigation:navigation},eventListenerProps,{__source:{fileName:_jsxFileName,lineNumber:108}})));var checkPropListenerIsCalled=function checkPropListenerIsCalled(eventName,propName){expect(eventListenerProps[propName]).toHaveBeenCalledTimes(0);NavigationListenersAPI.call(eventName);expect(eventListenerProps[propName]).toHaveBeenCalledTimes(1);};checkPropListenerIsCalled('willFocus','onWillFocus');checkPropListenerIsCalled('didFocus','onDidFocus');checkPropListenerIsCalled('willBlur','onWillBlur');checkPropListenerIsCalled('didBlur','onDidBlur');});it('wire latest props listener to navigation listeners on updates (support closure/arrow functions update)',function(){var _createTestNavigation4=createTestNavigationAndHelpers(),navigation=_createTestNavigation4.navigation,NavigationListenersAPI=_createTestNavigation4.NavigationListenersAPI;var component=renderer.create(React.createElement(NavigationEvents,_extends({navigation:navigation},createEventListenersProp(),{__source:{fileName:_jsxFileName,lineNumber:130}})));component.update(React.createElement(NavigationEvents,{navigation:navigation,onWillBlur:function onWillBlur(){throw new Error('should not be called');},onDidFocus:function onDidFocus(){throw new Error('should not be called');},__source:{fileName:_jsxFileName,lineNumber:137}}));component.update(React.createElement(NavigationEvents,_extends({navigation:navigation},createEventListenersProp(),{__source:{fileName:_jsxFileName,lineNumber:149}})));var latestEventListenerProps=createEventListenersProp();component.update(React.createElement(NavigationEvents,_extends({navigation:navigation},latestEventListenerProps,{__source:{fileName:_jsxFileName,lineNumber:157}})));var checkLatestPropListenerCalled=function checkLatestPropListenerCalled(eventName,propName){expect(latestEventListenerProps[propName]).toHaveBeenCalledTimes(0);NavigationListenersAPI.call(eventName);expect(latestEventListenerProps[propName]).toHaveBeenCalledTimes(1);};checkLatestPropListenerCalled('willFocus','onWillFocus');checkLatestPropListenerCalled('didFocus','onDidFocus');checkLatestPropListenerCalled('willBlur','onWillBlur');checkLatestPropListenerCalled('didBlur','onDidBlur');});});
2
2
  //# sourceMappingURL=NavigationEvents-test.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["NavigationEvents-test.js"],"names":["React","renderer","NavigationEvents","NavigationContext","createPropListener","jest","fn","createEventListenersProp","onWillFocus","onDidFocus","onWillBlur","onDidBlur","createTestNavigationAndHelpers","NavigationListenersAPI","listeners","willFocus","didFocus","willBlur","didBlur","add","eventName","handler","push","remove","filter","h","get","call","forEach","listener","navigation","addListener","describe","it","component","create","expect","length","toBe","unmount","eventListenerProps","checkPropListenerIsCalled","propName","toHaveBeenCalledTimes","update","Error","latestEventListenerProps","checkLatestPropListenerCalled"],"mappings":"oKAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,MAAOC,CAAAA,QAAP,KAAqB,qBAArB,CACA,MAAOC,CAAAA,gBAAP,KAA6B,qBAA7B,CACA,MAAOC,CAAAA,iBAAP,KAA8B,sBAA9B,CAEA,GAAMC,CAAAA,kBAAkB,CAAG,QAArBA,CAAAA,kBAAqB,SAAMC,CAAAA,IAAI,CAACC,EAAL,EAAN,EAA3B,CAGA,GAAMC,CAAAA,wBAAwB,CAAG,QAA3BA,CAAAA,wBAA2B,SAAO,CACtCC,WAAW,CAAEJ,kBAAkB,EADO,CAEtCK,UAAU,CAAEL,kBAAkB,EAFQ,CAGtCM,UAAU,CAAEN,kBAAkB,EAHQ,CAItCO,SAAS,CAAEP,kBAAkB,EAJS,CAAP,EAAjC,CAOA,GAAMQ,CAAAA,8BAA8B,CAAG,QAAjCA,CAAAA,8BAAiC,EAAM,CAC3C,GAAMC,CAAAA,sBAAsB,CAAI,UAAM,CACpC,GAAIC,CAAAA,SAAS,CAAG,CACdC,SAAS,CAAE,EADG,CAEdC,QAAQ,CAAE,EAFI,CAGdC,QAAQ,CAAE,EAHI,CAIdC,OAAO,CAAE,EAJK,CAAhB,CAMA,MAAO,CACLC,GAAG,CAAE,aAACC,SAAD,CAAYC,OAAZ,CAAwB,CAC3BP,SAAS,CAACM,SAAD,CAAT,CAAqBE,IAArB,CAA0BD,OAA1B,EACD,CAHI,CAILE,MAAM,CAAE,gBAACH,SAAD,CAAYC,OAAZ,CAAwB,CAC9BP,SAAS,CAACM,SAAD,CAAT,CAAuBN,SAAS,CAACM,SAAD,CAAT,CAAqBI,MAArB,CAA4B,SAAAC,CAAC,QAAIA,CAAAA,CAAC,GAAKJ,OAAV,EAA7B,CAAvB,CACD,CANI,CAOLK,GAAG,CAAE,aAAAN,SAAS,CAAI,CAChB,MAAON,CAAAA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AC,WAAD,CAAc,aAAd,CAA7B,CACAA,6BAA6B,CAAC,UAAD,CAAa,YAAb,CAA7B,CACAA,6BAA6B,CAAC,UAAD,CAAa,YAAb,CAA7B,CACAA,6BAA6B,CAAC,SAAD,CAAY,WAAZ,CAA7B,CACD,CA/CC,CAAF,CAgDD,CApHO,CAAR","sourcesContent":["import React from 'react';\nimport renderer from 'react-test-renderer';\nimport NavigationEvents from '../NavigationEvents';\nimport NavigationContext from '../NavigationContext';\n\nconst createPropListener = () => jest.fn();\n\n// An easy way to create the 4 listeners prop\nconst createEventListenersProp = () => ({\n onWillFocus: createPropListener(),\n onDidFocus: createPropListener(),\n onWillBlur: createPropListener(),\n onDidBlur: createPropListener(),\n});\n\nconst createTestNavigationAndHelpers = () => {\n const NavigationListenersAPI = (() => {\n let listeners = {\n willFocus: [],\n didFocus: [],\n willBlur: [],\n didBlur: [],\n };\n return {\n add: (eventName, handler) => {\n listeners[eventName].push(handler);\n },\n remove: (eventName, handler) => {\n listeners[eventName] = listeners[eventName].filter(h => h !== handler);\n },\n get: eventName => {\n return listeners[eventName];\n },\n call: eventName => {\n listeners[eventName].forEach(listener => listener());\n },\n };\n })();\n\n const navigation = {\n addListener: jest.fn((eventName, handler) => {\n NavigationListenersAPI.add(eventName, handler);\n return {\n remove: () => NavigationListenersAPI.remove(eventName, handler),\n };\n }),\n };\n\n return {\n navigation,\n NavigationListenersAPI,\n };\n};\n\ndescribe('NavigationEvents', () => {\n it('add all listeners on mount and remove them on unmount, even without any event prop provided (see #5058)', () => {\n const {\n navigation,\n NavigationListenersAPI,\n } = createTestNavigationAndHelpers();\n\n const component = renderer.create(\n <NavigationEvents navigation={navigation} />\n );\n expect(NavigationListenersAPI.get('willFocus').length).toBe(1);\n expect(NavigationListenersAPI.get('didFocus').length).toBe(1);\n expect(NavigationListenersAPI.get('willBlur').length).toBe(1);\n expect(NavigationListenersAPI.get('didBlur').length).toBe(1);\n\n component.unmount();\n expect(NavigationListenersAPI.get('willFocus').length).toBe(0);\n expect(NavigationListenersAPI.get('didFocus').length).toBe(0);\n expect(NavigationListenersAPI.get('willBlur').length).toBe(0);\n expect(NavigationListenersAPI.get('didBlur').length).toBe(0);\n });\n\n it('support context-provided navigation', () => {\n const {\n navigation,\n NavigationListenersAPI,\n } = createTestNavigationAndHelpers();\n const component = renderer.create(\n <NavigationContext.Provider value={navigation}>\n <NavigationEvents />\n </NavigationContext.Provider>\n );\n\n expect(NavigationListenersAPI.get('willFocus').length).toBe(1);\n expect(NavigationListenersAPI.get('didFocus').length).toBe(1);\n expect(NavigationListenersAPI.get('willBlur').length).toBe(1);\n expect(NavigationListenersAPI.get('didBlur').length).toBe(1);\n\n component.unmount();\n expect(NavigationListenersAPI.get('willFocus').length).toBe(0);\n expect(NavigationListenersAPI.get('didFocus').length).toBe(0);\n expect(NavigationListenersAPI.get('willBlur').length).toBe(0);\n expect(NavigationListenersAPI.get('didBlur').length).toBe(0);\n });\n\n it('wire props listeners to navigation listeners', () => {\n const {\n navigation,\n NavigationListenersAPI,\n } = createTestNavigationAndHelpers();\n\n const eventListenerProps = createEventListenersProp();\n renderer.create(\n <NavigationEvents navigation={navigation} {...eventListenerProps} />\n );\n\n const checkPropListenerIsCalled = (eventName, propName) => {\n expect(eventListenerProps[propName]).toHaveBeenCalledTimes(0);\n NavigationListenersAPI.call(eventName);\n expect(eventListenerProps[propName]).toHaveBeenCalledTimes(1);\n };\n\n checkPropListenerIsCalled('willFocus', 'onWillFocus');\n checkPropListenerIsCalled('didFocus', 'onDidFocus');\n checkPropListenerIsCalled('willBlur', 'onWillBlur');\n checkPropListenerIsCalled('didBlur', 'onDidBlur');\n });\n\n it('wire latest props listener to navigation listeners on updates (support closure/arrow functions update)', () => {\n const {\n navigation,\n NavigationListenersAPI,\n } = createTestNavigationAndHelpers();\n\n const component = renderer.create(\n <NavigationEvents\n navigation={navigation}\n {...createEventListenersProp()}\n />\n );\n\n component.update(\n <NavigationEvents\n navigation={navigation}\n onWillBlur={() => {\n throw new Error('should not be called');\n }}\n onDidFocus={() => {\n throw new Error('should not be called');\n }}\n />\n );\n\n component.update(\n <NavigationEvents\n navigation={navigation}\n {...createEventListenersProp()}\n />\n );\n\n const latestEventListenerProps = createEventListenersProp();\n component.update(\n <NavigationEvents navigation={navigation} {...latestEventListenerProps} />\n );\n\n const checkLatestPropListenerCalled = (eventName, propName) => {\n expect(latestEventListenerProps[propName]).toHaveBeenCalledTimes(0);\n NavigationListenersAPI.call(eventName);\n expect(latestEventListenerProps[propName]).toHaveBeenCalledTimes(1);\n };\n\n checkLatestPropListenerCalled('willFocus', 'onWillFocus');\n checkLatestPropListenerCalled('didFocus', 'onDidFocus');\n checkLatestPropListenerCalled('willBlur', 'onWillBlur');\n checkLatestPropListenerCalled('didBlur', 'onDidBlur');\n });\n});\n"]}
1
+ {"version":3,"sources":["NavigationEvents-test.js"],"names":["React","renderer","NavigationEvents","NavigationContext","createPropListener","jest","fn","createEventListenersProp","onWillFocus","onDidFocus","onWillBlur","onDidBlur","createTestNavigationAndHelpers","NavigationListenersAPI","listeners","willFocus","didFocus","willBlur","didBlur","add","eventName","handler","push","remove","filter","h","get","call","forEach","listener","navigation","addListener","describe","it","component","create","expect","length","toBe","unmount","eventListenerProps","checkPropListenerIsCalled","propName","toHaveBeenCalledTimes","update","Error","latestEventListenerProps","checkLatestPropListenerCalled"],"mappings":"4KAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,MAAOC,CAAAA,QAAP,KAAqB,qBAArB,CACA,MAAOC,CAAAA,gBAAP,KAA6B,qBAA7B,CACA,MAAOC,CAAAA,iBAAP,KAA8B,sBAA9B,CAEA,GAAMC,CAAAA,kBAAkB,CAAG,QAArBA,CAAAA,kBAAqB,SAAMC,CAAAA,IAAI,CAACC,EAAL,EAAN,EAA3B,CAGA,GAAMC,CAAAA,wBAAwB,CAAG,QAA3BA,CAAAA,wBAA2B,SAAO,CACtCC,WAAW,CAAEJ,kBAAkB,EADO,CAEtCK,UAAU,CAAEL,k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BAAM,CAChB,KAAM,IAAIe,CAAAA,KAAJ,CAAU,sBAAV,CAAN,CACD,CAJH,CAKE,UAAU,CAAE,qBAAM,CAChB,KAAM,IAAIA,CAAAA,KAAJ,CAAU,sBAAV,CAAN,CACD,CAPH,kDADF,EAYAX,SAAS,CAACU,MAAV,CACE,oBAAC,gBAAD,WACE,UAAU,CAAEd,UADd,EAEMvB,wBAAwB,EAF9B,oDADF,EAOA,GAAMuC,CAAAA,wBAAwB,CAAGvC,wBAAwB,EAAzD,CACA2B,SAAS,CAACU,MAAV,CACE,oBAAC,gBAAD,WAAkB,UAAU,CAAEd,UAA9B,EAA8CgB,wBAA9C,oDADF,EAIA,GAAMC,CAAAA,6BAA6B,CAAG,QAAhCA,CAAAA,6BAAgC,CAAC3B,SAAD,CAAYsB,QAAZ,CAAyB,CAC7DN,MAAM,CAACU,wBAAwB,CAACJ,QAAD,CAAzB,CAAN,CAA2CC,qBAA3C,CAAiE,CAAjE,EACA9B,sBAAsB,CAACc,IAAvB,CAA4BP,SAA5B,EACAgB,MAAM,CAACU,wBAAwB,CAACJ,QAAD,CAAzB,CAAN,CAA2CC,qBAA3C,CAAiE,CAAjE,EACD,CAJD,CAMAI,6BAA6B,CAAC,WAAD,CAAc,aAAd,CAA7B,CACAA,6BAA6B,CAAC,UAAD,CAAa,YAAb,CAA7B,CACAA,6BAA6B,CAAC,UAAD,CAAa,YAAb,CAA7B,CACAA,6BAA6B,CAAC,SAAD,CAAY,WAAZ,CAA7B,CACD,CA/CC,CAAF,CAgDD,CApHO,CAAR","sourcesContent":["import React from 'react';\nimport renderer from 'react-test-renderer';\nimport NavigationEvents from '../NavigationEvents';\nimport NavigationContext from '../NavigationContext';\n\nconst createPropListener = () => jest.fn();\n\n// An easy way to create the 4 listeners prop\nconst createEventListenersProp = () => ({\n onWillFocus: createPropListener(),\n onDidFocus: createPropListener(),\n onWillBlur: createPropListener(),\n onDidBlur: createPropListener(),\n});\n\nconst createTestNavigationAndHelpers = () => {\n const NavigationListenersAPI = (() => {\n let listeners = {\n willFocus: [],\n didFocus: [],\n willBlur: [],\n didBlur: [],\n };\n return {\n add: (eventName, handler) => {\n listeners[eventName].push(handler);\n },\n remove: (eventName, handler) => {\n listeners[eventName] = listeners[eventName].filter(h => h !== handler);\n },\n get: eventName => {\n return listeners[eventName];\n },\n call: eventName => {\n listeners[eventName].forEach(listener => listener());\n },\n };\n })();\n\n const navigation = {\n addListener: jest.fn((eventName, handler) => {\n NavigationListenersAPI.add(eventName, handler);\n return {\n remove: () => NavigationListenersAPI.remove(eventName, handler),\n };\n }),\n };\n\n return {\n navigation,\n NavigationListenersAPI,\n };\n};\n\ndescribe('NavigationEvents', () => {\n it('add all listeners on mount and remove them on unmount, even without any event prop provided (see #5058)', () => {\n const {\n navigation,\n NavigationListenersAPI,\n } = createTestNavigationAndHelpers();\n\n const component = renderer.create(\n <NavigationEvents navigation={navigation} />\n );\n expect(NavigationListenersAPI.get('willFocus').length).toBe(1);\n expect(NavigationListenersAPI.get('didFocus').length).toBe(1);\n expect(NavigationListenersAPI.get('willBlur').length).toBe(1);\n expect(NavigationListenersAPI.get('didBlur').length).toBe(1);\n\n component.unmount();\n expect(NavigationListenersAPI.get('willFocus').length).toBe(0);\n expect(NavigationListenersAPI.get('didFocus').length).toBe(0);\n expect(NavigationListenersAPI.get('willBlur').length).toBe(0);\n expect(NavigationListenersAPI.get('didBlur').length).toBe(0);\n });\n\n it('support context-provided navigation', () => {\n const {\n navigation,\n NavigationListenersAPI,\n } = createTestNavigationAndHelpers();\n const component = renderer.create(\n <NavigationContext.Provider value={navigation}>\n <NavigationEvents />\n </NavigationContext.Provider>\n );\n\n expect(NavigationListenersAPI.get('willFocus').length).toBe(1);\n expect(NavigationListenersAPI.get('didFocus').length).toBe(1);\n expect(NavigationListenersAPI.get('willBlur').length).toBe(1);\n expect(NavigationListenersAPI.get('didBlur').length).toBe(1);\n\n component.unmount();\n expect(NavigationListenersAPI.get('willFocus').length).toBe(0);\n expect(NavigationListenersAPI.get('didFocus').length).toBe(0);\n expect(NavigationListenersAPI.get('willBlur').length).toBe(0);\n expect(NavigationListenersAPI.get('didBlur').length).toBe(0);\n });\n\n it('wire props listeners to navigation listeners', () => {\n const {\n navigation,\n NavigationListenersAPI,\n } = createTestNavigationAndHelpers();\n\n const eventListenerProps = createEventListenersProp();\n renderer.create(\n <NavigationEvents navigation={navigation} {...eventListenerProps} />\n );\n\n const checkPropListenerIsCalled = (eventName, propName) => {\n expect(eventListenerProps[propName]).toHaveBeenCalledTimes(0);\n NavigationListenersAPI.call(eventName);\n expect(eventListenerProps[propName]).toHaveBeenCalledTimes(1);\n };\n\n checkPropListenerIsCalled('willFocus', 'onWillFocus');\n checkPropListenerIsCalled('didFocus', 'onDidFocus');\n checkPropListenerIsCalled('willBlur', 'onWillBlur');\n checkPropListenerIsCalled('didBlur', 'onDidBlur');\n });\n\n it('wire latest props listener to navigation listeners on updates (support closure/arrow functions update)', () => {\n const {\n navigation,\n NavigationListenersAPI,\n } = createTestNavigationAndHelpers();\n\n const component = renderer.create(\n <NavigationEvents\n navigation={navigation}\n {...createEventListenersProp()}\n />\n );\n\n component.update(\n <NavigationEvents\n navigation={navigation}\n onWillBlur={() => {\n throw new Error('should not be called');\n }}\n onDidFocus={() => {\n throw new Error('should not be called');\n }}\n />\n );\n\n component.update(\n <NavigationEvents\n navigation={navigation}\n {...createEventListenersProp()}\n />\n );\n\n const latestEventListenerProps = createEventListenersProp();\n component.update(\n <NavigationEvents navigation={navigation} {...latestEventListenerProps} />\n );\n\n const checkLatestPropListenerCalled = (eventName, propName) => {\n expect(latestEventListenerProps[propName]).toHaveBeenCalledTimes(0);\n NavigationListenersAPI.call(eventName);\n expect(latestEventListenerProps[propName]).toHaveBeenCalledTimes(1);\n };\n\n checkLatestPropListenerCalled('willFocus', 'onWillFocus');\n checkLatestPropListenerCalled('didFocus', 'onDidFocus');\n checkLatestPropListenerCalled('willBlur', 'onWillBlur');\n checkLatestPropListenerCalled('didBlur', 'onDidBlur');\n });\n});\n"]}
@@ -1,2 +1,2 @@
1
- import _extends from"@babel/runtime/helpers/extends";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _inherits from"@babel/runtime/helpers/inherits";var _jsxFileName="/Users/brentvatne/coding/react-navigation-core/src/views/withNavigation.js";import React from'react';import hoistStatics from'hoist-non-react-statics';import invariant from'../utils/invariant';import NavigationContext from'./NavigationContext';export default function withNavigation(Component){var config=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{forwardRef:true};var ComponentWithNavigation=function(_React$Component){_inherits(ComponentWithNavigation,_React$Component);function ComponentWithNavigation(){_classCallCheck(this,ComponentWithNavigation);return _possibleConstructorReturn(this,_getPrototypeOf(ComponentWithNavigation).apply(this,arguments));}_createClass(ComponentWithNavigation,[{key:"render",value:function render(){var _this=this;var navigationProp=this.props.navigation;return React.createElement(NavigationContext.Consumer,{__source:{fileName:_jsxFileName,lineNumber:17}},function(navigationContext){var navigation=navigationProp||navigationContext;invariant(!!navigation,'withNavigation can only be used on a view hierarchy of a navigator. The wrapped component is unable to get access to navigation from props or context.');return React.createElement(Component,_extends({},_this.props,{navigation:navigation,ref:config.forwardRef?_this.props.onRef:undefined,__source:{fileName:_jsxFileName,lineNumber:25}}));});}}]);return ComponentWithNavigation;}(React.Component);ComponentWithNavigation.displayName="withNavigation("+(Component.displayName||Component.name)+")";return hoistStatics(ComponentWithNavigation,Component);}
1
+ import _extends from"@babel/runtime/helpers/extends";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _inherits from"@babel/runtime/helpers/inherits";var _jsxFileName="/Users/satya/Workspace/Callstack/react-navigation-core/src/views/withNavigation.js";import React from'react';import hoistStatics from'hoist-non-react-statics';import invariant from'../utils/invariant';import NavigationContext from'./NavigationContext';export default function withNavigation(Component){var config=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{forwardRef:true};var ComponentWithNavigation=function(_React$Component){_inherits(ComponentWithNavigation,_React$Component);function ComponentWithNavigation(){_classCallCheck(this,ComponentWithNavigation);return _possibleConstructorReturn(this,_getPrototypeOf(ComponentWithNavigation).apply(this,arguments));}_createClass(ComponentWithNavigation,[{key:"render",value:function render(){var _this=this;var navigationProp=this.props.navigation;return React.createElement(NavigationContext.Consumer,{__source:{fileName:_jsxFileName,lineNumber:17}},function(navigationContext){var navigation=navigationProp||navigationContext;invariant(!!navigation,'withNavigation can only be used on a view hierarchy of a navigator. The wrapped component is unable to get access to navigation from props or context.');return React.createElement(Component,_extends({},_this.props,{navigation:navigation,ref:config.forwardRef?_this.props.onRef:undefined,__source:{fileName:_jsxFileName,lineNumber:25}}));});}}]);return ComponentWithNavigation;}(React.Component);ComponentWithNavigation.displayName="withNavigation("+(Component.displayName||Component.name)+")";return hoistStatics(ComponentWithNavigation,Component);}
2
2
  //# sourceMappingURL=withNavigation.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["withNavigation.js"],"names":["React","hoistStatics","invariant","NavigationContext","withNavigation","Component","config","forwardRef","ComponentWithNavigation","navigationProp","props","navigation","navigationContext","onRef","undefined","displayName","name"],"mappings":"seAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,MAAOC,CAAAA,YAAP,KAAyB,yBAAzB,CACA,MAAOC,CAAAA,SAAP,KAAsB,oBAAtB,CACA,MAAOC,CAAAA,iBAAP,KAA8B,qBAA9B,CAEA,cAAe,SAASC,CAAAA,cAAT,CACbC,SADa,CAGb,IADAC,CAAAA,MACA,2DADS,CAAEC,UAAU,CAAE,IAAd,CACT,IACMC,CAAAA,uBADN,oVAKW,gBACP,GAAMC,CAAAA,cAAc,CAAG,KAAKC,KAAL,CAAWC,UAAlC,CACA,MACE,qBAAC,iBAAD,CAAmB,QAAnB,kDACG,SAAAC,iBAAiB,CAAI,CACpB,GAAMD,CAAAA,UAAU,CAAGF,cAAc,EAAIG,iBAArC,CACAV,SAAS,CACP,CAAC,CAACS,UADK,CAEP,wJAFO,CAAT,CAIA,MACE,qBAAC,SAAD,aACM,KAAI,CAACD,KADX,EAEE,UAAU,CAAEC,UAFd,CAGE,GAAG,CAAEL,MAAM,CAACC,UAAP,CAAoB,KAAI,CAACG,KAAL,CAAWG,KAA/B,CAAuCC,SAH9C,kDADF,CAOD,CAdH,CADF,CAkBD,CAzBH,qCACsCd,KAAK,CAACK,SAD5C,EACMG,uBADN,CAESO,WAFT,oBAEyCV,SAAS,CAACU,WAAV,EACrCV,SAAS,CAACW,IAHd,MA4BA,MAAOf,CAAAA,YAAY,CAACO,uBAAD,CAA0BH,SAA1B,CAAnB,CACD","sourcesContent":["import React from 'react';\nimport hoistStatics from 'hoist-non-react-statics';\nimport invariant from '../utils/invariant';\nimport NavigationContext from './NavigationContext';\n\nexport default function withNavigation(\n Component,\n config = { forwardRef: true }\n) {\n class ComponentWithNavigation extends React.Component {\n static displayName = `withNavigation(${Component.displayName ||\n Component.name})`;\n\n render() {\n const navigationProp = this.props.navigation;\n return (\n <NavigationContext.Consumer>\n {navigationContext => {\n const navigation = navigationProp || navigationContext;\n invariant(\n !!navigation,\n 'withNavigation can only be used on a view hierarchy of a navigator. The wrapped component is unable to get access to navigation from props or context.'\n );\n return (\n <Component\n {...this.props}\n navigation={navigation}\n ref={config.forwardRef ? this.props.onRef : undefined}\n />\n );\n }}\n </NavigationContext.Consumer>\n );\n }\n }\n\n return hoistStatics(ComponentWithNavigation, Component);\n}\n"]}
1
+ {"version":3,"sources":["withNavigation.js"],"names":["React","hoistStatics","invariant","NavigationContext","withNavigation","Component","config","forwardRef","ComponentWithNavigation","navigationProp","props","navigation","navigationContext","onRef","undefined","displayName","name"],"mappings":"8eAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,MAAOC,CAAAA,YAAP,KAAyB,yBAAzB,CACA,MAAOC,CAAAA,SAAP,KAAsB,oBAAtB,CACA,MAAOC,CAAAA,iBAAP,KAA8B,qBAA9B,CAEA,cAAe,SAASC,CAAAA,cAAT,CACbC,SADa,CAGb,IADAC,CAAAA,MACA,2DADS,CAAEC,UAAU,CAAE,IAAd,CACT,IACMC,CAAAA,uBADN,oVAKW,gBACP,GAAMC,CAAAA,cAAc,CAAG,KAAKC,KAAL,CAAWC,UAAlC,CACA,MACE,qBAAC,iBAAD,CAAmB,QAAnB,kDACG,SAAAC,iBAAiB,CAAI,CACpB,GAAMD,CAAAA,UAAU,CAAGF,cAAc,EAAIG,iBAArC,CACAV,SAAS,CACP,CAAC,CAACS,UADK,CAEP,wJAFO,CAAT,CAIA,MACE,qBAAC,SAAD,aACM,KAAI,CAACD,KADX,EAEE,UAAU,CAAEC,UAFd,CAGE,GAAG,CAAEL,MAAM,CAACC,UAAP,CAAoB,KAAI,CAACG,KAAL,CAAWG,KAA/B,CAAuCC,SAH9C,kDADF,CAOD,CAdH,CADF,CAkBD,CAzBH,qCACsCd,KAAK,CAACK,SAD5C,EACMG,uBADN,CAESO,WAFT,oBAEyCV,SAAS,CAACU,WAAV,EACrCV,SAAS,CAACW,IAHd,MA4BA,MAAOf,CAAAA,YAAY,CAACO,uBAAD,CAA0BH,SAA1B,CAAnB,CACD","sourcesContent":["import React from 'react';\nimport hoistStatics from 'hoist-non-react-statics';\nimport invariant from '../utils/invariant';\nimport NavigationContext from './NavigationContext';\n\nexport default function withNavigation(\n Component,\n config = { forwardRef: true }\n) {\n class ComponentWithNavigation extends React.Component {\n static displayName = `withNavigation(${Component.displayName ||\n Component.name})`;\n\n render() {\n const navigationProp = this.props.navigation;\n return (\n <NavigationContext.Consumer>\n {navigationContext => {\n const navigation = navigationProp || navigationContext;\n invariant(\n !!navigation,\n 'withNavigation can only be used on a view hierarchy of a navigator. The wrapped component is unable to get access to navigation from props or context.'\n );\n return (\n <Component\n {...this.props}\n navigation={navigation}\n ref={config.forwardRef ? this.props.onRef : undefined}\n />\n );\n }}\n </NavigationContext.Consumer>\n );\n }\n }\n\n return hoistStatics(ComponentWithNavigation, Component);\n}\n"]}
@@ -1,2 +1,2 @@
1
- import _extends from"@babel/runtime/helpers/extends";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _inherits from"@babel/runtime/helpers/inherits";var _jsxFileName="/Users/brentvatne/coding/react-navigation-core/src/views/withNavigationFocus.js";import React from'react';import hoistStatics from'hoist-non-react-statics';import withNavigation from'./withNavigation';export default function withNavigationFocus(Component){var ComponentWithNavigationFocus=function(_React$Component){_inherits(ComponentWithNavigationFocus,_React$Component);function ComponentWithNavigationFocus(props){var _this;_classCallCheck(this,ComponentWithNavigationFocus);_this=_possibleConstructorReturn(this,_getPrototypeOf(ComponentWithNavigationFocus).call(this,props));_this.subscriptions=[props.navigation.addListener('didFocus',function(){return _this.setState({isFocused:true});}),props.navigation.addListener('willBlur',function(){return _this.setState({isFocused:false});})];_this.state={isFocused:props.navigation?props.navigation.isFocused():false};return _this;}_createClass(ComponentWithNavigationFocus,[{key:"componentWillUnmount",value:function componentWillUnmount(){this.subscriptions.forEach(function(sub){return sub.remove();});}},{key:"render",value:function render(){return React.createElement(Component,_extends({},this.props,{isFocused:this.state.isFocused,ref:this.props.onRef,__source:{fileName:_jsxFileName,lineNumber:33}}));}}]);return ComponentWithNavigationFocus;}(React.Component);ComponentWithNavigationFocus.displayName="withNavigationFocus("+(Component.displayName||Component.name)+")";return hoistStatics(withNavigation(ComponentWithNavigationFocus,{forwardRef:false}),Component);}
1
+ import _extends from"@babel/runtime/helpers/extends";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _possibleConstructorReturn from"@babel/runtime/helpers/possibleConstructorReturn";import _getPrototypeOf from"@babel/runtime/helpers/getPrototypeOf";import _inherits from"@babel/runtime/helpers/inherits";var _jsxFileName="/Users/satya/Workspace/Callstack/react-navigation-core/src/views/withNavigationFocus.js";import React from'react';import hoistStatics from'hoist-non-react-statics';import withNavigation from'./withNavigation';export default function withNavigationFocus(Component){var ComponentWithNavigationFocus=function(_React$Component){_inherits(ComponentWithNavigationFocus,_React$Component);function ComponentWithNavigationFocus(props){var _this;_classCallCheck(this,ComponentWithNavigationFocus);_this=_possibleConstructorReturn(this,_getPrototypeOf(ComponentWithNavigationFocus).call(this,props));_this.subscriptions=[props.navigation.addListener('didFocus',function(){return _this.setState({isFocused:true});}),props.navigation.addListener('willBlur',function(){return _this.setState({isFocused:false});})];_this.state={isFocused:props.navigation?props.navigation.isFocused():false};return _this;}_createClass(ComponentWithNavigationFocus,[{key:"componentWillUnmount",value:function componentWillUnmount(){this.subscriptions.forEach(function(sub){return sub.remove();});}},{key:"render",value:function render(){return React.createElement(Component,_extends({},this.props,{isFocused:this.state.isFocused,ref:this.props.onRef,__source:{fileName:_jsxFileName,lineNumber:33}}));}}]);return ComponentWithNavigationFocus;}(React.Component);ComponentWithNavigationFocus.displayName="withNavigationFocus("+(Component.displayName||Component.name)+")";return hoistStatics(withNavigation(ComponentWithNavigationFocus,{forwardRef:false}),Component);}
2
2
  //# sourceMappingURL=withNavigationFocus.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["withNavigationFocus.js"],"names":["React","hoistStatics","withNavigation","withNavigationFocus","Component","ComponentWithNavigationFocus","props","subscriptions","navigation","addListener","setState","isFocused","state","forEach","sub","remove","onRef","displayName","name","forwardRef"],"mappings":"2eAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,MAAOC,CAAAA,YAAP,KAAyB,yBAAzB,CACA,MAAOC,CAAAA,cAAP,KAA2B,kBAA3B,CAEA,cAAe,SAASC,CAAAA,mBAAT,CAA6BC,SAA7B,CAAwC,IAC/CC,CAAAA,4BAD+C,qFAKnD,sCAAYC,KAAZ,CAAmB,8DACjB,8FAAMA,KAAN,GAEA,MAAKC,aAAL,CAAqB,CACnBD,KAAK,CAACE,UAAN,CAAiBC,WAAjB,CAA6B,UAA7B,CAAyC,iBACvC,OAAKC,QAAL,CAAc,CAAEC,SAAS,CAAE,IAAb,CAAd,CADuC,EAAzC,CADmB,CAInBL,KAAK,CAACE,UAAN,CAAiBC,WAAjB,CAA6B,UAA7B,CAAyC,iBACvC,OAAKC,QAAL,CAAc,CAAEC,SAAS,CAAE,KAAb,CAAd,CADuC,EAAzC,CAJmB,CAArB,CASA,MAAKC,KAAL,CAAa,CACXD,SAAS,CAAEL,KAAK,CAACE,UAAN,CAAmBF,KAAK,CAACE,UAAN,CAAiBG,SAAjB,EAAnB,CAAkD,KADlD,CAAb,CAZiB,aAelB,CApBkD,4GAsB5B,CACrB,KAAKJ,aAAL,CAAmBM,OAAnB,CAA2B,SAAAC,GAAG,QAAIA,CAAAA,GAAG,CAACC,MAAJ,EAAJ,EAA9B,EACD,CAxBkD,uCA0B1C,CACP,MACE,qBAAC,SAAD,aACM,KAAKT,KADX,EAEE,SAAS,CAAE,KAAKM,KAAL,CAAWD,SAFxB,CAGE,GAAG,CAAE,KAAKL,KAAL,CAAWU,KAHlB,kDADF,CAOD,CAlCkD,0CACVhB,KAAK,CAACI,SADI,EAC/CC,4BAD+C,CAE5CY,WAF4C,yBAEPb,SAAS,CAACa,WAAV,EAC1Cb,SAAS,CAACc,IAHuC,MAqCrD,MAAOjB,CAAAA,YAAY,CACjBC,cAAc,CAACG,4BAAD,CAA+B,CAAEc,UAAU,CAAE,KAAd,CAA/B,CADG,CAEjBf,SAFiB,CAAnB,CAID","sourcesContent":["import React from 'react';\nimport hoistStatics from 'hoist-non-react-statics';\nimport withNavigation from './withNavigation';\n\nexport default function withNavigationFocus(Component) {\n class ComponentWithNavigationFocus extends React.Component {\n static displayName = `withNavigationFocus(${Component.displayName ||\n Component.name})`;\n\n constructor(props) {\n super(props);\n\n this.subscriptions = [\n props.navigation.addListener('didFocus', () =>\n this.setState({ isFocused: true })\n ),\n props.navigation.addListener('willBlur', () =>\n this.setState({ isFocused: false })\n ),\n ];\n\n this.state = {\n isFocused: props.navigation ? props.navigation.isFocused() : false,\n };\n }\n\n componentWillUnmount() {\n this.subscriptions.forEach(sub => sub.remove());\n }\n\n render() {\n return (\n <Component\n {...this.props}\n isFocused={this.state.isFocused}\n ref={this.props.onRef}\n />\n );\n }\n }\n\n return hoistStatics(\n withNavigation(ComponentWithNavigationFocus, { forwardRef: false }),\n Component\n );\n}\n"]}
1
+ {"version":3,"sources":["withNavigationFocus.js"],"names":["React","hoistStatics","withNavigation","withNavigationFocus","Component","ComponentWithNavigationFocus","props","subscriptions","navigation","addListener","setState","isFocused","state","forEach","sub","remove","onRef","displayName","name","forwardRef"],"mappings":"mfAAA,MAAOA,CAAAA,KAAP,KAAkB,OAAlB,CACA,MAAOC,CAAAA,YAAP,KAAyB,yBAAzB,CACA,MAAOC,CAAAA,cAAP,KAA2B,kBAA3B,CAEA,cAAe,SAASC,CAAAA,mBAAT,CAA6BC,SAA7B,CAAwC,IAC/CC,CAAAA,4BAD+C,qFAKnD,sCAAYC,KAAZ,CAAmB,8DACjB,8FAAMA,KAAN,GAEA,MAAKC,aAAL,CAAqB,CACnBD,KAAK,CAACE,UAAN,CAAiBC,WAAjB,CAA6B,UAA7B,CAAyC,iBACvC,OAAKC,QAAL,CAAc,CAAEC,SAAS,CAAE,IAAb,CAAd,CADuC,EAAzC,CADmB,CAInBL,KAAK,CAACE,UAAN,CAAiBC,WAAjB,CAA6B,UAA7B,CAAyC,iBACvC,OAAKC,QAAL,CAAc,CAAEC,SAAS,CAAE,KAAb,CAAd,CADuC,EAAzC,CAJmB,CAArB,CASA,MAAKC,KAAL,CAAa,CACXD,SAAS,CAAEL,KAAK,CAACE,UAAN,CAAmBF,KAAK,CAACE,UAAN,CAAiBG,SAAjB,EAAnB,CAAkD,KADlD,CAAb,CAZiB,aAelB,CApBkD,4GAsB5B,CACrB,KAAKJ,aAAL,CAAmBM,OAAnB,CAA2B,SAAAC,GAAG,QAAIA,CAAAA,GAAG,CAACC,MAAJ,EAAJ,EAA9B,EACD,CAxBkD,uCA0B1C,CACP,MACE,qBAAC,SAAD,aACM,KAAKT,KADX,EAEE,SAAS,CAAE,KAAKM,KAAL,CAAWD,SAFxB,CAGE,GAAG,CAAE,KAAKL,KAAL,CAAWU,KAHlB,kDADF,CAOD,CAlCkD,0CACVhB,KAAK,CAACI,SADI,EAC/CC,4BAD+C,CAE5CY,WAF4C,yBAEPb,SAAS,CAACa,WAAV,EAC1Cb,SAAS,CAACc,IAHuC,MAqCrD,MAAOjB,CAAAA,YAAY,CACjBC,cAAc,CAACG,4BAAD,CAA+B,CAAEc,UAAU,CAAE,KAAd,CAA/B,CADG,CAEjBf,SAFiB,CAAnB,CAID","sourcesContent":["import React from 'react';\nimport hoistStatics from 'hoist-non-react-statics';\nimport withNavigation from './withNavigation';\n\nexport default function withNavigationFocus(Component) {\n class ComponentWithNavigationFocus extends React.Component {\n static displayName = `withNavigationFocus(${Component.displayName ||\n Component.name})`;\n\n constructor(props) {\n super(props);\n\n this.subscriptions = [\n props.navigation.addListener('didFocus', () =>\n this.setState({ isFocused: true })\n ),\n props.navigation.addListener('willBlur', () =>\n this.setState({ isFocused: false })\n ),\n ];\n\n this.state = {\n isFocused: props.navigation ? props.navigation.isFocused() : false,\n };\n }\n\n componentWillUnmount() {\n this.subscriptions.forEach(sub => sub.remove());\n }\n\n render() {\n return (\n <Component\n {...this.props}\n isFocused={this.state.isFocused}\n ref={this.props.onRef}\n />\n );\n }\n }\n\n return hoistStatics(\n withNavigation(ComponentWithNavigationFocus, { forwardRef: false }),\n Component\n );\n}\n"]}
@@ -1,2 +1,2 @@
1
- declare const _default: import("./views/ThemeContext").ThemeContextType;
1
+ declare const _default: () => import("./views/ThemeContext").ThemeContextType;
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-navigation/core",
3
- "version": "3.5.0-alpha.6",
3
+ "version": "3.5.1",
4
4
  "description": "Core utilities for the react-navigation framework",
5
5
  "main": "lib/commonjs/index.js",
6
6
  "react-native": "lib/module/index.js",
@@ -1,18 +1,26 @@
1
1
  import React from 'react';
2
2
  import invariant from '../utils/invariant';
3
+ import ThemeContext from '../views/ThemeContext';
3
4
 
4
5
  function createNavigator(NavigatorView, router, navigationConfig) {
5
6
  class Navigator extends React.Component {
7
+ static contextType = ThemeContext;
6
8
  static router = router;
7
9
  static navigationOptions = navigationConfig.navigationOptions;
8
10
 
9
- state = {
10
- descriptors: {},
11
- screenProps: this.props.screenProps,
12
- };
11
+ constructor(props, context) {
12
+ super(props, context);
13
13
 
14
- static getDerivedStateFromProps(nextProps, prevState) {
15
- const prevDescriptors = prevState.descriptors;
14
+ this.state = {
15
+ descriptors: {},
16
+ screenProps: this.props.screenProps,
17
+ theme: context,
18
+ themeContext: context,
19
+ };
20
+ }
21
+
22
+ static getDerivedStateFromProps(nextProps, currentState) {
23
+ const prevDescriptors = currentState.descriptors;
16
24
  const { navigation, screenProps } = nextProps;
17
25
  invariant(
18
26
  navigation != null,
@@ -26,34 +34,45 @@ function createNavigator(NavigatorView, router, navigationConfig) {
26
34
  );
27
35
  }
28
36
 
29
- const descriptors = {};
30
-
31
- routes.forEach(route => {
37
+ const descriptors = routes.reduce((acc, route) => {
32
38
  if (
33
39
  prevDescriptors &&
34
40
  prevDescriptors[route.key] &&
35
41
  route === prevDescriptors[route.key].state &&
36
- screenProps === prevState.screenProps
42
+ screenProps === currentState.screenProps &&
43
+ currentState.themeContext === currentState.theme
37
44
  ) {
38
- descriptors[route.key] = prevDescriptors[route.key];
39
- return;
45
+ acc[route.key] = prevDescriptors[route.key];
46
+ return acc;
40
47
  }
41
48
  const getComponent = router.getComponentForRouteName.bind(
42
49
  null,
43
50
  route.routeName
44
51
  );
45
52
  const childNavigation = navigation.getChildNavigation(route.key);
46
- const options = router.getScreenOptions(childNavigation, screenProps);
47
- descriptors[route.key] = {
53
+ const options = router.getScreenOptions(
54
+ childNavigation,
55
+ screenProps,
56
+ currentState.themeContext
57
+ );
58
+ acc[route.key] = {
48
59
  key: route.key,
49
60
  getComponent,
50
61
  options,
51
62
  state: route,
52
63
  navigation: childNavigation,
53
64
  };
54
- });
65
+ return acc;
66
+ }, {});
55
67
 
56
- return { descriptors, screenProps };
68
+ return { descriptors, screenProps, theme: state.themeContext };
69
+ }
70
+
71
+ componentDidUpdate() {
72
+ if (this.context !== this.state.themeContext) {
73
+ // eslint-disable-next-line react/no-did-update-set-state
74
+ this.setState({ themeContext: this.context });
75
+ }
57
76
  }
58
77
 
59
78
  render() {
@@ -186,17 +186,19 @@ export default (routeConfigs, config = {}) => {
186
186
 
187
187
  return getNextState(action, prevState, {
188
188
  ...state,
189
- routes: state.routes.map((route, i) =>
190
- i === index
191
- ? {
192
- ...route,
193
- params: {
194
- ...route.params,
195
- ...params,
196
- },
197
- }
198
- : route
199
- ),
189
+ routes: params
190
+ ? state.routes.map((route, i) =>
191
+ i === index
192
+ ? {
193
+ ...route,
194
+ params: {
195
+ ...route.params,
196
+ ...params,
197
+ },
198
+ }
199
+ : route
200
+ )
201
+ : state.routes,
200
202
  index,
201
203
  });
202
204
  }
@@ -24,7 +24,7 @@ it('urlToPathAndParams with params', () => {
24
24
  expect(params).toEqual({ asdf: '1', dude: 'foo' });
25
25
  });
26
26
 
27
- it('urlToPathAndParams with custom delimeter', () => {
27
+ it('urlToPathAndParams with custom delimeter string', () => {
28
28
  const { path, params } = urlToPathAndParams(
29
29
  'https://example.com/foo/bar?asdf=1',
30
30
  'https://example.com/'
@@ -32,3 +32,39 @@ it('urlToPathAndParams with custom delimeter', () => {
32
32
  expect(path).toBe('foo/bar');
33
33
  expect(params).toEqual({ asdf: '1' });
34
34
  });
35
+
36
+ it('urlToPathAndParams with custom delimeter RegExp', () => {
37
+ const { path, params } = urlToPathAndParams(
38
+ 'https://example.com/foo/bar?asdf=1',
39
+ new RegExp('https://example.com/')
40
+ );
41
+ expect(path).toBe('foo/bar');
42
+ expect(params).toEqual({ asdf: '1' });
43
+ });
44
+
45
+ it('urlToPathAndParams with duplicate prefix in query parameters', () => {
46
+ const { path, params } = urlToPathAndParams(
47
+ 'example://whatever?related=example://something',
48
+ 'example://'
49
+ );
50
+ expect(path).toBe('whatever');
51
+ expect(params).toEqual({ related: 'example://something' });
52
+ });
53
+
54
+ it('urlToPathAndParams with array of custom delimiters, should use first match', () => {
55
+ const { path, params } = urlToPathAndParams(
56
+ 'https://example.com/foo/bar?asdf=1',
57
+ ['baz', 'https://example.com/', 'https://example.com/foo']
58
+ );
59
+ expect(path).toBe('foo/bar');
60
+ expect(params).toEqual({ asdf: '1' });
61
+ });
62
+
63
+ it('urlToPathAndParams with array of custom delimiters where none match, should resort to default delimiter', () => {
64
+ const { path, params } = urlToPathAndParams('foo://foo/bar?asdf=1', [
65
+ 'baz',
66
+ 'bazzlefraz',
67
+ ]);
68
+ expect(path).toBe('foo/bar');
69
+ expect(params).toEqual({ asdf: '1' });
70
+ });
@@ -24,7 +24,8 @@ function applyConfig(configurer, navigationOptions, configProps) {
24
24
 
25
25
  export default (routeConfigs, navigatorScreenConfig) => (
26
26
  navigation,
27
- screenProps
27
+ screenProps,
28
+ theme
28
29
  ) => {
29
30
  const { state } = navigation;
30
31
  const route = state;
@@ -42,7 +43,7 @@ export default (routeConfigs, navigatorScreenConfig) => (
42
43
  routeConfig === Component ? null : routeConfig.navigationOptions;
43
44
  const componentScreenConfig = Component.navigationOptions;
44
45
 
45
- const configOptions = { navigation, screenProps: screenProps || {} };
46
+ const configOptions = { navigation, screenProps: screenProps || {}, theme };
46
47
 
47
48
  let outputConfig = applyConfig(navigatorScreenConfig, {}, configOptions);
48
49
  outputConfig = applyConfig(
@@ -40,14 +40,25 @@ const getRestOfPath = (pathMatch, pathMatchKeys) => {
40
40
  return rest;
41
41
  };
42
42
 
43
+ const determineDelimiter = (uri, uriPrefix) => {
44
+ if (Array.isArray(uriPrefix)) {
45
+ if (uriPrefix.length === 1) return uriPrefix[0];
46
+ for (let prefix of uriPrefix) {
47
+ if (uri.startsWith(prefix)) return prefix;
48
+ }
49
+ return null;
50
+ }
51
+ return uriPrefix;
52
+ };
53
+
43
54
  export const urlToPathAndParams = (url, uriPrefix) => {
44
55
  const searchMatch = url.match(/^(.*)\?(.*)$/);
45
- const params = searchMatch ? queryString.parse(searchMatch[2]) : {};
46
- const urlWithoutSearch = searchMatch ? searchMatch[1] : url;
47
- const delimiter = uriPrefix || '://';
48
- let path = urlWithoutSearch.split(delimiter)[1];
56
+ const [, urlWithoutQuery, query] = searchMatch || [null, url, {}];
57
+ const params = queryString.parse(query);
58
+ const delimiter = determineDelimiter(urlWithoutQuery, uriPrefix) || '://';
59
+ let path = urlWithoutQuery.split(delimiter)[1];
49
60
  if (path === undefined) {
50
- path = urlWithoutSearch;
61
+ path = urlWithoutQuery;
51
62
  }
52
63
  if (path === '/') {
53
64
  path = '';
package/src/useTheme.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { useContext } from 'react';
2
2
  import ThemeContext from './views/ThemeContext';
3
3
 
4
- export default useContext(ThemeContext);
4
+ export default () => useContext(ThemeContext);