99import React , { Component , Animated , PropTypes , StyleSheet , View , NavigationExperimental } from "react-native" ;
1010const {
1111 AnimatedView : NavigationAnimatedView ,
12- Card : NavigationCard ,
13- RootContainer : NavigationRootContainer ,
14- Header : NavigationHeader ,
15- } = NavigationExperimental ;
12+ Card : NavigationCard
13+ } = NavigationExperimental ;
14+
15+ const {
16+ CardStackPanResponder : NavigationCardStackPanResponder ,
17+ CardStackStyleInterpolator : NavigationCardStackStyleInterpolator
18+ } = NavigationCard ;
19+
1620import TabBar from "./TabBar" ;
1721import NavBar from "./NavBar" ;
1822import Actions from './Actions' ;
@@ -59,13 +63,13 @@ export default class DefaultRenderer extends Component {
5963 return null ;
6064 }
6165 let Component = navigationState . component ;
62- if ( navigationState . tabs && ! Component ) {
66+ if ( navigationState . tabs && ! Component ) {
6367 Component = TabBar ;
6468 }
6569 if ( Component ) {
6670 return (
6771 < View style = { [ { flex : 1 } , navigationState . sceneStyle ] } >
68- < Component { ...navigationState } navigationState = { navigationState } />
72+ < Component { ...navigationState } navigationState = { navigationState } />
6973 </ View >
7074 )
7175 }
@@ -75,7 +79,6 @@ export default class DefaultRenderer extends Component {
7579
7680 let applyAnimation = selected . applyAnimation || navigationState . applyAnimation ;
7781 let style = selected . style || navigationState . style ;
78- let direction = selected . direction || navigationState . direction || "horizontal" ;
7982
8083 let optionals = { } ;
8184 if ( applyAnimation ) {
@@ -85,7 +88,11 @@ export default class DefaultRenderer extends Component {
8588 if ( duration === null || duration === undefined ) duration = navigationState . duration ;
8689 if ( duration !== null && duration !== undefined ) {
8790 optionals . applyAnimation = function ( pos , navState ) {
88- Animated . timing ( pos , { toValue : navState . index , duration} ) . start ( ) ;
91+ if ( duration === 0 ) {
92+ pos . setValue ( navState . index ) ;
93+ } else {
94+ Animated . timing ( pos , { toValue : navState . index , duration} ) . start ( ) ;
95+ }
8996 } ;
9097 }
9198 }
@@ -95,7 +102,6 @@ export default class DefaultRenderer extends Component {
95102 navigationState = { navigationState }
96103 style = { [ styles . animatedView , style ] }
97104 renderOverlay = { this . _renderHeader }
98- direction = { direction }
99105 renderScene = { this . _renderCard }
100106 { ...optionals }
101107 />
@@ -104,25 +110,40 @@ export default class DefaultRenderer extends Component {
104110
105111 _renderHeader ( /*NavigationSceneRendererProps*/ props ) {
106112 return < NavBar
107- { ...props }
108- getTitle = { state => state . title }
109- /> ;
113+ { ...props }
114+ getTitle = { state => state . title }
115+ /> ;
110116 }
111117
112118 _renderCard ( /*NavigationSceneRendererProps*/ props ) {
113- const { key, direction, panHandlers, getSceneStyle } = props . scene . navigationState ;
119+ const { key, direction, getSceneStyle} = props . scene . navigationState ;
120+ let { panHandlers, animationStyle} = props . scene . navigationState ;
121+
122+ // Since we always need to pass a style for the direction, we can avoid #526
123+ let style = { } ;
124+ if ( getSceneStyle ) style = getSceneStyle ( props ) ;
114125
115- const optionals = { } ;
116- if ( getSceneStyle ) optionals . style = getSceneStyle ( props ) ;
126+ const isVertical = direction === "vertical" ;
127+
128+ if ( typeof ( animationStyle ) === 'undefined' ) {
129+ animationStyle = ( isVertical ?
130+ NavigationCardStackStyleInterpolator . forVertical ( props ) :
131+ NavigationCardStackStyleInterpolator . forHorizontal ( props ) ) ;
132+ }
133+
134+ if ( typeof ( panHandlers ) === 'undefined' ) {
135+ panHandlers = panHandlers || ( isVertical ?
136+ NavigationCardStackPanResponder . forVertical ( props ) :
137+ NavigationCardStackPanResponder . forHorizontal ( props ) ) ;
138+ }
117139
118140 return (
119141 < NavigationCard
120142 { ...props }
121143 key = { 'card_' + key }
122- direction = { direction || 'horizontal' }
144+ style = { [ animationStyle , style ] }
123145 panHandlers = { panHandlers }
124146 renderScene = { this . _renderScene }
125- { ...optionals }
126147 />
127148 ) ;
128149 }
@@ -136,6 +157,6 @@ export default class DefaultRenderer extends Component {
136157const styles = StyleSheet . create ( {
137158 animatedView : {
138159 flex : 1 ,
139- backgroundColor :"transparent"
160+ backgroundColor : "transparent"
140161 } ,
141162} ) ;
0 commit comments