mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
PointerEvents: Use event.getSource() to distinguish
Summary: Changelog: [Internal] - Instead of using toolType which is a property per pointer in the MotionEvent, let's use [getSource](https://developer.android.com/reference/android/view/MotionEvent#getSource()) which is the source for the entire event (all pointers). This aligns with what we've seen on Android when we have a mouse and touch input, there is only one active source input device. And removes the need for checking a flag we set here: D36958947 Reviewed By: NickGerleman Differential Revision: D37702090 fbshipit-source-id: ba2a4f0c28e1aff2b8b04314fe6f737b66ed0be3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
333583bfbe
commit
cec20c3b97
+3
-23
@@ -7,6 +7,7 @@
|
||||
|
||||
package com.facebook.react.uimanager.events;
|
||||
|
||||
import android.view.InputDevice;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -22,8 +23,6 @@ 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,
|
||||
@@ -147,26 +146,7 @@ public class PointerEventHelper {
|
||||
}
|
||||
|
||||
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)) {
|
||||
return true;
|
||||
} else if (pointerType.equals(POINTER_TYPE_PEN)) {
|
||||
return true; // true?
|
||||
} else if (pointerType.equals(POINTER_TYPE_TOUCH)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
int source = motionEvent.getSource();
|
||||
return source == InputDevice.SOURCE_MOUSE || source == InputDevice.SOURCE_CLASS_POINTER;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user