-
-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: Update scale event with custom recognizer #3782
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?
Changes from all commits
b95ce23
4b8bc31
487e579
01e81cd
8701f00
8b7105a
9723f97
28e24bf
9c2acf6
975bbdb
bea44fc
d6f78cb
987f977
f7b7153
cbc2333
6162fb3
528e665
f945eea
8ddce28
1ce9618
c18fd0c
bf69b48
5369f79
c6e9b98
0d10332
4a8f8ad
4441db2
47eb614
64fe308
42f0d18
d5b0086
77df27a
bd6bd89
d6995a8
9a010d3
f1cd9eb
b78a284
0ff1070
b21afe3
bf1398a
58e986f
38d5e8c
7e65ee6
2aa5be5
be53a17
51b2308
31813e5
5d58587
b34e0ca
233d991
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,11 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:flame/components.dart'; | ||
| import 'package:flame/events.dart'; | ||
| import 'package:flame/src/events/flame_drag_adapter.dart'; | ||
| import 'package:flame/src/events/tagged_component.dart'; | ||
| import 'package:flame/src/game/flame_game.dart'; | ||
| import 'package:flame/src/game/game_render_box.dart'; | ||
| import 'package:flutter/gestures.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:meta/meta.dart'; | ||
|
|
||
| class MultiDragDispatcherKey implements ComponentKey { | ||
|
|
@@ -28,32 +27,10 @@ class MultiDragDispatcher extends Component implements MultiDragListener { | |
| /// The record of all components currently being touched. | ||
| final Set<TaggedComponent<DragCallbacks>> _records = {}; | ||
|
|
||
| final _dragUpdateController = StreamController<DragUpdateEvent>.broadcast( | ||
| sync: true, | ||
| ); | ||
|
|
||
| Stream<DragUpdateEvent> get onUpdate => _dragUpdateController.stream; | ||
|
|
||
| final _dragStartController = StreamController<DragStartEvent>.broadcast( | ||
| sync: true, | ||
| ); | ||
|
|
||
| Stream<DragStartEvent> get onStart => _dragStartController.stream; | ||
|
|
||
| final _dragEndController = StreamController<DragEndEvent>.broadcast( | ||
| sync: true, | ||
| ); | ||
|
|
||
| Stream<DragEndEvent> get onEnd => _dragEndController.stream; | ||
|
|
||
| final _dragCancelController = StreamController<DragCancelEvent>.broadcast( | ||
| sync: true, | ||
| ); | ||
|
|
||
| Stream<DragCancelEvent> get onCancel => _dragCancelController.stream; | ||
|
|
||
| FlameGame get game => parent! as FlameGame; | ||
|
|
||
| bool _shouldBeRemoved = false; | ||
|
|
||
| /// Called when the user initiates a drag gesture, for example by touching the | ||
| /// screen and then moving the finger. | ||
| /// | ||
|
|
@@ -134,39 +111,59 @@ class MultiDragDispatcher extends Component implements MultiDragListener { | |
| @internal | ||
| @override | ||
| void handleDragStart(int pointerId, DragStartDetails details) { | ||
| if (_shouldBeRemoved) { | ||
| return; | ||
| } | ||
| final event = DragStartEvent(pointerId, game, details); | ||
| onDragStart(event); | ||
| _dragStartController.add(event); | ||
| } | ||
|
|
||
| @internal | ||
| @override | ||
| void handleDragUpdate(int pointerId, DragUpdateDetails details) { | ||
| final event = DragUpdateEvent(pointerId, game, details); | ||
| onDragUpdate(event); | ||
| _dragUpdateController.add(event); | ||
| } | ||
|
|
||
| @internal | ||
| @override | ||
| void handleDragEnd(int pointerId, DragEndDetails details) { | ||
| final event = DragEndEvent(pointerId, details); | ||
| onDragEnd(event); | ||
| _dragEndController.add(event); | ||
| _tryRemoving(); | ||
| } | ||
|
|
||
| @internal | ||
| @override | ||
| void handleDragCancel(int pointerId) { | ||
| final event = DragCancelEvent(pointerId); | ||
| onDragCancel(event); | ||
| _dragCancelController.add(event); | ||
| _tryRemoving(); | ||
| } | ||
|
|
||
| void markForRemoval() { | ||
| _shouldBeRemoved = true; | ||
| _tryRemoving(); | ||
| } | ||
|
|
||
| bool _tryRemoving() { | ||
| // there's no more fingers | ||
| // that started dragging before _shouldBeRemoved flag was set to true. | ||
| if (_records.isEmpty && _shouldBeRemoved && isMounted) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it remove it directly even if there are fingers still left on the screen?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so the thought behind this is that removing immediately the recognizer would abruptly end currently performed gestures which sounds like unwanted behavior to me (but let me know if that's acceptable). I didn't check if removing immediately would do that though but I wrote a test for that so I can try and run the test if I just call removeFromParent immediately instead.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it should send out a cancel event for the gesture when this happens. |
||
| removeFromParent(); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| //#endregion | ||
|
|
||
| @override | ||
| void onMount() { | ||
| if (_tryRemoving()) { | ||
| return; | ||
| } | ||
|
|
||
| game.gestureDetectors.add<ImmediateMultiDragGestureRecognizer>( | ||
| ImmediateMultiDragGestureRecognizer.new, | ||
| (ImmediateMultiDragGestureRecognizer instance) { | ||
|
|
@@ -179,10 +176,6 @@ class MultiDragDispatcher extends Component implements MultiDragListener { | |
| void onRemove() { | ||
| game.gestureDetectors.remove<ImmediateMultiDragGestureRecognizer>(); | ||
| game.unregisterKey(const MultiDragDispatcherKey()); | ||
| _dragUpdateController.close(); | ||
| _dragCancelController.close(); | ||
| _dragStartController.close(); | ||
| _dragEndController.close(); | ||
| } | ||
|
|
||
| @override | ||
|
|
||
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.
Are these
hides really necessary?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.
might be leftover I'll check