Skip to content

Commit 1eebbbc

Browse files
vincentriemerfacebook-github-bot
authored andcommitted
Implement offsetX/offsetY properties on the PointerEvent interface
Summary: Changelog: [iOS][Internal] - Implement offsetX/offsetY properties on the PointerEvent interface Simple diff implementing the offsetX/offsetY properties on PointerEvent — thankfully the touch events already kept track of these so it was mostly a matter of forwarding that data to the pointer events. Reviewed By: lunaleaps Differential Revision: D37830139 fbshipit-source-id: 77f33a99393350d32cbe449e6a009bdeb2a12d08
1 parent cd8dbd1 commit 1eebbbc

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

React/Fabric/RCTSurfaceTouchHandler.mm

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ static PointerEvent CreatePointerEventFromActiveTouch(ActiveTouch activeTouch, R
258258
event.pointerType = PointerTypeCStringFromUITouchType(activeTouch.touchType);
259259
event.clientPoint = touch.pagePoint;
260260
event.screenPoint = touch.screenPoint;
261+
event.offsetPoint = touch.offsetPoint;
261262

262263
CGFloat pointerSize = activeTouch.majorRadius * 2.0;
263264
if (@available(iOS 13.4, *)) {
@@ -292,6 +293,7 @@ static PointerEvent CreatePointerEventFromIncompleteHoverData(
292293
UIView *view,
293294
CGPoint clientLocation,
294295
CGPoint screenLocation,
296+
CGPoint offsetLocation,
295297
NSTimeInterval timestamp)
296298
{
297299
PointerEvent event = {};
@@ -303,6 +305,7 @@ static PointerEvent CreatePointerEventFromIncompleteHoverData(
303305
event.pointerType = "mouse";
304306
event.clientPoint = RCTPointFromCGPoint(clientLocation);
305307
event.screenPoint = RCTPointFromCGPoint(screenLocation);
308+
event.offsetPoint = RCTPointFromCGPoint(offsetLocation);
306309
event.width = 1.0;
307310
event.height = 1.0;
308311
event.tiltX = 0;
@@ -690,6 +693,8 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0))
690693
targetView = FindClosestFabricManagedTouchableView(targetView);
691694
UIView *prevTargetView = [_currentlyHoveredViews firstObject];
692695

696+
CGPoint offsetLocation = [recognizer locationInView:targetView];
697+
693698
NSOrderedSet *eventPathViews = GetTouchableViewsInPathToRoot(targetView);
694699

695700
NSTimeInterval timestamp = CACurrentMediaTime();
@@ -701,8 +706,8 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0))
701706
BOOL shouldEmitOverEvent = IsAnyViewInPathListeningToEvent(eventPathViews, ViewEvents::Offset::PointerOver);
702707
SharedTouchEventEmitter eventEmitter = GetTouchEmitterFromView(targetView, [recognizer locationInView:targetView]);
703708
if (shouldEmitOverEvent && eventEmitter != nil) {
704-
PointerEvent event =
705-
CreatePointerEventFromIncompleteHoverData(targetView, clientLocation, screenLocation, timestamp);
709+
PointerEvent event = CreatePointerEventFromIncompleteHoverData(
710+
targetView, clientLocation, screenLocation, offsetLocation, timestamp);
706711
eventEmitter->onPointerOver(event);
707712
}
708713
}
@@ -724,8 +729,8 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0))
724729
SharedTouchEventEmitter eventEmitter =
725730
GetTouchEmitterFromView(componentView, [recognizer locationInView:componentView]);
726731
if (eventEmitter != nil) {
727-
PointerEvent event =
728-
CreatePointerEventFromIncompleteHoverData(componentView, clientLocation, screenLocation, timestamp);
732+
PointerEvent event = CreatePointerEventFromIncompleteHoverData(
733+
componentView, clientLocation, screenLocation, offsetLocation, timestamp);
729734
eventEmitter->onPointerEnter(event);
730735
}
731736
}
@@ -743,8 +748,8 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0))
743748
if (hasMoveListenerInEventPath) {
744749
SharedTouchEventEmitter eventEmitter = GetTouchEmitterFromView(targetView, [recognizer locationInView:targetView]);
745750
if (eventEmitter != nil) {
746-
PointerEvent event =
747-
CreatePointerEventFromIncompleteHoverData(targetView, clientLocation, screenLocation, timestamp);
751+
PointerEvent event = CreatePointerEventFromIncompleteHoverData(
752+
targetView, clientLocation, screenLocation, offsetLocation, timestamp);
748753
eventEmitter->onPointerMove(event);
749754
}
750755
}
@@ -755,8 +760,8 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0))
755760
SharedTouchEventEmitter eventEmitter =
756761
GetTouchEmitterFromView(prevTargetView, [recognizer locationInView:prevTargetView]);
757762
if (shouldEmitOutEvent && eventEmitter != nil) {
758-
PointerEvent event =
759-
CreatePointerEventFromIncompleteHoverData(prevTargetView, clientLocation, screenLocation, timestamp);
763+
PointerEvent event = CreatePointerEventFromIncompleteHoverData(
764+
prevTargetView, clientLocation, screenLocation, offsetLocation, timestamp);
760765
eventEmitter->onPointerOut(event);
761766
}
762767
}
@@ -787,8 +792,8 @@ - (void)hovering:(UIHoverGestureRecognizer *)recognizer API_AVAILABLE(ios(13.0))
787792
SharedTouchEventEmitter eventEmitter =
788793
GetTouchEmitterFromView(componentView, [recognizer locationInView:componentView]);
789794
if (eventEmitter != nil) {
790-
PointerEvent event =
791-
CreatePointerEventFromIncompleteHoverData(componentView, clientLocation, screenLocation, timestamp);
795+
PointerEvent event = CreatePointerEventFromIncompleteHoverData(
796+
componentView, clientLocation, screenLocation, offsetLocation, timestamp);
792797
eventEmitter->onPointerLeave(event);
793798
}
794799
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ std::vector<DebugStringConvertibleObject> getDebugProps(
2525
{"pointerType", getDebugDescription(pointerEvent.pointerType, options)},
2626
{"clientPoint", getDebugDescription(pointerEvent.clientPoint, options)},
2727
{"screenPoint", getDebugDescription(pointerEvent.screenPoint, options)},
28+
{"offsetPoint", getDebugDescription(pointerEvent.offsetPoint, options)},
2829
{"width", getDebugDescription(pointerEvent.width, options)},
2930
{"height", getDebugDescription(pointerEvent.height, options)},
3031
{"tiltX", getDebugDescription(pointerEvent.tiltX, options)},

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ struct PointerEvent {
3838
* The X/Y coordinate of the pointer in global (screen) coordinates.
3939
*/
4040
Point screenPoint;
41+
/*
42+
* The X/Y coordinate of the pointer relative to the position of the padding
43+
* edge of the target node.
44+
*/
45+
Point offsetPoint;
4146
/*
4247
* The width (magnitude on the X axis), in CSS pixels, of the contact geometry
4348
* of the pointer

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ static jsi::Value pointerEventPayload(
7777
object.setProperty(runtime, "pageY", event.clientPoint.y);
7878
object.setProperty(runtime, "screenX", event.screenPoint.x);
7979
object.setProperty(runtime, "screenY", event.screenPoint.y);
80+
object.setProperty(runtime, "offsetX", event.offsetPoint.x);
81+
object.setProperty(runtime, "offsetY", event.offsetPoint.y);
8082
object.setProperty(runtime, "width", event.width);
8183
object.setProperty(runtime, "height", event.height);
8284
object.setProperty(runtime, "tiltX", event.tiltX);

0 commit comments

Comments
 (0)