Skip to content

Commit

Permalink
PointerEvents: Fix x/y coordinate system for PointerEvents, set some …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Luna Wei authored and facebook-github-bot committed Sep 1, 2022
1 parent 64ae12e commit b098215
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,18 @@ 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));

// 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);

Expand All @@ -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;
}

Expand Down

0 comments on commit b098215

Please sign in to comment.