Skip to content

Commit 0e8e8bb

Browse files
committed
Finish dartdoc for gestures.dart (flutter#3994)
1 parent 8339427 commit 0e8e8bb

File tree

8 files changed

+313
-25
lines changed

8 files changed

+313
-25
lines changed

packages/flutter/lib/src/gestures/drag.dart

+25
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,22 @@ bool _isFlingGesture(Velocity velocity) {
6363
}
6464

6565
abstract class _DragGestureRecognizer<T extends dynamic> extends OneSequenceGestureRecognizer {
66+
/// A pointer has contacted the screen and might begin to move.
6667
GestureDragDownCallback onDown;
68+
69+
/// A pointer has contacted the screen and has begun to move.
6770
GestureDragStartCallback onStart;
71+
72+
/// A pointer that is in contact with the screen and moving has moved again.
6873
_GesturePolymorphicUpdateCallback<T> onUpdate;
74+
75+
/// A pointer that was previously in contact with the screen and moving is no
76+
/// longer in contact with the screen and was moving at a specific velocity
77+
/// when it stopped contacting the screen.
6978
GestureDragEndCallback onEnd;
79+
80+
/// Signature for when the pointer that previously triggered [onDown] did not
81+
/// complete.
7082
GestureDragCancelCallback onCancel;
7183

7284
_DragState _state = _DragState.ready;
@@ -168,6 +180,10 @@ abstract class _DragGestureRecognizer<T extends dynamic> extends OneSequenceGest
168180
/// Recognizes movement in the vertical direction.
169181
///
170182
/// Used for vertical scrolling.
183+
///
184+
/// See also:
185+
///
186+
/// * [VerticalMultiDragGestureRecognizer]
171187
class VerticalDragGestureRecognizer extends _DragGestureRecognizer<double> {
172188
@override
173189
double get _initialPendingDragDelta => 0.0;
@@ -185,6 +201,10 @@ class VerticalDragGestureRecognizer extends _DragGestureRecognizer<double> {
185201
/// Recognizes movement in the horizontal direction.
186202
///
187203
/// Used for horizontal scrolling.
204+
///
205+
/// See also:
206+
///
207+
/// * [HorizontalMultiDragGestureRecognizer]
188208
class HorizontalDragGestureRecognizer extends _DragGestureRecognizer<double> {
189209
@override
190210
double get _initialPendingDragDelta => 0.0;
@@ -200,6 +220,11 @@ class HorizontalDragGestureRecognizer extends _DragGestureRecognizer<double> {
200220
}
201221

202222
/// Recognizes movement both horizontally and vertically.
223+
///
224+
/// See also:
225+
///
226+
/// * [ImmediateMultiDragGestureRecognizer]
227+
/// * [DelayedMultiDragGestureRecognizer]
203228
class PanGestureRecognizer extends _DragGestureRecognizer<Offset> {
204229
@override
205230
Offset get _initialPendingDragDelta => Offset.zero;

packages/flutter/lib/src/gestures/multidrag.dart

+111-8
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,49 @@ import 'events.dart';
1212
import 'recognizer.dart';
1313
import 'velocity_tracker.dart';
1414

15+
/// Signature for when [MultiDragGestureRecognizer] recognizes the start of a drag gesture.
1516
typedef Drag GestureMultiDragStartCallback(Point position);
1617

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.
1821
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.
1925
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.
2031
void cancel() { }
2132
}
2233

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].
2338
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+
}
2545

46+
/// The global coordinates of the pointer when the pointer contacted the screen.
2647
final Point initialPosition;
2748

2849
final VelocityTracker _velocityTracker = new VelocityTracker();
2950
Drag _client;
3051

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.
3158
Offset get pendingDelta => _pendingDelta;
3259
Offset _pendingDelta = Offset.zero;
3360

@@ -39,6 +66,7 @@ abstract class MultiDragPointerState {
3966
_arenaEntry = entry;
4067
}
4168

69+
/// Resolve this pointer's entry in the [GestureArenaManager] with the given disposition.
4270
void resolve(GestureDisposition disposition) {
4371
_arenaEntry.resolve(disposition);
4472
}
@@ -115,12 +143,35 @@ abstract class MultiDragPointerState {
115143
_arenaEntry = null;
116144
}
117145

146+
/// Releases any resources used by the object.
118147
void dispose() {
119148
assert(() { _pendingDelta = null; return true; });
120149
}
121150
}
122151

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]
123170
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.
124175
GestureMultiDragStartCallback onStart;
125176

126177
Map<int, T> _pointers = <int, T>{};
@@ -133,13 +184,15 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
133184
assert(!_pointers.containsKey(event.pointer));
134185
T state = createNewPointerState(event);
135186
_pointers[event.pointer] = state;
136-
GestureBinding.instance.pointerRouter.addRoute(event.pointer, handleEvent);
187+
GestureBinding.instance.pointerRouter.addRoute(event.pointer, _handleEvent);
137188
state._setArenaEntry(GestureBinding.instance.gestureArena.add(event.pointer, this));
138189
}
139190

