@@ -12,22 +12,49 @@ import 'events.dart';
12
12
import 'recognizer.dart' ;
13
13
import 'velocity_tracker.dart' ;
14
14
15
+ /// Signature for when [MultiDragGestureRecognizer] recognizes the start of a drag gesture.
15
16
typedef Drag GestureMultiDragStartCallback (Point position);
16
17
17
- class Drag {
18
+ /// Interface for receiving updates about drags from a [MultiDragGestureRecognizer] .
19
+ abstract class Drag {
20
+ /// The pointer has moved by the given offset.
18
21
void move (Offset offset) { }
22
+
23
+ /// The pointer is no longer in contact with the screen and was moving at a
24
+ /// given velocity when it stopped contacting the screen.
19
25
void end (Velocity velocity) { }
26
+
27
+ /// The input from the pointer is no longer directed towards this receiver.
28
+ ///
29
+ /// For example, the user might have been interrupted by a system-modal dialog
30
+ /// in the middle of the drag.
20
31
void cancel () { }
21
32
}
22
33
34
+ /// Per-pointer state for a [MultiDragGestureRecognizer] .
35
+ ///
36
+ /// A [MultiDragGestureRecognizer] tracks each pointer separately. The state for
37
+ /// each pointer is a subclass of [MultiDragPointerState] .
23
38
abstract class MultiDragPointerState {
24
- MultiDragPointerState (this .initialPosition);
39
+ /// Creates per-pointer state for a [MultiDragGestureRecognizer] .
40
+ ///
41
+ /// The [initialPosition] argument must not be null.
42
+ MultiDragPointerState (this .initialPosition) {
43
+ assert (initialPosition != null );
44
+ }
25
45
46
+ /// The global coordinates of the pointer when the pointer contacted the screen.
26
47
final Point initialPosition;
27
48
28
49
final VelocityTracker _velocityTracker = new VelocityTracker ();
29
50
Drag _client;
30
51
52
+ /// The offset of the pointer from the last position that was reported to the client.
53
+ ///
54
+ /// After the pointer contacts the screen, the pointer might move some
55
+ /// distance before this movement will be recognized as a drag. This field
56
+ /// accumulates that movement so that we can report it to the client after
57
+ /// the drag starts.
31
58
Offset get pendingDelta => _pendingDelta;
32
59
Offset _pendingDelta = Offset .zero;
33
60
@@ -39,6 +66,7 @@ abstract class MultiDragPointerState {
39
66
_arenaEntry = entry;
40
67
}
41
68
69
+ /// Resolve this pointer's entry in the [GestureArenaManager] with the given disposition.
42
70
void resolve (GestureDisposition disposition) {
43
71
_arenaEntry.resolve (disposition);
44
72
}
@@ -115,12 +143,35 @@ abstract class MultiDragPointerState {
115
143
_arenaEntry = null ;
116
144
}
117
145
146
+ /// Releases any resources used by the object.
118
147
void dispose () {
119
148
assert (() { _pendingDelta = null ; return true ; });
120
149
}
121
150
}
122
151
152
+ /// Recognizes movement on a per-pointer basis.
153
+ ///
154
+ /// In contrast to [HorizontalDragGestureRecognizer] ,
155
+ /// [VerticalDragGestureRecognizer] , and [PanGestureRecognizer] ,
156
+ /// [MultiDragGestureRecognizer] watches each pointer separately, which means
157
+ /// multiple drags can be recognized concurrently if multiple pointers are in
158
+ /// contact with the screen.
159
+ ///
160
+ /// [MultiDragGestureRecognizer] is not intended to be used directly. Instead,
161
+ /// consider using one of its subclasses to recognize specific types for drag
162
+ /// gestures.
163
+ ///
164
+ /// See also:
165
+ ///
166
+ /// * [HorizontalMultiDragGestureRecognizer]
167
+ /// * [VerticalMultiDragGestureRecognizer]
168
+ /// * [ImmediateMultiDragGestureRecognizer]
169
+ /// * [DelayedMultiDragGestureRecognizer]
123
170
abstract class MultiDragGestureRecognizer <T extends MultiDragPointerState > extends GestureRecognizer {
171
+ /// Called when this class recognizes the start of a drag gesture.
172
+ ///
173
+ /// The remaining notifications for this drag gesture are delivered to the
174
+ /// [Drag] object returned by this callback.
124
175
GestureMultiDragStartCallback onStart;
125
176
126
177
Map <int , T > _pointers = < int , T > {};
@@ -133,13 +184,15 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
133
184
assert (! _pointers.containsKey (event.pointer));
134
185
T state = createNewPointerState (event);
135
186
_pointers[event.pointer] = state;
136
- GestureBinding .instance.pointerRouter.addRoute (event.pointer, handleEvent );
187
+ GestureBinding .instance.pointerRouter.addRoute (event.pointer, _handleEvent );
137
188
state._setArenaEntry (GestureBinding .instance.gestureArena.add (event.pointer, this ));
138
189
}
139
190
191
+ /// Subclasses should override this function to create per-pointer state
192
+ /// objects to track the pointer associated with the given event.
140
193
T createNewPointerState (PointerDownEvent event);
141
194
142
- void handleEvent (PointerEvent event) {
195
+ void _handleEvent (PointerEvent event) {
143
196
assert (_pointers != null );
144
197
assert (event.pointer != null );
145
198
assert (event.timeStamp != null );
@@ -203,7 +256,7 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
203
256
void _removeState (int pointer) {
204
257
assert (_pointers != null );
205
258
assert (_pointers.containsKey (pointer));
206
- GestureBinding .instance.pointerRouter.removeRoute (pointer, handleEvent );
259
+ GestureBinding .instance.pointerRouter.removeRoute (pointer, _handleEvent );
207
260
_pointers[pointer].dispose ();
208
261
_pointers.remove (pointer);
209
262
}
@@ -215,10 +268,8 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
215
268
_pointers = null ;
216
269
super .dispose ();
217
270
}
218
-
219
271
}
220
272
221
-
222
273
class _ImmediatePointerState extends MultiDragPointerState {
223
274
_ImmediatePointerState (Point initialPosition) : super (initialPosition);
224
275
@@ -235,6 +286,16 @@ class _ImmediatePointerState extends MultiDragPointerState {
235
286
}
236
287
}
237
288
289
+ /// Recognizes movement both horizontally and vertically on a per-pointer basis.
290
+ ///
291
+ /// In contrast to [PanGestureRecognizer] , [ImmediateMultiDragGestureRecognizer]
292
+ /// watches each pointer separately, which means multiple drags can be
293
+ /// recognized concurrently if multiple pointers are in contact with the screen.
294
+ ///
295
+ /// See also:
296
+ ///
297
+ /// * [PanGestureRecognizer]
298
+ /// * [DelayedMultiDragGestureRecognizer]
238
299
class ImmediateMultiDragGestureRecognizer extends MultiDragGestureRecognizer <_ImmediatePointerState > {
239
300
@override
240
301
_ImmediatePointerState createNewPointerState (PointerDownEvent event) {
@@ -262,6 +323,16 @@ class _HorizontalPointerState extends MultiDragPointerState {
262
323
}
263
324
}
264
325
326
+ /// Recognizes movement in the horizontal direction on a per-pointer basis.
327
+ ///
328
+ /// In contrast to [HorizontalDragGestureRecognizer] ,
329
+ /// [HorizontalMultiDragGestureRecognizer] watches each pointer separately,
330
+ /// which means multiple drags can be recognized concurrently if multiple
331
+ /// pointers are in contact with the screen.
332
+ ///
333
+ /// See also:
334
+ ///
335
+ /// * [HorizontalDragGestureRecognizer]
265
336
class HorizontalMultiDragGestureRecognizer extends MultiDragGestureRecognizer <_HorizontalPointerState > {
266
337
@override
267
338
_HorizontalPointerState createNewPointerState (PointerDownEvent event) {
@@ -289,6 +360,16 @@ class _VerticalPointerState extends MultiDragPointerState {
289
360
}
290
361
}
291
362
363
+ /// Recognizes movement in the vertical direction on a per-pointer basis.
364
+ ///
365
+ /// In contrast to [VerticalDragGestureRecognizer] ,
366
+ /// [VerticalMultiDragGestureRecognizer] watches each pointer separately,
367
+ /// which means multiple drags can be recognized concurrently if multiple
368
+ /// pointers are in contact with the screen.
369
+ ///
370
+ /// See also:
371
+ ///
372
+ /// * [VerticalDragGestureRecognizer]
292
373
class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer <_VerticalPointerState > {
293
374
@override
294
375
_VerticalPointerState createNewPointerState (PointerDownEvent event) {
@@ -299,7 +380,6 @@ class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_Ver
299
380
String toStringShort () => 'vertical multidrag' ;
300
381
}
301
382
302
-
303
383
class _DelayedPointerState extends MultiDragPointerState {
304
384
_DelayedPointerState (Point initialPosition, Duration delay) : super (initialPosition) {
305
385
assert (delay != null );
@@ -348,13 +428,36 @@ class _DelayedPointerState extends MultiDragPointerState {
348
428
}
349
429
}
350
430
431
+ /// Recognizes movement both horizontally and vertically on a per-pointer basis after a delay.
432
+ ///
433
+ /// In constrast to [ImmediateMultiDragGestureRecognizer] ,
434
+ /// [DelayedMultiDragGestureRecognizer] waits for a [delay] before recognizing
435
+ /// the drag. If the pointer moves more than [kTouchSlop] before the delay
436
+ /// expires, the gesture is not recognized.
437
+ ///
438
+ /// In contrast to [PanGestureRecognizer] , [DelayedMultiDragGestureRecognizer]
439
+ /// watches each pointer separately, which means multiple drags can be
440
+ /// recognized concurrently if multiple pointers are in contact with the screen.
441
+ ///
442
+ /// See also:
443
+ ///
444
+ /// * [PanGestureRecognizer]
445
+ /// * [ImmediateMultiDragGestureRecognizer]
351
446
class DelayedMultiDragGestureRecognizer extends MultiDragGestureRecognizer <_DelayedPointerState > {
447
+ /// Creates a drag recognizer that works on a per-pointer basis after a delay.
448
+ ///
449
+ /// In order for a drag to be recognized by this recognizer, the pointer must
450
+ /// remain in the same place for [delay] (up to [kTouchSlop] ). The [delay]
451
+ /// defaults to [kLongPressTimeout] to match [LongPressGestureRecognizer] but
452
+ /// can be changed for specific behaviors.
352
453
DelayedMultiDragGestureRecognizer ({
353
454
Duration delay: kLongPressTimeout
354
455
}) : _delay = delay {
355
456
assert (delay != null );
356
457
}
357
458
459
+ /// The amount of time the pointer must remain in the same place for the drag
460
+ /// to be recognized.
358
461
Duration get delay => _delay;
359
462
Duration _delay;
360
463
set delay (Duration value) {
0 commit comments