1- 'use strict' ;
1+ import React from 'react-native' ;
2+ import { EventEmitter } from 'fbemitter' ;
23
3- var React = require ( 'react-native' ) ;
4- var { EventEmitter} = require ( 'fbemitter' ) ;
4+ import NavBarContainer from './components/NavBarContainer' ;
55
6- var NavBarContainer = require ( './components/NavBarContainer' ) ;
7-
8- var {
6+ const {
97 StyleSheet,
108 Navigator,
119 StatusBarIOS,
1210 View,
13- Platform
11+ Platform,
1412} = React ;
1513
16- class Router extends React . Component {
14+ class Router extends React . Component {
1715 constructor ( props ) {
1816 super ( props ) ;
17+
18+ this . toRoute = this . onForward . bind ( this ) ;
19+ this . toBack = this . onBack . bind ( this ) ;
20+ this . customAction = this . customAction . bind ( this ) ;
21+ this . renderScene = this . renderScene . bind ( this ) ;
22+ this . onDidFocus = this . onDidFocus . bind ( this ) ;
23+ this . onWillFocus = this . onWillFocus . bind ( this ) ;
24+
1925 this . state = {
2026 route : {
2127 name : null ,
22- index : null
23- }
28+ index : null ,
29+ } ,
2430 } ;
2531 this . emitter = new EventEmitter ( ) ;
2632 }
2733
2834 onWillFocus ( route ) {
29- this . setState ( { route : route } ) ;
35+ this . setState ( { route } ) ;
3036 this . emitter . emit ( 'willFocus' , route . name ) ;
3137 }
3238
@@ -54,68 +60,67 @@ class Router extends React.Component{
5460 }
5561
5662 setTitleProps ( props ) {
57- this . setState ( { titleProps : props } ) ;
63+ this . setState ( { titleProps : props } ) ;
5864 }
5965
6066 customAction ( opts ) {
6167 this . props . customAction ( opts ) ;
6268 }
6369
64- configureScene ( route ) {
65- return route . sceneConfig || Navigator . SceneConfigs . FloatFromRight ;
70+ configureScene ( route ) {
71+ return route . sceneConfig || Navigator . SceneConfigs . FloatFromRight ;
6672 }
6773
6874 renderScene ( route , navigator ) {
69-
70- var goForward = function ( route ) {
75+ const goForward = function goForward ( route ) {
7176 route . index = this . state . route . index + 1 || 1 ;
7277 navigator . push ( route ) ;
7378 } . bind ( this ) ;
7479
75- var replaceRoute = function ( route ) {
80+ const replaceRoute = function replaceRoute ( route ) {
7681 route . index = this . state . route . index || 0 ;
7782 navigator . replace ( route ) ;
7883 } . bind ( this ) ;
7984
80- var resetToRoute = function ( route ) {
85+ const resetToRoute = function resetToRoute ( route ) {
8186 route . index = 0 ;
8287 navigator . resetTo ( route ) ;
83- } . bind ( this ) ;
88+ } ;
8489
85- var goBackwards = function ( ) {
90+ const goBackwards = function goBackwards ( ) {
8691 this . onBack ( navigator ) ;
8792 } . bind ( this ) ;
8893
89- var goToFirstRoute = function ( ) {
94+ const goToFirstRoute = function goToFirstRoute ( ) {
9095 navigator . popToTop ( ) ;
9196 } ;
9297
93- var setRightProps = function ( props ) {
98+ const setRightProps = function setRightProps ( props ) {
9499 this . setState ( { rightProps : props } ) ;
95100 } . bind ( this ) ;
96101
97- var setLeftProps = function ( props ) {
102+ const setLeftProps = function setLeftProps ( props ) {
98103 this . setState ( { leftProps : props } ) ;
99104 } . bind ( this ) ;
100105
101- var setTitleProps = function ( props ) {
102- this . setState ( { titleProps : props } ) ;
103- } . bind ( this ) ;
106+ const setTitleProps = function setTitleProps ( props ) {
107+ this . setState ( { titleProps : props } ) ;
108+ } . bind ( this ) ;
104109
105- var customAction = function ( opts ) {
110+ const customAction = function customAction ( opts ) {
106111 this . customAction ( opts ) ;
107112 } . bind ( this ) ;
108113
109- var Content = route . component ;
114+ const Content = route . component ;
110115
111116 // Remove the margin of the navigation bar if not using navigation bar
112- var extraStyling = { } ;
117+ const extraStyling = { } ;
113118 if ( this . props . hideNavigationBar ) {
114119 extraStyling . marginTop = 0 ;
115120 }
116121
117- var margin ;
118- if ( route . trans ) {
122+ let margin ;
123+ if ( route . trans ) {
119124 margin = 0 ;
120125 } else if ( this . props . hideNavigationBar || route . hideNavigationBar ) {
121126 margin = this . props . noStatusBar ? 0 : 20 ;
@@ -125,7 +130,7 @@ class Router extends React.Component{
125130
126131 return (
127132 < View
128- style = { [ styles . container , this . props . bgStyle , extraStyling , { marginTop : margin } ] } >
133+ style = { [ styles . container , this . props . bgStyle , extraStyling , { marginTop : margin } ] } >
129134 < Content
130135 name = { route . name }
131136 index = { route . index }
@@ -144,11 +149,10 @@ class Router extends React.Component{
144149 />
145150 </ View >
146151 ) ;
147-
148152 }
149153
150154 render ( ) {
151- var navigationBar ;
155+ let navigationBar ;
152156 // Status bar color
153157 if ( Platform . OS === 'ios' ) {
154158 if ( this . props . statusBarColor === 'black' ) {
@@ -161,44 +165,45 @@ class Router extends React.Component{
161165 }
162166
163167 if ( ! this . props . hideNavigationBar ) {
164- navigationBar =
165- < NavBarContainer
166- style = { this . props . headerStyle }
167- navigator = { navigator }
168- currentRoute = { this . state . route }
169- backButtonComponent = { this . props . backButtonComponent }
170- rightCorner = { this . props . rightCorner }
171- titleStyle = { this . props . titleStyle }
172- borderBottomWidth = { this . props . borderBottomWidth }
173- borderColor = { this . props . borderColor }
174- toRoute = { this . onForward . bind ( this ) }
175- toBack = { this . onBack . bind ( this ) }
176- leftProps = { this . state . leftProps }
177- rightProps = { this . state . rightProps }
178- titleProps = { this . state . titleProps }
179- customAction = { this . customAction . bind ( this ) }
180- />
168+ navigationBar = (
169+ < NavBarContainer
170+ style = { this . props . headerStyle }
171+ navigator = { navigator }
172+ currentRoute = { this . state . route }
173+ backButtonComponent = { this . props . backButtonComponent }
174+ rightCorner = { this . props . rightCorner }
175+ titleStyle = { this . props . titleStyle }
176+ borderBottomWidth = { this . props . borderBottomWidth }
177+ borderColor = { this . props . borderColor }
178+ toRoute = { this . onForward }
179+ toBack = { this . onBack }
180+ leftProps = { this . state . leftProps }
181+ rightProps = { this . state . rightProps }
182+ titleProps = { this . state . titleProps }
183+ customAction = { this . customAction }
184+ />
185+ ) ;
181186 }
182187
183188 return (
184189 < Navigator
185- ref = ' navigator'
190+ ref = " navigator"
186191 initialRoute = { this . props . firstRoute }
187192 navigationBar = { navigationBar }
188- renderScene = { this . renderScene . bind ( this ) }
189- onDidFocus = { this . onDidFocus . bind ( this ) }
190- onWillFocus = { this . onWillFocus . bind ( this ) }
193+ renderScene = { this . renderScene }
194+ onDidFocus = { this . onDidFocus }
195+ onWillFocus = { this . onWillFocus }
191196 configureScene = { this . configureScene }
192197 />
193198 ) ;
194199 }
195200}
196201
197- var styles = StyleSheet . create ( {
202+ const styles = StyleSheet . create ( {
198203 container : {
199204 flex : 1 ,
200- backgroundColor : '#FFFFFF'
205+ backgroundColor : '#FFFFFF' ,
201206 } ,
202207} ) ;
203208
204- module . exports = Router ;
209+ export default Router ;
0 commit comments