Commit 709b3550 authored by Kris Giesing's avatar Kris Giesing

Address comments

parent 608e971f
...@@ -11,7 +11,6 @@ import 'recognizer.dart'; ...@@ -11,7 +11,6 @@ import 'recognizer.dart';
import 'tap.dart'; import 'tap.dart';
class DoubleTapGestureRecognizer extends DisposableArenaMember { class DoubleTapGestureRecognizer extends DisposableArenaMember {
static int sInstances = 0;
DoubleTapGestureRecognizer({ this.router, this.onDoubleTap }); DoubleTapGestureRecognizer({ this.router, this.onDoubleTap });
...@@ -133,12 +132,13 @@ class DoubleTapGestureRecognizer extends DisposableArenaMember { ...@@ -133,12 +132,13 @@ class DoubleTapGestureRecognizer extends DisposableArenaMember {
tracker.entry.resolve(GestureDisposition.accepted); tracker.entry.resolve(GestureDisposition.accepted);
_freezeTracker(tracker); _freezeTracker(tracker);
_trackers.remove(tracker.pointer); _trackers.remove(tracker.pointer);
onDoubleTap?.call(); if (onDoubleTap != null)
onDoubleTap();
_reset(); _reset();
} }
void _clearTrackers() { void _clearTrackers() {
List<TapTracker> localTrackers = new List.from(_trackers.values); List<TapTracker> localTrackers = new List<TapTracker>.from(_trackers.values);
for (TapTracker tracker in localTrackers) for (TapTracker tracker in localTrackers)
_reject(tracker); _reject(tracker);
assert(_trackers.isEmpty); assert(_trackers.isEmpty);
......
...@@ -23,47 +23,45 @@ enum TapResolution { ...@@ -23,47 +23,45 @@ enum TapResolution {
class TapTracker { class TapTracker {
TapTracker({ PointerInputEvent event, this.entry }) TapTracker({ PointerInputEvent event, this.entry })
: pointer = event.pointer, : pointer = event.pointer,
initialPosition = event.position, _initialPosition = event.position,
isTrackingPointer = false { _isTrackingPointer = false {
assert(event.type == 'pointerdown'); assert(event.type == 'pointerdown');
} }
int pointer; int pointer;
ui.Point initialPosition;
bool isTrackingPointer;
Timer timer;
GestureArenaEntry entry; GestureArenaEntry entry;
ui.Point _initialPosition;
bool _isTrackingPointer;
Timer _timer;
void startTimer(void callback()) { void startTimer(void callback()) {
if (timer == null) { _timer ??= new Timer(kTapTimeout, callback);
timer = new Timer(kTapTimeout, callback);
}
} }
void stopTimer() { void stopTimer() {
if (timer != null) { if (_timer != null) {
timer.cancel(); _timer.cancel();
timer = null; _timer = null;
} }
} }
void startTrackingPointer(PointerRouter router, PointerRoute route) { void startTrackingPointer(PointerRouter router, PointerRoute route) {
if (!isTrackingPointer) { if (!_isTrackingPointer) {
isTrackingPointer = true; _isTrackingPointer = true;
router.addRoute(pointer, route); router.addRoute(pointer, route);
} }
} }
void stopTrackingPointer(PointerRouter router, PointerRoute route) { void stopTrackingPointer(PointerRouter router, PointerRoute route) {
if (isTrackingPointer) { if (_isTrackingPointer) {
isTrackingPointer = false; _isTrackingPointer = false;
router.removeRoute(pointer, route); router.removeRoute(pointer, route);
} }
} }
bool isWithinTolerance(PointerInputEvent event, double tolerance) { bool isWithinTolerance(PointerInputEvent event, double tolerance) {
ui.Offset offset = event.position - initialPosition; ui.Offset offset = event.position - _initialPosition;
return offset.distance <= tolerance; return offset.distance <= tolerance;
} }
...@@ -75,13 +73,13 @@ class TapTracker { ...@@ -75,13 +73,13 @@ class TapTracker {
class TapGesture extends TapTracker { class TapGesture extends TapTracker {
TapGesture({ this.gestureRecognizer, PointerInputEvent event }) TapGesture({ this.gestureRecognizer, PointerInputEvent event })
: super(event: event) { : super(event: event) {
entry = GestureArena.instance.add(event.pointer, gestureRecognizer); entry = GestureArena.instance.add(event.pointer, gestureRecognizer);
_wonArena = false; _wonArena = false;
_didTap = false; _didTap = false;
startTimer(() => cancel()); startTimer(() => cancel());
startTrackingPointer(gestureRecognizer.router, handleEvent); startTrackingPointer(gestureRecognizer.router, handleEvent);
} }
TapGestureRecognizer gestureRecognizer; TapGestureRecognizer gestureRecognizer;
...@@ -144,7 +142,8 @@ class TapGestureRecognizer extends DisposableArenaMember { ...@@ -144,7 +142,8 @@ class TapGestureRecognizer extends DisposableArenaMember {
gestureRecognizer: this, gestureRecognizer: this,
event: event event: event
); );
onTapDown?.call(); if (onTapDown != null)
onTapDown();
} }
void acceptGesture(int pointer) { void acceptGesture(int pointer) {
...@@ -157,14 +156,17 @@ class TapGestureRecognizer extends DisposableArenaMember { ...@@ -157,14 +156,17 @@ class TapGestureRecognizer extends DisposableArenaMember {
void _resolveTap(int pointer, TapResolution resolution) { void _resolveTap(int pointer, TapResolution resolution) {
_gestureMap.remove(pointer); _gestureMap.remove(pointer);
if (resolution == TapResolution.tap) if (resolution == TapResolution.tap) {
onTap?.call(); if (onTap != null)
else onTap();
onTapCancel?.call(); } else {
if (onTapCancel != null)
onTapCancel();
}
} }
void dispose() { void dispose() {
List<TapGesture> localGestures = new List.from(_gestureMap.values); List<TapGesture> localGestures = new List<TapGesture>.from(_gestureMap.values);
for (TapGesture gesture in localGestures) for (TapGesture gesture in localGestures)
gesture.cancel(); gesture.cancel();
// Rejection of each gesture should cause it to be removed from our map // Rejection of each gesture should cause it to be removed from our map
......
...@@ -140,7 +140,7 @@ class _GestureDetectorState extends State<GestureDetector> { ...@@ -140,7 +140,7 @@ class _GestureDetectorState extends State<GestureDetector> {
if (config.onDoubleTap == null) { if (config.onDoubleTap == null) {
_doubleTap = _ensureDisposed(_doubleTap); _doubleTap = _ensureDisposed(_doubleTap);
} else { } else {
_doubleTap = new DoubleTapGestureRecognizer(router: _router); _doubleTap ??= new DoubleTapGestureRecognizer(router: _router);
_doubleTap.onDoubleTap = config.onDoubleTap; _doubleTap.onDoubleTap = config.onDoubleTap;
} }
} }
......
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