@@ -58,10 +58,13 @@ const ScrollableTabView = React.createClass({
5858 } ,
5959
6060 getInitialState ( ) {
61+ const width = Dimensions . get ( 'window' ) . width ;
62+ const initialOffset = width * this . props . initialPage ;
6163 return {
6264 currentPage : this . props . initialPage ,
6365 scrollValue : new Animated . Value ( this . props . initialPage ) ,
64- containerWidth : Dimensions . get ( 'window' ) . width ,
66+ scrollX : new Animated . Value ( initialOffset ) ,
67+ containerWidth : width ,
6568 sceneKeys : this . newSceneKeys ( { currentPage : this . props . initialPage , } ) ,
6669 } ;
6770 } ,
@@ -80,7 +83,7 @@ const ScrollableTabView = React.createClass({
8083 if ( Platform . OS === 'ios' ) {
8184 const offset = pageNumber * this . state . containerWidth ;
8285 if ( this . scrollView ) {
83- this . scrollView . scrollTo ( { x : offset , y : 0 , animated : ! this . props . scrollWithoutAnimation , } ) ;
86+ this . scrollView . getNode ( ) . scrollTo ( { x : offset , y : 0 , animated : ! this . props . scrollWithoutAnimation , } ) ;
8487 }
8588 } else {
8689 if ( this . scrollView ) {
@@ -142,21 +145,33 @@ const ScrollableTabView = React.createClass({
142145
143146 renderScrollableContent ( ) {
144147 if ( Platform . OS === 'ios' ) {
148+ //onScroll={(e) => {
149+ //const offsetX = e.nativeEvent.contentOffset.x;
150+ //if (offsetX === 0 && !this.scrollOnMountCalled) {
151+ //this.scrollOnMountCalled = true;
152+ //} else {
153+ //this._updateScrollValue(offsetX / this.state.containerWidth);
154+ //}
155+ //}}
156+
157+ //onPageScroll={(e) => {
158+ //const { offset, position, } = e.nativeEvent;
159+ //this._updateScrollValue(position + offset);
160+ //}}
145161 const scenes = this . _composeScenes ( ) ;
146- return < ScrollView
162+ return < Animated . ScrollView
147163 horizontal
148164 pagingEnabled
149165 automaticallyAdjustContentInsets = { false }
150166 contentOffset = { { x : this . props . initialPage * this . state . containerWidth , } }
151167 ref = { ( scrollView ) => { this . scrollView = scrollView ; } }
152- onScroll = { ( e ) => {
153- const offsetX = e . nativeEvent . contentOffset . x ;
154- if ( offsetX === 0 && ! this . scrollOnMountCalled ) {
155- this . scrollOnMountCalled = true ;
156- } else {
157- this . _updateScrollValue ( offsetX / this . state . containerWidth ) ;
158- }
159- } }
168+ onScroll = {
169+ Animated . event ( [ {
170+ nativeEvent : { contentOffset : { x : this . state . scrollX } }
171+ } ] , {
172+ useNativeDriver : true ,
173+ } )
174+ }
160175 onMomentumScrollBegin = { this . _onMomentumScrollBeginAndEnd }
161176 onMomentumScrollEnd = { this . _onMomentumScrollBeginAndEnd }
162177 scrollEventThrottle = { 16 }
@@ -169,7 +184,7 @@ const ScrollableTabView = React.createClass({
169184 { ...this . props . contentProps }
170185 >
171186 { scenes }
172- </ ScrollView > ;
187+ </ Animated . ScrollView > ;
173188 } else {
174189 const scenes = this . _composeScenes ( ) ;
175190 return < ViewPagerAndroid
@@ -179,10 +194,13 @@ const ScrollableTabView = React.createClass({
179194 onPageSelected = { this . _updateSelectedPage }
180195 keyboardDismissMode = "on-drag"
181196 scrollEnabled = { ! this . props . locked }
182- onPageScroll = { ( e ) => {
183- const { offset, position, } = e . nativeEvent ;
184- this . _updateScrollValue ( position + offset ) ;
185- } }
197+ onPageScroll = {
198+ Animated . event ( [ {
199+ nativeEvent : { contentOffset : { x : this . state . scrollX } }
200+ } ] , {
201+ useNativeDriver : true ,
202+ } )
203+ }
186204 ref = { ( scrollView ) => { this . scrollView = scrollView ; } }
187205 { ...this . props . contentProps }
188206 >
@@ -261,6 +279,7 @@ const ScrollableTabView = React.createClass({
261279 activeTab : this . state . currentPage ,
262280 scrollValue : this . state . scrollValue ,
263281 containerWidth : this . state . containerWidth ,
282+ scrollX : this . state . scrollX ,
264283 } ;
265284
266285 if ( this . props . tabBarBackgroundColor ) {
0 commit comments