Commit 7d9f8d90 authored by Adam Barth's avatar Adam Barth

Introduce TapDownDetails and TapUpDetails (#4431)

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