Skip to content

Commit

Permalink
Align format of touch events with Paper
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Dec 1, 2020
1 parent e28b25c commit ae6f4f3
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ReactCommon/react/renderer/components/view/TouchEventEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down

0 comments on commit ae6f4f3

Please sign in to comment.