mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-31 08:08:19 +08:00
@@ -1,87 +1,89 @@
|
|||||||
import 'package:PiliPlus/common/widgets/gesture/horizontal_drag_gesture_recognizer.dart';
|
import 'package:PiliPlus/common/widgets/gesture/horizontal_drag_gesture_recognizer.dart';
|
||||||
import 'package:PiliPlus/utils/platform_utils.dart';
|
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
|
|
||||||
mixin ImageGestureRecognizerMixin on GestureRecognizer {
|
|
||||||
int? _pointer;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void addPointer(PointerDownEvent event, {bool isPointerAllowed = true}) {
|
|
||||||
if (_pointer == event.pointer) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_pointer = event.pointer;
|
|
||||||
if (isPointerAllowed) {
|
|
||||||
super.addPointer(event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class ImageHorizontalDragGestureRecognizer
|
class ImageHorizontalDragGestureRecognizer
|
||||||
extends CustomHorizontalDragGestureRecognizer
|
extends CustomHorizontalDragGestureRecognizer {
|
||||||
with ImageGestureRecognizerMixin {
|
|
||||||
ImageHorizontalDragGestureRecognizer({
|
ImageHorizontalDragGestureRecognizer({
|
||||||
super.debugOwner,
|
super.debugOwner,
|
||||||
super.supportedDevices,
|
super.supportedDevices,
|
||||||
super.allowedButtonsFilter,
|
super.allowedButtonsFilter,
|
||||||
});
|
});
|
||||||
|
|
||||||
static final double _touchSlop = PlatformUtils.isDesktop
|
int? _pointer;
|
||||||
? kPrecisePointerHitSlop
|
|
||||||
: 3.0;
|
|
||||||
|
|
||||||
@override
|
bool _reset = true;
|
||||||
DeviceGestureSettings get gestureSettings => _gestureSettings;
|
bool _hasAcceptedOrRejected = false;
|
||||||
final _gestureSettings = DeviceGestureSettings(touchSlop: _touchSlop);
|
|
||||||
|
|
||||||
bool isAtLeftEdge = false;
|
bool isAtLeftEdge = false;
|
||||||
bool isAtRightEdge = false;
|
bool isAtRightEdge = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void addPointer(PointerDownEvent event, {bool isPointerAllowed = true}) {
|
||||||
|
if (_pointer == event.pointer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!_reset &&
|
||||||
|
_pointer != event.pointer &&
|
||||||
|
isPointerAllowed &&
|
||||||
|
!_hasAcceptedOrRejected) {
|
||||||
|
rejectGesture(_pointer!);
|
||||||
|
_pointer = event.pointer;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_reset = false;
|
||||||
|
_pointer = event.pointer;
|
||||||
|
if (isPointerAllowed) {
|
||||||
|
super.addPointer(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void setAtBothEdges() {
|
void setAtBothEdges() {
|
||||||
isAtLeftEdge = isAtRightEdge = true;
|
isAtLeftEdge = isAtRightEdge = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isEdgeAllowed(double dx) {
|
bool _isEdgeAllowed(double dx) {
|
||||||
if ((initialPosition!.dx - dx).abs() < _touchSlop) return true;
|
|
||||||
if (isAtLeftEdge) {
|
if (isAtLeftEdge) {
|
||||||
if (isAtRightEdge) {
|
if (isAtRightEdge) {
|
||||||
return _hasAcceptedOrChecked = true;
|
return true;
|
||||||
}
|
}
|
||||||
_hasAcceptedOrChecked = true;
|
|
||||||
return initialPosition!.dx < dx;
|
return initialPosition!.dx < dx;
|
||||||
} else if (isAtRightEdge) {
|
} else if (isAtRightEdge) {
|
||||||
_hasAcceptedOrChecked = true;
|
|
||||||
return initialPosition!.dx > dx;
|
return initialPosition!.dx > dx;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
void handleEvent(PointerEvent event) {
|
|
||||||
if (!_hasAcceptedOrChecked &&
|
|
||||||
event is PointerMoveEvent &&
|
|
||||||
_pointer == event.pointer) {
|
|
||||||
if (!_isEdgeAllowed(event.position.dx)) {
|
|
||||||
rejectGesture(event.pointer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
super.handleEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool _hasAcceptedOrChecked = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void acceptGesture(int pointer) {
|
void acceptGesture(int pointer) {
|
||||||
_hasAcceptedOrChecked = true;
|
_hasAcceptedOrRejected = true;
|
||||||
super.acceptGesture(pointer);
|
super.acceptGesture(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void rejectGesture(int pointer) {
|
||||||
|
_hasAcceptedOrRejected = true;
|
||||||
|
super.rejectGesture(pointer);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void stopTrackingPointer(int pointer) {
|
void stopTrackingPointer(int pointer) {
|
||||||
_hasAcceptedOrChecked = false;
|
_reset = true;
|
||||||
|
_hasAcceptedOrRejected = false;
|
||||||
|
|
||||||
isAtLeftEdge = false;
|
isAtLeftEdge = false;
|
||||||
isAtRightEdge = false;
|
isAtRightEdge = false;
|
||||||
super.stopTrackingPointer(pointer);
|
super.stopTrackingPointer(pointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool hasSufficientGlobalDistanceToAccept(
|
||||||
|
PointerDeviceKind pointerDeviceKind,
|
||||||
|
double? deviceTouchSlop,
|
||||||
|
) {
|
||||||
|
return super.hasSufficientGlobalDistanceToAccept(
|
||||||
|
pointerDeviceKind,
|
||||||
|
deviceTouchSlop,
|
||||||
|
) &&
|
||||||
|
_isEdgeAllowed(lastPosition.global.dx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user