1+ import React , { PropTypes as T } from 'react'
2+
3+ import {
4+ StyleSheet ,
5+ View ,
6+ Text ,
7+ NavigationExperimental ,
8+ Easing ,
9+ Dimensions
10+ } from 'react-native'
11+
12+ const {
13+ Header : NavigationHeader ,
14+ Transitioner : NavigationTransitioner ,
15+ CardStack : NavigationCardStack
16+ } = NavigationExperimental ;
17+
18+ const { width, height } = Dimensions . get ( 'window' ) ;
19+
20+ import routes from '../../routes' ;
21+ import appStyles from '../../styles/app'
22+ import Header from './Header'
23+
24+ export class FirestackNavigator extends React . Component {
25+ static propTypes : {
26+ navigationState: NavigationPropTypes . navigationState . isRequired ,
27+ navigate : PropTypes . func . isRequired ,
28+ } ;
29+
30+ _render ( props ) {
31+ const { scene} = props ;
32+ return (
33+ < View style = { appStyles . container } key = { scene . key } >
34+ { this . _renderHeader ( props ) }
35+ { props . scenes
36+ . map ( scene => this . _renderScene ( { ...props , scene } ) ) }
37+ </ View >
38+ ) ;
39+ }
40+
41+ _renderScene ( sceneProps ) {
42+ const { scene} = sceneProps ;
43+ const { route} = scene ;
44+ const definedRoute = this . _lookupRoute ( route ) ;
45+
46+ let Component = definedRoute . Component ;
47+ if ( ! Component ) {
48+ Component = (
49+ < View style = { styles . scene } key = { sceneProps . scene . key } >
50+ < Text > Render scene</ Text >
51+ </ View >
52+ )
53+ }
54+
55+ return React . createElement ( Component , {
56+ ...this . props ,
57+ ...sceneProps ,
58+ key : scene . key ,
59+ route : definedRoute
60+ } ) ;
61+ }
62+
63+ _renderHeader ( sceneProps ) {
64+ const { actions, navigationState} = this . props ;
65+ const { scene} = sceneProps ;
66+ let route = this . _lookupRoute ( scene . route ) ;
67+
68+ if ( ! route . noHeader ) {
69+ // Route not implemented yet, use a default header
70+ if ( ! route . Component && navigationState . index > 0 ) {
71+ const title = route . key
72+ route = Object . assign ( { } , routes . default , { title, actions} ) ;
73+ }
74+
75+ route . actions = actions
76+ const { headerStyle} = route ;
77+ let headerProps = Object . assign ( { } , sceneProps , {
78+ route,
79+ style : headerStyle || { }
80+ } ) ;
81+
82+ const { title, titleComponent} = route ;
83+ if ( title || titleComponent ) {
84+ headerProps . renderTitleComponent = ( props ) => {
85+ return titleComponent ?
86+ titleComponent ( { ...props , actions} ) : ( < NavigationHeader . Title > { title } </ NavigationHeader . Title > ) ;
87+ }
88+ }
89+
90+ const { leftComponent, rightComponent} = route ;
91+ headerProps . renderLeftComponent = leftComponent ?
92+ leftComponent . bind ( null , actions ) : ( ) => ( < View /> )
93+ headerProps . renderRightComponent = rightComponent ?
94+ rightComponent . bind ( null , actions ) : ( ) => ( < View /> )
95+
96+ return ( < Header { ...headerProps } /> )
97+ }
98+ }
99+
100+ _lookupRoute ( routeObject ) {
101+ const key = routeObject . key || 'default' ;
102+ return routes [ key ] ;
103+ }
104+
105+ _configureTransition ( ) {
106+ const easing = Easing . inOut ( Easing . ease ) ;
107+ return { easing, duration : 200 }
108+ }
109+
110+ render ( ) {
111+ const { navigationState} = this . props ;
112+ return (
113+ < NavigationTransitioner
114+ navigationState = { navigationState }
115+ render = { ( transitionProps ) => this . _render ( transitionProps ) }
116+ configureTransition = { this . _configureTransition }
117+ />
118+ )
119+ }
120+ }
121+
122+ const styles = StyleSheet . create ( {
123+ container : {
124+ } ,
125+ scene : {
126+ backgroundColor : '#E9E9EF' ,
127+ bottom : 0 ,
128+ flex : 1 ,
129+ left : 0 ,
130+ position : 'absolute' ,
131+ right : 0 ,
132+ shadowColor : 'black' ,
133+ shadowOffset : { width : 0 , height : 0 } ,
134+ shadowOpacity : 0.4 ,
135+ shadowRadius : 10 ,
136+ top : 0 ,
137+ } ,
138+ scrollView : {
139+ flex : 1 ,
140+ } ,
141+ } )
142+
143+ export default FirestackNavigator
0 commit comments