diff --git a/ReactCommon/fabric/components/view/TouchEventEmitter.cpp b/ReactCommon/fabric/components/view/TouchEventEmitter.cpp index 4951c300e..ddf69aa40 100644 --- a/ReactCommon/fabric/components/view/TouchEventEmitter.cpp +++ b/ReactCommon/fabric/components/view/TouchEventEmitter.cpp @@ -12,59 +12,71 @@ namespace react { #pragma mark - Touches -static folly::dynamic touchPayload(const Touch &touch) { - folly::dynamic object = folly::dynamic::object(); - object["locationX"] = touch.offsetPoint.x; - object["locationY"] = touch.offsetPoint.y; - object["pageX"] = touch.pagePoint.x; - object["pageY"] = touch.pagePoint.y; - object["screenX"] = touch.screenPoint.x; - object["screenY"] = touch.screenPoint.y; - object["identifier"] = touch.identifier; - object["target"] = touch.target; - object["timestamp"] = touch.timestamp * 1000; - object["force"] = touch.force; +static jsi::Value touchPayload(jsi::Runtime &runtime, const Touch &touch) { + auto object = jsi::Object(runtime); + object.setProperty(runtime, "locationX", touch.offsetPoint.x); + object.setProperty(runtime, "locationY", touch.offsetPoint.y); + object.setProperty(runtime, "pageX", touch.pagePoint.x); + object.setProperty(runtime, "pageY", touch.pagePoint.y); + object.setProperty(runtime, "screenX", touch.screenPoint.x); + object.setProperty(runtime, "screenY", touch.screenPoint.y); + object.setProperty(runtime, "identifier", touch.identifier); + object.setProperty(runtime, "target", touch.target); + object.setProperty(runtime, "timestamp", touch.timestamp * 1000); + object.setProperty(runtime, "force", touch.force); return object; } -static folly::dynamic touchesPayload(const Touches &touches) { - folly::dynamic array = folly::dynamic::array(); +static jsi::Value touchesPayload( + jsi::Runtime &runtime, + const Touches &touches) { + auto array = jsi::Array(runtime, touches.size()); + int i = 0; for (const auto &touch : touches) { - array.push_back(touchPayload(touch)); + array.setValueAtIndex(runtime, i++, touchPayload(runtime, touch)); } return array; } -static folly::dynamic touchEventPayload(const TouchEvent &event) { - folly::dynamic object = folly::dynamic::object(); - object["touches"] = touchesPayload(event.touches); - object["changedTouches"] = touchesPayload(event.changedTouches); - object["targetTouches"] = touchesPayload(event.targetTouches); +static jsi::Value touchEventPayload( + jsi::Runtime &runtime, + const TouchEvent &event) { + auto object = jsi::Object(runtime); + object.setProperty( + runtime, "touches", touchesPayload(runtime, event.touches)); + object.setProperty( + runtime, "changedTouches", touchesPayload(runtime, event.changedTouches)); + object.setProperty( + runtime, "targetTouches", touchesPayload(runtime, event.targetTouches)); return object; } -void TouchEventEmitter::onTouchStart(const TouchEvent &event) const { +void TouchEventEmitter::dispatchTouchEvent( + const std::string &type, + const TouchEvent &event, + const EventPriority &priority) const { dispatchEvent( - "touchStart", - touchEventPayload(event), - EventPriority::SynchronousUnbatched); + type, + [event](jsi::Runtime &runtime) { + return touchEventPayload(runtime, event); + }, + priority); +} + +void TouchEventEmitter::onTouchStart(const TouchEvent &event) const { + dispatchTouchEvent("touchStart", event, EventPriority::SynchronousUnbatched); } void TouchEventEmitter::onTouchMove(const TouchEvent &event) const { - dispatchEvent( - "touchMove", touchEventPayload(event), EventPriority::SynchronousBatched); + dispatchTouchEvent("touchMove", event, EventPriority::SynchronousBatched); } void TouchEventEmitter::onTouchEnd(const TouchEvent &event) const { - dispatchEvent( - "touchEnd", touchEventPayload(event), EventPriority::SynchronousBatched); + dispatchTouchEvent("touchEnd", event, EventPriority::SynchronousBatched); } void TouchEventEmitter::onTouchCancel(const TouchEvent &event) const { - dispatchEvent( - "touchCancel", - touchEventPayload(event), - EventPriority::SynchronousBatched); + dispatchTouchEvent("touchCancel", event, EventPriority::SynchronousBatched); } } // namespace react diff --git a/ReactCommon/fabric/components/view/TouchEventEmitter.h b/ReactCommon/fabric/components/view/TouchEventEmitter.h index c00e27552..3bf5e50fb 100644 --- a/ReactCommon/fabric/components/view/TouchEventEmitter.h +++ b/ReactCommon/fabric/components/view/TouchEventEmitter.h @@ -110,6 +110,12 @@ class TouchEventEmitter : public EventEmitter { void onTouchMove(const TouchEvent &event) const; void onTouchEnd(const TouchEvent &event) const; void onTouchCancel(const TouchEvent &event) const; + + private: + void dispatchTouchEvent( + const std::string &type, + const TouchEvent &event, + const EventPriority &priority) const; }; } // namespace react