Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleanup and fix some issues reported by eslint
- Loading branch information
Showing
4 changed files
with
274 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,91 @@ | ||
/*eslint no-unused-vars: 0*/ | ||
|
||
import React, { Component, InteractionManager } from 'react-native'; | ||
|
||
/* eslint no-unused-vars: 0*/ | ||
import React from 'react'; | ||
import { InteractionManager } from 'react-native'; | ||
import ExNavigator from '@exponent/react-native-navigator'; | ||
|
||
import applyNavigatorChanges from './applyNavigatorChanges'; | ||
import NavigatorWrapper from './NavigatorWrapper'; | ||
|
||
export default class ExNavigatorAutopilot extends Component { | ||
static Styles = ExNavigator.Styles; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
if (!props.routeMapping) { | ||
throw new Error('ExNavigatorAutopilot: routeMapping prop is required!'); | ||
} | ||
|
||
// initialRouteStack | ||
this.originRouteStack = props.routes && props.routes.length ? props.routes : [ null ]; | ||
this.mappedRouteStack = this.originRouteStack.map(props.routeMapping); | ||
} | ||
|
||
componentDidMount() { | ||
const navigator = this.refs.navigator; | ||
const context = navigator.navigationContext; | ||
|
||
this.didFocusListener = context.addListener('didfocus', (event) => { | ||
const mappedRoute = event.data.route; | ||
InteractionManager.runAfterInteractions(() => { | ||
this.onFocus(mappedRoute); | ||
}); | ||
}); | ||
} | ||
|
||
componentWillUnmount() { | ||
if (this.didFocusListener) { | ||
this.didFocusListener.remove(); | ||
this.didFocusListener = null; | ||
} | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (!nextProps.routeMapping) { | ||
throw new Error('ExNavigatorAutopilot: routeMapping prop is required!'); | ||
} | ||
|
||
var compareRoute = nextProps.compareRoute || function(routeA, routeB) { | ||
return routeA === routeB; | ||
}; | ||
|
||
var prevRouteStack = this.originRouteStack; | ||
this.originRouteStack = nextProps.routes && nextProps.routes.length ? nextProps.routes : [ null ]; | ||
this.mappedRouteStack = this.originRouteStack.map((route, index) => { | ||
if (compareRoute(prevRouteStack[index], route) && this.mappedRouteStack[index]) { | ||
return this.mappedRouteStack[index]; | ||
} | ||
return nextProps.routeMapping(route); | ||
}); | ||
|
||
if (this.refs.navigator) { | ||
var navigator = new NavigatorWrapper(this.refs.navigator); | ||
applyNavigatorChanges(navigator.getCurrentRoutes(), this.mappedRouteStack, navigator); | ||
} | ||
} | ||
|
||
render() { | ||
return <ExNavigator | ||
ref='navigator' | ||
initialRouteStack={ this.mappedRouteStack } | ||
|
||
showNavigationBar={ this.props.showNavigationBar } | ||
navigationBarStyle={ this.props.navigationBarStyle } | ||
titleStyle={ this.props.titleStyle } | ||
barButtonTextStyle={ this.props.barButtonTextStyle } | ||
barButtonIconStyle={ this.props.barButtonIconStyle } | ||
renderNavigationBar={ this.props.renderNavigationBar } | ||
renderBackButton={ this.props.renderBackButton } | ||
sceneStyle={ this.props.sceneStyle } | ||
style={ this.props.style } />; | ||
} | ||
|
||
onFocus(mappedRoute) { | ||
const index = this.mappedRouteStack.indexOf(mappedRoute); | ||
if (index !== -1 && index + 1 !== this.originRouteStack.length) { | ||
const newRouteStack = this.originRouteStack.slice(0, index + 1); | ||
if (this.props.persistRoutes) { | ||
this.props.persistRoutes(newRouteStack); | ||
} | ||
} | ||
} | ||
export default class ExNavigatorAutopilot extends React.Component { | ||
static Styles = ExNavigator.Styles; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
if (!props.routeMapping) { | ||
throw new Error('ExNavigatorAutopilot: routeMapping prop is required!'); | ||
} | ||
|
||
// initialRouteStack | ||
this.originRouteStack = props.routes && props.routes.length ? props.routes : [ null ]; | ||
this.mappedRouteStack = this.originRouteStack.map(props.routeMapping); | ||
} | ||
|
||
componentDidMount() { | ||
const navigator = this.refs.navigator; | ||
const context = navigator.navigationContext; | ||
|
||
this.didFocusListener = context.addListener('didfocus', (event) => { | ||
const mappedRoute = event.data.route; | ||
InteractionManager.runAfterInteractions(() => { | ||
this.onFocus(mappedRoute); | ||
}); | ||
}); | ||
} | ||
|
||
componentWillUnmount() { | ||
if (this.didFocusListener) { | ||
this.didFocusListener.remove(); | ||
this.didFocusListener = null; | ||
} | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (!nextProps.routeMapping) { | ||
throw new Error('ExNavigatorAutopilot: routeMapping prop is required!'); | ||
} | ||
|
||
var compareRoute = nextProps.compareRoute || function(routeA, routeB) { | ||
return routeA === routeB; | ||
}; | ||
|
||
var prevRouteStack = this.originRouteStack; | ||
this.originRouteStack = nextProps.routes && nextProps.routes.length ? nextProps.routes : [ null ]; | ||
this.mappedRouteStack = this.originRouteStack.map((route, index) => { | ||
if (compareRoute(prevRouteStack[index], route) && this.mappedRouteStack[index]) { | ||
return this.mappedRouteStack[index]; | ||
} | ||
return nextProps.routeMapping(route); | ||
}); | ||
|
||
if (this.refs.navigator) { | ||
var navigator = new NavigatorWrapper(this.refs.navigator); | ||
applyNavigatorChanges(navigator.getCurrentRoutes(), this.mappedRouteStack, navigator); | ||
} | ||
} | ||
|
||
render() { | ||
return <ExNavigator | ||
ref='navigator' | ||
initialRouteStack={ this.mappedRouteStack } | ||
|
||
showNavigationBar={ this.props.showNavigationBar } | ||
navigationBarStyle={ this.props.navigationBarStyle } | ||
titleStyle={ this.props.titleStyle } | ||
barButtonTextStyle={ this.props.barButtonTextStyle } | ||
barButtonIconStyle={ this.props.barButtonIconStyle } | ||
renderNavigationBar={ this.props.renderNavigationBar } | ||
renderBackButton={ this.props.renderBackButton } | ||
sceneStyle={ this.props.sceneStyle } | ||
style={ this.props.style } />; | ||
} | ||
|
||
onFocus(mappedRoute) { | ||
const index = this.mappedRouteStack.indexOf(mappedRoute); | ||
if (index !== -1 && index + 1 !== this.originRouteStack.length) { | ||
const newRouteStack = this.originRouteStack.slice(0, index + 1); | ||
if (this.props.persistRoutes) { | ||
this.props.persistRoutes(newRouteStack); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,109 @@ | ||
/*eslint no-unused-vars: 0*/ | ||
|
||
import React, { Component, InteractionManager, Navigator, Text } from 'react-native'; | ||
import React from 'react'; | ||
import { InteractionManager, Navigator } from 'react-native'; | ||
|
||
import applyNavigatorChanges from './applyNavigatorChanges'; | ||
import NavigatorWrapper from './NavigatorWrapper'; | ||
|
||
export default class NavigatorAutopilot extends Component { | ||
static NavigationBar = Navigator.NavigationBar; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
if (!props.routeMapping) { | ||
throw new Error('NavigatorAutopilot: routeMapping prop is required!'); | ||
} | ||
|
||
// initialRouteStack | ||
this.originRouteStack = props.routes && props.routes.length ? props.routes : [ null ]; | ||
// this.mappedRouteStack = this.originRouteStack.map(props.routeMapping); | ||
} | ||
|
||
componentDidMount() { | ||
const navigator = this.refs.navigator; | ||
const context = navigator.navigationContext; | ||
|
||
this.didFocusListener = context.addListener('didfocus', (event) => { | ||
const mappedRoute = event.data.route; | ||
InteractionManager.runAfterInteractions(() => { | ||
this.onFocus(mappedRoute); | ||
}); | ||
}); | ||
} | ||
|
||
componentWillUnmount() { | ||
if (this.didFocusListener) { | ||
this.didFocusListener.remove(); | ||
this.didFocusListener = null; | ||
} | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (!nextProps.routeMapping) { | ||
throw new Error('NavigatorAutopilot: routeMapping prop is required!'); | ||
} | ||
|
||
var compareRoute = nextProps.compareRoute || function(routeA, routeB) { | ||
return routeA === routeB; | ||
}; | ||
|
||
var prevRouteStack = this.originRouteStack; | ||
this.originRouteStack = nextProps.routes && nextProps.routes.length ? nextProps.routes : [ null ]; | ||
// this.mappedRouteStack = this.originRouteStack.map((route, index) => { | ||
// if (compareRoute(prevRouteStack[index], route) && this.mappedRouteStack[index]) { | ||
// return this.mappedRouteStack[index]; | ||
// } | ||
// return nextProps.routeMapping(route); | ||
// }); | ||
|
||
if (this.refs.navigator) { | ||
var navigator = new NavigatorWrapper(this.refs.navigator); | ||
applyNavigatorChanges(navigator.getCurrentRoutes(), this.originRouteStack, navigator); | ||
} | ||
} | ||
|
||
render() { | ||
return <Navigator | ||
ref='navigator' | ||
initialRouteStack={ this.originRouteStack } | ||
renderScene={ this.renderScene.bind(this) } | ||
configureScene={ this.configureScene.bind(this) } | ||
navigationBar={ this.props.navigationBar } | ||
sceneStyle={ this.props.sceneStyle } | ||
style={ this.props.style } />; | ||
} | ||
|
||
renderScene(route) { | ||
return this.props.routeMapping(route); | ||
} | ||
|
||
configureScene(route) { | ||
const defaultSceneConfig = Navigator.SceneConfigs.PushFromRight; | ||
if (route && typeof route.sceneConfig === 'string') { | ||
return Navigator.SceneConfigs[route.sceneConfig] || defaultSceneConfig; | ||
} else if (route && typeof route.sceneConfig === 'object') { | ||
return route.sceneConfig; | ||
} else { | ||
return defaultSceneConfig; | ||
} | ||
} | ||
|
||
onFocus(mappedRoute) { | ||
const index = this.originRouteStack.indexOf(mappedRoute); | ||
if (index !== -1 && index + 1 !== this.originRouteStack.length) { | ||
const newRouteStack = this.originRouteStack.slice(0, index + 1); | ||
if (this.props.persistRoutes) { | ||
this.props.persistRoutes(newRouteStack); | ||
} | ||
} | ||
} | ||
export default class NavigatorAutopilot extends React.Component { | ||
static NavigationBar = Navigator.NavigationBar; | ||
|
||
constructor(props) { | ||
super(props); | ||
|
||
if (!props.routeMapping) { | ||
throw new Error('NavigatorAutopilot: routeMapping prop is required!'); | ||
} | ||
|
||
// initialRouteStack | ||
this.originRouteStack = props.routes && props.routes.length ? props.routes : [ null ]; | ||
// this.mappedRouteStack = this.originRouteStack.map(props.routeMapping); | ||
} | ||
|
||
componentDidMount() { | ||
const navigator = this.refs.navigator; | ||
const context = navigator.navigationContext; | ||
|
||
this.didFocusListener = context.addListener('didfocus', (event) => { | ||
const mappedRoute = event.data.route; | ||
InteractionManager.runAfterInteractions(() => { | ||
this.onFocus(mappedRoute); | ||
}); | ||
}); | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (!nextProps.routeMapping) { | ||
throw new Error('NavigatorAutopilot: routeMapping prop is required!'); | ||
} | ||
|
||
// const compareRoute = nextProps.compareRoute || function(routeA, routeB) { | ||
// return routeA === routeB; | ||
// }; | ||
|
||
// const prevRouteStack = this.originRouteStack; | ||
this.originRouteStack = nextProps.routes && | ||
nextProps.routes.length ? | ||
nextProps.routes : [null]; | ||
// this.mappedRouteStack = this.originRouteStack.map((route, index) => { | ||
// if (compareRoute(prevRouteStack[index], route) && this.mappedRouteStack[index]) { | ||
// return this.mappedRouteStack[index]; | ||
// } | ||
// return nextProps.routeMapping(route); | ||
// }); | ||
|
||
if (this.refs.navigator) { | ||
const navigator = new NavigatorWrapper(this.refs.navigator); | ||
applyNavigatorChanges(navigator.getCurrentRoutes(), this.originRouteStack, navigator); | ||
} | ||
} | ||
|
||
componentWillUnmount() { | ||
if (this.didFocusListener) { | ||
this.didFocusListener.remove(); | ||
this.didFocusListener = null; | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<Navigator | ||
ref="navigator" | ||
initialRouteStack={this.originRouteStack} | ||
renderScene={this.renderScene.bind(this)} | ||
configureScene={this.configureScene.bind(this)} | ||
navigationBar={this.props.navigationBar} | ||
sceneStyle={this.props.sceneStyle} | ||
style={this.props.style} /> | ||
); | ||
} | ||
|
||
onFocus(mappedRoute) { | ||
const index = this.originRouteStack.indexOf(mappedRoute); | ||
if (index !== -1 && index + 1 !== this.originRouteStack.length) { | ||
const newRouteStack = this.originRouteStack.slice(0, index + 1); | ||
if (this.props.persistRoutes) { | ||
this.props.persistRoutes(newRouteStack); | ||
} | ||
} | ||
} | ||
|
||
configureScene(route) { | ||
const defaultSceneConfig = Navigator.SceneConfigs.PushFromRight; | ||
if (route && typeof route.sceneConfig === 'string') { | ||
return Navigator.SceneConfigs[route.sceneConfig] || defaultSceneConfig; | ||
} else if (route && typeof route.sceneConfig === 'object') { | ||
return route.sceneConfig; | ||
} | ||
|
||
return defaultSceneConfig; | ||
} | ||
|
||
renderScene(route) { | ||
return this.props.routeMapping(route); | ||
} | ||
} | ||
|
||
NavigatorAutopilot.propTypes = { | ||
routeMapping: React.PropTypes.func.isRequired, | ||
persistRoutes: React.PropTypes.func.isRequired, | ||
}; |
Oops, something went wrong.