@@ -78,18 +78,24 @@ const ScrollableTabBar = React.createClass({
7878 } ,
7979
8080 updateTabPanel ( position , pageOffset ) {
81- const absolutePageOffset = pageOffset * this . _tabsMeasurements [ position ] . width ;
82- let newScrollX = this . _tabsMeasurements [ position ] . left + absolutePageOffset ;
83-
84- newScrollX -= this . props . scrollOffset ;
81+ const containerWidth = this . _containerMeasurements . width ;
82+ const tabWidth = this . _tabsMeasurements [ position ] . width ;
83+ const nextTabMeasurements = this . _tabsMeasurements [ position + 1 ] ;
84+ const nextTabWidth = nextTabMeasurements && nextTabMeasurements . width || 0 ;
85+ const tabOffset = this . _tabsMeasurements [ position ] . left ;
86+ const absolutePageOffset = pageOffset * tabWidth ;
87+ let newScrollX = tabOffset + absolutePageOffset ;
88+
89+ // center tab and smooth tab change (for when tabWidth changes a lot between two tabs)
90+ newScrollX -= ( containerWidth - ( 1 - pageOffset ) * tabWidth - pageOffset * nextTabWidth ) / 2 ;
8591 newScrollX = newScrollX >= 0 ? newScrollX : 0 ;
8692
8793 if ( Platform . OS === 'android' ) {
88- this . _scrollView . scrollTo ( { x : newScrollX , y : 0 , } ) ;
94+ this . _scrollView . scrollTo ( { x : newScrollX , y : 0 , animated : false , } ) ;
8995 } else {
9096 const rightBoundScroll = this . _tabContainerMeasurements . width - ( this . _containerMeasurements . width ) ;
9197 newScrollX = newScrollX > rightBoundScroll ? rightBoundScroll : newScrollX ;
92- this . _scrollView . scrollTo ( { x : newScrollX , y : 0 , } ) ;
98+ this . _scrollView . scrollTo ( { x : newScrollX , y : 0 , animated : false , } ) ;
9399 }
94100
95101 } ,
@@ -120,7 +126,7 @@ const ScrollableTabBar = React.createClass({
120126 const fontWeight = isTabActive ? 'bold' : 'normal' ;
121127
122128 return < TouchableOpacity
123- key = { name }
129+ key = { ` ${ name } _ ${ page } ` }
124130 ref = { 'tab_' + page }
125131 accessible = { true }
126132 accessibilityLabel = { name }
@@ -167,7 +173,6 @@ const ScrollableTabBar = React.createClass({
167173 showsHorizontalScrollIndicator = { false }
168174 showsVerticalScrollIndicator = { false }
169175 directionalLockEnabled = { true }
170- scrollEventThrottle = { 16 }
171176 bounces = { false }
172177 >
173178 < View
@@ -203,7 +208,6 @@ const styles = StyleSheet.create({
203208 height : 49 ,
204209 alignItems : 'center' ,
205210 justifyContent : 'center' ,
206- paddingBottom : 30 ,
207211 paddingLeft : 20 ,
208212 paddingRight : 20 ,
209213 } ,
0 commit comments