Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/src/custom_long_press_gesture_recognizer.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/gestures.dart';

const Duration _kLongPressTimeout = Duration(milliseconds: 250);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's stick constants below the class. No need to litter the top of this file with random values.

Please don't use leading "k"s, those "k"s don't tell us anything useful.

Please document each global property.


const double _kTouchSlop = 5.0;

class CustomLongPressGestureRecognizer extends LongPressGestureRecognizer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid naming things as "Custom" - that doesn't tell us anything about why we created this, or what it does differently.

Also, always include useful Dart Docs for public classes.

CustomLongPressGestureRecognizer({
Duration? duration,
super.postAcceptSlopTolerance,
super.supportedDevices,
super.debugOwner,
AllowedButtonsFilter? allowedButtonsFilter,
}) : super(
duration: duration ?? _kLongPressTimeout,
allowedButtonsFilter: allowedButtonsFilter,
);

@override
// TODO: implement preAcceptSlopTolerance
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this "TODO" still valid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Will be removed.

double? get preAcceptSlopTolerance => _kTouchSlop;
}
39 changes: 26 additions & 13 deletions lib/src/page_list_viewport_gestures.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:math';
import 'package:flutter/gestures.dart';
import 'package:flutter/physics.dart';
import 'package:flutter/widgets.dart';
import 'package:page_list_viewport/src/custom_long_press_gesture_recognizer.dart';

import 'logging.dart';
import 'page_list_viewport.dart';
Expand Down Expand Up @@ -300,19 +301,31 @@ class _PageListViewportGesturesState extends State<PageListViewportGestures> wit
onPointerDown: _onPointerDown,
onPointerUp: _onPointerUp,
onPointerCancel: _onPointerCancel,
child: GestureDetector(
onTapUp: widget.onTapUp,
onLongPressStart: widget.onLongPressStart,
onLongPressMoveUpdate: widget.onLongPressMoveUpdate,
onLongPressEnd: widget.onLongPressEnd,
onDoubleTapDown: widget.onDoubleTapDown,
onDoubleTap: widget.onDoubleTap,
onDoubleTapCancel: widget.onDoubleTapCancel,
onScaleStart: _onScaleStart,
onScaleUpdate: _onScaleUpdate,
onScaleEnd: _onScaleEnd,
supportedDevices: widget.panAndZoomPointerDevices,
child: widget.child,
child: RawGestureDetector(
gestures: {
CustomLongPressGestureRecognizer: GestureRecognizerFactoryWithHandlers<CustomLongPressGestureRecognizer>(
() => CustomLongPressGestureRecognizer(
supportedDevices: widget.panAndZoomPointerDevices,
),
(CustomLongPressGestureRecognizer instance) {
instance
..onLongPressEnd = widget.onLongPressEnd
..onLongPressStart = widget.onLongPressStart
..onLongPressMoveUpdate = widget.onLongPressMoveUpdate;
},
),
},
child: GestureDetector(
onTapUp: widget.onTapUp,
onDoubleTapDown: widget.onDoubleTapDown,
onDoubleTap: widget.onDoubleTap,
onDoubleTapCancel: widget.onDoubleTapCancel,
onScaleStart: _onScaleStart,
onScaleUpdate: _onScaleUpdate,
onScaleEnd: _onScaleEnd,
supportedDevices: widget.panAndZoomPointerDevices,
child: widget.child,
),
),
);
}
Expand Down