@@ -3,11 +3,15 @@ import Router from './Router';
33import Route from './Route' ;
44import * as Components from './Common' ;
55import ExNavigator from '@exponent/react-native-navigator' ;
6+ import ExNavigatorStyles from '@exponent/react-native-navigator/ExNavigatorStyles' ;
7+ import { BackIcon } from '@exponent/react-native-navigator/ExNavigatorIcons' ;
68import Animations from './Animations' ;
79const { TouchableOpacity, StyleSheet, View, Text} = React ;
810import ReactRouter from './ReactRouter' ;
11+ import Actions from './Actions' ;
12+ import debug from './debug' ;
913
10- export class ExRoute {
14+ export class ExRouteAdapter {
1115 name : string ;
1216 navigator: ExNavigator ;
1317 route: Route ;
@@ -31,6 +35,7 @@ export class ExRoute {
3135 }
3236
3337 renderScene ( navigator ) {
38+ debug ( "RENDER SCENE:" , this . route . name , Object . keys ( this . route . props ) ) ;
3439 const Component = this . route . component ;
3540 const child = Component ?
3641 ! this . route . wrapRouter ? < Component key = { this . route . name } name = { this . route . name } { ...this . route . props } { ...this . props } route = { this . route } /> :
@@ -57,6 +62,49 @@ export class ExRoute {
5762 return title . length > 10 ? null : title ;
5863 }
5964
65+ renderLeftButton ( navigator , index , state ) {
66+ if ( index === 0 ) {
67+ return null ;
68+ }
69+
70+ let previousIndex = index - 1 ;
71+ let previousRoute = state . routeStack [ previousIndex ] ;
72+ if ( previousRoute . renderBackButton ) {
73+ return previousRoute . renderBackButton ( navigator , previousIndex , state ) ;
74+ }
75+
76+ let title = this . getBackButtonTitle ( navigator , index , state ) ;
77+
78+ if ( title ) {
79+ var buttonText =
80+ < Text
81+ numberOfLines = { 1 }
82+ style = { [
83+ ExNavigatorStyles . barButtonText ,
84+ ExNavigatorStyles . barBackButtonText ,
85+ this . _barButtonTextStyle ,
86+ ] }
87+ >
88+ { title }
89+ </ Text > ;
90+ }
91+
92+ return (
93+ < TouchableOpacity
94+ pressRetentionOffset = { ExNavigatorStyles . barButtonPressRetentionOffset }
95+ onPress = { ( ) => Actions . pop ( ) }
96+ style = { [ ExNavigatorStyles . barBackButton , styles . backButtonStyle ] } >
97+ < BackIcon
98+ style = { [
99+ ExNavigatorStyles . barButtonIcon ,
100+ this . _barButtonIconStyle ,
101+ ] }
102+ />
103+ { buttonText }
104+ </ TouchableOpacity >
105+ ) ;
106+ }
107+
60108 renderRightButton ( ) {
61109 if ( this . route . onRight && this . route . rightTitle ) {
62110 return ( < TouchableOpacity
@@ -71,10 +119,6 @@ export class ExRoute {
71119 }
72120}
73121
74- const defaultCreateRoute = function ( route , data ) {
75- return new ExRoute ( route , data ) ;
76- } ;
77-
78122export default class ExRouter extends React . Component {
79123 router : Router ;
80124
@@ -95,7 +139,7 @@ export default class ExRouter extends React.Component {
95139 return false ;
96140 }
97141 }
98- this . refs . nav . push ( new ExRoute ( route , props ) ) ;
142+ this . refs . nav . push ( new ExRouteAdapter ( route , props ) ) ;
99143 return true ;
100144 }
101145
@@ -106,7 +150,7 @@ export default class ExRouter extends React.Component {
106150 return false ;
107151 }
108152 }
109- this . refs . nav . replace ( new ExRoute ( route , props ) ) ;
153+ this . refs . nav . replace ( new ExRouteAdapter ( route , props ) ) ;
110154 return true ;
111155 }
112156
@@ -123,7 +167,7 @@ export default class ExRouter extends React.Component {
123167 if ( exist . length ) {
124168 navigator . jumpTo ( exist [ 0 ] ) ;
125169 } else {
126- navigator . push ( new ExRoute ( route , props ) ) ;
170+ navigator . push ( new ExRouteAdapter ( route , props ) ) ;
127171
128172 }
129173 this . setState ( { selected : route . name } ) ;
@@ -151,11 +195,12 @@ export default class ExRouter extends React.Component {
151195
152196 const Footer = this . props . footer ;
153197 const footer = Footer ? < Footer { ...this . props } { ...this . state } /> : null ;
198+ debug ( "RENDER ROUTER:" , router . name , Object . keys ( this . props ) , Object . keys ( this . state || { } ) ) ;
154199
155200 return (
156201 < View style = { styles . transparent } >
157202 { header }
158- < ExNavigator ref = "nav" initialRouteStack = { router . stack . map ( route => new ExRoute ( router . routes [ route ] ) ) }
203+ < ExNavigator ref = "nav" initialRouteStack = { router . stack . map ( route => new ExRouteAdapter ( router . routes [ route ] ) ) }
159204 style = { styles . transparent }
160205 sceneStyle = { { paddingTop : 0 } }
161206 showNavigationBar = { ! this . props . hideNavBar }
0 commit comments