mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
eb10d3e1d6
Summary: When we designed the Fabric's event priorities we followed the model "let's assign all priorities to all events as they should theoretically be and create a flag that disables sync execution (because we were unsure that it's stable enough". After some experiments, it's clear that this model is not feasible. We realized that we were often not sure about the exact event priority that should be assigned to a particular event. We also realized that the priorities in web work differently compare to RN. And we are not sure how we should ensure ordering among events in different queues with different priorities. At the same time, we want to use (or experiment with) sync events for in some cases when we sure about desired behavior and/or where async events make no sense. This diff deletes the macro that disables sync priorities and explicitly assigns async priorities to events that previously had sync ones. The actual behavior should not change. Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D18950431 fbshipit-source-id: 4033ef63d4e736075b525a693cd514d7b92d5bb0
84 lines
2.6 KiB
C++
84 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its 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 jsi::Value touchPayload(jsi::Runtime &runtime, Touch const &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 jsi::Value touchesPayload(
|
|
jsi::Runtime &runtime,
|
|
Touches const &touches) {
|
|
auto array = jsi::Array(runtime, touches.size());
|
|
int i = 0;
|
|
for (auto const &touch : touches) {
|
|
array.setValueAtIndex(runtime, i++, touchPayload(runtime, touch));
|
|
}
|
|
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));
|
|
return object;
|
|
}
|
|
|
|
void TouchEventEmitter::dispatchTouchEvent(
|
|
std::string const &type,
|
|
TouchEvent const &event,
|
|
EventPriority const &priority) const {
|
|
dispatchEvent(
|
|
type,
|
|
[event](jsi::Runtime &runtime) {
|
|
return touchEventPayload(runtime, event);
|
|
},
|
|
priority);
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchStart(TouchEvent const &event) const {
|
|
dispatchTouchEvent("touchStart", event, EventPriority::AsynchronousBatched);
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchMove(TouchEvent const &event) const {
|
|
dispatchTouchEvent("touchMove", event, EventPriority::AsynchronousBatched);
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchEnd(TouchEvent const &event) const {
|
|
dispatchTouchEvent("touchEnd", event, EventPriority::AsynchronousBatched);
|
|
}
|
|
|
|
void TouchEventEmitter::onTouchCancel(TouchEvent const &event) const {
|
|
dispatchTouchEvent("touchCancel", event, EventPriority::AsynchronousBatched);
|
|
}
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|