@@ -27,28 +27,25 @@ var ScrollableTabView = React.createClass({
2727
2828 componentWillMount ( ) {
2929 this . state . scrollValue . addListener ( ( { value} ) => {
30- this . refs [ TAB_BAR_REF ] . setAnimationValue ( value ) ;
30+ this . refs [ TAB_BAR_REF ] &&
31+ this . refs [ TAB_BAR_REF ] . setAnimationValue ( value ) ;
3132 } ) ;
3233
3334 var release = ( e , gestureState ) => {
3435 var relativeGestureDistance = gestureState . dx / deviceWidth ,
3536 lastPageIndex = this . props . children . length - 1 ,
36- vx = gestureState . vx ,
37- newPage = this . state . currentPage ;
37+ vx = gestureState . vx ;
3838
39- if ( this . state . currentPage !== lastPageIndex &&
40- ( relativeGestureDistance < - 0.5 || ( relativeGestureDistance < 0 && vx <= 0.5 ) ) ) {
39+ if ( relativeGestureDistance < - 0.5 || ( relativeGestureDistance < 0 && vx <= 0.5 ) ) {
4140 newPage = newPage + 1 ;
42- } else if ( this . state . currentPage !== 0 &&
43- ( relativeGestureDistance > 0.5 || ( relativeGestureDistance > 0 && vx >= 0.5 ) ) ) {
41+ } else if ( relativeGestureDistance > 0.5 || ( relativeGestureDistance > 0 && vx >= 0.5 ) ) {
4442 newPage = newPage - 1 ;
4543 }
4644
4745 this . props . hasTouch && this . props . hasTouch ( false ) ;
4846 this . goToPage ( newPage ) ;
4947 }
5048
51-
5249 this . _panResponder = PanResponder . create ( {
5350 // Claim responder if it's a horizontal pan
5451 onMoveShouldSetPanResponder : ( e , gestureState ) => {
@@ -71,16 +68,10 @@ var ScrollableTabView = React.createClass({
7168 var dx = gestureState . dx ;
7269 var lastPageIndex = this . props . children . length - 1 ;
7370
74- if ( this . state . currentPage === 0 && dx > 0 ) {
75- // Don't set the spring if we're on the first page and trying to move before it
76- } else if ( this . state . currentPage === lastPageIndex && dx < 0 ) {
77- // Don't set the spring if we're already on the last page and trying to move to the next
78- } else {
79- // This is awkward because when we are scrolling we are offsetting the underlying view
80- // to the left (-x)
81- var offsetX = dx - ( this . state . currentPage * deviceWidth ) ;
82- this . state . scrollValue . setValue ( - 1 * offsetX / deviceWidth ) ;
83- }
71+ // This is awkward because when we are scrolling we are offsetting the underlying view
72+ // to the left (-x)
73+ var offsetX = dx - ( this . state . currentPage * deviceWidth ) ;
74+ this . state . scrollValue . setValue ( - 1 * offsetX / deviceWidth ) ;
8475 } ,
8576 } ) ;
8677 } ,
@@ -95,13 +86,12 @@ var ScrollableTabView = React.createClass({
9586 } ) ;
9687
9788 Animated . spring ( this . state . scrollValue , { toValue : pageNumber , friction : 10 , tension : 50 } ) . start ( ) ;
98- this . setState ( { currentPage : pageNumber } ) ;
9989 } ,
10090
10191 renderTabBar ( props ) {
10292 if ( this . props . renderTabBar === false ) {
10393 return null ;
104- else if ( this . props . renderTabBar ) {
94+ } else if ( this . props . renderTabBar ) {
10595 return React . cloneElement ( this . props . renderTabBar ( ) , props ) ;
10696 } else {
10797 return < DefaultTabBar { ...props } /> ;
0 commit comments