Skip to content

Commit

Permalink
Add width/height properties to PointerEvent object
Browse files Browse the repository at this point in the history
Summary: Changelog: [iOS][Internal] Add width/height properties to the PointerEvent object

Reviewed By: kacieb

Differential Revision: D37116854

fbshipit-source-id: 686266d480bb2ee1d2b6696d80ad42865fa2111c
  • Loading branch information
vincentriemer authored and facebook-github-bot committed Jun 16, 2022
1 parent 033ffcc commit 8cf57a5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
19 changes: 19 additions & 0 deletions React/Fabric/RCTSurfaceTouchHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ typedef NS_ENUM(NSInteger, RCTTouchEventType) {
*/
UITouchType touchType;

/*
* The radius (in points) of the touch.
*/
CGFloat majorRadius;

/*
* A component view on which the touch was begun.
*/
Expand Down Expand Up @@ -105,6 +110,7 @@ static void UpdateActiveTouchWithUITouch(
}

activeTouch.touchType = uiTouch.type;
activeTouch.majorRadius = uiTouch.majorRadius;
}

static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponentView, CGPoint rootViewOriginOffset)
Expand Down Expand Up @@ -180,6 +186,17 @@ static PointerEvent CreatePointerEventFromActiveTouch(ActiveTouch activeTouch)
event.pressure = touch.force;
event.pointerType = PointerTypeCStringFromUITouchType(activeTouch.touchType);
event.clientPoint = touch.pagePoint;

CGFloat pointerSize = activeTouch.majorRadius * 2.0;
if (@available(iOS 13.4, *)) {
if (activeTouch.touchType == UITouchTypeIndirectPointer) {
// mouse type pointers should always report a size of 1
pointerSize = 1.0;
}
}
event.width = pointerSize;
event.height = pointerSize;

return event;
}

Expand All @@ -194,6 +211,8 @@ static PointerEvent CreatePointerEventFromActiveTouch(ActiveTouch activeTouch)
event.pressure = 0.0;
event.pointerType = "mouse";
event.clientPoint = RCTPointFromCGPoint(clientLocation);
event.width = 1.0;
event.height = 1.0;
return event;
}

Expand Down
2 changes: 2 additions & 0 deletions ReactCommon/react/renderer/components/view/PointerEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ std::vector<DebugStringConvertibleObject> getDebugProps(
{"pressure", getDebugDescription(pointerEvent.pressure, options)},
{"pointerType", getDebugDescription(pointerEvent.pointerType, options)},
{"clientPoint", getDebugDescription(pointerEvent.clientPoint, options)},
{"width", getDebugDescription(pointerEvent.width, options)},
{"height", getDebugDescription(pointerEvent.height, options)},
};
}

Expand Down
10 changes: 10 additions & 0 deletions ReactCommon/react/renderer/components/view/PointerEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ struct PointerEvent {
* opposed to the coordinate within the page).
*/
Point clientPoint;
/*
* The width (magnitude on the X axis), in CSS pixels, of the contact geometry
* of the pointer
*/
Float width;
/*
* The height (magnitude on the y axis), in CSS pixels, of the contact
* geometry of the pointer
*/
Float height;
};

#if RN_DEBUG_STRING_CONVERTIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ static jsi::Value pointerEventPayload(
object.setProperty(runtime, "pointerType", event.pointerType);
object.setProperty(runtime, "clientX", event.clientPoint.x);
object.setProperty(runtime, "clientY", event.clientPoint.y);
object.setProperty(runtime, "width", event.width);
object.setProperty(runtime, "height", event.height);
return object;
}

Expand Down

0 comments on commit 8cf57a5

Please sign in to comment.