From b09821591c328ea683d9adb5329210a22b312fd9 Mon Sep 17 00:00:00 2001 From: Luna Wei Date: Thu, 1 Sep 2022 13:11:44 -0700 Subject: [PATCH] PointerEvents: Fix x/y coordinate system for PointerEvents, set some properties for "mouse" pointerType Summary: Changelog: [Internal] - Fix more pointer event platform tests. * Fix the coordinate system to use DIP * Set some properties for when pointerType="mouse" Reviewed By: vincentriemer Differential Revision: D39184713 fbshipit-source-id: d86f798f3e0a377ff1c159fb308329a2c9ae03ff --- .../react/uimanager/events/PointerEvent.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.java index 7ed9c7723b0af7..e968826a7e2d3a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/PointerEvent.java @@ -172,8 +172,9 @@ private WritableMap createPointerEventData(int index) { // https://www.w3.org/TR/pointerevents/#pointerevent-interface pointerEvent.putDouble("pointerId", pointerId); pointerEvent.putDouble("pressure", mMotionEvent.getPressure(index)); - pointerEvent.putString( - "pointerType", PointerEventHelper.getW3CPointerType(mMotionEvent.getToolType(index))); + + String pointerType = PointerEventHelper.getW3CPointerType(mMotionEvent.getToolType(index)); + pointerEvent.putString("pointerType", pointerType); pointerEvent.putBoolean( "isPrimary", PointerEventHelper.isPrimary(pointerId, mPrimaryPointerId, mMotionEvent)); @@ -181,8 +182,8 @@ private WritableMap createPointerEventData(int index) { // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent // Client refers to upper left edge of the content area (viewport) // We define the viewport to be ReactRootView - double clientX = mMotionEvent.getX(index); - double clientY = mMotionEvent.getX(index); + double clientX = PixelUtil.toDIPFromPixel(mMotionEvent.getX(index)); + double clientY = PixelUtil.toDIPFromPixel(mMotionEvent.getY(index)); pointerEvent.putDouble("clientX", clientX); pointerEvent.putDouble("clientY", clientY); @@ -201,6 +202,13 @@ private WritableMap createPointerEventData(int index) { pointerEvent.putInt("target", this.getViewTag()); pointerEvent.putDouble("timestamp", this.getTimestampMs()); + if (pointerType.equals(PointerEventHelper.POINTER_TYPE_MOUSE)) { + pointerEvent.putDouble("width", 1); + pointerEvent.putDouble("height", 1); + pointerEvent.putDouble("tiltX", 0); + pointerEvent.putDouble("tiltY", 0); + } + return pointerEvent; }