mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-20 03:06:59 +08:00
@@ -0,0 +1,51 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart' show TransformationController;
|
||||
|
||||
class ImageHorizontalDragGestureRecognizer
|
||||
extends HorizontalDragGestureRecognizer {
|
||||
ImageHorizontalDragGestureRecognizer({
|
||||
super.debugOwner,
|
||||
super.supportedDevices,
|
||||
super.allowedButtonsFilter,
|
||||
required this.width,
|
||||
required this.transformationController,
|
||||
});
|
||||
|
||||
Offset? _initialPosition;
|
||||
|
||||
final double width;
|
||||
final TransformationController transformationController;
|
||||
|
||||
@override
|
||||
void addAllowedPointer(PointerDownEvent event) {
|
||||
super.addAllowedPointer(event);
|
||||
_initialPosition = event.position;
|
||||
}
|
||||
|
||||
bool _isBoundaryAllowed() {
|
||||
if (_initialPosition == null) {
|
||||
return true;
|
||||
}
|
||||
final scale = transformationController.value.row0[0];
|
||||
if (scale <= 1.0) {
|
||||
return true;
|
||||
}
|
||||
final double xOffset = transformationController.value.row0[3];
|
||||
final double boundaryEnd = width * scale;
|
||||
final int xPos = (boundaryEnd + xOffset).round();
|
||||
return (boundaryEnd.round() == xPos &&
|
||||
lastPosition.global.dx > _initialPosition!.dx) ||
|
||||
(width.round() == xPos &&
|
||||
lastPosition.global.dx < _initialPosition!.dx);
|
||||
}
|
||||
|
||||
@override
|
||||
bool hasSufficientGlobalDistanceToAccept(
|
||||
PointerDeviceKind pointerDeviceKind,
|
||||
double? deviceTouchSlop,
|
||||
) {
|
||||
return globalDistanceMoved.abs() >
|
||||
computeHitSlop(pointerDeviceKind, gestureSettings) &&
|
||||
_isBoundaryAllowed();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user