@@ -100,6 +100,12 @@ const axisProperties = {
100100 y : 'clientHeight' ,
101101 'y-reverse' : 'clientHeight' ,
102102 } ,
103+ padding : {
104+ x : [ 'paddingLeft' , 'paddingRight' ] ,
105+ 'x-reverse' : [ 'paddingRight' , 'paddingLeft' ] ,
106+ y : [ 'paddingTop' , 'paddingBottom' ] ,
107+ 'y-reverse' : [ 'paddingBottom' , 'paddingTop' ] ,
108+ } ,
103109} ;
104110
105111function createTransition ( property , options ) {
@@ -363,8 +369,13 @@ class SwipeableViews extends React.Component {
363369 const { axis } = this . props ;
364370
365371 const touch = applyRotationMatrix ( event . touches [ 0 ] , axis ) ;
372+ const rootStyle = window . getComputedStyle ( this . rootNode ) ;
373+
374+ this . viewLength =
375+ this . rootNode . getBoundingClientRect ( ) [ axisProperties . length [ axis ] ] -
376+ parseInt ( rootStyle [ axisProperties . padding [ axis ] [ 0 ] ] , 10 ) -
377+ parseInt ( rootStyle [ axisProperties . padding [ axis ] [ 1 ] ] , 10 ) ;
366378
367- this . viewLength = this . rootNode . getBoundingClientRect ( ) [ axisProperties . length [ axis ] ] ;
368379 this . startX = touch . pageX ;
369380 this . lastX = touch . pageX ;
370381 this . vx = 0 ;
@@ -382,7 +393,6 @@ class SwipeableViews extends React.Component {
382393 . split ( '(' ) [ 1 ]
383394 . split ( ')' ) [ 0 ]
384395 . split ( ',' ) ;
385- const rootStyle = window . getComputedStyle ( this . rootNode ) ;
386396
387397 const tranformNormalized = applyRotationMatrix (
388398 {
@@ -392,11 +402,7 @@ class SwipeableViews extends React.Component {
392402 axis ,
393403 ) ;
394404
395- this . startIndex =
396- - tranformNormalized . pageX /
397- ( this . viewLength -
398- parseInt ( rootStyle . paddingLeft , 10 ) -
399- parseInt ( rootStyle . paddingRight , 10 ) ) || 0 ;
405+ this . startIndex = - tranformNormalized . pageX / this . viewLength ;
400406 }
401407 } ;
402408
0 commit comments