-
Notifications
You must be signed in to change notification settings - Fork 5
Adds custom LongPress gesture recognizer (Resolves #54) #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…d of duplicating it for creating CustomLongPressGestureRecognizer
@dodgog Could you please confirm if this resolves the stutter and lag issue you encountered? |
@kirkbyo can you check if this PR solves the problem? |
@rutvik110 your videos shows small pans, but it doesn't show you activating a long press. Can you show a video demonstrating that long presses are easy to use, too? For example, maybe this change makes it difficult to long press because your finger naturally moves more than 5 pixels. |
|
||
const double _kTouchSlop = 5.0; | ||
|
||
class CustomLongPressGestureRecognizer extends LongPressGestureRecognizer { |
There was a problem hiding this comment.
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.
@@ -0,0 +1,22 @@ | |||
import 'package:flutter/gestures.dart'; | |||
|
|||
const Duration _kLongPressTimeout = Duration(milliseconds: 250); |
There was a problem hiding this comment.
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.
); | ||
|
||
@override | ||
// TODO: implement preAcceptSlopTolerance |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Will be removed.
@kirkbyo and I tested this PR, thank you. It looks like a huge improvement: the long tap gesture is very rarely in the way now. |
@dodgog We are talking abt exposing those at |
I think this needs to be there. Currently, there's an issue where the long press gesture set on s_demo.mp4We may need to introduce something within Probably a way to know if the render object being hit tested is related to our |
@matthew-carroll The usual long press gestures on the PXL_20230930_063751229.2.mp4But there's this another issue that I came across which affects long press on other widgets within |
@rutvik110 it's not clear to me what the problem is that you claim you found. Can you state the problem explicitly? |
Sure! So currently the |
@rutvik110 I see a description of things that can happen but I still don't see a clear problem statement. What's the desired behavior? What's the actual behavior? |
@matthew-carroll Lets go back to this example. The white container is one of the widgets within the But with the current implementation of our custom long press recognizer within the This is because when both the gestures are in the gesture arena, our custom one wins early as it's exceeding its deadline period(250ms) before the default deadline period(500ms) set for long press gestures recognizers in Flutter. Due to this, any standard long press gestures on any other widgets never get a chance to win in the arena and thus their long press callbacks are never called. This creates issues when we want to detect long press on any other widgets within the One way to tackle this is that our custom recognizer should only recognize the long press but shouldn't go into accepted state when it exceeds it deadline. This will give other recognizers a chance to win in the arena and not block them. I think for our case, we should be fine with that. But I wanna hear from others before I go further. PXL_20230930_063751229.2.mp4 |
Ok, the concise answer to my question is this: Situation: a page in the viewport has a long press callback, in addition to the custom long press callback that's installed on the viewport, itself. Expected behavior: ??? - this is actually unclear. If you have two long press callbacks, which one is supposed to win in that scenario? Actual behavior: The viewport long-press always gets the callback because its time limit is 250ms vs standard Flutter 500ms. |
So, what should we do in this case? Do we want to detect the long press on the IMO, It's likely that we don't want that. If we take an example of text selection within the |
Adds custom LongPress gesture recognizer (Resolves #54)
The Issue:
When the user executes tiny swipes (imagine a flick of approximately 10 pixels of translation distance) the viewport will seemingly stutter and start the scrolling movement with a noticeable delay of the order of 100ms.
Demo:
https://www.loom.com/share/82d9eeff4f1c4928825fcfb489c13a6c
Removing onLongPress start as a callback on the PageListViewportGestures resolves the stutter and delay issue.
The presence of the onLongPress recognizer in the Flutter gesture arena is not eliminated until the gesture exceeds a certain translation distance delta(18.0px) and/or enough time(500ms) has passed.
Gesture metrics as found here.
We would like the swiping gestures to be recognized as onScale as soon as possible to reduce the stutter and lag being noticed.
The Solution:
To achieve this, this PR adds
CustomLongPressGestureRecognizer
which is aLongPressGestureRecognizer
but with adjusted deadline period (250ms) andpreAcceptSlopTolerance
(5.0) to make it loose out early in the arena and let other gestures win.With these changes, the swiping gesture events are recognized early on as
onScale
to start the scrolling as soon as possible without any stutter and delay.Demo (Tested on Ipad):
viewport_scroll.mp4
Changes:
CustomLongPressGestureRecognizer
, a custom long press gesture recognizer with adjusted gesturedeadline
period andpreAcceptSlopTolerance
.RawGestureDetector
within thePageListViewportGestures
and includesCustomLongPressGestureRecognizer
to handle long press gestures,onLongPressStart
,onLongPressMoveUpdate
onLongPressEnd
.