forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 166
Expand file tree
/
Copy pathTouchEventEmitter.cpp
More file actions
151 lines (126 loc) · 4.47 KB
/
TouchEventEmitter.cpp
File metadata and controls
151 lines (126 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* 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::react {
#pragma mark - Touches
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) {
auto object = jsi::Object(runtime);
setTouchPayloadOnObject(object, runtime, touch);
array.setValueAtIndex(runtime, i++, object);
}
return array;
}
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));
if (!event.changedTouches.empty()) {
const auto& firstChangedTouch = *event.changedTouches.begin();
setTouchPayloadOnObject(object, runtime, firstChangedTouch);
}
return object;
}
void TouchEventEmitter::dispatchTouchEvent(
std::string type,
TouchEvent event,
RawEvent::Category category) const {
dispatchEvent(
std::move(type),
[event = std::move(event)](jsi::Runtime& runtime) {
return touchEventPayload(runtime, event);
},
category);
}
void TouchEventEmitter::dispatchPointerEvent(
std::string type,
PointerEvent event,
RawEvent::Category category) const {
dispatchEvent(
std::move(type),
std::make_shared<PointerEvent>(std::move(event)),
category);
}
void TouchEventEmitter::onTouchStart(TouchEvent event) const {
dispatchTouchEvent(
"touchStart", std::move(event), RawEvent::Category::ContinuousStart);
}
void TouchEventEmitter::onTouchMove(TouchEvent event) const {
dispatchUniqueEvent(
"touchMove", [event = std::move(event)](jsi::Runtime& runtime) {
return touchEventPayload(runtime, event);
});
}
void TouchEventEmitter::onTouchEnd(TouchEvent event) const {
dispatchTouchEvent(
"touchEnd", std::move(event), RawEvent::Category::ContinuousEnd);
}
void TouchEventEmitter::onTouchCancel(TouchEvent event) const {
dispatchTouchEvent(
"touchCancel", std::move(event), RawEvent::Category::ContinuousEnd);
}
void TouchEventEmitter::onAuxClick(PointerEvent event) const {
dispatchPointerEvent("auxClick", std::move(event), RawEvent::Category::Discrete);
}
void TouchEventEmitter::onClick(PointerEvent event) const {
dispatchPointerEvent("click", std::move(event), RawEvent::Category::Discrete);
}
void TouchEventEmitter::onPointerCancel(PointerEvent event) const {
dispatchPointerEvent(
"pointerCancel", std::move(event), RawEvent::Category::ContinuousEnd);
}
void TouchEventEmitter::onPointerDown(PointerEvent event) const {
dispatchPointerEvent(
"pointerDown", std::move(event), RawEvent::Category::ContinuousStart);
}
void TouchEventEmitter::onPointerMove(PointerEvent event) const {
dispatchUniqueEvent(
"pointerMove", std::make_shared<PointerEvent>(std::move(event)));
}
void TouchEventEmitter::onPointerUp(PointerEvent event) const {
dispatchPointerEvent(
"pointerUp", std::move(event), RawEvent::Category::ContinuousEnd);
}
void TouchEventEmitter::onPointerEnter(PointerEvent event) const {
dispatchPointerEvent(
"pointerEnter", std::move(event), RawEvent::Category::ContinuousStart);
}
void TouchEventEmitter::onPointerLeave(PointerEvent event) const {
dispatchPointerEvent(
"pointerLeave", std::move(event), RawEvent::Category::ContinuousEnd);
}
void TouchEventEmitter::onPointerOver(PointerEvent event) const {
dispatchPointerEvent(
"pointerOver", std::move(event), RawEvent::Category::ContinuousStart);
}
void TouchEventEmitter::onPointerOut(PointerEvent event) const {
dispatchPointerEvent(
"pointerOut", std::move(event), RawEvent::Category::ContinuousStart);
}
void TouchEventEmitter::onGotPointerCapture(PointerEvent event) const {
dispatchPointerEvent(
"gotPointerCapture",
std::move(event),
RawEvent::Category::ContinuousStart);
}
void TouchEventEmitter::onLostPointerCapture(PointerEvent event) const {
dispatchPointerEvent(
"lostPointerCapture",
std::move(event),
RawEvent::Category::ContinuousEnd);
}
} // namespace facebook::react