React Native: Touch Instrumentation Interface (#21024)
Timothy Yung committed
Mar 17, 2021 at 13:46 UTC
3fb11eed9a166ebab23b778662f54c449fcffad0
1 file changed
+13
packages/react-native-renderer/src/legacy-events/ResponderTouchHistoryStore.js
+13
@@ -184,8 +184,21 @@ function printTouchBank(): string {
184
return printed;
185
}
186
187
+let instrumentationCallback: ?(string, TouchEvent) => void;
188
+
189
const ResponderTouchHistoryStore = {
190
+ /**
191
+ * Registers a listener which can be used to instrument every touch event.
192
+ */
193
+ instrument(callback: (string, TouchEvent) => void): void {
194
+ instrumentationCallback = callback;
195
+ },
196
+
197
recordTouchTrack(topLevelType: string, nativeEvent: TouchEvent): void {
198
+ if (instrumentationCallback != null) {
199
+ instrumentationCallback(topLevelType, nativeEvent);
200
+ }
201
+
202
if (isMoveish(topLevelType)) {
203
nativeEvent.changedTouches.forEach(recordTouchMove);
204
} else if (isStartish(topLevelType)) {