11import React , { Component , PropTypes } from 'react' ;
2- import { View , Dimensions , StyleSheet , TouchableOpacity , Text , Platform , ScrollView , Animated , ViewPagerAndroid } from 'react-native' ;
2+ import {
3+ View ,
4+ Dimensions ,
5+ StyleSheet ,
6+ TouchableOpacity ,
7+ Text ,
8+ Platform ,
9+ ScrollView ,
10+ Animated ,
11+ ViewPagerAndroid
12+ } from 'react-native' ;
313import PureRenderMixin from 'react-addons-pure-render-mixin' ;
414
515
@@ -32,9 +42,9 @@ class ScrollableTabs extends Component {
3242 x : new Animated . Value ( - offset )
3343 } ;
3444 this . state . x . addListener ( ( e ) => {
35- if ( e . value % ( this . space + tabNavItemWidth ) == 0 ) {
45+ if ( e . value % ( this . space + tabNavItemWidth ) === 0 ) {
3646 let index = Math . abs ( e . value / ( this . space + tabNavItemWidth ) ) ;
37- typeof this . props . onPageChangedAndAnimateEnd == 'function' && this . props . onPageChangedAndAnimateEnd ( index ) ;
47+ typeof this . props . onPageChangedAndAnimateEnd === 'function' && this . props . onPageChangedAndAnimateEnd ( index , this . _isScrolling ( ) ) ;
3848 }
3949 } ) ;
4050 this . _navs = { } ;
@@ -82,18 +92,31 @@ class ScrollableTabs extends Component {
8292 }
8393
8494
95+ _isScrolling ( ) {
96+ return ( ) => this . _scrolling ;
97+ }
98+
8599 _onScroll ( e ) {
86100 const { x} = e . nativeEvent . contentOffset ;
87101 this . _animateScroll ( x ) ;
88102 }
89103
90104
91105 _onMomentumScrollBegin ( e ) {
106+ this . _scrolling = true ;
107+ const offsetX = e . nativeEvent . contentOffset . x ;
108+ this . _animateScroll ( offsetX ) ;
109+ }
110+
111+
112+ _onMomentumScrollEnd ( e ) {
113+ this . _scrolling = true ;
92114 const offsetX = e . nativeEvent . contentOffset . x ;
93115 const page = parseInt ( offsetX / width , 10 ) ;
94116 this . _animateScroll ( offsetX ) ;
95117 if ( page !== this . index ) {
96- typeof this . props . onPageChanged == 'function' && this . props . onPageChanged ( page ) ;
118+ this . _scrolling = false ;
119+ typeof this . props . onPageChanged === 'function' && this . props . onPageChanged ( page , this . _isScrolling ( ) ) ;
97120 }
98121 this . index = page ;
99122 }
@@ -102,10 +125,10 @@ class ScrollableTabs extends Component {
102125 _onPageSelected ( e ) {
103126 const { position} = e . nativeEvent ;
104127 this . index = position ;
105- if ( position == undefined ) {
106- return
128+ if ( position === undefined ) {
129+ return ;
107130 }
108- typeof this . props . onPageChanged == 'function' && this . props . onPageChanged ( position ) ;
131+ typeof this . props . onPageChanged === 'function' && this . props . onPageChanged ( position , this . _isScrolling ( ) ) ;
109132 }
110133
111134
@@ -133,7 +156,7 @@ class ScrollableTabs extends Component {
133156 _getActiveNavItemStyle ( opacity ) {
134157 return {
135158 borderTopColor : 'rgba(241,196,15,' + opacity + ')'
136- }
159+ } ;
137160 }
138161
139162
@@ -155,7 +178,7 @@ class ScrollableTabs extends Component {
155178
156179 </ View >
157180 </ TouchableOpacity >
158- )
181+ ) ;
159182 } ) ;
160183 }
161184
@@ -168,8 +191,8 @@ class ScrollableTabs extends Component {
168191 style = { styles . page } >
169192 { pageContent }
170193 </ View >
171- )
172- } )
194+ ) ;
195+ } ) ;
173196 }
174197
175198
@@ -204,7 +227,7 @@ class ScrollableTabs extends Component {
204227 { this . _renderChildren ( ) }
205228
206229 </ ScrollView >
207- )
230+ ) ;
208231 }
209232 return (
210233 < ViewPagerAndroid
@@ -217,7 +240,7 @@ class ScrollableTabs extends Component {
217240 { this . _renderChildren ( ) }
218241
219242 </ ViewPagerAndroid >
220- )
243+ ) ;
221244 }
222245
223246
@@ -241,7 +264,7 @@ class ScrollableTabs extends Component {
241264 { this . _renderPageScroll ( ) }
242265
243266 </ View >
244- )
267+ ) ;
245268 }
246269}
247270
0 commit comments