From 303aaf88ed5e7d8b83dd3978a0b06b3a829a27ac Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Tue, 5 Jul 2022 20:00:42 -0700 Subject: [PATCH] PointerEvents: Use MotionEvent flags to indicate hoverability Summary: Changelog: [Internal] Allow for MotionEvents to indicate whether they are dispatched from an input device that supports hoverability Reviewed By: javache Differential Revision: D37543296 fbshipit-source-id: 4f70d2bf69ff1c563d8e4a6b5eb6b13b53996b9a --- .../react/uimanager/JSPointerDispatcher.java | 3 +-- .../react/uimanager/events/PointerEventHelper.java | 14 +++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java index 71b9a6be59d..48319952d1e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSPointerDispatcher.java @@ -72,8 +72,7 @@ public class JSPointerDispatcher { } public void handleMotionEvent(MotionEvent motionEvent, EventDispatcher eventDispatcher) { - boolean supportsHover = - PointerEventHelper.supportsHover(motionEvent.getToolType(motionEvent.getActionIndex())); + boolean supportsHover = PointerEventHelper.supportsHover(motionEvent); int surfaceId = UIManagerHelper.getSurfaceId(mRootViewGroup); int action = motionEvent.getActionMasked(); diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEventHelper.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEventHelper.java index 2d4286df414..4ea2fd1ec5c 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEventHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEventHelper.java @@ -22,6 +22,8 @@ public class PointerEventHelper { public static final String POINTER_TYPE_MOUSE = "mouse"; public static final String POINTER_TYPE_UNKNOWN = ""; + private static final int X_FLAG_SUPPORTS_HOVER = 0x01000000; + public static enum EVENT { CANCEL, CANCEL_CAPTURE, @@ -144,7 +146,17 @@ public class PointerEventHelper { return EventCategoryDef.UNSPECIFIED; } - public static boolean supportsHover(final int toolType) { + public static boolean supportsHover(MotionEvent motionEvent) { + // A flag has been set on the MotionEvent to indicate it supports hover + // See D36958947 on justifications for this. + // TODO(luwe): Leverage previous events to determine if MotionEvent + // is from an input device that supports hover + boolean supportsHoverFlag = (motionEvent.getFlags() & X_FLAG_SUPPORTS_HOVER) != 0; + if (supportsHoverFlag) { + return true; + } + + int toolType = motionEvent.getToolType(motionEvent.getActionIndex()); String pointerType = getW3CPointerType(toolType); if (pointerType.equals(POINTER_TYPE_MOUSE)) {