mini-antui
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -84,2 +84,11 @@ { | ||
}, | ||
"vtabs/demo/index": { | ||
"enableWK": "YES", | ||
"enableDSL": "YES", | ||
"enableJSC": "YES", | ||
"defaultTitle": "纵向选项卡", | ||
"backgroundColor": 16119289, | ||
"pullRefresh": false, | ||
"allowsBounceVertical": false | ||
}, | ||
"stepper/demo/index": { | ||
@@ -86,0 +95,0 @@ "enableWK": "YES", |
Component({ | ||
data: { | ||
X: null, | ||
leftPos: 0, | ||
swiping: false | ||
swiping: false, | ||
holdSwipe: true | ||
}, | ||
@@ -11,11 +11,9 @@ props: { | ||
restore: false, | ||
index: null, | ||
holdSwipe: false | ||
index: null | ||
}, | ||
didUpdate: function didUpdate(prevProps) { | ||
var _props = this.props, | ||
restore = _props.restore, | ||
holdSwipe = _props.holdSwipe; | ||
didUpdate: function didUpdate(_prevProps, prevData) { | ||
var restore = this.props.restore; | ||
var holdSwipe = this.data.holdSwipe; | ||
if (restore === true || prevProps.holdSwipe === true && holdSwipe === false) { | ||
if (restore === true || prevData.holdSwipe === true && holdSwipe === false) { | ||
this.setData({ | ||
@@ -38,10 +36,10 @@ leftPos: 0, | ||
onSwipeStart: function onSwipeStart(e) { | ||
this.setData({ | ||
X: e.touches[0].pageX | ||
}); | ||
this.touchObject = { | ||
startX: e.touches[0].pageX, | ||
startY: e.touches[0].pageY | ||
}; | ||
var _props = this.props, | ||
index = _props.index, | ||
onSwipeStart = _props.onSwipeStart; | ||
var _props2 = this.props, | ||
index = _props2.index, | ||
onSwipeStart = _props2.onSwipeStart; | ||
if (onSwipeStart) { | ||
@@ -52,44 +50,97 @@ onSwipeStart({ index: index }); | ||
onSwipeMove: function onSwipeMove(e) { | ||
var touchObject = this.touchObject; | ||
var touchePoint = e.touches[0]; | ||
var leftPos = this.data.leftPos; | ||
// 滑动距离 | ||
var direction = e.touches[0].pageX - this.data.X; | ||
var newLeftPos = leftPos; | ||
// 左划 | ||
if (direction < 0) { | ||
newLeftPos = Math.max(direction, -this.props.right.length * 60); | ||
// 右划 | ||
} else { | ||
newLeftPos = 0; | ||
touchObject.endX = touchePoint.pageX; | ||
// 首次触发时,计算滑动角度 | ||
if (touchObject.direction === undefined) { | ||
var direction = 0; | ||
var xDist = touchObject.startX - touchePoint.pageX || 0; | ||
var yDist = touchObject.startY - touchePoint.pageY || 0; | ||
var r = Math.atan2(yDist, xDist); | ||
var swipeAngle = Math.round(r * 180 / Math.PI); | ||
if (swipeAngle < 0) { | ||
swipeAngle = 360 - Math.abs(swipeAngle); | ||
} | ||
if (swipeAngle <= 45 && swipeAngle >= 0) { | ||
direction = 1; | ||
} | ||
if (swipeAngle <= 360 && swipeAngle >= 315) { | ||
direction = 1; | ||
} | ||
if (swipeAngle >= 135 && swipeAngle <= 225) { | ||
direction = -1; | ||
} | ||
touchObject.direction = direction; | ||
} | ||
this.setData({ | ||
leftPos: newLeftPos, | ||
swiping: direction < 0 | ||
}); | ||
// 通过角度判断是左右方向 | ||
if (touchObject.direction !== 0) { | ||
var newLeftPos = leftPos; | ||
// 滑动距离 | ||
var distance = touchObject.endX - touchObject.startX; | ||
// 左划 | ||
if (distance < 0) { | ||
newLeftPos = Math.max(distance, -this.props.right.length * 60); | ||
// 右划 | ||
} else { | ||
newLeftPos = 0; | ||
} | ||
if (Math.abs(distance) > 10) { | ||
this.setData({ | ||
leftPos: newLeftPos, | ||
swiping: distance < 0 | ||
}); | ||
} | ||
} | ||
}, | ||
onSwipeEnd: function onSwipeEnd(e) { | ||
var leftPos = this.data.leftPos; | ||
var touchObject = this.touchObject; | ||
var direction = e.changedTouches[0].pageX - this.data.X; | ||
var newLeftPos = leftPos; | ||
if (direction < 0) { | ||
if (Math.abs(direction + leftPos) > this.props.right.length * 60 * 0.7) { | ||
newLeftPos = -this.props.right.length * 60; | ||
} else { | ||
newLeftPos = 0; | ||
if (touchObject.direction !== 0) { | ||
var touchePoint = e.changedTouches[0]; | ||
touchObject.endX = touchePoint.pageX; | ||
var leftPos = this.data.leftPos; | ||
var distance = touchObject.endX - touchObject.startX; | ||
var newLeftPos = leftPos; | ||
if (distance < 0) { | ||
if (Math.abs(distance + leftPos) > this.props.right.length * 60 * 0.7) { | ||
newLeftPos = -this.props.right.length * 60; | ||
} else { | ||
newLeftPos = 0; | ||
} | ||
} | ||
this.setData({ | ||
leftPos: newLeftPos, | ||
swiping: false | ||
}); | ||
} | ||
}, | ||
done: function done() { | ||
var _this = this; | ||
this.setData({ | ||
leftPos: newLeftPos, | ||
swiping: false, | ||
X: null | ||
holdSwipe: false | ||
}, function () { | ||
_this.setData({ | ||
holdSwipe: true | ||
}); | ||
}); | ||
}, | ||
onItemClick: function onItemClick(e) { | ||
var _this = this; | ||
var _this2 = this; | ||
var _props3 = this.props, | ||
onRightItemClick = _props3.onRightItemClick, | ||
holdSwipe = _props3.holdSwipe; | ||
var onRightItemClick = this.props.onRightItemClick; | ||
var holdSwipe = this.data.holdSwipe; | ||
@@ -102,3 +153,4 @@ if (onRightItemClick) { | ||
extra: this.props.extra, | ||
detail: this.props.right[index] | ||
detail: this.props.right[index], | ||
done: this.done.bind(this) | ||
}); | ||
@@ -109,3 +161,3 @@ } | ||
setTimeout(function () { | ||
_this.setData({ | ||
_this2.setData({ | ||
leftPos: 0, | ||
@@ -112,0 +164,0 @@ swiping: false |
{ | ||
"name": "mini-antui", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "小程序版AntUI", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
107
1752
115634