onPointerMove method
指针移动处理
Implementation
@override
bool? onPointerMove(PointerMoveEvent e) {
assert(velocityTracker != null);
// 添加触摸的数据,当触摸结束后会计算最终的速度
velocityTracker!.addPosition(e.timeStamp, e.position);
bool isActive = true;
// 指针首次移动会触发 onDragStart 事件,后续移动才触发 onDragUpdate 事件
if (isActiveDrag != true) {
final moveDelta = e.position - pointerDownEvent!.position;
// 移动范围需要到达一定幅度才触发拖拽
if (moveDelta.distance <= activeDelta) return false;
isActiveDrag = true;
// 确定拖拽方向
final direction = moveDelta.direction;
final angle = horizontalAngle;
if ((-angle <= direction && direction <= angle) ||
(direction <= -pi + angle || direction >= pi - angle)) {
_dragDireaction = e.delta.dx < 0
? AxisDirection.left
: AxisDirection.right;
} else {
_dragDireaction = e.delta.dy < 0
? AxisDirection.up
: AxisDirection.down;
}
if (triggerDrag) {
final result = onDragStart(
ElDragStartDetails(
pointerDownEvent: pointerDownEvent!,
dragDirection: dragDireaction,
),
);
// 若 onDragStart 返回 true,则关闭竞技场并忽略其他指针,反之将自身排除
if (result == true) {
ElPointerManager.isOpen = false;
ElPointerManager.eager(hashCode);
} else {
ElPointerManager.removePointer(hashCode);
isActive = false;
}
} else {
ElPointerManager.removePointer(hashCode);
isActive = false;
}
}
if (isActive) {
onDragUpdate(
DragUpdateDetails(
sourceTimeStamp: e.timeStamp,
globalPosition: e.position,
localPosition: e.localPosition,
delta: calcDelta(e.delta),
primaryDelta: calcPrimaryDelta(e.delta),
),
);
} else {
isActiveDrag = null;
velocityTracker = null;
}
return null;
}