From ccef1b29411dd7c639261154220892135bc9bd06 Mon Sep 17 00:00:00 2001 From: Dave Miller Date: Mon, 16 May 2016 02:33:50 -0700 Subject: [PATCH] More touch logging Reviewed By: andreicoman11 Differential Revision: D3298518 fbshipit-source-id: 0ddbba5c05848ac164f6f1562b26609924978169 --- .../facebook/react/uimanager/JSTouchDispatcher.java | 10 +++++++++- .../events/TouchEventCoalescingKeyHelper.java | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java index fefab066f..a5d7056ce 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java @@ -18,6 +18,7 @@ import com.facebook.react.common.ReactConstants; import com.facebook.react.common.SystemClock; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.uimanager.events.TouchEvent; +import com.facebook.react.uimanager.events.TouchEventCoalescingKeyHelper; import com.facebook.react.uimanager.events.TouchEventType; /** @@ -137,7 +138,14 @@ public class JSTouchDispatcher { mTargetCoordinates[0], mTargetCoordinates[1])); } else if (action == MotionEvent.ACTION_CANCEL) { - dispatchCancelEvent(ev, eventDispatcher); + if (TouchEventCoalescingKeyHelper.hasCoalescingKey(ev.getDownTime())) { + dispatchCancelEvent(ev, eventDispatcher); + } else { + FLog.e( + ReactConstants.TAG, + "Received an ACTION_CANCEL touch event for which we have no corresponding ACTION_DOWN" + ); + } mTargetTag = -1; } else { FLog.w( diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/TouchEventCoalescingKeyHelper.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/TouchEventCoalescingKeyHelper.java index e5783e3c5..acc2d3afa 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/TouchEventCoalescingKeyHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/TouchEventCoalescingKeyHelper.java @@ -83,4 +83,12 @@ public class TouchEventCoalescingKeyHelper { public static void removeCoalescingKey(long downTime) { sDownTimeToCoalescingKey.delete((int) downTime); } + + public static boolean hasCoalescingKey(long downTime) { + int currentValue = sDownTimeToCoalescingKey.get((int) downTime, -1); + if (currentValue == -1) { + return false; + } + return true; + } }