Skip to content

Commit

Permalink
W3CPointerEvents: include modifier key properties in Android pointer …
Browse files Browse the repository at this point in the history
…events (#38197)

Summary:
Pull Request resolved: #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
  • Loading branch information
Alex Danoff authored and facebook-github-bot committed Jul 6, 2023
1 parent 0f393a5 commit 2bd4429
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -183,6 +184,13 @@ private List<WritableMap> 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);
Expand Down Expand Up @@ -254,6 +262,8 @@ private WritableMap createW3CPointerEvent(int index) {
pointerEvent.putDouble("pressure", pressure);
pointerEvent.putDouble("tangentialPressure", 0.0);

addModifierKeyData(pointerEvent, mMotionEvent.getMetaState());

return pointerEvent;
}

Expand Down

0 comments on commit 2bd4429

Please sign in to comment.