From ae6f4f308e1dad6c3cdf45a2393426682c543a55 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Tue, 1 Dec 2020 09:20:45 -0800 Subject: [PATCH] Align format of touch events with Paper Summary: Changelog: [internal] Touch events should be of a type PressEvent. Fabric only provided touches, changedTouches and targetTouches and leaves out force, identifier, locationX, locationY, pageX, pageY and timestamp. Reviewed By: shergin Differential Revision: D25243347 fbshipit-source-id: e824558bd43f51c0c6dcca62bfc98318aa61678e --- .../components/view/TouchEventEmitter.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ReactCommon/react/renderer/components/view/TouchEventEmitter.cpp b/ReactCommon/react/renderer/components/view/TouchEventEmitter.cpp index 738dec8d6467c7..c02b1c3bcc784e 100644 --- a/ReactCommon/react/renderer/components/view/TouchEventEmitter.cpp +++ b/ReactCommon/react/renderer/components/view/TouchEventEmitter.cpp @@ -12,8 +12,10 @@ namespace react { #pragma mark - Touches -static jsi::Value touchPayload(jsi::Runtime &runtime, Touch const &touch) { - auto object = jsi::Object(runtime); +static void setTouchPayloadOnObject( + jsi::Object &object, + jsi::Runtime &runtime, + Touch const &touch) { object.setProperty(runtime, "locationX", touch.offsetPoint.x); object.setProperty(runtime, "locationY", touch.offsetPoint.y); object.setProperty(runtime, "pageX", touch.pagePoint.x); @@ -24,7 +26,6 @@ static jsi::Value touchPayload(jsi::Runtime &runtime, Touch const &touch) { object.setProperty(runtime, "target", touch.target); object.setProperty(runtime, "timestamp", touch.timestamp * 1000); object.setProperty(runtime, "force", touch.force); - return object; } static jsi::Value touchesPayload( @@ -33,7 +34,9 @@ static jsi::Value touchesPayload( auto array = jsi::Array(runtime, touches.size()); int i = 0; for (auto const &touch : touches) { - array.setValueAtIndex(runtime, i++, touchPayload(runtime, touch)); + auto object = jsi::Object(runtime); + setTouchPayloadOnObject(object, runtime, touch); + array.setValueAtIndex(runtime, i++, object); } return array; } @@ -48,6 +51,11 @@ static jsi::Value touchEventPayload( runtime, "changedTouches", touchesPayload(runtime, event.changedTouches)); object.setProperty( runtime, "targetTouches", touchesPayload(runtime, event.targetTouches)); + + if (!event.changedTouches.empty()) { + auto const &firstChangedTouch = *event.changedTouches.begin(); + setTouchPayloadOnObject(object, runtime, firstChangedTouch); + } return object; }