Introduce TapDownDetails and TapUpDetails (#4431)
We have these details objects for the same reason we now have drag details objects: future extensibility.
This commit is contained in:
parent
cd23ca1242
commit
7d9f8d903d
@ -108,7 +108,7 @@ class CardBuilder extends LazyBlockDelegate {
|
|||||||
CardModel cardModel = cardModels[index];
|
CardModel cardModel = cardModels[index];
|
||||||
return new GestureDetector(
|
return new GestureDetector(
|
||||||
key: cardModel.key,
|
key: cardModel.key,
|
||||||
onTapUp: (Point globalPosition) { onTapUp(cardModel.targetKey, globalPosition); },
|
onTapUp: (TapUpDetails details) { onTapUp(cardModel.targetKey, details.globalPosition); },
|
||||||
child: new Card(
|
child: new Card(
|
||||||
key: cardModel.targetKey,
|
key: cardModel.targetKey,
|
||||||
color: cardModel.color,
|
color: cardModel.color,
|
||||||
|
@ -56,7 +56,7 @@ class DragUpdateDetails {
|
|||||||
/// coordinates of [delta] and the other coordinate must be zero.
|
/// coordinates of [delta] and the other coordinate must be zero.
|
||||||
DragUpdateDetails({
|
DragUpdateDetails({
|
||||||
this.delta: Offset.zero,
|
this.delta: Offset.zero,
|
||||||
this.primaryDelta: 0.0
|
this.primaryDelta
|
||||||
}) {
|
}) {
|
||||||
assert(primaryDelta == null
|
assert(primaryDelta == null
|
||||||
|| (primaryDelta == delta.dx && delta.dy == 0.0)
|
|| (primaryDelta == delta.dx && delta.dy == 0.0)
|
||||||
@ -90,7 +90,7 @@ class DragEndDetails {
|
|||||||
/// Creates details for a [GestureDragEndCallback].
|
/// Creates details for a [GestureDragEndCallback].
|
||||||
///
|
///
|
||||||
/// The [velocity] argument must not be null.
|
/// The [velocity] argument must not be null.
|
||||||
DragEndDetails({ this.velocity: Velocity.zero }) {
|
DragEndDetails({ this.velocity }) {
|
||||||
assert(velocity != null);
|
assert(velocity != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,6 +100,9 @@ class DragEndDetails {
|
|||||||
|
|
||||||
/// Signature for when a pointer that was previously in contact with the screen
|
/// Signature for when a pointer that was previously in contact with the screen
|
||||||
/// and moving is no longer in contact with the screen.
|
/// and moving is no longer in contact with the screen.
|
||||||
|
///
|
||||||
|
/// The velocity at which the pointer was moving when it stopped contacting
|
||||||
|
/// the screen is available in the `details`.
|
||||||
typedef void GestureDragEndCallback(DragEndDetails details);
|
typedef void GestureDragEndCallback(DragEndDetails details);
|
||||||
|
|
||||||
/// Signature for when the pointer that previously triggered a
|
/// Signature for when the pointer that previously triggered a
|
||||||
|
@ -8,6 +8,7 @@ import 'dart:ui' show Point, Offset;
|
|||||||
import 'arena.dart';
|
import 'arena.dart';
|
||||||
import 'binding.dart';
|
import 'binding.dart';
|
||||||
import 'constants.dart';
|
import 'constants.dart';
|
||||||
|
import 'drag.dart';
|
||||||
import 'events.dart';
|
import 'events.dart';
|
||||||
import 'recognizer.dart';
|
import 'recognizer.dart';
|
||||||
import 'velocity_tracker.dart';
|
import 'velocity_tracker.dart';
|
||||||
@ -17,12 +18,14 @@ typedef Drag GestureMultiDragStartCallback(Point position);
|
|||||||
|
|
||||||
/// Interface for receiving updates about drags from a [MultiDragGestureRecognizer].
|
/// Interface for receiving updates about drags from a [MultiDragGestureRecognizer].
|
||||||
abstract class Drag {
|
abstract class Drag {
|
||||||
/// The pointer has moved by the given offset.
|
/// The pointer has moved.
|
||||||
void move(Offset offset) { }
|
void update(DragUpdateDetails details) { }
|
||||||
|
|
||||||
/// The pointer is no longer in contact with the screen and was moving at a
|
/// The pointer is no longer in contact with the screen.
|
||||||
/// given velocity when it stopped contacting the screen.
|
///
|
||||||
void end(Velocity velocity) { }
|
/// The velocity at which the pointer was moving when it stopped contacting
|
||||||
|
/// the screen is available in the `details`.
|
||||||
|
void end(DragEndDetails details) { }
|
||||||
|
|
||||||
/// The input from the pointer is no longer directed towards this receiver.
|
/// The input from the pointer is no longer directed towards this receiver.
|
||||||
///
|
///
|
||||||
@ -76,7 +79,7 @@ abstract class MultiDragPointerState {
|
|||||||
_velocityTracker.addPosition(event.timeStamp, event.position);
|
_velocityTracker.addPosition(event.timeStamp, event.position);
|
||||||
if (_client != null) {
|
if (_client != null) {
|
||||||
assert(pendingDelta == null);
|
assert(pendingDelta == null);
|
||||||
_client.move(event.delta);
|
_client.update(new DragUpdateDetails(delta: event.delta));
|
||||||
} else {
|
} else {
|
||||||
assert(pendingDelta != null);
|
assert(pendingDelta != null);
|
||||||
_pendingDelta += event.delta;
|
_pendingDelta += event.delta;
|
||||||
@ -113,7 +116,7 @@ abstract class MultiDragPointerState {
|
|||||||
assert(client != null);
|
assert(client != null);
|
||||||
assert(pendingDelta != null);
|
assert(pendingDelta != null);
|
||||||
_client = client;
|
_client = client;
|
||||||
_client.move(pendingDelta);
|
_client.update(new DragUpdateDetails(delta: pendingDelta));
|
||||||
_pendingDelta = null;
|
_pendingDelta = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +124,7 @@ abstract class MultiDragPointerState {
|
|||||||
assert(_arenaEntry != null);
|
assert(_arenaEntry != null);
|
||||||
if (_client != null) {
|
if (_client != null) {
|
||||||
assert(pendingDelta == null);
|
assert(pendingDelta == null);
|
||||||
_client.end(_velocityTracker.getVelocity());
|
_client.end(new DragEndDetails(velocity: _velocityTracker.getVelocity() ?? Velocity.zero));
|
||||||
_client = null;
|
_client = null;
|
||||||
} else {
|
} else {
|
||||||
assert(pendingDelta != null);
|
assert(pendingDelta != null);
|
||||||
|
@ -11,6 +11,7 @@ import 'constants.dart';
|
|||||||
import 'events.dart';
|
import 'events.dart';
|
||||||
import 'pointer_router.dart';
|
import 'pointer_router.dart';
|
||||||
import 'recognizer.dart';
|
import 'recognizer.dart';
|
||||||
|
import 'tap.dart';
|
||||||
|
|
||||||
/// Signature for callback when the user has tapped the screen at the same
|
/// Signature for callback when the user has tapped the screen at the same
|
||||||
/// location twice in quick succession.
|
/// location twice in quick succession.
|
||||||
@ -18,11 +19,11 @@ typedef void GestureDoubleTapCallback();
|
|||||||
|
|
||||||
/// Signature used by [MultiTapGestureRecognizer] for when a pointer that might
|
/// Signature used by [MultiTapGestureRecognizer] for when a pointer that might
|
||||||
/// cause a tap has contacted the screen at a particular location.
|
/// cause a tap has contacted the screen at a particular location.
|
||||||
typedef void GestureMultiTapDownCallback(Point globalPosition, int pointer);
|
typedef void GestureMultiTapDownCallback(int pointer, TapDownDetails details);
|
||||||
|
|
||||||
/// Signature used by [MultiTapGestureRecognizer] for when a pointer that will
|
/// Signature used by [MultiTapGestureRecognizer] for when a pointer that will
|
||||||
/// trigger a tap has stopped contacting the screen at a particular location.
|
/// trigger a tap has stopped contacting the screen at a particular location.
|
||||||
typedef void GestureMultiTapUpCallback(Point globalPosition, int pointer);
|
typedef void GestureMultiTapUpCallback(int pointer, TapUpDetails details);
|
||||||
|
|
||||||
/// Signature used by [MultiTapGestureRecognizer] for when a tap has occurred.
|
/// Signature used by [MultiTapGestureRecognizer] for when a tap has occurred.
|
||||||
typedef void GestureMultiTapCallback(int pointer);
|
typedef void GestureMultiTapCallback(int pointer);
|
||||||
@ -358,7 +359,7 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
|
|||||||
longTapDelay: longTapDelay
|
longTapDelay: longTapDelay
|
||||||
);
|
);
|
||||||
if (onTapDown != null)
|
if (onTapDown != null)
|
||||||
onTapDown(event.position, event.pointer);
|
onTapDown(event.pointer, new TapDownDetails(globalPosition: event.position));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -379,7 +380,7 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
|
|||||||
_gestureMap.remove(pointer);
|
_gestureMap.remove(pointer);
|
||||||
if (resolution == _TapResolution.tap) {
|
if (resolution == _TapResolution.tap) {
|
||||||
if (onTapUp != null)
|
if (onTapUp != null)
|
||||||
onTapUp(globalPosition, pointer);
|
onTapUp(pointer, new TapUpDetails(globalPosition: globalPosition));
|
||||||
if (onTap != null)
|
if (onTap != null)
|
||||||
onTap(pointer);
|
onTap(pointer);
|
||||||
} else {
|
} else {
|
||||||
@ -391,7 +392,7 @@ class MultiTapGestureRecognizer extends GestureRecognizer {
|
|||||||
void _handleLongTap(int pointer, Point lastPosition) {
|
void _handleLongTap(int pointer, Point lastPosition) {
|
||||||
assert(_gestureMap.containsKey(pointer));
|
assert(_gestureMap.containsKey(pointer));
|
||||||
if (onLongTapDown != null)
|
if (onLongTapDown != null)
|
||||||
onLongTapDown(lastPosition, pointer);
|
onLongTapDown(pointer, new TapDownDetails(globalPosition: lastPosition));
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -7,13 +7,45 @@ import 'constants.dart';
|
|||||||
import 'events.dart';
|
import 'events.dart';
|
||||||
import 'recognizer.dart';
|
import 'recognizer.dart';
|
||||||
|
|
||||||
/// Signature for when a pointer that might cause a tap has contacted the screen
|
/// Details for [GestureTapDownCallback], such as position.
|
||||||
/// at a particular location.
|
class TapDownDetails {
|
||||||
typedef void GestureTapDownCallback(Point globalPosition);
|
/// Creates details for a [GestureTapDownCallback].
|
||||||
|
///
|
||||||
|
/// The [globalPosition] argument must not be null.
|
||||||
|
TapDownDetails({ this.globalPosition: Point.origin }) {
|
||||||
|
assert(globalPosition != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The global position at which the pointer contacted the screen.
|
||||||
|
final Point globalPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Signature for when a pointer that might cause a tap has contacted the
|
||||||
|
/// screen.
|
||||||
|
///
|
||||||
|
/// The position at which the pointer contacted the screen is available in the
|
||||||
|
/// `details`.
|
||||||
|
typedef void GestureTapDownCallback(TapDownDetails details);
|
||||||
|
|
||||||
|
/// Details for [GestureTapUpCallback], such as position.
|
||||||
|
class TapUpDetails {
|
||||||
|
/// Creates details for a [GestureTapUpCallback].
|
||||||
|
///
|
||||||
|
/// The [globalPosition] argument must not be null.
|
||||||
|
TapUpDetails({ this.globalPosition: Point.origin }) {
|
||||||
|
assert(globalPosition != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The global position at which the pointer contacted the screen.
|
||||||
|
final Point globalPosition;
|
||||||
|
}
|
||||||
|
|
||||||
/// Signature for when a pointer that will trigger a tap has stopped contacting
|
/// Signature for when a pointer that will trigger a tap has stopped contacting
|
||||||
/// the screen at a particular location.
|
/// the screen.
|
||||||
typedef void GestureTapUpCallback(Point globalPosition);
|
///
|
||||||
|
/// The position at which the pointer stopped contacting the screen is available
|
||||||
|
/// in the `details`.
|
||||||
|
typedef void GestureTapUpCallback(TapUpDetails details);
|
||||||
|
|
||||||
/// Signature for when a tap has occurred.
|
/// Signature for when a tap has occurred.
|
||||||
typedef void GestureTapCallback();
|
typedef void GestureTapCallback();
|
||||||
@ -102,7 +134,7 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
|
|||||||
void _checkDown() {
|
void _checkDown() {
|
||||||
if (!_sentTapDown) {
|
if (!_sentTapDown) {
|
||||||
if (onTapDown != null)
|
if (onTapDown != null)
|
||||||
onTapDown(initialPosition);
|
onTapDown(new TapDownDetails(globalPosition: initialPosition));
|
||||||
_sentTapDown = true;
|
_sentTapDown = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,7 +143,7 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
|
|||||||
if (_wonArena && _finalPosition != null) {
|
if (_wonArena && _finalPosition != null) {
|
||||||
resolve(GestureDisposition.accepted);
|
resolve(GestureDisposition.accepted);
|
||||||
if (onTapUp != null)
|
if (onTapUp != null)
|
||||||
onTapUp(_finalPosition);
|
onTapUp(new TapUpDetails(globalPosition: _finalPosition));
|
||||||
if (onTap != null)
|
if (onTap != null)
|
||||||
onTap();
|
onTap();
|
||||||
_reset();
|
_reset();
|
||||||
|
@ -127,14 +127,14 @@ class _InkResponseState<T extends InkResponse> extends State<T> {
|
|||||||
config.onHighlightChanged(value);
|
config.onHighlightChanged(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleTapDown(Point position) {
|
void _handleTapDown(TapDownDetails details) {
|
||||||
RenderBox referenceBox = context.findRenderObject();
|
RenderBox referenceBox = context.findRenderObject();
|
||||||
assert(Material.of(context) != null);
|
assert(Material.of(context) != null);
|
||||||
InkSplash splash;
|
InkSplash splash;
|
||||||
RectCallback rectCallback = config.getRectCallback(referenceBox);
|
RectCallback rectCallback = config.getRectCallback(referenceBox);
|
||||||
splash = Material.of(context).splashAt(
|
splash = Material.of(context).splashAt(
|
||||||
referenceBox: referenceBox,
|
referenceBox: referenceBox,
|
||||||
position: referenceBox.globalToLocal(position),
|
position: referenceBox.globalToLocal(details.globalPosition),
|
||||||
color: Theme.of(context).splashColor,
|
color: Theme.of(context).splashColor,
|
||||||
containedInkWell: config.containedInkWell,
|
containedInkWell: config.containedInkWell,
|
||||||
rectCallback: config.containedInkWell ? rectCallback : null,
|
rectCallback: config.containedInkWell ? rectCallback : null,
|
||||||
|
@ -213,9 +213,9 @@ abstract class RenderToggleable extends RenderConstrainedBox implements Semantic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleTapDown(Point globalPosition) {
|
void _handleTapDown(TapDownDetails details) {
|
||||||
if (isInteractive) {
|
if (isInteractive) {
|
||||||
_downPosition = globalToLocal(globalPosition);
|
_downPosition = globalToLocal(details.globalPosition);
|
||||||
_reactionController.forward();
|
_reactionController.forward();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -225,7 +225,7 @@ abstract class RenderToggleable extends RenderConstrainedBox implements Semantic
|
|||||||
onChanged(!_value);
|
onChanged(!_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleTapUp(Point globalPosition) {
|
void _handleTapUp(TapUpDetails details) {
|
||||||
_downPosition = null;
|
_downPosition = null;
|
||||||
if (isInteractive)
|
if (isInteractive)
|
||||||
_reactionController.reverse();
|
_reactionController.reverse();
|
||||||
|
@ -217,8 +217,8 @@ class RenderEditableLine extends RenderBox {
|
|||||||
|
|
||||||
Point _lastTapDownPosition;
|
Point _lastTapDownPosition;
|
||||||
Point _longPressPosition;
|
Point _longPressPosition;
|
||||||
void _handleTapDown(Point globalPosition) {
|
void _handleTapDown(TapDownDetails details) {
|
||||||
_lastTapDownPosition = globalPosition + -paintOffset;
|
_lastTapDownPosition = details.globalPosition + -paintOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleTap() {
|
void _handleTap() {
|
||||||
|
@ -416,7 +416,7 @@ class _DragAvatar<T> extends Drag {
|
|||||||
_entry = new OverlayEntry(builder: _build);
|
_entry = new OverlayEntry(builder: _build);
|
||||||
overlay.insert(_entry);
|
overlay.insert(_entry);
|
||||||
_position = initialPosition;
|
_position = initialPosition;
|
||||||
update(initialPosition);
|
updateDrag(initialPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
final T data;
|
final T data;
|
||||||
@ -433,22 +433,22 @@ class _DragAvatar<T> extends Drag {
|
|||||||
|
|
||||||
// Drag API
|
// Drag API
|
||||||
@override
|
@override
|
||||||
void move(Offset offset) {
|
void update(DragUpdateDetails details) {
|
||||||
_position += offset;
|
_position += details.delta;
|
||||||
update(_position);
|
updateDrag(_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void end(Velocity velocity) {
|
void end(DragEndDetails details) {
|
||||||
finish(_DragEndKind.dropped, velocity);
|
finishDrag(_DragEndKind.dropped, details.velocity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void cancel() {
|
void cancel() {
|
||||||
finish(_DragEndKind.canceled);
|
finishDrag(_DragEndKind.canceled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(Point globalPosition) {
|
void updateDrag(Point globalPosition) {
|
||||||
_lastOffset = globalPosition - dragStartPoint;
|
_lastOffset = globalPosition - dragStartPoint;
|
||||||
_entry.markNeedsBuild();
|
_entry.markNeedsBuild();
|
||||||
HitTestResult result = new HitTestResult();
|
HitTestResult result = new HitTestResult();
|
||||||
@ -505,7 +505,7 @@ class _DragAvatar<T> extends Drag {
|
|||||||
_enteredTargets.clear();
|
_enteredTargets.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void finish(_DragEndKind endKind, [Velocity velocity]) {
|
void finishDrag(_DragEndKind endKind, [Velocity velocity]) {
|
||||||
bool wasAccepted = false;
|
bool wasAccepted = false;
|
||||||
if (endKind == _DragEndKind.dropped && _activeTarget != null) {
|
if (endKind == _DragEndKind.dropped && _activeTarget != null) {
|
||||||
_activeTarget.didDrop(data);
|
_activeTarget.didDrop(data);
|
||||||
|
@ -26,6 +26,8 @@ export 'package:flutter/gestures.dart' show
|
|||||||
GestureScaleStartCallback,
|
GestureScaleStartCallback,
|
||||||
GestureScaleUpdateCallback,
|
GestureScaleUpdateCallback,
|
||||||
GestureScaleEndCallback,
|
GestureScaleEndCallback,
|
||||||
|
TapDownDetails,
|
||||||
|
TapUpDetails,
|
||||||
Velocity;
|
Velocity;
|
||||||
|
|
||||||
/// Signature for creating gesture recognizers.
|
/// Signature for creating gesture recognizers.
|
||||||
@ -479,9 +481,9 @@ class _GestureSemantics extends SingleChildRenderObjectWidget {
|
|||||||
TapGestureRecognizer recognizer = owner._recognizers[TapGestureRecognizer];
|
TapGestureRecognizer recognizer = owner._recognizers[TapGestureRecognizer];
|
||||||
assert(recognizer != null);
|
assert(recognizer != null);
|
||||||
if (recognizer.onTapDown != null)
|
if (recognizer.onTapDown != null)
|
||||||
recognizer.onTapDown(Point.origin);
|
recognizer.onTapDown(new TapDownDetails());
|
||||||
if (recognizer.onTapUp != null)
|
if (recognizer.onTapUp != null)
|
||||||
recognizer.onTapUp(Point.origin);
|
recognizer.onTapUp(new TapUpDetails());
|
||||||
if (recognizer.onTap != null)
|
if (recognizer.onTap != null)
|
||||||
recognizer.onTap();
|
recognizer.onTap();
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class ModalBarrier extends StatelessWidget {
|
|||||||
return new Semantics(
|
return new Semantics(
|
||||||
container: true,
|
container: true,
|
||||||
child: new GestureDetector(
|
child: new GestureDetector(
|
||||||
onTapDown: (Point position) {
|
onTapDown: (TapDownDetails details) {
|
||||||
if (dismissable)
|
if (dismissable)
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user