From e0391d6bc060782a552fdd08dc17df83661dd72b Mon Sep 17 00:00:00 2001 From: aksonov Date: Mon, 10 Jul 2017 15:27:20 +0200 Subject: [PATCH] eslint formatting, remove obsolete code --- .eslintrc.js | 4 + CHANGELOG.md | 12 + dist/LightboxNavigator.js | 4 +- dist/NavBar.js | 490 +------------------------------------- dist/Reducer.js | 2 +- dist/Router.js | 65 ++--- dist/Scene.js | 10 +- dist/index.js | 5 +- dist/navigationStore.js | 28 +-- package.json | 9 +- src/LightboxNavigator.js | 12 +- src/NavBar.js | 489 +------------------------------------ src/Reducer.js | 2 +- src/Router.js | 145 +++++------ src/Scene.js | 9 +- src/index.js | 9 +- src/navigationStore.js | 84 ++++--- yarn.lock | 445 ++++++++++++++++++++++++++-------- 18 files changed, 555 insertions(+), 1269 deletions(-) create mode 100644 CHANGELOG.md diff --git a/.eslintrc.js b/.eslintrc.js index 41fcb3779..bad3317bb 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -7,6 +7,10 @@ module.exports = { rules: { 'react/forbid-prop-types': 0, 'no-console': 0, + 'new-cap': 0, + 'no-underscore-dangle': 0, + 'no-use-before-define': 0, + 'max-len': ["error", 180], 'import/no-unresolved': [ 2, { diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..715410227 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# Change Log + +## 4.0.0-beta.7 + +- Fix: Mobx enabled useStrict (#1994) +- Improvement: Support Actions.popTo(sceneName) (#1987) +- Fix: Support v3 syntax `panHandlers={null}` to disable gestures for back transition. You may also pass `gesturesEnabled={false}` (#2002) +- Fix: Support for renderTitle, drawerImage, navigationBarTitleImage, navigationBarTitleImageStyle props for `Scene` (#1991) +- Fix: Pass drawerPosition, drawerOptions, drawerWidth and other Scene params to react-navigation DrawerNavigator +- Fix: Pass all container scene props to StackNavigator config +- Fix: ESLint formatting + diff --git a/dist/LightboxNavigator.js b/dist/LightboxNavigator.js index 8f948818f..d89d3e2ff 100644 --- a/dist/LightboxNavigator.js +++ b/dist/LightboxNavigator.js @@ -2,7 +2,7 @@ Object.defineProperty(exports,"__esModule",{value:true});var _jsxFileName='src/L var _react=require('react');var _react2=_interopRequireDefault(_react); var _reactNavigation=require('react-navigation'); -var _reactNative=require('react-native');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function _objectWithoutProperties(obj,keys){var target={};for(var i in obj){if(keys.indexOf(i)>=0)continue;if(!Object.prototype.hasOwnProperty.call(obj,i))continue;target[i]=obj[i];}return target;} +var _reactNative=require('react-native');function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};} var LightboxNavigator=function LightboxNavigator( routeConfigs) @@ -15,7 +15,7 @@ router, routeConfigs, tabsConfig, 'react-navigation/STACK')( -function(_ref){var navigation=_ref.navigation,props=_objectWithoutProperties(_ref,['navigation']);var +function(_ref){var navigation=_ref.navigation;var state=navigation.state,dispatch=navigation.dispatch;var routes=state.routes,index=state.index; diff --git a/dist/NavBar.js b/dist/NavBar.js index 4780e9c03..61e39162e 100644 --- a/dist/NavBar.js +++ b/dist/NavBar.js @@ -1,34 +1,4 @@ -Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i1&&arguments[1]!==undefined?arguments[1]:{};var clones=arguments.length>2&&arguments[2]!==undefined?arguments[2]:[]; (0,_Util.assert)(scene.props,'props should be defined'); if(!scene.props.children){ -return; +return null; } var res={}; var order=[];var _scene$props= @@ -188,14 +170,13 @@ var children=!Array.isArray(parentProps.children)?[parentProps.children]:[].conc if(!drawer&&!tabs){ children.push.apply(children,_toConsumableArray(clones)); } -var initialRouteName=void 0,initialRouteParams=void 0;var _loop=function _loop( +var initialRouteName=void 0; +var initialRouteParams=void 0;var _loop=function _loop( child){ (0,_Util.assert)(child.key,'key should be defined for '+child); var key=child.key; var init=key===children[0].key; -if(reservedKeys.indexOf(key)!==-1){ -throw'Scene name cannot be reserved word: '+child.key; -}var _child$props= +(0,_Util.assert)(reservedKeys.indexOf(key)===-1,'Scene name cannot be reserved word: '+child.key);var _child$props= child.props,component=_child$props.component,_child$props$type=_child$props.type,type=_child$props$type===undefined?'push':_child$props$type,onEnter=_child$props.onEnter,onExit=_child$props.onExit,on=_child$props.on,failure=_child$props.failure,success=_child$props.success,props=_objectWithoutProperties(_child$props,['component','type','onEnter','onExit','on','failure','success']); if(child.props.clone){ if(clones.indexOf(child)===-1){ @@ -212,10 +193,10 @@ _navigationStore2.default.states[key][transition]=props[transition]; } delete props.children; if(success){ -_navigationStore2.default.states[key].success=success instanceof Function?success:function(props){console.log('Transition to state='+success);_navigationStore2.default[success](props);}; +_navigationStore2.default.states[key].success=success instanceof Function?success:function(args){console.log('Transition to state='+success);_navigationStore2.default[success](args);}; } if(failure){ -_navigationStore2.default.states[key].failure=failure instanceof Function?failure:function(props){console.log('Transition to state='+failure);_navigationStore2.default[failure](props);}; +_navigationStore2.default.states[key].failure=failure instanceof Function?failure:function(args){console.log('Transition to state='+failure);_navigationStore2.default[failure](args);}; } var screen={ @@ -235,7 +216,8 @@ res[key]=screen; props.init=true; if(!_navigationStore2.default[key]){ -_navigationStore2.default[key]=new Function('actions','props','type','return function '+key+'(params){ actions[type](\''+key+'\', props, params)}')(_navigationStore2.default,_extends({},commonProps,props),type); +_navigationStore2.default[key]=new Function('actions','props','type','return function '+ +key+'(params){ actions[type](\''+key+'\', props, params)}')(_navigationStore2.default,_extends({},commonProps,props),type); } if((onEnter||on)&&!_navigationStore2.default[key+_Util.OnEnter]){ @@ -256,23 +238,28 @@ var mode=modal?'modal':'card'; if(lightbox){ return(0,_LightboxNavigator2.default)(res,{mode:mode,initialRouteParams:initialRouteParams,initialRouteName:initialRouteName,navigationOptions:createNavigationOptions(parentProps)}); }else if(tabs){ -return(0,_reactNavigation.TabNavigator)(res,_extends({lazy:lazy,initialRouteName:initialRouteName,initialRouteParams:initialRouteParams,order:order},parentProps,{tabBarOptions:createTabBarOptions(parentProps),navigationOptions:createNavigationOptions(parentProps)})); +return(0,_reactNavigation.TabNavigator)(res,_extends({lazy:lazy,initialRouteName:initialRouteName,initialRouteParams:initialRouteParams,order:order},parentProps,{ +tabBarOptions:createTabBarOptions(parentProps),navigationOptions:createNavigationOptions(parentProps)})); }else if(drawer){ return(0,_reactNavigation.DrawerNavigator)(res,_extends({initialRouteName:initialRouteName,contentComponent:contentComponent,order:order,backBehavior:'none'},parentProps)); -}else{ +} if(navigator){ return navigator(res,_extends({lazy:lazy,initialRouteName:initialRouteName,initialRouteParams:initialRouteParams,order:order},parentProps,{navigationOptions:createNavigationOptions(parentProps)})); -}else{ -return(0,_reactNavigation.StackNavigator)(res,_extends({mode:mode,initialRouteParams:initialRouteParams,initialRouteName:initialRouteName},parentProps,{navigationOptions:createNavigationOptions(parentProps)})); } +return(0,_reactNavigation.StackNavigator)(res,_extends({mode:mode,initialRouteParams:initialRouteParams,initialRouteName:initialRouteName},parentProps,{navigationOptions:createNavigationOptions(parentProps)})); } -}exports.default= -function(_ref7){var createReducer=_ref7.createReducer,props=_objectWithoutProperties(_ref7,['createReducer']); +var Router=function Router(_ref7){var createReducer=_ref7.createReducer,props=_objectWithoutProperties(_ref7,['createReducer']); var scene=props.children; var AppNavigator=processScene(scene,props); _navigationStore2.default.router=AppNavigator.router; _navigationStore2.default.reducer=createReducer&&createReducer(props); -return _react2.default.createElement(App,{navigator:AppNavigator,__source:{fileName:_jsxFileName,lineNumber:277}}); -}; \ No newline at end of file +return _react2.default.createElement(App,{navigator:AppNavigator,__source:{fileName:_jsxFileName,lineNumber:258}}); +}; +Router.propTypes={ +createReducer:_propTypes2.default.func, +children:_propTypes2.default.element};exports.default= + + +Router; \ No newline at end of file diff --git a/dist/Scene.js b/dist/Scene.js index ddcad2f0a..4ae3b812e 100644 --- a/dist/Scene.js +++ b/dist/Scene.js @@ -1,4 +1,4 @@ -Object.defineProperty(exports,"__esModule",{value:true});exports.default=undefined;var _createClass=function(){function defineProperties(target,props){for(var i=0;i1?_len2-1:0),_key2=1;_key2<_len2;_key2++){params[_key2-1]=arguments[_key2];} @@ -186,15 +182,15 @@ drawerClose=function(){ _this.dispatch(_reactNavigation.NavigationActions.navigate({routeName:'DrawerClose'})); };this. -currentState=function(state){ +currentState=function(param){ +var state=param; if(!state){ state=_this._state; } if(!state.routes){ return state; -}else{ -return _this.currentState(state.routes[state.index]); } +return _this.currentState(state.routes[state.index]); };this. refresh=function(params){ @@ -226,7 +222,7 @@ _this.run(ActionConst.REPLACE,routeName,[_reactNavigation.NavigationActions.navi routeName:routeName, params:res})]); -};var defaultSuccess=function defaultSuccess(){};var defaultFailure=function defaultFailure(){};(0,_mobx.autorunAsync)(function _callee(){var handler,res,_handler,success,failure,params,_res;return regeneratorRuntime.async(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.prev=0;if(_this.prevScene&&_this.currentScene!==_this.prevScene){handler=_this[_this.prevScene+_Util.OnExit];if(handler){try{res=handler();if(res instanceof Promise){res.then(defaultSuccess,defaultFailure);}}catch(e){console.error("Error during onExit handler:",e);}}}if(!(_this.currentScene&&_this.currentScene!==_this.prevScene&&_this.states[_this.currentScene])){_context.next=20;break;}_handler=_this[_this.currentScene+_Util.OnEnter];success=_this.states[_this.currentScene].success||defaultSuccess;failure=_this.states[_this.currentScene].failure||defaultFailure;if(!_handler){_context.next=20;break;}_context.prev=7;params=_this.currentState().params;console.log("RUN onEnter handler for state=",_this.currentScene,' params='+JSON.stringify(params));_context.next=12;return regeneratorRuntime.awrap(_handler(params));case 12:_res=_context.sent;if(_res){console.log("SUCCESS",_res);success(_res);}else{console.log("FAILURE NULL RES");failure();}_context.next=20;break;case 16:_context.prev=16;_context.t0=_context['catch'](7);console.log("FAILURE EXCEPTION",_context.t0);failure(_context.t0);case 20:_context.next=25;break;case 22:_context.prev=22;_context.t1=_context['catch'](0);console.error("Error handling:"+_context.t1);case 25:case'end':return _context.stop();}}},null,_this,[[0,22],[7,16]]);});}return NavigationStore;}(),(_descriptor=_applyDecoratedDescriptor(_class.prototype,'_state',[_mobx.observable],{enumerable:true,initializer:null}),_descriptor2=_applyDecoratedDescriptor(_class.prototype,'currentScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_descriptor3=_applyDecoratedDescriptor(_class.prototype,'prevScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_applyDecoratedDescriptor(_class.prototype,'state',[_mobx.computed],Object.getOwnPropertyDescriptor(_class.prototype,'state'),_class.prototype),_descriptor4=_applyDecoratedDescriptor(_class.prototype,'setState',[_mobx.action],{enumerable:true,initializer:function initializer(){var _this2=this;return function(newState){if(!newState||_this2.currentState(newState).routeName===_this2.currentScene){return;}_this2._state=newState;_this2.prevScene=_this2.currentScene;_this2.currentScene=_this2.currentState(_this2._state).routeName;};}})),_class);exports.default= +};var defaultSuccess=function defaultSuccess(){};var defaultFailure=function defaultFailure(){};(0,_mobx.autorunAsync)(function _callee(){var handler,res,_handler,success,failure,params,_res;return regeneratorRuntime.async(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:_context.prev=0;if(_this.prevScene&&_this.currentScene!==_this.prevScene){handler=_this[_this.prevScene+_Util.OnExit];if(handler){try{res=handler();if(res instanceof Promise){res.then(defaultSuccess,defaultFailure);}}catch(e){console.error('Error during onExit handler:',e);}}}if(!(_this.currentScene&&_this.currentScene!==_this.prevScene&&_this.states[_this.currentScene])){_context.next=20;break;}_handler=_this[_this.currentScene+_Util.OnEnter];success=_this.states[_this.currentScene].success||defaultSuccess;failure=_this.states[_this.currentScene].failure||defaultFailure;if(!_handler){_context.next=20;break;}_context.prev=7;params=_this.currentState().params;console.log('RUN onEnter handler for state=',_this.currentScene,' params='+JSON.stringify(params));_context.next=12;return regeneratorRuntime.awrap(_handler(params));case 12:_res=_context.sent;if(_res){console.log('SUCCESS',_res);success(_res);}else{console.log('FAILURE NULL RES');failure();}_context.next=20;break;case 16:_context.prev=16;_context.t0=_context['catch'](7);console.log('FAILURE EXCEPTION',_context.t0);failure(_context.t0);case 20:_context.next=25;break;case 22:_context.prev=22;_context.t1=_context['catch'](0);console.error('Error handling:'+_context.t1);case 25:case'end':return _context.stop();}}},null,_this,[[0,22],[7,16]]);});}return NavigationStore;}(),(_descriptor=_applyDecoratedDescriptor(_class.prototype,'_state',[_mobx.observable],{enumerable:true,initializer:null}),_descriptor2=_applyDecoratedDescriptor(_class.prototype,'currentScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_descriptor3=_applyDecoratedDescriptor(_class.prototype,'prevScene',[_mobx.observable],{enumerable:true,initializer:function initializer(){return'';}}),_applyDecoratedDescriptor(_class.prototype,'state',[_mobx.computed],Object.getOwnPropertyDescriptor(_class.prototype,'state'),_class.prototype),_descriptor4=_applyDecoratedDescriptor(_class.prototype,'setState',[_mobx.action],{enumerable:true,initializer:function initializer(){var _this2=this;return function(newState){if(!newState||_this2.currentState(newState).routeName===_this2.currentScene){return;}_this2._state=newState;_this2.prevScene=_this2.currentScene;_this2.currentScene=_this2.currentState(_this2._state).routeName;};}})),_class);exports.default= diff --git a/package.json b/package.json index d6c101a28..242caa034 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-router-flux", - "version": "4.0.0-beta.6", + "version": "4.0.0-beta.7", "description": "React Native Router using Flux architecture", "repository": { "type": "git", @@ -17,6 +17,7 @@ "mobx": "^3.1.16", "mobx-react": "^4.2.1", "opencollective": "^1.0.3", + "prop-types": "^15.5.10", "react-native-button": "^2.0.0", "react-navigation": "^1.0.0-beta.11" }, @@ -24,8 +25,10 @@ "babel-jest": "20.0.3", "babel-preset-react-native": "2.0.0", "babel-preset-react-native-stage-0": "^1.0.1", - "eslint": "^4.0.0", + "eslint": "^3.0.0", "jest": "20.0.4", + "prettier-eslint": "^6.4.2", + "prettier-eslint-cli": "^4.1.1", "react": "16.0.0-alpha.12", "react-native": "0.45.1", "react-test-renderer": "16.0.0-alpha.12" @@ -51,4 +54,4 @@ "url": "https://opencollective.com/react-native-router-flux", "logo": "https://opencollective.com/opencollective/logo.txt" } -} \ No newline at end of file +} diff --git a/src/LightboxNavigator.js b/src/LightboxNavigator.js index 0ba02b681..d19999103 100644 --- a/src/LightboxNavigator.js +++ b/src/LightboxNavigator.js @@ -1,8 +1,8 @@ /* @flow */ import React from 'react'; -import {createNavigationContainer, createNavigator, StackRouter, TabRouter, TabView, TabBarTop, TabBarBottom} from 'react-navigation'; -import {View, Text} from 'react-native'; +import { createNavigationContainer, createNavigator, TabRouter } from 'react-navigation'; +import { View } from 'react-native'; const LightboxNavigator = ( routeConfigs, @@ -15,14 +15,14 @@ const LightboxNavigator = ( routeConfigs, tabsConfig, 'react-navigation/STACK' - )(({navigation, ...props}) => { + )(({ navigation }) => { const { state, dispatch } = navigation; const { routes, index } = state; // Figure out what to render based on the navigation state and the router: const Component = routeConfigs[tabsConfig.initialRouteName].screen; let initialIndex = 0; - for (let i=0;i + return ( {Popup && } - + ); }); return createNavigationContainer(navigator, tabsConfig.containerOptions); diff --git a/src/NavBar.js b/src/NavBar.js index 5327053b9..0c4e7a945 100644 --- a/src/NavBar.js +++ b/src/NavBar.js @@ -1,45 +1,15 @@ -/** - * Copyright (c) 2015, Facebook, Inc. All rights reserved. - * - * Facebook, Inc. ("Facebook") owns all right, title and interest, including - * all intellectual property and other proprietary rights, in and to the React - * Native CustomComponents software (the "Software"). Subject to your - * compliance with these terms, you are hereby granted a non-exclusive, - * worldwide, royalty-free copyright license to (1) use and copy the Software; - * and (2) reproduce and distribute the Software as part of your own software - * ("Your Software"). Facebook reserves all rights not expressly granted to - * you in this license agreement. - * - * THE SOFTWARE AND DOCUMENTATION, IF ANY, ARE PROVIDED "AS IS" AND ANY EXPRESS - * OR IMPLIED WARRANTIES (INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE) ARE DISCLAIMED. - * IN NO EVENT SHALL FACEBOOK OR ITS AFFILIATES, OFFICERS, DIRECTORS OR - * EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THE SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -import React, { - PropTypes, -} from 'react'; +import React from 'react'; import { Platform, - Animated, I18nManager, Image, StyleSheet, Text, TouchableOpacity, View, - ViewPropTypes, } from 'react-native'; import Actions from './navigationStore'; import _backButtonImage from '../images/back_chevron.png'; -import _drawerImage from '../images/menu_burger.png'; export function renderBackButton(state) { const textButtonStyle = [ @@ -67,12 +37,11 @@ export function renderBackButton(state) { return ( - {buttonImage && !state.hideBackImage && - - {leftTitle && - + {leftTitle && {leftTitle} } - {!leftTitle && buttonImage && - + {!leftTitle && buttonImage && {menuIcon || - {rightTitle && - + {rightTitle && {rightTitle} } - {buttonImage && - + {buttonImage && {menuIcon || - ); - } - const buttonImage = childState.backButtonImage || - state.backButtonImage || this.props.backButtonImage; - let onPress = childState.onBack || childState.component.onBack; - if (onPress) { - onPress = onPress.bind(null, state); - } else { - onPress = Actions.pop; - } - - const text = childState.backTitle ? - ( - {childState.backTitle} - ) - : null; - - return ( - - {buttonImage && !childState.hideBackImage && - - } - {text} - - ); - } - - renderRightButton(navProps) { - const self = this; - const drawer = this.context.drawer; - function tryRender(state, wrapBy) { - if (!state) { - return null; - } - - let onPress = state.onRight; - let buttonImage = state.rightButtonImage; - let menuIcon = state.drawerIcon; - const style = [styles.rightButton, self.props.rightButtonStyle, state.rightButtonStyle]; - const textStyle = [styles.barRightButtonText, self.props.rightButtonTextStyle, - state.rightButtonTextStyle]; - const rightButtonStyle = [styles.defaultImageStyle, state.rightButtonIconStyle]; - const rightTitle = state.getRightTitle ? state.getRightTitle(navProps) : state.rightTitle; - - if (state.rightButton) { - let Button = state.rightButton; - if (wrapBy) { - Button = wrapBy(Button); - } - return ( -