Skip to content

Commit

Permalink
fix: should set viewLength to the content size, without paddings
Browse files Browse the repository at this point in the history
  • Loading branch information
Berton Zhu committed Jun 24, 2021
1 parent a12dd90 commit ce0cdb1
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions packages/react-swipeable-views/src/SwipeableViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ const axisProperties = {
y: 'clientHeight',
'y-reverse': 'clientHeight',
},
padding: {
x: ['paddingLeft', 'paddingRight'],
'x-reverse': ['paddingRight', 'paddingLeft'],
y: ['paddingTop', 'paddingBottom'],
'y-reverse': ['paddingBottom', 'paddingTop'],
},
};

function createTransition(property, options) {
Expand Down Expand Up @@ -363,8 +369,13 @@ class SwipeableViews extends React.Component {
const { axis } = this.props;

const touch = applyRotationMatrix(event.touches[0], axis);
const rootStyle = window.getComputedStyle(this.rootNode);

this.viewLength =
this.rootNode.getBoundingClientRect()[axisProperties.length[axis]] -
parseInt(rootStyle[axisProperties.padding[axis][0]], 10) -
parseInt(rootStyle[axisProperties.padding[axis][1]], 10);

this.viewLength = this.rootNode.getBoundingClientRect()[axisProperties.length[axis]];
this.startX = touch.pageX;
this.lastX = touch.pageX;
this.vx = 0;
Expand All @@ -382,7 +393,6 @@ class SwipeableViews extends React.Component {
.split('(')[1]
.split(')')[0]
.split(',');
const rootStyle = window.getComputedStyle(this.rootNode);

const tranformNormalized = applyRotationMatrix(
{
Expand All @@ -392,11 +402,7 @@ class SwipeableViews extends React.Component {
axis,
);

this.startIndex =
-tranformNormalized.pageX /
(this.viewLength -
parseInt(rootStyle.paddingLeft, 10) -
parseInt(rootStyle.paddingRight, 10)) || 0;
this.startIndex = -tranformNormalized.pageX / this.viewLength;
}
};

Expand Down

0 comments on commit ce0cdb1

Please sign in to comment.