-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
Gesture recognizers hooks #190
Comments
I'm honestly not sure. In which situation would you need that? |
For example when you have a final tapRecognizer = useTapGestureRecognizer()
..onTap = () => print('Hello!');
return Text.rich(TextSpan(
text: 'Hello there! ',
children: [
TextSpan(
text: 'Tap me.',
recognizer: tapRecognizer,
),
],
)) |
What about: final recognizer = useGestureRecognizer(
onTap: () => print('hello'),
onLongPress: () => print('world'),
); I don't think that having one hook per class is a good API And we can technically use Text.rich(
TextSpan(
text: 'Hello there! ',
children: [
WidgetSpan(
child: GestureDetector(
onTap: () => print('hello'),
child: Text('Tap me')
)
),
],
),
), |
Hmm, I just thought as it would be nice to have the family of hooks more complete with gesture recognizers, as they need proper disposing, and also hooks are more than appropriate for this as the description says:
What do you think then? Should we (you) limit hooks provided OOTB (in this repository) only to those that manage some state or just to any that would "help manage a Widget life-cycle" with Flutter framework provided classes? |
I'm not against adding hooks to the core. But hooks aren't always the logical choice. In this case, I don't see a use-case for such a hook other than Similarly, to its core this family of hooks can be attributed as a We can also implement this T useDisposable<T>(T Function() cb, {List<Object> keys}) {
final obj = useMemoized(cb, keys);
assert((obj as dynamic).dispose is void Function(), '$T does not have a `void dispose()` method');
useEffect(() {
dynamic disposable = obj;
return disposable.dispose;
}, keys);
} If not for the fact that this hook isn't "sound" due to the lack of a |
Although I agree with @rrousselGit comments, I found that a I implemented a simple hook expecting a function that builds the gesture recognizer and just handles the recognizer disposal. I'm sharing to anyone looking for a solution. This is my first look at implementing a hook. It works for my case, hopefully it may work for someone else. This is how to use it:
and this is the code for the hook implementation:
I'm not 100% sure if this code works exactly the same as the |
Any updates on this? |
Gesture recognizers need to be disposed. Hooks for them would make using them correctly really simple.
I'm creating this issue to track which gesture recognizers still need a hook and which don't. I'm gonna start working on the Pull Requests.
GestureRecognizer
DoubleTapGestureRecognizer
MultiDragGestureRecognizer
DelayedMultiDragGestureRecognizer
HorizontalMultiDragGestureRecognizer
ImmediateMultiDragGestureRecognizer
VerticalMultiDragGestureRecognizer
MultiTapGestureRecognizer
OneSequenceGestureRecognizer
DragGestureRecognizer
HorizontalDragGestureRecognizer
PanGestureRecognizer
VerticalDragGestureRecognizer
EagerGestureRecognizer
ForcePressGestureRecognizer
PrimaryPointerGestureRecognizer
BaseTapGestureRecognizer
TapGestureRecognizer
Generic GestureRecognizer and TapGestureRecognizer hooks #191LongPressGestureRecognizer
ScaleGestureRecognizer
BTW I see GitHub likes to flatten my nested list. Here's a screenshot of the hierarchy:
The text was updated successfully, but these errors were encountered: