mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
3cc335e615
Summary: Changelog: [iOS][internal] - Add tangentialPressure property to PointerEvent interface This diff adds the tangentialPressure property to the PointerEvent implementation on iOS. This one is pretty simple considering iOS doesn't have the concept of tangential pressure so we just hard code it to 0 as defined by the spec. Reviewed By: lunaleaps Differential Revision: D37759634 fbshipit-source-id: 7ca0e47267f5fde76ace2b96d05ea2e154cb4b8f
203 lines
6.0 KiB
C++
203 lines
6.0 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* 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 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);
|
|
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);
|
|
}
|
|
|
|
static jsi::Value touchesPayload(
|
|
jsi::Runtime &runtime,
|
|
Touches const &touches) {
|
|
auto array = jsi::Array(runtime, touches.size());
|
|
int i = 0;
|
|
for (auto const &touch : touches) {
|
|
auto object = jsi::Object(runtime);
|
|
setTouchPayloadOnObject(object, runtime, touch);
|
|
array.setValueAtIndex(runtime, i++, object);
|
|
}
|
|
return array;
|
|
}
|
|
|
|
static jsi::Value touchEventPayload(
|
|
jsi::Runtime &runtime,
|
|
TouchEvent const &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));
|
|
|
|
if (!event.changedTouches.empty()) {
|
|
auto const &firstChangedTouch = *event.changedTouches.begin();
|
|
setTouchPayloadOnObject(object, runtime, firstChangedTouch);
|
|
}
|
|
return object;
|
|
}
|
|
|
|
static jsi::Value pointerEventPayload(
|
|
jsi::Runtime &runtime,
|
|
PointerEvent const &event) {
|
|
auto object = jsi::Object(runtime);
|
|
object.setProperty(runtime, "pointerId", event.pointerId);
|
|
object.setProperty(runtime, "pressure", event.pressure);
|
|
object.setProperty(runtime, "pointerType", event.pointerType);
|
|
object.setProperty(runtime, "clientX", event.clientPoint.x);
|
|
object.setProperty(runtime, "clientY", event.clientPoint.y);
|
|
object.setProperty(runtime, "width", event.width);
|
|
object.setProperty(runtime, "height", event.height);
|
|
object.setProperty(runtime, "tiltX", event.tiltX);
|
|
object.setProperty(runtime, "tiltY", event.tiltY);
|
|
object.setProperty(runtime, "detail", event.detail);
|
|
object.setProperty(runtime, "buttons", event.buttons);
|
|
object.setProperty(runtime, "tangentialPressure", event.tangentialPressure);
|
|
return object;
|
|
}
|
|
|
|
void TouchEventEmitter::dispatchTouchEvent(
|
|
std::string type,
|
|
TouchEvent const &event,
|
|
EventPriority priority,
|
|
RawEvent::Category category) const {
|
|
dispatchEvent(
|
|
std::move(type),
|
|
[event](jsi::Runtime &runtime) {
|
|
return touchEventPayload(runtime, event);
|
|
},
|
|
priority,
|
|
category);
|
|
}
|
|
|
|
void TouchEventEmitter::dispatchPointerEvent(
|
|
std::string type,
|
|
PointerEvent const &event,
|
|
EventPriority priority,
|
|
RawEvent::Category category) const {
|
|
dispatchEvent(
|
|
std::move(type),
|
|
[event](jsi::Runtime &runtime) {
|
|
return pointerEventPayload(runtime, event);
|
|
},
|
|
priority,
|
|
category);
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchStart(TouchEvent const &event) const {
|
|
dispatchTouchEvent(
|
|
"touchStart",
|
|
event,
|
|
EventPriority::AsynchronousBatched,
|
|
RawEvent::Category::ContinuousStart);
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchMove(TouchEvent const &event) const {
|
|
dispatchUniqueEvent("touchMove", [event](jsi::Runtime &runtime) {
|
|
return touchEventPayload(runtime, event);
|
|
});
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchEnd(TouchEvent const &event) const {
|
|
dispatchTouchEvent(
|
|
"touchEnd",
|
|
event,
|
|
EventPriority::AsynchronousBatched,
|
|
RawEvent::Category::ContinuousEnd);
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchCancel(TouchEvent const &event) const {
|
|
dispatchTouchEvent(
|
|
"touchCancel",
|
|
event,
|
|
EventPriority::AsynchronousBatched,
|
|
RawEvent::Category::ContinuousEnd);
|
|
}
|
|
|
|
void TouchEventEmitter::onPointerCancel(const PointerEvent &event) const {
|
|
dispatchPointerEvent(
|
|
"pointerCancel",
|
|
event,
|
|
EventPriority::AsynchronousBatched,
|
|
RawEvent::Category::ContinuousEnd);
|
|
}
|
|
|
|
void TouchEventEmitter::onPointerDown(const PointerEvent &event) const {
|
|
dispatchPointerEvent(
|
|
"pointerDown",
|
|
event,
|
|
EventPriority::AsynchronousBatched,
|
|
RawEvent::Category::ContinuousStart);
|
|
}
|
|
|
|
void TouchEventEmitter::onPointerMove(const PointerEvent &event) const {
|
|
dispatchUniqueEvent("pointerMove", [event](jsi::Runtime &runtime) {
|
|
return pointerEventPayload(runtime, event);
|
|
});
|
|
}
|
|
|
|
void TouchEventEmitter::onPointerUp(const PointerEvent &event) const {
|
|
dispatchPointerEvent(
|
|
"pointerUp",
|
|
event,
|
|
EventPriority::AsynchronousBatched,
|
|
RawEvent::Category::ContinuousEnd);
|
|
}
|
|
|
|
void TouchEventEmitter::onPointerEnter(const PointerEvent &event) const {
|
|
dispatchPointerEvent(
|
|
"pointerEnter",
|
|
event,
|
|
EventPriority::AsynchronousBatched,
|
|
RawEvent::Category::ContinuousStart);
|
|
}
|
|
|
|
void TouchEventEmitter::onPointerLeave(const PointerEvent &event) const {
|
|
dispatchPointerEvent(
|
|
"pointerLeave",
|
|
event,
|
|
EventPriority::AsynchronousBatched,
|
|
RawEvent::Category::ContinuousEnd);
|
|
}
|
|
|
|
void TouchEventEmitter::onPointerOver(const PointerEvent &event) const {
|
|
dispatchPointerEvent(
|
|
"pointerOver",
|
|
event,
|
|
EventPriority::AsynchronousBatched,
|
|
RawEvent::Category::ContinuousStart);
|
|
}
|
|
|
|
void TouchEventEmitter::onPointerOut(const PointerEvent &event) const {
|
|
dispatchPointerEvent(
|
|
"pointerOut",
|
|
event,
|
|
EventPriority::AsynchronousBatched,
|
|
RawEvent::Category::ContinuousStart);
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|