mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-28 17:29:16 +08:00
feat(Swipe): improve swipe threshold (#6003)
This commit is contained in:
parent
a72942f31a
commit
14299a2011
@ -199,6 +199,7 @@ export default createComponent({
|
||||
if (!this.touchable) return;
|
||||
|
||||
this.clear();
|
||||
this.touchStartTime = Date.now();
|
||||
this.touchStart(event);
|
||||
this.correctPosition();
|
||||
},
|
||||
@ -217,23 +218,28 @@ export default createComponent({
|
||||
onTouchEnd() {
|
||||
if (!this.touchable || !this.swiping) return;
|
||||
|
||||
if (this.delta && this.isCorrectDirection) {
|
||||
const { size, delta } = this;
|
||||
const duration = Date.now() - this.touchStartTime;
|
||||
const speed = delta / duration;
|
||||
const shouldSwipe = Math.abs(speed) > 0.25 || Math.abs(delta) > size / 2;
|
||||
|
||||
if (shouldSwipe && this.isCorrectDirection) {
|
||||
const offset = this.vertical ? this.offsetY : this.offsetX;
|
||||
|
||||
let pace = 0;
|
||||
|
||||
if (this.loop) {
|
||||
pace = offset > 0 ? (this.delta > 0 ? -1 : 1) : 0;
|
||||
pace = offset > 0 ? (delta > 0 ? -1 : 1) : 0;
|
||||
} else {
|
||||
pace = -Math[this.delta > 0 ? 'ceil' : 'floor'](
|
||||
this.delta / this.size
|
||||
);
|
||||
pace = -Math[delta > 0 ? 'ceil' : 'floor'](delta / size);
|
||||
}
|
||||
|
||||
this.move({
|
||||
pace,
|
||||
emitChange: true,
|
||||
});
|
||||
} else if (delta) {
|
||||
this.move({ pace: 0 });
|
||||
}
|
||||
|
||||
this.swiping = false;
|
||||
@ -280,12 +286,12 @@ export default createComponent({
|
||||
|
||||
// auto move first and last swipe in loop mode
|
||||
if (loop) {
|
||||
if (children[0]) {
|
||||
if (children[0] && targetOffset !== minOffset) {
|
||||
const outRightBound = targetOffset < minOffset;
|
||||
children[0].offset = outRightBound ? trackSize : 0;
|
||||
}
|
||||
|
||||
if (children[count - 1]) {
|
||||
if (children[count - 1] && targetOffset !== 0) {
|
||||
const outLeftBound = targetOffset > 0;
|
||||
children[count - 1].offset = outLeftBound ? -trackSize : 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user