cleanup swipes

pull/2269/head
Steven Lageveen 2 weeks ago
parent decf4ee07a
commit 92d17e7b57

@ -31,11 +31,6 @@ class HorizontalSwipeRecognizer extends HorizontalDragGestureRecognizer {
super.addAllowedPointer(event);
}
double _slopFor(PointerEvent event) {
final kind = _pointerKind ?? event.kind;
return computeHitSlop(kind, gestureSettings);
}
@override
void handleEvent(PointerEvent event) {
if (!_resolvedDirection &&
@ -47,7 +42,8 @@ class HorizontalSwipeRecognizer extends HorizontalDragGestureRecognizer {
if (deltaX != 0.0) {
final logicalDelta = deltaX * allowedSign;
_accumulatedDelta += logicalDelta;
final slop = _slopFor(event);
final slop =
computeHitSlop(_pointerKind ?? event.kind, gestureSettings);
if (_accumulatedDelta.abs() > slop) {
_resolvedDirection = true;
if (_accumulatedDelta < 0) {

@ -51,7 +51,16 @@ class _ReplySwipeState extends State<ReplySwipe>
setState(() => _dragX = clamped);
final crossed = _dragX >= widget.thresholdPx;
if (widget.hapticOnThreshold && crossed && !_thresholdBuzzed) {
HapticFeedback.selectionClick();
final future = HapticFeedback.selectionClick();
assert(() {
future.then(
(_) => debugPrint('ReplySwipe: selectionClick succeeded'),
onError: (Object error, StackTrace stack) {
debugPrint('ReplySwipe: selectionClick failed: $error');
},
);
return true;
}());
_thresholdBuzzed = true;
}
if (!crossed) _thresholdBuzzed = false;
@ -87,9 +96,9 @@ class _ReplySwipeState extends State<ReplySwipe>
final allowedSign = widget.leftToRight ? -1 : 1;
final sign = allowedSign.toDouble();
final progress = (_dragX / widget.maxDragPx).clamp(0.0, 1.0).toDouble();
final backgroundBuilder = widget.backgroundBuilder;
return RawGestureDetector(
behavior: HitTestBehavior.deferToChild,
gestures: {
HorizontalSwipeRecognizer:
GestureRecognizerFactoryWithHandlers<HorizontalSwipeRecognizer>(
@ -120,13 +129,14 @@ class _ReplySwipeState extends State<ReplySwipe>
child: Stack(
alignment: Alignment.center,
children: [
Positioned.fill(
child: widget.backgroundBuilder!(
context,
widget.leftToRight,
progress,
if (backgroundBuilder != null)
Positioned.fill(
child: backgroundBuilder(
context,
widget.leftToRight,
progress,
),
),
),
Transform.translate(
offset: Offset(sign * _dragX, 0.0),
child: widget.child,

@ -194,9 +194,10 @@ class _FullScreenPopGestureDetectorState<T>
@override
void didChangeDependencies() {
super.didChangeDependencies();
_recognizer.gestureSettings = MediaQuery.maybeGestureSettingsOf(context);
final textDirection = Directionality.of(context);
_recognizer.allowedSign = textDirection == TextDirection.rtl ? -1 : 1;
_recognizer
..gestureSettings = MediaQuery.maybeGestureSettingsOf(context)
..allowedSign = textDirection == TextDirection.rtl ? -1 : 1;
}
/// Dispose the recognizer and ensure the navigator ends any active gesture.

Loading…
Cancel
Save