From 2bd4429365c37e9ce70b12ff3f8d9a3c10af2a4b Mon Sep 17 00:00:00 2001 From: Alex Danoff Date: Thu, 6 Jul 2023 10:26:42 -0700 Subject: [PATCH] W3CPointerEvents: include modifier key properties in Android pointer events (#38197) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38197 Changelog: [Android] [Fixed] - W3CPointerEvents: include modifier key properties in Android pointer events The [spec](https://www.w3.org/TR/uievents/#idl-mouseevent) says there should be properties on mouse events (and hence pointer events) indicating whether ctrl, alt, shift, and/or meta are pressed during the event. This change adds those properties. Reviewed By: javache Differential Revision: D47162963 fbshipit-source-id: fa76795217c08ef410fbc5467e9547074b47f3f7 --- .../facebook/react/uimanager/events/PointerEvent.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.java index 02b99115070478..d0f221d127de7c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.java @@ -7,6 +7,7 @@ package com.facebook.react.uimanager.events; +import android.view.KeyEvent; import android.view.MotionEvent; import androidx.annotation.Nullable; import androidx.core.util.Pools; @@ -183,6 +184,13 @@ private List createW3CPointerEvents() { return w3cPointerEvents; } + private void addModifierKeyData(WritableMap pointerEvent, int modifierKeyMask) { + pointerEvent.putBoolean("ctrlKey", (modifierKeyMask & KeyEvent.META_CTRL_ON) != 0); + pointerEvent.putBoolean("shiftKey", (modifierKeyMask & KeyEvent.META_SHIFT_ON) != 0); + pointerEvent.putBoolean("altKey", (modifierKeyMask & KeyEvent.META_ALT_ON) != 0); + pointerEvent.putBoolean("metaKey", (modifierKeyMask & KeyEvent.META_META_ON) != 0); + } + private WritableMap createW3CPointerEvent(int index) { WritableMap pointerEvent = Arguments.createMap(); int pointerId = mMotionEvent.getPointerId(index); @@ -254,6 +262,8 @@ private WritableMap createW3CPointerEvent(int index) { pointerEvent.putDouble("pressure", pressure); pointerEvent.putDouble("tangentialPressure", 0.0); + addModifierKeyData(pointerEvent, mMotionEvent.getMetaState()); + return pointerEvent; }