@@ -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,49 @@ var BASE_STYLES = {
4948 } ,
5049} ;
5150
51+ var caches = { }
52+ var opacityRatio = 100 ;
53+
5254// There are 3 stages: left, center, right. All previous navigation
5355// items are in the left stage. The current navigation item is in the
5456// center stage. All upcoming navigation items are in the right stage.
5557// Another way to think of the stages is in terms of transitions. When
5658// we move forward in the navigation stack, we perform a
5759// right-to-center transition on the new navigation item and a
5860// 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- } ;
61+ function calcStyles ( screenWidth ) {
62+ const Stages = {
63+ Left : {
64+ Title : merge ( BASE_STYLES . Title , { left : - screenWidth / 2 , opacity : 0 } ) ,
65+ LeftButton : merge ( BASE_STYLES . LeftButton , { left : - screenWidth / 3 , opacity : 1 } ) ,
66+ RightButton : merge ( BASE_STYLES . RightButton , { left : screenWidth / 3 , opacity : 0 } ) ,
67+ } ,
68+ Center : {
69+ Title : merge ( BASE_STYLES . Title , { left : 0 , opacity : 1 } ) ,
70+ LeftButton : merge ( BASE_STYLES . LeftButton , { left : 0 , opacity : 1 } ) ,
71+ RightButton : merge ( BASE_STYLES . RightButton , { left : 2 * screenWidth / 3 - 0 , opacity : 1 } ) ,
72+ } ,
73+ Right : {
74+ Title : merge ( BASE_STYLES . Title , { left : screenWidth / 2 , opacity : 0 } ) ,
75+ LeftButton : merge ( BASE_STYLES . LeftButton , { left : 0 , opacity : 0 } ) ,
76+ RightButton : merge ( BASE_STYLES . RightButton , { left : screenWidth , opacity : 0 } ) ,
77+ } ,
78+ }
7679
80+ const Interpolators = {
81+ // Animating *into* the center stage from the right
82+ RightToCenter : buildSceneInterpolators ( Stages . Right , Stages . Center ) ,
83+ // Animating out of the center stage, to the left
84+ CenterToLeft : buildSceneInterpolators ( Stages . Center , Stages . Left ) ,
85+ // Both stages (animating *past* the center stage)
86+ RightToLeft : buildSceneInterpolators ( Stages . Right , Stages . Left ) ,
87+ }
7788
78- var opacityRatio = 100 ;
89+ return {
90+ Stages,
91+ Interpolators
92+ }
93+ } ;
7994
8095function buildSceneInterpolators ( startStyles , endStyles ) {
8196 return {
@@ -134,22 +149,25 @@ function buildSceneInterpolators(startStyles, endStyles) {
134149 } ;
135150}
136151
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- } ;
152+ function getStyles ( ) {
153+ const screenWidth = Dimensions . get ( 'window' ) . width
154+ if ( ! caches [ screenWidth ] ) {
155+ caches [ screenWidth ] = calcStyles ( screenWidth )
156+ }
145157
158+ return caches [ screenWidth ]
159+ }
146160
147161module . exports = {
148162 General : {
149163 NavBarHeight : NAV_BAR_HEIGHT ,
150164 StatusBarHeight : STATUS_BAR_HEIGHT ,
151165 TotalNavHeight : NAV_HEIGHT ,
152166 } ,
153- Interpolators,
154- Stages,
167+ get Interpolators ( ) {
168+ return getStyles ( ) . Interpolators
169+ } ,
170+ get Stages ( ) {
171+ return getStyles ( ) . Stages
172+ } ,
155173} ;
0 commit comments