Skip to content

Commit edd5973

Browse files
M-i-k-e-lethanshar
authored andcommitted
Feat/improve pan (#467)
* Add some comments * Add shouldAnimateDismiss * Revert shouldAnimateDismiss
1 parent 64206b0 commit edd5973

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/components/panningViews/panDismissibleView.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class PanDismissibleView extends PureComponent {
144144
const {directions} = this.props;
145145
if (this.swipe.x || this.swipe.y) {
146146
const {isRight, isDown} = this.getDismissAnimationDirection();
147-
this.animateDismiss(isRight, isDown);
147+
this._animateDismiss(isRight, isDown);
148148
} else {
149149
const endValue = {x: Math.round(this.left), y: Math.round(this.top)};
150150
if (
@@ -154,7 +154,7 @@ class PanDismissibleView extends PureComponent {
154154
(directions.includes(PanningProvider.Directions.DOWN) && endValue.y >= this.thresholdY)
155155
) {
156156
const {isRight, isDown} = this.getDismissAnimationDirection();
157-
this.animateDismiss(isRight, isDown);
157+
this._animateDismiss(isRight, isDown);
158158
} else {
159159
this.animateToInitialPosition();
160160
}
@@ -226,7 +226,23 @@ class PanDismissibleView extends PureComponent {
226226
return {isRight, isDown};
227227
};
228228

229-
animateDismiss = (isRight, isDown) => {
229+
// Send undefined to not animate in the horizontal\vertical direction
230+
// isRight === true --> animate to the right
231+
// isRight === false --> animate to the left
232+
// isDown === true --> animate to the bottom
233+
// isDown === false --> animate to the top
234+
animateDismiss = () => {
235+
const {directions = []} = this.props;
236+
const hasUp = directions.includes(PanningProvider.Directions.UP);
237+
const hasRight = directions.includes(PanningProvider.Directions.RIGHT);
238+
const hasLeft = directions.includes(PanningProvider.Directions.LEFT);
239+
const hasDown = !hasUp && !hasLeft && !hasRight; // default
240+
const verticalDismiss = hasDown ? true : hasUp ? false : undefined;
241+
const horizontalDismiss = hasRight ? true : hasLeft ? false : undefined;
242+
this._animateDismiss(horizontalDismiss, verticalDismiss);
243+
};
244+
245+
_animateDismiss = (isRight, isDown) => {
230246
const {animTranslateX, animTranslateY} = this.state;
231247
const {duration} = this.props.animationOptions;
232248
const animations = [];

0 commit comments

Comments
 (0)