1212
1313var DefaultTabBar = require ( './DefaultTabBar' ) ;
1414var deviceWidth = Dimensions . get ( 'window' ) . width ;
15- var TAB_BAR_REF = 'TAB_BAR' ;
1615
1716var ScrollableTabView = React . createClass ( {
1817 getDefaultProps ( ) {
@@ -26,15 +25,11 @@ var ScrollableTabView = React.createClass({
2625 } ,
2726
2827 componentWillMount ( ) {
29- this . state . scrollValue . addListener ( ( { value} ) => {
30- this . refs [ TAB_BAR_REF ] &&
31- this . refs [ TAB_BAR_REF ] . setAnimationValue ( value ) ;
32- } ) ;
33-
3428 var release = ( e , gestureState ) => {
3529 var relativeGestureDistance = gestureState . dx / deviceWidth ,
3630 lastPageIndex = this . props . children . length - 1 ,
37- vx = gestureState . vx ;
31+ vx = gestureState . vx ,
32+ newPage = this . state . currentPage ;
3833
3934 if ( relativeGestureDistance < - 0.5 || ( relativeGestureDistance < 0 && vx <= 0.5 ) ) {
4035 newPage = newPage + 1 ;
@@ -43,7 +38,7 @@ var ScrollableTabView = React.createClass({
4338 }
4439
4540 this . props . hasTouch && this . props . hasTouch ( false ) ;
46- this . goToPage ( newPage ) ;
41+ this . goToPage ( Math . max ( 0 , Math . min ( newPage , this . props . children . length - 1 ) ) ) ;
4742 }
4843
4944 this . _panResponder = PanResponder . create ( {
@@ -79,14 +74,14 @@ var ScrollableTabView = React.createClass({
7974 } ,
8075
8176 goToPage ( pageNumber ) {
82- if ( this . props . currentPage == pageNumber ) {
83- return ;
84- }
85-
8677 this . props . onChangeTab && this . props . onChangeTab ( {
8778 i : pageNumber , ref : this . props . children [ pageNumber ]
8879 } ) ;
8980
81+ this . setState ( {
82+ currentPage : pageNumber
83+ } ) ;
84+
9085 Animated . spring ( this . state . scrollValue , { toValue : pageNumber , friction : 10 , tension : 50 } ) . start ( ) ;
9186 } ,
9287
@@ -116,7 +111,7 @@ var ScrollableTabView = React.createClass({
116111 { this . renderTabBar ( { goToPage : this . goToPage ,
117112 tabs : this . props . children . map ( ( child ) => child . props . tabLabel ) ,
118113 activeTab : this . state . currentPage ,
119- ref : TAB_BAR_REF } ) }
114+ scrollValue : this . state . scrollValue } ) }
120115
121116 < Animated . View style = { [ sceneContainerStyle , { transform : [ { translateX} ] } ] }
122117 { ...this . _panResponder . panHandlers } >
0 commit comments