Skip to content

Commit 8cf57a5

Browse files
vincentriemerfacebook-github-bot
authored andcommitted
Add width/height properties to PointerEvent object
Summary: Changelog: [iOS][Internal] Add width/height properties to the PointerEvent object Reviewed By: kacieb Differential Revision: D37116854 fbshipit-source-id: 686266d480bb2ee1d2b6696d80ad42865fa2111c
1 parent 033ffcc commit 8cf57a5

4 files changed

Lines changed: 33 additions & 0 deletions

File tree

React/Fabric/RCTSurfaceTouchHandler.mm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ typedef NS_ENUM(NSInteger, RCTTouchEventType) {
6363
*/
6464
UITouchType touchType;
6565

66+
/*
67+
* The radius (in points) of the touch.
68+
*/
69+
CGFloat majorRadius;
70+
6671
/*
6772
* A component view on which the touch was begun.
6873
*/
@@ -105,6 +110,7 @@ static void UpdateActiveTouchWithUITouch(
105110
}
106111

107112
activeTouch.touchType = uiTouch.type;
113+
activeTouch.majorRadius = uiTouch.majorRadius;
108114
}
109115

110116
static ActiveTouch CreateTouchWithUITouch(UITouch *uiTouch, UIView *rootComponentView, CGPoint rootViewOriginOffset)
@@ -180,6 +186,17 @@ static PointerEvent CreatePointerEventFromActiveTouch(ActiveTouch activeTouch)
180186
event.pressure = touch.force;
181187
event.pointerType = PointerTypeCStringFromUITouchType(activeTouch.touchType);
182188
event.clientPoint = touch.pagePoint;
189+
190+
CGFloat pointerSize = activeTouch.majorRadius * 2.0;
191+
if (@available(iOS 13.4, *)) {
192+
if (activeTouch.touchType == UITouchTypeIndirectPointer) {
193+
// mouse type pointers should always report a size of 1
194+
pointerSize = 1.0;
195+
}
196+
}
197+
event.width = pointerSize;
198+
event.height = pointerSize;
199+
183200
return event;
184201
}
185202

@@ -194,6 +211,8 @@ static PointerEvent CreatePointerEventFromActiveTouch(ActiveTouch activeTouch)
194211
event.pressure = 0.0;
195212
event.pointerType = "mouse";
196213
event.clientPoint = RCTPointFromCGPoint(clientLocation);
214+
event.width = 1.0;
215+
event.height = 1.0;
197216
return event;
198217
}
199218

ReactCommon/react/renderer/components/view/PointerEvent.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ std::vector<DebugStringConvertibleObject> getDebugProps(
2424
{"pressure", getDebugDescription(pointerEvent.pressure, options)},
2525
{"pointerType", getDebugDescription(pointerEvent.pointerType, options)},
2626
{"clientPoint", getDebugDescription(pointerEvent.clientPoint, options)},
27+
{"width", getDebugDescription(pointerEvent.width, options)},
28+
{"height", getDebugDescription(pointerEvent.height, options)},
2729
};
2830
}
2931

ReactCommon/react/renderer/components/view/PointerEvent.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ struct PointerEvent {
3434
* opposed to the coordinate within the page).
3535
*/
3636
Point clientPoint;
37+
/*
38+
* The width (magnitude on the X axis), in CSS pixels, of the contact geometry
39+
* of the pointer
40+
*/
41+
Float width;
42+
/*
43+
* The height (magnitude on the y axis), in CSS pixels, of the contact
44+
* geometry of the pointer
45+
*/
46+
Float height;
3747
};
3848

3949
#if RN_DEBUG_STRING_CONVERTIBLE

ReactCommon/react/renderer/components/view/TouchEventEmitter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ static jsi::Value pointerEventPayload(
6868
object.setProperty(runtime, "pointerType", event.pointerType);
6969
object.setProperty(runtime, "clientX", event.clientPoint.x);
7070
object.setProperty(runtime, "clientY", event.clientPoint.y);
71+
object.setProperty(runtime, "width", event.width);
72+
object.setProperty(runtime, "height", event.height);
7173
return object;
7274
}
7375

0 commit comments

Comments
 (0)