191+
/// Subclasses should override this function to create per-pointer state
192+
/// objects to track the pointer associated with the given event.
140193
T createNewPointerState(PointerDownEvent event);
141194

142-
void handleEvent(PointerEvent event) {
195+
void _handleEvent(PointerEvent event) {
143196
assert(_pointers != null);
144197
assert(event.pointer != null);
145198
assert(event.timeStamp != null);
@@ -203,7 +256,7 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
203256
void _removeState(int pointer) {
204257
assert(_pointers != null);
205258
assert(_pointers.containsKey(pointer));
206-
GestureBinding.instance.pointerRouter.removeRoute(pointer, handleEvent);
259+
GestureBinding.instance.pointerRouter.removeRoute(pointer, _handleEvent);
207260
_pointers[pointer].dispose();
208261
_pointers.remove(pointer);
209262
}
@@ -215,10 +268,8 @@ abstract class MultiDragGestureRecognizer<T extends MultiDragPointerState> exten
215268
_pointers = null;
216269
super.dispose();
217270
}
218-
219271
}
220272

221-
222273
class _ImmediatePointerState extends MultiDragPointerState {
223274
_ImmediatePointerState(Point initialPosition) : super(initialPosition);
224275

@@ -235,6 +286,16 @@ class _ImmediatePointerState extends MultiDragPointerState {
235286
}
236287
}
237288

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]
238299
class ImmediateMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_ImmediatePointerState> {
239300
@override
240301
_ImmediatePointerState createNewPointerState(PointerDownEvent event) {
@@ -262,6 +323,16 @@ class _HorizontalPointerState extends MultiDragPointerState {
262323
}
263324
}
264325

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]
265336
class HorizontalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_HorizontalPointerState> {
266337
@override
267338
_HorizontalPointerState createNewPointerState(PointerDownEvent event) {
@@ -289,6 +360,16 @@ class _VerticalPointerState extends MultiDragPointerState {
289360
}
290361
}
291362

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]
292373
class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_VerticalPointerState> {
293374
@override
294375
_VerticalPointerState createNewPointerState(PointerDownEvent event) {
@@ -299,7 +380,6 @@ class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer<_Ver
299380
String toStringShort() => 'vertical multidrag';
300381
}
301382

302-
303383
class _DelayedPointerState extends MultiDragPointerState {
304384
_DelayedPointerState(Point initialPosition, Duration delay) : super(initialPosition) {
305385
assert(delay != null);
@@ -348,13 +428,36 @@ class _DelayedPointerState extends MultiDragPointerState {
348428
}
349429
}
350430

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]
351446
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.
352453
DelayedMultiDragGestureRecognizer({
353454
Duration delay: kLongPressTimeout
354455
}) : _delay = delay {
355456
assert(delay != null);
356457
}
357458

459+
/// The amount of time the pointer must remain in the same place for the drag
460+
/// to be recognized.
358461
Duration get delay => _delay;
359462
Duration _delay;
360463
set delay(Duration value) {

0 commit comments

Comments
 (0)