@@ -13,7 +13,6 @@ import Dimensions from 'ReactDimensions';
1313import buildStyleInterpolator from './polyfills/buildStyleInterpolator' ;
1414import merge from './polyfills/merge' ;
1515
16- var SCREEN_WIDTH = Dimensions . get ( 'window' ) . width ;
1716var NAV_BAR_HEIGHT = 44 ;
1817var STATUS_BAR_HEIGHT = 20 ;
1918var NAV_HEIGHT = NAV_BAR_HEIGHT + STATUS_BAR_HEIGHT ;
@@ -49,33 +48,48 @@ var BASE_STYLES = {
4948 } ,
5049} ;
5150
51+ var opacityRatio = 100 ;
52+
5253// There are 3 stages: left, center, right. All previous navigation
5354// items are in the left stage. The current navigation item is in the
5455// center stage. All upcoming navigation items are in the right stage.
5556// Another way to think of the stages is in terms of transitions. When
5657// we move forward in the navigation stack, we perform a
5758// right-to-center transition on the new navigation item and a
5859// center-to-left transition on the current navigation item.
59- var Stages = {
60- Left : {
61- Title : merge ( BASE_STYLES . Title , { left : - SCREEN_WIDTH / 2 , opacity : 0 } ) ,
62- LeftButton : merge ( BASE_STYLES . LeftButton , { left : - SCREEN_WIDTH / 3 , opacity : 1 } ) ,
63- RightButton : merge ( BASE_STYLES . RightButton , { left : SCREEN_WIDTH / 3 , opacity : 0 } ) ,
64- } ,
65- Center : {
66- Title : merge ( BASE_STYLES . Title , { left : 0 , opacity : 1 } ) ,
67- LeftButton : merge ( BASE_STYLES . LeftButton , { left : 0 , opacity : 1 } ) ,
68- RightButton : merge ( BASE_STYLES . RightButton , { left : 2 * SCREEN_WIDTH / 3 - 0 , opacity : 1 } ) ,
69- } ,
70- Right : {
71- Title : merge ( BASE_STYLES . Title , { left : SCREEN_WIDTH / 2 , opacity : 0 } ) ,
72- LeftButton : merge ( BASE_STYLES . LeftButton , { left : 0 , opacity : 0 } ) ,
73- RightButton : merge ( BASE_STYLES . RightButton , { left : SCREEN_WIDTH , opacity : 0 } ) ,
74- } ,
75- } ;
60+ function calcStyles ( screenWidth ) {
61+ const Stages = {
62+ Left : {
63+ Title : merge ( BASE_STYLES . Title , { left : - screenWidth / 2 , opacity : 0 } ) ,
64+ LeftButton : merge ( BASE_STYLES . LeftButton , { left : - screenWidth / 3 , opacity : 1 } ) ,
65+ RightButton : merge ( BASE_STYLES . RightButton , { left : screenWidth / 3 , opacity : 0 } ) ,
66+ } ,
67+ Center : {
68+ Title : merge ( BASE_STYLES . Title , { left : 0 , opacity : 1 } ) ,
69+ LeftButton : merge ( BASE_STYLES . LeftButton , { left : 0 , opacity : 1 } ) ,
70+ RightButton : merge ( BASE_STYLES . RightButton , { left : 2 * screenWidth / 3 - 0 , opacity : 1 } ) ,
71+ } ,
72+ Right : {
73+ Title : merge ( BASE_STYLES . Title , { left : screenWidth / 2 , opacity : 0 } ) ,
74+ LeftButton : merge ( BASE_STYLES . LeftButton , { left : 0 , opacity : 0 } ) ,
75+ RightButton : merge ( BASE_STYLES . RightButton , { left : screenWidth , opacity : 0 } ) ,
76+ } ,
77+ }
7678
79+ const Interpolators = {
80+ // Animating *into* the center stage from the right
81+ RightToCenter : buildSceneInterpolators ( Stages . Right , Stages . Center ) ,
82+ // Animating out of the center stage, to the left
83+ CenterToLeft : buildSceneInterpolators ( Stages . Center , Stages . Left ) ,
84+ // Both stages (animating *past* the center stage)
85+ RightToLeft : buildSceneInterpolators ( Stages . Right , Stages . Left ) ,
86+ }
7787
78- var opacityRatio = 100 ;
88+ return {
89+ Stages,
90+ Interpolators
91+ }
92+ } ;
7993
8094function buildSceneInterpolators ( startStyles , endStyles ) {
8195 return {
@@ -134,22 +148,25 @@ function buildSceneInterpolators(startStyles, endStyles) {
134148 } ;
135149}
136150
137- var Interpolators = {
138- // Animating *into* the center stage from the right
139- RightToCenter : buildSceneInterpolators ( Stages . Right , Stages . Center ) ,
140- // Animating out of the center stage, to the left
141- CenterToLeft : buildSceneInterpolators ( Stages . Center , Stages . Left ) ,
142- // Both stages (animating *past* the center stage)
143- RightToLeft : buildSceneInterpolators ( Stages . Right , Stages . Left ) ,
144- } ;
151+ function getStyles ( ) {
152+ const screenWidth = Dimensions . get ( 'window' ) . width
153+ if ( ! caches [ screenWidth ] ) {
154+ caches [ screenWidth ] = calcStyles ( screenWidth )
155+ }
145156
157+ return caches [ screenWidth ]
158+ }
146159
147160module . exports = {
148161 General : {
149162 NavBarHeight : NAV_BAR_HEIGHT ,
150163 StatusBarHeight : STATUS_BAR_HEIGHT ,
151164 TotalNavHeight : NAV_HEIGHT ,
152165 } ,
153- Interpolators,
154- Stages,
166+ get Interpolators ( ) {
167+ return getStyles ( ) . Interpolators
168+ } ,
169+ get Stages ( ) {
170+ return getStyles ( ) . Stages
171+ } ,
155172} ;
0 commit comments