5d7a956679b22c31768af7e6d313a018.json
9.75 KB
{"ast":null,"code":"var _interopRequireDefault=require(\"@babel/runtime/helpers/interopRequireDefault\");Object.defineProperty(exports,\"__esModule\",{value:true});exports.default=void 0;var _extends2=_interopRequireDefault(require(\"@babel/runtime/helpers/extends\"));var _classCallCheck2=_interopRequireDefault(require(\"@babel/runtime/helpers/classCallCheck\"));var _createClass2=_interopRequireDefault(require(\"@babel/runtime/helpers/createClass\"));var _possibleConstructorReturn2=_interopRequireDefault(require(\"@babel/runtime/helpers/possibleConstructorReturn\"));var _getPrototypeOf2=_interopRequireDefault(require(\"@babel/runtime/helpers/getPrototypeOf\"));var _inherits2=_interopRequireDefault(require(\"@babel/runtime/helpers/inherits\"));var _react=_interopRequireDefault(require(\"react\"));var _invariant=_interopRequireDefault(require(\"../utils/invariant\"));var _ThemeContext=_interopRequireDefault(require(\"../views/ThemeContext\"));var _jsxFileName=\"/Users/satya/Workspace/Callstack/react-navigation-core/src/navigators/createNavigator.js\";function createNavigator(NavigatorView,router,navigationConfig){var Navigator=function(_React$Component){(0,_inherits2.default)(Navigator,_React$Component);function Navigator(props,context){var _this;(0,_classCallCheck2.default)(this,Navigator);_this=(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf2.default)(Navigator).call(this,props,context));_this.state={descriptors:{},screenProps:_this.props.screenProps,theme:context,themeContext:context};return _this;}(0,_createClass2.default)(Navigator,[{key:\"componentDidUpdate\",value:function componentDidUpdate(){if(this.context!==this.state.themeContext){this.setState({themeContext:this.context});}}},{key:\"render\",value:function render(){return _react.default.createElement(NavigatorView,(0,_extends2.default)({},this.props,{screenProps:this.state.screenProps,navigation:this.props.navigation,navigationConfig:navigationConfig,descriptors:this.state.descriptors,__source:{fileName:_jsxFileName,lineNumber:80}}));}}],[{key:\"getDerivedStateFromProps\",value:function getDerivedStateFromProps(nextProps,currentState){var prevDescriptors=currentState.descriptors;var navigation=nextProps.navigation,screenProps=nextProps.screenProps;(0,_invariant.default)(navigation!=null,'The navigation prop is missing for this navigator. In react-navigation 3 you must set up your app container directly. More info: https://reactnavigation.org/docs/en/app-containers.html');var state=navigation.state;var routes=state.routes;if(typeof routes==='undefined'){throw new TypeError('No \"routes\" found in navigation state. Did you try to pass the navigation prop of a React component to a Navigator child? See https://reactnavigation.org/docs/en/custom-navigators.html#navigator-navigation-prop');}var descriptors=routes.reduce(function(acc,route){if(prevDescriptors&&prevDescriptors[route.key]&&route===prevDescriptors[route.key].state&&screenProps===currentState.screenProps&¤tState.themeContext===currentState.theme){acc[route.key]=prevDescriptors[route.key];return acc;}var getComponent=router.getComponentForRouteName.bind(null,route.routeName);var childNavigation=navigation.getChildNavigation(route.key);var options=router.getScreenOptions(childNavigation,screenProps,currentState.themeContext);acc[route.key]={key:route.key,getComponent:getComponent,options:options,state:route,navigation:childNavigation};return acc;},{});return{descriptors:descriptors,screenProps:screenProps,theme:state.themeContext};}}]);return Navigator;}(_react.default.Component);Navigator.contextType=_ThemeContext.default;Navigator.router=router;Navigator.navigationOptions=navigationConfig.navigationOptions;return Navigator;}var _default=createNavigator;exports.default=_default;","map":{"version":3,"sources":["createNavigator.js"],"names":["Navigator","React","navigationConfig","descriptors","screenProps","theme","themeContext","prevDescriptors","currentState","navigation","nextProps","invariant","state","routes","route","acc","getComponent","router","childNavigation","options","key"],"mappings":"6sBAAA,oDACA,qEACA,2E,4GAEA,QAAA,CAAA,eAAA,CAAA,aAAA,CAAA,MAAA,CAAA,gBAAA,CAAkE,CAAA,GAC1DA,CAAAA,SAD0D,CAAA,SAAA,gBAAA,CAAA,CAAA,uBAAA,SAAA,CAAA,gBAAA,EAM9D,QAAA,CAAA,SAAA,CAAA,KAAA,CAAA,OAAA,CAA4B,CAAA,GAAA,CAAA,KAAA,CAAA,6BAAA,IAAA,CAAA,SAAA,EAC1B,KAAA,CAAA,wCAAA,IAAA,CAAA,6BAAA,SAAA,EAAA,IAAA,CAAA,IAAA,CAAA,KAAA,CAAA,OAAA,CAAA,CAAA,CAEA,KAAA,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BC,KAAK,CAAEO,KAAK,CAA/C,YAAO,CAAP,CA/D4D,CAAA,CAAA,CAAA,EAAA,MAAA,CAAA,SAAA,CAAA,CAAA,CACxCX,eADwC,SAAA,CAAA,CAC1DD,SAD0D,CAAA,WAC1DA,CAD0D,qBAC1DA,CAAAA,SAD0D,CAAA,MAC1DA,CAD0D,MAC1DA,CAAAA,SAD0D,CAAA,iBAC1DA,CAGuBE,gBAAgB,CAJmB,iBAC1DF,CAqFN,MAAA,CAAA,SAAA,CAGF,C,aAAA,e","sourcesContent":["import React from 'react';\nimport invariant from '../utils/invariant';\nimport ThemeContext from '../views/ThemeContext';\n\nfunction createNavigator(NavigatorView, router, navigationConfig) {\n class Navigator extends React.Component {\n static contextType = ThemeContext;\n static router = router;\n static navigationOptions = navigationConfig.navigationOptions;\n\n constructor(props, context) {\n super(props, context);\n\n this.state = {\n descriptors: {},\n screenProps: this.props.screenProps,\n theme: context,\n themeContext: context,\n };\n }\n\n static getDerivedStateFromProps(nextProps, currentState) {\n const prevDescriptors = currentState.descriptors;\n const { navigation, screenProps } = nextProps;\n invariant(\n navigation != null,\n 'The navigation prop is missing for this navigator. In react-navigation 3 you must set up your app container directly. More info: https://reactnavigation.org/docs/en/app-containers.html'\n );\n const { state } = navigation;\n const { routes } = state;\n if (typeof routes === 'undefined') {\n throw new TypeError(\n 'No \"routes\" found in navigation state. Did you try to pass the navigation prop of a React component to a Navigator child? See https://reactnavigation.org/docs/en/custom-navigators.html#navigator-navigation-prop'\n );\n }\n\n const descriptors = routes.reduce((acc, route) => {\n if (\n prevDescriptors &&\n prevDescriptors[route.key] &&\n route === prevDescriptors[route.key].state &&\n screenProps === currentState.screenProps &&\n currentState.themeContext === currentState.theme\n ) {\n acc[route.key] = prevDescriptors[route.key];\n return acc;\n }\n const getComponent = router.getComponentForRouteName.bind(\n null,\n route.routeName\n );\n const childNavigation = navigation.getChildNavigation(route.key);\n const options = router.getScreenOptions(\n childNavigation,\n screenProps,\n currentState.themeContext\n );\n acc[route.key] = {\n key: route.key,\n getComponent,\n options,\n state: route,\n navigation: childNavigation,\n };\n return acc;\n }, {});\n\n return { descriptors, screenProps, theme: state.themeContext };\n }\n\n componentDidUpdate() {\n if (this.context !== this.state.themeContext) {\n // eslint-disable-next-line react/no-did-update-set-state\n this.setState({ themeContext: this.context });\n }\n }\n\n render() {\n return (\n <NavigatorView\n {...this.props}\n screenProps={this.state.screenProps}\n navigation={this.props.navigation}\n navigationConfig={navigationConfig}\n descriptors={this.state.descriptors}\n />\n );\n }\n }\n\n return Navigator;\n}\n\nexport default createNavigator;\n"]},"metadata":{},"sourceType":"script"}