Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loadmore.vue touchmove 操作 新增 判断是否纵向滑动,优化 此组件和 swipe.vue 混合使用时抖动问题 #1383

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/loadmore/src/loadmore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</style>

<script type="text/babel">
/* eslint-disable radix */
import spinner from 'mint-ui/packages/spinner/src/spinner/fading-circle.vue';
export default {
name: 'mt-loadmore',
Expand Down Expand Up @@ -132,8 +133,10 @@
bottomDropped: false,
bottomReached: false,
direction: '',
startX: 0,
startY: 0,
startScrollTop: 0,
currentX: 0,
currentY: 0,
topStatus: '',
bottomStatus: ''
Expand Down Expand Up @@ -273,6 +276,7 @@
},

handleTouchStart(event) {
this.startX = event.touches[0].clientX;
this.startY = event.touches[0].clientY;
this.startScrollTop = this.getScrollTop(this.scrollEventTarget);
this.bottomReached = false;
Expand All @@ -290,7 +294,14 @@
if (this.startY < this.$el.getBoundingClientRect().top && this.startY > this.$el.getBoundingClientRect().bottom) {
return;
}
this.currentY = event.touches[0].clientY;
let touchesEvent = event.touches[0];
this.currentX = touchesEvent.clientX;
this.currentY = touchesEvent.clientY;
let moveX = Math.abs(this.currentX - this.startX);
let moveY = Math.abs(this.currentY - this.startY);
if (moveX * 2 > moveY) {
return;
}
let distance = (this.currentY - this.startY) / this.distanceIndex;
this.direction = distance > 0 ? 'down' : 'up';
if (typeof this.topMethod === 'function' && this.direction === 'down' &&
Expand Down
6 changes: 6 additions & 0 deletions packages/swipe/src/swipe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@
doOnTouchStart(event) {
if (this.noDrag) return;

this.$emit('touch-state', 'start');

var element = this.$el;
var dragState = this.dragState;
var touch = event.touches[0];
Expand Down Expand Up @@ -425,6 +427,8 @@
doOnTouchMove(event) {
if (this.noDrag) return;

this.$emit('touch-state', 'move');

var dragState = this.dragState;
var touch = event.touches[0];

Expand Down Expand Up @@ -461,6 +465,8 @@
doOnTouchEnd() {
if (this.noDrag) return;

this.$emit('touch-state', 'end');

var dragState = this.dragState;

var dragDuration = new Date() - dragState.startTime;
Expand Down