|
import React, { Component } from 'react' |
|
import { Navigator, StatusBar, View } from 'react-native' |
|
|
|
import customNavigatorScenes from '../../common/customNavigatorScenes' |
|
import style from './style' |
|
import ErrorListener from './errorListener' |
|
import NetworkConnectivity from '../networkConnectivity' |
|
import _ from 'lodash' |
|
import { brandPrimary } from '../../styleVariables' |
|
import { reduxComponentName } from '../../common/reduxComponentName' |
|
const navigatorComponents = {} |
|
let navigatorInstance |
|
|
|
class Navigator1 extends Component { |
|
onDidFocus = (route) => { |
|
if (route.resetRouteStack) { |
|
this.refs.navigator.immediatelyResetRouteStack(route.resetRouteStack) |
|
} |
|
const componentInstance = navigatorComponents[reduxComponentName(route.component)] |
|
if (componentInstance) { |
|
if (!_.isUndefined(componentInstance.componentDidFocus)) { |
|
componentInstance.componentDidFocus() |
|
} |
|
if (!_.isUndefined(componentInstance.getWrappedInstance) && !_.isUndefined(componentInstance.getWrappedInstance().componentDidFocus)) { |
|
componentInstance.getWrappedInstance().componentDidFocus() |
|
} |
|
} |
|
} |
|
render() { |
|
return ( |
|
<View style={style.container}> |
|
<NetworkConnectivity /> |
|
<StatusBar hidden={this.props.hideStatusBar} backgroundColor={brandPrimary} /> |
|
<Navigator |
|
ref="navigator" |
|
initialRoute={this.props.initialRoute} |
|
renderScene={(route, navigator) => { |
|
if (this.props.navigatorRef) { |
|
navigatorInstance = navigator |
|
this.props.navigatorRef(navigator) |
|
} |
|
const RouteComponent = route.component |
|
return ( |
|
<View style={style.container}> |
|
<ErrorListener navigator={navigator} /> |
|
<RouteComponent |
|
navigator={navigator} |
|
{...route.passProps} |
|
ref={(view) => { |
|
navigatorComponents[reduxComponentName(RouteComponent)] = view |
|
}} |
|
/> |
|
</View> |
|
) |
|
}} |
|
onDidFocus={this.onDidFocus} |
|
configureScene={(route) => { |
|
this.props.sceneChanged(route, navigatorInstance) |
|
if (route.sceneConfig) { |
|
return route.sceneConfig |
|
} |
|
return customNavigatorScenes.HorizontalJump |
|
}} |
|
/> |
|
</View> |
|
) |
|
} |
|
} |
|
|
|
/* eslint-disable no-unused-vars */ |
|
Navigator1.defaultProps = { hideStatusBar: false, sceneChanged: (route, navigator) => route } |
|
export default Navigator1 |