mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 15:18:10 +00:00
Summary: All code styles are terribly ugly. We have the only choise - choise something and embrace it. This particular code style was borrowed from a neibour Fabric-friendly project because it follows established Facebook guides and respects client-side traditions. Reviewed By: mdvacca Differential Revision: D10218598 fbshipit-source-id: 8c4cf6713c07768566dadef479191661c79988f0
72 lines
2.1 KiB
C++
72 lines
2.1 KiB
C++
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include "TouchEventEmitter.h"
|
|
|
|
namespace facebook {
|
|
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.x;
|
|
object["pageX"] = touch.pagePoint.x;
|
|
object["pageY"] = touch.pagePoint.x;
|
|
object["screenX"] = touch.screenPoint.x;
|
|
object["screenY"] = touch.screenPoint.x;
|
|
object["identifier"] = touch.identifier;
|
|
object["target"] = touch.target;
|
|
object["timestamp"] = touch.timestamp * 1000;
|
|
object["force"] = touch.force;
|
|
return object;
|
|
}
|
|
|
|
static folly::dynamic touchesPayload(const Touches &touches) {
|
|
folly::dynamic array = folly::dynamic::array();
|
|
for (const auto &touch : touches) {
|
|
array.push_back(touchPayload(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);
|
|
return object;
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchStart(const TouchEvent &event) const {
|
|
dispatchEvent(
|
|
"touchStart",
|
|
touchEventPayload(event),
|
|
EventPriority::SynchronousUnbatched);
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchMove(const TouchEvent &event) const {
|
|
dispatchEvent(
|
|
"touchMove", touchEventPayload(event), EventPriority::SynchronousBatched);
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchEnd(const TouchEvent &event) const {
|
|
dispatchEvent(
|
|
"touchEnd", touchEventPayload(event), EventPriority::SynchronousBatched);
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchCancel(const TouchEvent &event) const {
|
|
dispatchEvent(
|
|
"touchCancel",
|
|
touchEventPayload(event),
|
|
EventPriority::SynchronousBatched);
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|