@tamagui/react-native-use-pressable 1.0.1-rc.5 → 1.0.1-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -73,7 +73,8 @@ const isButtonRole = (element) => element.getAttribute("role") === "button";
|
|
|
73
73
|
const isPressStartSignal = (signal) => signal === RESPONDER_INACTIVE_PRESS_START || signal === RESPONDER_ACTIVE_PRESS_START || signal === RESPONDER_ACTIVE_LONG_PRESS_START;
|
|
74
74
|
const isTerminalSignal = (signal) => signal === RESPONDER_TERMINATED || signal === RESPONDER_RELEASE;
|
|
75
75
|
const isValidKeyPress = (event) => {
|
|
76
|
-
const key = event.key
|
|
76
|
+
const key = event.key;
|
|
77
|
+
const target = event.target;
|
|
77
78
|
const role = target.getAttribute("role");
|
|
78
79
|
const isSpacebar = key === " " || key === "Spacebar";
|
|
79
80
|
return key === "Enter" || isSpacebar && role === "button";
|
|
@@ -168,7 +169,8 @@ class PressResponder {
|
|
|
168
169
|
},
|
|
169
170
|
onKeyDown: (event) => {
|
|
170
171
|
const disabled = this._config.disabled;
|
|
171
|
-
const key = event.key
|
|
172
|
+
const key = event.key;
|
|
173
|
+
const target = event.target;
|
|
172
174
|
if (!disabled && isValidKeyPress(event)) {
|
|
173
175
|
if (this._touchState === NOT_RESPONDER) {
|
|
174
176
|
start(event, false);
|
|
@@ -205,7 +207,10 @@ class PressResponder {
|
|
|
205
207
|
this._receiveSignal(RESPONDER_TERMINATED, event);
|
|
206
208
|
},
|
|
207
209
|
onResponderTerminationRequest: (event) => {
|
|
208
|
-
const _this$_config = this._config
|
|
210
|
+
const _this$_config = this._config;
|
|
211
|
+
const cancelable = _this$_config.cancelable;
|
|
212
|
+
const disabled = _this$_config.disabled;
|
|
213
|
+
const onLongPress = _this$_config.onLongPress;
|
|
209
214
|
if (!disabled && onLongPress != null && this._isPointerTouch && event.nativeEvent.type === "contextmenu") {
|
|
210
215
|
return false;
|
|
211
216
|
}
|
|
@@ -215,7 +220,9 @@ class PressResponder {
|
|
|
215
220
|
return cancelable;
|
|
216
221
|
},
|
|
217
222
|
onClick: (event) => {
|
|
218
|
-
const _this$_config2 = this._config
|
|
223
|
+
const _this$_config2 = this._config;
|
|
224
|
+
const disabled = _this$_config2.disabled;
|
|
225
|
+
const onPress = _this$_config2.onPress;
|
|
219
226
|
if (!disabled) {
|
|
220
227
|
event.stopPropagation();
|
|
221
228
|
if (this._longPressDispatched || this._selectionTerminated) {
|
|
@@ -230,7 +237,9 @@ class PressResponder {
|
|
|
230
237
|
}
|
|
231
238
|
},
|
|
232
239
|
onContextMenu: (event) => {
|
|
233
|
-
const _this$_config3 = this._config
|
|
240
|
+
const _this$_config3 = this._config;
|
|
241
|
+
const disabled = _this$_config3.disabled;
|
|
242
|
+
const onLongPress = _this$_config3.onLongPress;
|
|
234
243
|
if (!disabled) {
|
|
235
244
|
if (onLongPress != null && this._isPointerTouch && !event.defaultPrevented) {
|
|
236
245
|
event.preventDefault();
|
|
@@ -255,7 +264,7 @@ class PressResponder {
|
|
|
255
264
|
}
|
|
256
265
|
if (nextState == null || nextState === ERROR) {
|
|
257
266
|
console.error(
|
|
258
|
-
|
|
267
|
+
`PressResponder: Invalid signal ${signal} for state ${prevState} on responder`
|
|
259
268
|
);
|
|
260
269
|
} else if (prevState !== nextState) {
|
|
261
270
|
this._performTransitionSideEffects(prevState, nextState, signal, event);
|
|
@@ -285,11 +294,13 @@ class PressResponder {
|
|
|
285
294
|
this._deactivate(event);
|
|
286
295
|
}
|
|
287
296
|
if (isPressStartSignal(prevState) && signal === RESPONDER_RELEASE) {
|
|
288
|
-
const _this$_config4 = this._config
|
|
297
|
+
const _this$_config4 = this._config;
|
|
298
|
+
const _onLongPress = _this$_config4.onLongPress;
|
|
299
|
+
const onPress = _this$_config4.onPress;
|
|
289
300
|
if (onPress != null) {
|
|
290
301
|
const isPressCanceledByLongPress = _onLongPress != null && prevState === RESPONDER_ACTIVE_LONG_PRESS_START;
|
|
291
302
|
if (!isPressCanceledByLongPress) {
|
|
292
|
-
if (!isNextActive
|
|
303
|
+
if (!(isNextActive || isPrevActive)) {
|
|
293
304
|
this._activate(event);
|
|
294
305
|
this._deactivate(event);
|
|
295
306
|
}
|
|
@@ -299,7 +310,9 @@ class PressResponder {
|
|
|
299
310
|
this._cancelPressDelayTimeout();
|
|
300
311
|
}
|
|
301
312
|
_activate(event) {
|
|
302
|
-
const _this$_config5 = this._config
|
|
313
|
+
const _this$_config5 = this._config;
|
|
314
|
+
const onPressChange = _this$_config5.onPressChange;
|
|
315
|
+
const onPressStart = _this$_config5.onPressStart;
|
|
303
316
|
const touch = getTouchFromResponderEvent(event);
|
|
304
317
|
this._touchActivatePosition = {
|
|
305
318
|
pageX: touch.pageX,
|
|
@@ -313,7 +326,9 @@ class PressResponder {
|
|
|
313
326
|
}
|
|
314
327
|
}
|
|
315
328
|
_deactivate(event) {
|
|
316
|
-
const _this$_config6 = this._config
|
|
329
|
+
const _this$_config6 = this._config;
|
|
330
|
+
const onPressChange = _this$_config6.onPressChange;
|
|
331
|
+
const onPressEnd = _this$_config6.onPressEnd;
|
|
317
332
|
function end() {
|
|
318
333
|
if (onPressEnd != null) {
|
|
319
334
|
onPressEnd(event);
|
|
@@ -365,7 +380,9 @@ function normalizeDelay(delay, min, fallback) {
|
|
|
365
380
|
return Math.max(min, delay !== null && delay !== void 0 ? delay : fallback);
|
|
366
381
|
}
|
|
367
382
|
function getTouchFromResponderEvent(event) {
|
|
368
|
-
const _event$nativeEvent = event.nativeEvent
|
|
383
|
+
const _event$nativeEvent = event.nativeEvent;
|
|
384
|
+
const changedTouches = _event$nativeEvent.changedTouches;
|
|
385
|
+
const touches = _event$nativeEvent.touches;
|
|
369
386
|
if (touches != null && touches.length > 0) {
|
|
370
387
|
return touches[0];
|
|
371
388
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/PressResponder.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n *\n * @format\n */\n'use strict'\n\nconst DELAY = 'DELAY'\nconst ERROR = 'ERROR'\nconst LONG_PRESS_DETECTED = 'LONG_PRESS_DETECTED'\nconst NOT_RESPONDER = 'NOT_RESPONDER'\nconst RESPONDER_ACTIVE_LONG_PRESS_START = 'RESPONDER_ACTIVE_LONG_PRESS_START'\nconst RESPONDER_ACTIVE_PRESS_START = 'RESPONDER_ACTIVE_PRESS_START'\nconst RESPONDER_INACTIVE_PRESS_START = 'RESPONDER_INACTIVE_PRESS_START'\nconst RESPONDER_GRANT = 'RESPONDER_GRANT'\nconst RESPONDER_RELEASE = 'RESPONDER_RELEASE'\nconst RESPONDER_TERMINATED = 'RESPONDER_TERMINATED'\nconst Transitions = Object.freeze({\n NOT_RESPONDER: {\n DELAY: ERROR,\n RESPONDER_GRANT: RESPONDER_INACTIVE_PRESS_START,\n RESPONDER_RELEASE: ERROR,\n RESPONDER_TERMINATED: ERROR,\n LONG_PRESS_DETECTED: ERROR,\n },\n RESPONDER_INACTIVE_PRESS_START: {\n DELAY: RESPONDER_ACTIVE_PRESS_START,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: ERROR,\n },\n RESPONDER_ACTIVE_PRESS_START: {\n DELAY: ERROR,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: RESPONDER_ACTIVE_LONG_PRESS_START,\n },\n RESPONDER_ACTIVE_LONG_PRESS_START: {\n DELAY: ERROR,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: RESPONDER_ACTIVE_LONG_PRESS_START,\n },\n ERROR: {\n DELAY: NOT_RESPONDER,\n RESPONDER_GRANT: RESPONDER_INACTIVE_PRESS_START,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: NOT_RESPONDER,\n },\n})\n\nconst isActiveSignal = (signal) =>\n signal === RESPONDER_ACTIVE_PRESS_START || signal === RESPONDER_ACTIVE_LONG_PRESS_START\n\nconst isButtonRole = (element) => element.getAttribute('role') === 'button'\n\nconst isPressStartSignal = (signal) =>\n signal === RESPONDER_INACTIVE_PRESS_START ||\n signal === RESPONDER_ACTIVE_PRESS_START ||\n signal === RESPONDER_ACTIVE_LONG_PRESS_START\n\nconst isTerminalSignal = (signal) => signal === RESPONDER_TERMINATED || signal === RESPONDER_RELEASE\n\nconst isValidKeyPress = (event) => {\n const key = event.key,\n target = event.target\n const role = target.getAttribute('role')\n const isSpacebar = key === ' ' || key === 'Spacebar'\n return key === 'Enter' || (isSpacebar && role === 'button')\n}\n\nconst DEFAULT_LONG_PRESS_DELAY_MS = 450 // 500 - 50\n\nconst DEFAULT_PRESS_DELAY_MS = 50\n/**\n * =========================== PressResponder Tutorial ===========================\n *\n * The `PressResponder` class helps you create press interactions by analyzing the\n * geometry of elements and observing when another responder (e.g. ScrollView)\n * has stolen the touch lock. It offers hooks for your component to provide\n * interaction feedback to the user:\n *\n * - When a press has activated (e.g. highlight an element)\n * - When a press has deactivated (e.g. un-highlight an element)\n * - When a press sould trigger an action, meaning it activated and deactivated\n * while within the geometry of the element without the lock being stolen.\n *\n * A high quality interaction isn't as simple as you might think. There should\n * be a slight delay before activation. Moving your finger beyond an element's\n * bounds should trigger deactivation, but moving the same finger back within an\n * element's bounds should trigger reactivation.\n *\n * In order to use `PressResponder`, do the following:\n *\n * const pressResponder = new PressResponder(config);\n *\n * 2. Choose the rendered component who should collect the press events. On that\n * element, spread `pressability.getEventHandlers()` into its props.\n *\n * return (\n * <View {...this.state.pressResponder.getEventHandlers()} />\n * );\n *\n * 3. Reset `PressResponder` when your component unmounts.\n *\n * componentWillUnmount() {\n * this.state.pressResponder.reset();\n * }\n *\n * ==================== Implementation Details ====================\n *\n * `PressResponder` only assumes that there exists a `HitRect` node. The `PressRect`\n * is an abstract box that is extended beyond the `HitRect`.\n *\n * # Geometry\n *\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n * \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 - Presses start anywhere within `HitRect`.\n * \u2502 \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 \u2502\n * \u2502 \u2502 \u2502 VisualRect \u2502 \u2502 \u2502\n * \u2502 \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502 \u2502 - When pressed down for sufficient amount of time\n * \u2502 \u2502 HitRect \u2502 \u2502 before letting up, `VisualRect` activates.\n * \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502\n * \u2502 Out Region o \u2502\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2518\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500 When the press is released outside the `HitRect`,\n * the responder is NOT eligible for a \"press\".\n *\n * # State Machine\n *\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u25C0\u2500\u2500\u2500\u2500 RESPONDER_RELEASE\n * \u2502 NOT_RESPONDER \u2502\n * \u2514\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u25C0\u2500\u2500\u2500\u2500 RESPONDER_TERMINATED\n * \u2502\n * \u2502 RESPONDER_GRANT (HitRect)\n * \u2502\n * \u25BC\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n * \u2502 RESPONDER_INACTIVE_ \u2502 DELAY \u2502 RESPONDER_ACTIVE_ \u2502 T + DELAY \u2502 RESPONDER_ACTIVE_ \u2502\n * \u2502 PRESS_START \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25B6 \u2502 PRESS_START \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25B6 \u2502 LONG_PRESS_START \u2502\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n *\n * T + DELAY => LONG_PRESS_DELAY + DELAY\n *\n * Not drawn are the side effects of each transition. The most important side\n * effect is the invocation of `onLongPress`. Only when the browser produces a\n * `click` event is `onPress` invoked.\n */\n\nexport default class PressResponder {\n _touchActivatePosition = null as any\n _pressDelayTimeout = 0 as any\n _selectionTerminated = false\n _isPointerTouch = false\n _longPressDelayTimeout = 0 as any\n _longPressDispatched = false\n _pressOutDelayTimeout = 0 as any\n _touchState = NOT_RESPONDER\n _config = null as any\n _eventHandlers = null as any\n\n constructor(config) {\n this.configure(config)\n }\n\n configure(config) {\n this._config = config\n }\n /**\n * Resets any pending timers. This should be called on unmount.\n */\n\n reset() {\n this._cancelLongPressDelayTimeout()\n\n this._cancelPressDelayTimeout()\n\n this._cancelPressOutDelayTimeout()\n }\n /**\n * Returns a set of props to spread into the interactive element.\n */\n\n getEventHandlers() {\n if (this._eventHandlers == null) {\n this._eventHandlers = this._createEventHandlers()\n }\n\n return this._eventHandlers\n }\n\n _createEventHandlers() {\n const start = (event, shouldDelay?: boolean) => {\n event.persist()\n\n this._cancelPressOutDelayTimeout()\n\n this._longPressDispatched = false\n this._selectionTerminated = false\n this._touchState = NOT_RESPONDER\n this._isPointerTouch = event.nativeEvent.type === 'touchstart'\n\n this._receiveSignal(RESPONDER_GRANT, event)\n\n const delayPressStart = normalizeDelay(\n this._config.delayPressStart,\n 0,\n DEFAULT_PRESS_DELAY_MS\n )\n\n if (shouldDelay !== false && delayPressStart > 0) {\n this._pressDelayTimeout = setTimeout(() => {\n this._receiveSignal(DELAY, event)\n }, delayPressStart)\n } else {\n this._receiveSignal(DELAY, event)\n }\n\n const delayLongPress = normalizeDelay(\n this._config.delayLongPress,\n 10,\n DEFAULT_LONG_PRESS_DELAY_MS\n )\n this._longPressDelayTimeout = setTimeout(() => {\n this._handleLongPress(event)\n }, delayLongPress + delayPressStart)\n }\n\n const end = (event) => {\n this._receiveSignal(RESPONDER_RELEASE, event)\n }\n\n const keyupHandler = (event) => {\n const onPress = this._config.onPress\n const target = event.target\n\n if (this._touchState !== NOT_RESPONDER && isValidKeyPress(event)) {\n end(event)\n document.removeEventListener('keyup', keyupHandler)\n const role = target.getAttribute('role')\n const elementType = target.tagName.toLowerCase()\n const isNativeInteractiveElement =\n role === 'link' ||\n elementType === 'a' ||\n elementType === 'button' ||\n elementType === 'input' ||\n elementType === 'select' ||\n elementType === 'textarea'\n\n if (onPress != null && !isNativeInteractiveElement) {\n onPress(event)\n }\n }\n }\n\n return {\n onStartShouldSetResponder: (event) => {\n const disabled = this._config.disabled\n\n if (disabled && isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n\n if (disabled == null) {\n return true\n }\n\n return !disabled\n },\n onKeyDown: (event) => {\n const disabled = this._config.disabled\n const key = event.key,\n target = event.target\n\n if (!disabled && isValidKeyPress(event)) {\n if (this._touchState === NOT_RESPONDER) {\n start(event, false) // Listen to 'keyup' on document to account for situations where\n // focus is moved to another element during 'keydown'.\n\n document.addEventListener('keyup', keyupHandler)\n }\n\n const role = target.getAttribute('role')\n const isSpacebarKey = key === ' ' || key === 'Spacebar'\n\n const _isButtonRole = role === 'button' || role === 'menuitem'\n\n if (isSpacebarKey && _isButtonRole) {\n // Prevent spacebar scrolling the window\n event.preventDefault()\n }\n\n event.stopPropagation()\n }\n },\n onResponderGrant: (event) => start(event),\n onResponderMove: (event) => {\n if (this._config.onPressMove != null) {\n this._config.onPressMove(event)\n }\n\n const touch = getTouchFromResponderEvent(event)\n\n if (this._touchActivatePosition != null) {\n const deltaX = this._touchActivatePosition.pageX - touch.pageX\n const deltaY = this._touchActivatePosition.pageY - touch.pageY\n\n if (Math.hypot(deltaX, deltaY) > 10) {\n this._cancelLongPressDelayTimeout()\n }\n }\n },\n onResponderRelease: (event) => end(event),\n onResponderTerminate: (event) => {\n if (event.nativeEvent.type === 'selectionchange') {\n this._selectionTerminated = true\n }\n\n this._receiveSignal(RESPONDER_TERMINATED, event)\n },\n onResponderTerminationRequest: (event) => {\n const _this$_config = this._config,\n cancelable = _this$_config.cancelable,\n disabled = _this$_config.disabled,\n onLongPress = _this$_config.onLongPress // If `onLongPress` is provided, don't terminate on `contextmenu` as default\n // behavior will be prevented for non-mouse pointers.\n\n if (\n !disabled &&\n onLongPress != null &&\n this._isPointerTouch &&\n event.nativeEvent.type === 'contextmenu'\n ) {\n return false\n }\n\n if (cancelable == null) {\n return true\n }\n\n return cancelable\n },\n // NOTE: this diverges from react-native in 3 significant ways:\n // * The `onPress` callback is not connected to the responder system (the native\n // `click` event must be used but is dispatched in many scenarios where no pointers\n // are on the screen.) Therefore, it's possible for `onPress` to be called without\n // `onPress{Start,End}` being called first.\n // * The `onPress` callback is only be called on the first ancestor of the native\n // `click` target that is using the PressResponder.\n // * The event's `nativeEvent` is a `MouseEvent` not a `TouchEvent`.\n onClick: (event) => {\n const _this$_config2 = this._config,\n disabled = _this$_config2.disabled,\n onPress = _this$_config2.onPress\n\n if (!disabled) {\n // If long press dispatched, cancel default click behavior.\n // If the responder terminated because text was selected during the gesture,\n // cancel the default click behavior.\n event.stopPropagation()\n\n if (this._longPressDispatched || this._selectionTerminated) {\n event.preventDefault()\n } else if (onPress != null && event.altKey === false) {\n onPress(event)\n }\n } else {\n if (isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n }\n },\n // If `onLongPress` is provided and a touch pointer is being used, prevent the\n // default context menu from opening.\n onContextMenu: (event) => {\n const _this$_config3 = this._config,\n disabled = _this$_config3.disabled,\n onLongPress = _this$_config3.onLongPress\n\n if (!disabled) {\n if (onLongPress != null && this._isPointerTouch && !event.defaultPrevented) {\n event.preventDefault()\n event.stopPropagation()\n }\n } else {\n if (isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n }\n },\n }\n }\n /**\n * Receives a state machine signal, performs side effects of the transition\n * and stores the new state. Validates the transition as well.\n */\n\n _receiveSignal(signal, event) {\n const prevState = this._touchState\n let nextState = null\n\n if (Transitions[prevState] != null) {\n nextState = Transitions[prevState][signal]\n }\n\n if (this._touchState === NOT_RESPONDER && signal === RESPONDER_RELEASE) {\n return\n }\n\n if (nextState == null || nextState === ERROR) {\n // eslint-disable-next-line no-console\n console.error(\n 'PressResponder: Invalid signal ' + signal + ' for state ' + prevState + ' on responder'\n )\n } else if (prevState !== nextState) {\n this._performTransitionSideEffects(prevState, nextState, signal, event)\n\n this._touchState = nextState\n }\n }\n /**\n * Performs a transition between touchable states and identify any activations\n * or deactivations (and callback invocations).\n */\n\n _performTransitionSideEffects(prevState, nextState, signal, event) {\n if (isTerminalSignal(signal)) {\n // Pressable suppression of contextmenu on windows.\n // On Windows, the contextmenu is displayed after pointerup.\n // https://github.com/necolas/react-native-web/issues/2296\n setTimeout(() => {\n this._isPointerTouch = false\n }, 0)\n this._touchActivatePosition = null\n\n this._cancelLongPressDelayTimeout()\n }\n\n if (isPressStartSignal(prevState) && signal === LONG_PRESS_DETECTED) {\n const onLongPress = this._config.onLongPress // Long press is not supported for keyboards because 'click' can be dispatched\n // immediately (and multiple times) after 'keydown'.\n\n if (onLongPress != null && event.nativeEvent.key == null) {\n onLongPress(event)\n this._longPressDispatched = true\n }\n }\n\n const isPrevActive = isActiveSignal(prevState)\n const isNextActive = isActiveSignal(nextState)\n\n if (!isPrevActive && isNextActive) {\n this._activate(event)\n } else if (isPrevActive && !isNextActive) {\n this._deactivate(event)\n }\n\n if (isPressStartSignal(prevState) && signal === RESPONDER_RELEASE) {\n const _this$_config4 = this._config,\n _onLongPress = _this$_config4.onLongPress,\n onPress = _this$_config4.onPress\n\n if (onPress != null) {\n const isPressCanceledByLongPress =\n _onLongPress != null && prevState === RESPONDER_ACTIVE_LONG_PRESS_START\n\n if (!isPressCanceledByLongPress) {\n // If we never activated (due to delays), activate and deactivate now.\n if (!isNextActive && !isPrevActive) {\n this._activate(event)\n\n this._deactivate(event)\n }\n }\n }\n }\n\n this._cancelPressDelayTimeout()\n }\n\n _activate(event) {\n const _this$_config5 = this._config,\n onPressChange = _this$_config5.onPressChange,\n onPressStart = _this$_config5.onPressStart\n const touch = getTouchFromResponderEvent(event)\n this._touchActivatePosition = {\n pageX: touch.pageX,\n pageY: touch.pageY,\n }\n\n if (onPressStart != null) {\n onPressStart(event)\n }\n\n if (onPressChange != null) {\n onPressChange(true)\n }\n }\n\n _deactivate(event) {\n const _this$_config6 = this._config,\n onPressChange = _this$_config6.onPressChange,\n onPressEnd = _this$_config6.onPressEnd\n\n function end() {\n if (onPressEnd != null) {\n onPressEnd(event)\n }\n\n if (onPressChange != null) {\n onPressChange(false)\n }\n }\n\n const delayPressEnd = normalizeDelay(this._config.delayPressEnd)\n\n if (delayPressEnd > 0) {\n this._pressOutDelayTimeout = setTimeout(() => {\n end()\n }, delayPressEnd)\n } else {\n end()\n }\n }\n\n _handleLongPress(event) {\n if (\n this._touchState === RESPONDER_ACTIVE_PRESS_START ||\n this._touchState === RESPONDER_ACTIVE_LONG_PRESS_START\n ) {\n this._receiveSignal(LONG_PRESS_DETECTED, event)\n }\n }\n\n _cancelLongPressDelayTimeout() {\n if (this._longPressDelayTimeout != null) {\n clearTimeout(this._longPressDelayTimeout)\n this._longPressDelayTimeout = null\n }\n }\n\n _cancelPressDelayTimeout() {\n if (this._pressDelayTimeout != null) {\n clearTimeout(this._pressDelayTimeout)\n this._pressDelayTimeout = null\n }\n }\n\n _cancelPressOutDelayTimeout() {\n if (this._pressOutDelayTimeout != null) {\n clearTimeout(this._pressOutDelayTimeout)\n this._pressOutDelayTimeout = null\n }\n }\n}\n\nfunction normalizeDelay(delay, min?: number, fallback?: any) {\n if (min === void 0) {\n min = 0\n }\n\n if (fallback === void 0) {\n fallback = 0\n }\n\n return Math.max(min, delay !== null && delay !== void 0 ? delay : fallback)\n}\n\nfunction getTouchFromResponderEvent(event) {\n const _event$nativeEvent = event.nativeEvent,\n changedTouches = _event$nativeEvent.changedTouches,\n touches = _event$nativeEvent.touches\n\n if (touches != null && touches.length > 0) {\n return touches[0]\n }\n\n if (changedTouches != null && changedTouches.length > 0) {\n return changedTouches[0]\n }\n\n return event.nativeEvent\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,sBAAsB;AAC5B,MAAM,gBAAgB;AACtB,MAAM,oCAAoC;AAC1C,MAAM,+BAA+B;AACrC,MAAM,iCAAiC;AACvC,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAC1B,MAAM,uBAAuB;AAC7B,MAAM,cAAc,OAAO,OAAO;AAAA,EAChC,eAAe;AAAA,IACb,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AAAA,EACA,gCAAgC;AAAA,IAC9B,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AAAA,EACA,8BAA8B;AAAA,IAC5B,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AAAA,EACA,mCAAmC;AAAA,IACjC,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AACF,CAAC;AAED,MAAM,iBAAiB,CAAC,WACtB,WAAW,
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n *\n * @format\n */\n'use strict'\n\nconst DELAY = 'DELAY'\nconst ERROR = 'ERROR'\nconst LONG_PRESS_DETECTED = 'LONG_PRESS_DETECTED'\nconst NOT_RESPONDER = 'NOT_RESPONDER'\nconst RESPONDER_ACTIVE_LONG_PRESS_START = 'RESPONDER_ACTIVE_LONG_PRESS_START'\nconst RESPONDER_ACTIVE_PRESS_START = 'RESPONDER_ACTIVE_PRESS_START'\nconst RESPONDER_INACTIVE_PRESS_START = 'RESPONDER_INACTIVE_PRESS_START'\nconst RESPONDER_GRANT = 'RESPONDER_GRANT'\nconst RESPONDER_RELEASE = 'RESPONDER_RELEASE'\nconst RESPONDER_TERMINATED = 'RESPONDER_TERMINATED'\nconst Transitions = Object.freeze({\n NOT_RESPONDER: {\n DELAY: ERROR,\n RESPONDER_GRANT: RESPONDER_INACTIVE_PRESS_START,\n RESPONDER_RELEASE: ERROR,\n RESPONDER_TERMINATED: ERROR,\n LONG_PRESS_DETECTED: ERROR,\n },\n RESPONDER_INACTIVE_PRESS_START: {\n DELAY: RESPONDER_ACTIVE_PRESS_START,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: ERROR,\n },\n RESPONDER_ACTIVE_PRESS_START: {\n DELAY: ERROR,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: RESPONDER_ACTIVE_LONG_PRESS_START,\n },\n RESPONDER_ACTIVE_LONG_PRESS_START: {\n DELAY: ERROR,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: RESPONDER_ACTIVE_LONG_PRESS_START,\n },\n ERROR: {\n DELAY: NOT_RESPONDER,\n RESPONDER_GRANT: RESPONDER_INACTIVE_PRESS_START,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: NOT_RESPONDER,\n },\n})\n\nconst isActiveSignal = (signal) =>\n signal === RESPONDER_ACTIVE_PRESS_START ||\n signal === RESPONDER_ACTIVE_LONG_PRESS_START\n\nconst isButtonRole = (element) => element.getAttribute('role') === 'button'\n\nconst isPressStartSignal = (signal) =>\n signal === RESPONDER_INACTIVE_PRESS_START ||\n signal === RESPONDER_ACTIVE_PRESS_START ||\n signal === RESPONDER_ACTIVE_LONG_PRESS_START\n\nconst isTerminalSignal = (signal) =>\n signal === RESPONDER_TERMINATED || signal === RESPONDER_RELEASE\n\nconst isValidKeyPress = (event) => {\n const key = event.key\n const target = event.target\n const role = target.getAttribute('role')\n const isSpacebar = key === ' ' || key === 'Spacebar'\n return key === 'Enter' || (isSpacebar && role === 'button')\n}\n\nconst DEFAULT_LONG_PRESS_DELAY_MS = 450 // 500 - 50\n\nconst DEFAULT_PRESS_DELAY_MS = 50\n/**\n * =========================== PressResponder Tutorial ===========================\n *\n * The `PressResponder` class helps you create press interactions by analyzing the\n * geometry of elements and observing when another responder (e.g. ScrollView)\n * has stolen the touch lock. It offers hooks for your component to provide\n * interaction feedback to the user:\n *\n * - When a press has activated (e.g. highlight an element)\n * - When a press has deactivated (e.g. un-highlight an element)\n * - When a press sould trigger an action, meaning it activated and deactivated\n * while within the geometry of the element without the lock being stolen.\n *\n * A high quality interaction isn't as simple as you might think. There should\n * be a slight delay before activation. Moving your finger beyond an element's\n * bounds should trigger deactivation, but moving the same finger back within an\n * element's bounds should trigger reactivation.\n *\n * In order to use `PressResponder`, do the following:\n *\n * const pressResponder = new PressResponder(config);\n *\n * 2. Choose the rendered component who should collect the press events. On that\n * element, spread `pressability.getEventHandlers()` into its props.\n *\n * return (\n * <View {...this.state.pressResponder.getEventHandlers()} />\n * );\n *\n * 3. Reset `PressResponder` when your component unmounts.\n *\n * componentWillUnmount() {\n * this.state.pressResponder.reset();\n * }\n *\n * ==================== Implementation Details ====================\n *\n * `PressResponder` only assumes that there exists a `HitRect` node. The `PressRect`\n * is an abstract box that is extended beyond the `HitRect`.\n *\n * # Geometry\n *\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n * \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 - Presses start anywhere within `HitRect`.\n * \u2502 \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 \u2502\n * \u2502 \u2502 \u2502 VisualRect \u2502 \u2502 \u2502\n * \u2502 \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502 \u2502 - When pressed down for sufficient amount of time\n * \u2502 \u2502 HitRect \u2502 \u2502 before letting up, `VisualRect` activates.\n * \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502\n * \u2502 Out Region o \u2502\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2518\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500 When the press is released outside the `HitRect`,\n * the responder is NOT eligible for a \"press\".\n *\n * # State Machine\n *\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u25C0\u2500\u2500\u2500\u2500 RESPONDER_RELEASE\n * \u2502 NOT_RESPONDER \u2502\n * \u2514\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u25C0\u2500\u2500\u2500\u2500 RESPONDER_TERMINATED\n * \u2502\n * \u2502 RESPONDER_GRANT (HitRect)\n * \u2502\n * \u25BC\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n * \u2502 RESPONDER_INACTIVE_ \u2502 DELAY \u2502 RESPONDER_ACTIVE_ \u2502 T + DELAY \u2502 RESPONDER_ACTIVE_ \u2502\n * \u2502 PRESS_START \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25B6 \u2502 PRESS_START \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25B6 \u2502 LONG_PRESS_START \u2502\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n *\n * T + DELAY => LONG_PRESS_DELAY + DELAY\n *\n * Not drawn are the side effects of each transition. The most important side\n * effect is the invocation of `onLongPress`. Only when the browser produces a\n * `click` event is `onPress` invoked.\n */\n\nexport default class PressResponder {\n _touchActivatePosition = null as any\n _pressDelayTimeout = 0 as any\n _selectionTerminated = false\n _isPointerTouch = false\n _longPressDelayTimeout = 0 as any\n _longPressDispatched = false\n _pressOutDelayTimeout = 0 as any\n _touchState = NOT_RESPONDER\n _config = null as any\n _eventHandlers = null as any\n\n constructor(config) {\n this.configure(config)\n }\n\n configure(config) {\n this._config = config\n }\n /**\n * Resets any pending timers. This should be called on unmount.\n */\n\n reset() {\n this._cancelLongPressDelayTimeout()\n\n this._cancelPressDelayTimeout()\n\n this._cancelPressOutDelayTimeout()\n }\n /**\n * Returns a set of props to spread into the interactive element.\n */\n\n getEventHandlers() {\n if (this._eventHandlers == null) {\n this._eventHandlers = this._createEventHandlers()\n }\n\n return this._eventHandlers\n }\n\n _createEventHandlers() {\n const start = (event, shouldDelay?: boolean) => {\n event.persist()\n\n this._cancelPressOutDelayTimeout()\n\n this._longPressDispatched = false\n this._selectionTerminated = false\n this._touchState = NOT_RESPONDER\n this._isPointerTouch = event.nativeEvent.type === 'touchstart'\n\n this._receiveSignal(RESPONDER_GRANT, event)\n\n const delayPressStart = normalizeDelay(\n this._config.delayPressStart,\n 0,\n DEFAULT_PRESS_DELAY_MS,\n )\n\n if (shouldDelay !== false && delayPressStart > 0) {\n this._pressDelayTimeout = setTimeout(() => {\n this._receiveSignal(DELAY, event)\n }, delayPressStart)\n } else {\n this._receiveSignal(DELAY, event)\n }\n\n const delayLongPress = normalizeDelay(\n this._config.delayLongPress,\n 10,\n DEFAULT_LONG_PRESS_DELAY_MS,\n )\n this._longPressDelayTimeout = setTimeout(() => {\n this._handleLongPress(event)\n }, delayLongPress + delayPressStart)\n }\n\n const end = (event) => {\n this._receiveSignal(RESPONDER_RELEASE, event)\n }\n\n const keyupHandler = (event) => {\n const onPress = this._config.onPress\n const target = event.target\n\n if (this._touchState !== NOT_RESPONDER && isValidKeyPress(event)) {\n end(event)\n document.removeEventListener('keyup', keyupHandler)\n const role = target.getAttribute('role')\n const elementType = target.tagName.toLowerCase()\n const isNativeInteractiveElement =\n role === 'link' ||\n elementType === 'a' ||\n elementType === 'button' ||\n elementType === 'input' ||\n elementType === 'select' ||\n elementType === 'textarea'\n\n if (onPress != null && !isNativeInteractiveElement) {\n onPress(event)\n }\n }\n }\n\n return {\n onStartShouldSetResponder: (event) => {\n const disabled = this._config.disabled\n\n if (disabled && isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n\n if (disabled == null) {\n return true\n }\n\n return !disabled\n },\n onKeyDown: (event) => {\n const disabled = this._config.disabled\n const key = event.key\n const target = event.target\n\n if (!disabled && isValidKeyPress(event)) {\n if (this._touchState === NOT_RESPONDER) {\n start(event, false) // Listen to 'keyup' on document to account for situations where\n // focus is moved to another element during 'keydown'.\n\n document.addEventListener('keyup', keyupHandler)\n }\n\n const role = target.getAttribute('role')\n const isSpacebarKey = key === ' ' || key === 'Spacebar'\n\n const _isButtonRole = role === 'button' || role === 'menuitem'\n\n if (isSpacebarKey && _isButtonRole) {\n // Prevent spacebar scrolling the window\n event.preventDefault()\n }\n\n event.stopPropagation()\n }\n },\n onResponderGrant: (event) => start(event),\n onResponderMove: (event) => {\n if (this._config.onPressMove != null) {\n this._config.onPressMove(event)\n }\n\n const touch = getTouchFromResponderEvent(event)\n\n if (this._touchActivatePosition != null) {\n const deltaX = this._touchActivatePosition.pageX - touch.pageX\n const deltaY = this._touchActivatePosition.pageY - touch.pageY\n\n if (Math.hypot(deltaX, deltaY) > 10) {\n this._cancelLongPressDelayTimeout()\n }\n }\n },\n onResponderRelease: (event) => end(event),\n onResponderTerminate: (event) => {\n if (event.nativeEvent.type === 'selectionchange') {\n this._selectionTerminated = true\n }\n\n this._receiveSignal(RESPONDER_TERMINATED, event)\n },\n onResponderTerminationRequest: (event) => {\n const _this$_config = this._config\n const cancelable = _this$_config.cancelable\n const disabled = _this$_config.disabled\n const onLongPress = _this$_config.onLongPress // If `onLongPress` is provided, don't terminate on `contextmenu` as default\n // behavior will be prevented for non-mouse pointers.\n\n if (\n !disabled &&\n onLongPress != null &&\n this._isPointerTouch &&\n event.nativeEvent.type === 'contextmenu'\n ) {\n return false\n }\n\n if (cancelable == null) {\n return true\n }\n\n return cancelable\n },\n // NOTE: this diverges from react-native in 3 significant ways:\n // * The `onPress` callback is not connected to the responder system (the native\n // `click` event must be used but is dispatched in many scenarios where no pointers\n // are on the screen.) Therefore, it's possible for `onPress` to be called without\n // `onPress{Start,End}` being called first.\n // * The `onPress` callback is only be called on the first ancestor of the native\n // `click` target that is using the PressResponder.\n // * The event's `nativeEvent` is a `MouseEvent` not a `TouchEvent`.\n onClick: (event) => {\n const _this$_config2 = this._config\n const disabled = _this$_config2.disabled\n const onPress = _this$_config2.onPress\n\n if (!disabled) {\n // If long press dispatched, cancel default click behavior.\n // If the responder terminated because text was selected during the gesture,\n // cancel the default click behavior.\n event.stopPropagation()\n\n if (this._longPressDispatched || this._selectionTerminated) {\n event.preventDefault()\n } else if (onPress != null && event.altKey === false) {\n onPress(event)\n }\n } else {\n if (isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n }\n },\n // If `onLongPress` is provided and a touch pointer is being used, prevent the\n // default context menu from opening.\n onContextMenu: (event) => {\n const _this$_config3 = this._config\n const disabled = _this$_config3.disabled\n const onLongPress = _this$_config3.onLongPress\n\n if (!disabled) {\n if (\n onLongPress != null &&\n this._isPointerTouch &&\n !event.defaultPrevented\n ) {\n event.preventDefault()\n event.stopPropagation()\n }\n } else {\n if (isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n }\n },\n }\n }\n /**\n * Receives a state machine signal, performs side effects of the transition\n * and stores the new state. Validates the transition as well.\n */\n\n _receiveSignal(signal, event) {\n const prevState = this._touchState\n let nextState = null\n\n if (Transitions[prevState] != null) {\n nextState = Transitions[prevState][signal]\n }\n\n if (this._touchState === NOT_RESPONDER && signal === RESPONDER_RELEASE) {\n return\n }\n\n if (nextState == null || nextState === ERROR) {\n // eslint-disable-next-line no-console\n console.error(\n `PressResponder: Invalid signal ${signal} for state ${prevState} on responder`,\n )\n } else if (prevState !== nextState) {\n this._performTransitionSideEffects(prevState, nextState, signal, event)\n\n this._touchState = nextState\n }\n }\n /**\n * Performs a transition between touchable states and identify any activations\n * or deactivations (and callback invocations).\n */\n\n _performTransitionSideEffects(prevState, nextState, signal, event) {\n if (isTerminalSignal(signal)) {\n // Pressable suppression of contextmenu on windows.\n // On Windows, the contextmenu is displayed after pointerup.\n // https://github.com/necolas/react-native-web/issues/2296\n setTimeout(() => {\n this._isPointerTouch = false\n }, 0)\n this._touchActivatePosition = null\n\n this._cancelLongPressDelayTimeout()\n }\n\n if (isPressStartSignal(prevState) && signal === LONG_PRESS_DETECTED) {\n const onLongPress = this._config.onLongPress // Long press is not supported for keyboards because 'click' can be dispatched\n // immediately (and multiple times) after 'keydown'.\n\n if (onLongPress != null && event.nativeEvent.key == null) {\n onLongPress(event)\n this._longPressDispatched = true\n }\n }\n\n const isPrevActive = isActiveSignal(prevState)\n const isNextActive = isActiveSignal(nextState)\n\n if (!isPrevActive && isNextActive) {\n this._activate(event)\n } else if (isPrevActive && !isNextActive) {\n this._deactivate(event)\n }\n\n if (isPressStartSignal(prevState) && signal === RESPONDER_RELEASE) {\n const _this$_config4 = this._config\n const _onLongPress = _this$_config4.onLongPress\n const onPress = _this$_config4.onPress\n\n if (onPress != null) {\n const isPressCanceledByLongPress =\n _onLongPress != null && prevState === RESPONDER_ACTIVE_LONG_PRESS_START\n\n if (!isPressCanceledByLongPress) {\n // If we never activated (due to delays), activate and deactivate now.\n if (!(isNextActive || isPrevActive)) {\n this._activate(event)\n\n this._deactivate(event)\n }\n }\n }\n }\n\n this._cancelPressDelayTimeout()\n }\n\n _activate(event) {\n const _this$_config5 = this._config\n const onPressChange = _this$_config5.onPressChange\n const onPressStart = _this$_config5.onPressStart\n const touch = getTouchFromResponderEvent(event)\n this._touchActivatePosition = {\n pageX: touch.pageX,\n pageY: touch.pageY,\n }\n\n if (onPressStart != null) {\n onPressStart(event)\n }\n\n if (onPressChange != null) {\n onPressChange(true)\n }\n }\n\n _deactivate(event) {\n const _this$_config6 = this._config\n const onPressChange = _this$_config6.onPressChange\n const onPressEnd = _this$_config6.onPressEnd\n\n function end() {\n if (onPressEnd != null) {\n onPressEnd(event)\n }\n\n if (onPressChange != null) {\n onPressChange(false)\n }\n }\n\n const delayPressEnd = normalizeDelay(this._config.delayPressEnd)\n\n if (delayPressEnd > 0) {\n this._pressOutDelayTimeout = setTimeout(() => {\n end()\n }, delayPressEnd)\n } else {\n end()\n }\n }\n\n _handleLongPress(event) {\n if (\n this._touchState === RESPONDER_ACTIVE_PRESS_START ||\n this._touchState === RESPONDER_ACTIVE_LONG_PRESS_START\n ) {\n this._receiveSignal(LONG_PRESS_DETECTED, event)\n }\n }\n\n _cancelLongPressDelayTimeout() {\n if (this._longPressDelayTimeout != null) {\n clearTimeout(this._longPressDelayTimeout)\n this._longPressDelayTimeout = null\n }\n }\n\n _cancelPressDelayTimeout() {\n if (this._pressDelayTimeout != null) {\n clearTimeout(this._pressDelayTimeout)\n this._pressDelayTimeout = null\n }\n }\n\n _cancelPressOutDelayTimeout() {\n if (this._pressOutDelayTimeout != null) {\n clearTimeout(this._pressOutDelayTimeout)\n this._pressOutDelayTimeout = null\n }\n }\n}\n\nfunction normalizeDelay(delay, min?: number, fallback?: any) {\n if (min === void 0) {\n min = 0\n }\n\n if (fallback === void 0) {\n fallback = 0\n }\n\n return Math.max(min, delay !== null && delay !== void 0 ? delay : fallback)\n}\n\nfunction getTouchFromResponderEvent(event) {\n const _event$nativeEvent = event.nativeEvent\n const changedTouches = _event$nativeEvent.changedTouches\n const touches = _event$nativeEvent.touches\n\n if (touches != null && touches.length > 0) {\n return touches[0]\n }\n\n if (changedTouches != null && changedTouches.length > 0) {\n return changedTouches[0]\n }\n\n return event.nativeEvent\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,sBAAsB;AAC5B,MAAM,gBAAgB;AACtB,MAAM,oCAAoC;AAC1C,MAAM,+BAA+B;AACrC,MAAM,iCAAiC;AACvC,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAC1B,MAAM,uBAAuB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UAAI;AAAA,IACN;AAAA,EACF;AAAA,EAEA,iBAAiB,OAAO;AACtB,QACE,KAAK,gBAAgB,gCACrB,KAAK,gBAAgB,mCACrB;AACA,WAAK,eAAe,qBAAqB,KAAK;AAAA,IAChD;AAAA,EACF;AAAA,EAEA,+BAA+B;AAC7B,QAAI,KAAK,0BAA0B,MAAM;AACvC,mBAAa,KAAK,sBAAsB;AACxC,WAAK,yBAAyB;AAAA,IAChC;AAAA,EACF;AAAA,EAEA,2BAA2B;AACzB,QAAI,KAAK,sBAAsB,MAAM;AACnC,mBAAa,KAAK,kBAAkB;AACpC,WAAK,qBAAqB;AAAA,IAC5B;AAAA,EACF;AAAA,EAEA,8BAA8B;AAC5B,QAAI,KAAK,yBAAyB,MAAM;AACtC,mBAAa,KAAK,qBAAqB;AACvC,WAAK,wBAAwB;AAAA,IAC/B;AAAA,EACF;AACF;AAEA,SAAS,eAAe,OAAO,KAAc,UAAgB;AAC3D,MAAI,QAAQ,QAAQ;AAClB,UAAM;AAAA,EACR;AAEA,MAAI,aAAa,QAAQ;AACvB,eAAW;AAAA,EACb;AAEA,SAAO,KAAK,IAAI,KAAK,UAAU,QAAQ,UAAU,SAAS,QAAQ,QAAQ;AAC5E;AAEA,SAAS,2BAA2B,OAAO;AACzC,QAAM,qBAAqB,MAAM;AACjC,QAAM,iBAAiB,mBAAmB;AAC1C,QAAM,UAAU,mBAAmB;AAEnC,MAAI,WAAW,QAAQ,QAAQ,SAAS,GAAG;AACzC,WAAO,QAAQ;AAAA,EACjB;AAEA,MAAI,kBAAkB,QAAQ,eAAe,SAAS,GAAG;AACvD,WAAO,eAAe;AAAA,EACxB;AAEA,SAAO,MAAM;AACf;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -50,7 +50,8 @@ const isButtonRole = (element) => element.getAttribute("role") === "button";
|
|
|
50
50
|
const isPressStartSignal = (signal) => signal === RESPONDER_INACTIVE_PRESS_START || signal === RESPONDER_ACTIVE_PRESS_START || signal === RESPONDER_ACTIVE_LONG_PRESS_START;
|
|
51
51
|
const isTerminalSignal = (signal) => signal === RESPONDER_TERMINATED || signal === RESPONDER_RELEASE;
|
|
52
52
|
const isValidKeyPress = (event) => {
|
|
53
|
-
const key = event.key
|
|
53
|
+
const key = event.key;
|
|
54
|
+
const target = event.target;
|
|
54
55
|
const role = target.getAttribute("role");
|
|
55
56
|
const isSpacebar = key === " " || key === "Spacebar";
|
|
56
57
|
return key === "Enter" || isSpacebar && role === "button";
|
|
@@ -145,7 +146,8 @@ class PressResponder {
|
|
|
145
146
|
},
|
|
146
147
|
onKeyDown: (event) => {
|
|
147
148
|
const disabled = this._config.disabled;
|
|
148
|
-
const key = event.key
|
|
149
|
+
const key = event.key;
|
|
150
|
+
const target = event.target;
|
|
149
151
|
if (!disabled && isValidKeyPress(event)) {
|
|
150
152
|
if (this._touchState === NOT_RESPONDER) {
|
|
151
153
|
start(event, false);
|
|
@@ -182,7 +184,10 @@ class PressResponder {
|
|
|
182
184
|
this._receiveSignal(RESPONDER_TERMINATED, event);
|
|
183
185
|
},
|
|
184
186
|
onResponderTerminationRequest: (event) => {
|
|
185
|
-
const _this$_config = this._config
|
|
187
|
+
const _this$_config = this._config;
|
|
188
|
+
const cancelable = _this$_config.cancelable;
|
|
189
|
+
const disabled = _this$_config.disabled;
|
|
190
|
+
const onLongPress = _this$_config.onLongPress;
|
|
186
191
|
if (!disabled && onLongPress != null && this._isPointerTouch && event.nativeEvent.type === "contextmenu") {
|
|
187
192
|
return false;
|
|
188
193
|
}
|
|
@@ -192,7 +197,9 @@ class PressResponder {
|
|
|
192
197
|
return cancelable;
|
|
193
198
|
},
|
|
194
199
|
onClick: (event) => {
|
|
195
|
-
const _this$_config2 = this._config
|
|
200
|
+
const _this$_config2 = this._config;
|
|
201
|
+
const disabled = _this$_config2.disabled;
|
|
202
|
+
const onPress = _this$_config2.onPress;
|
|
196
203
|
if (!disabled) {
|
|
197
204
|
event.stopPropagation();
|
|
198
205
|
if (this._longPressDispatched || this._selectionTerminated) {
|
|
@@ -207,7 +214,9 @@ class PressResponder {
|
|
|
207
214
|
}
|
|
208
215
|
},
|
|
209
216
|
onContextMenu: (event) => {
|
|
210
|
-
const _this$_config3 = this._config
|
|
217
|
+
const _this$_config3 = this._config;
|
|
218
|
+
const disabled = _this$_config3.disabled;
|
|
219
|
+
const onLongPress = _this$_config3.onLongPress;
|
|
211
220
|
if (!disabled) {
|
|
212
221
|
if (onLongPress != null && this._isPointerTouch && !event.defaultPrevented) {
|
|
213
222
|
event.preventDefault();
|
|
@@ -232,7 +241,7 @@ class PressResponder {
|
|
|
232
241
|
}
|
|
233
242
|
if (nextState == null || nextState === ERROR) {
|
|
234
243
|
console.error(
|
|
235
|
-
|
|
244
|
+
`PressResponder: Invalid signal ${signal} for state ${prevState} on responder`
|
|
236
245
|
);
|
|
237
246
|
} else if (prevState !== nextState) {
|
|
238
247
|
this._performTransitionSideEffects(prevState, nextState, signal, event);
|
|
@@ -262,11 +271,13 @@ class PressResponder {
|
|
|
262
271
|
this._deactivate(event);
|
|
263
272
|
}
|
|
264
273
|
if (isPressStartSignal(prevState) && signal === RESPONDER_RELEASE) {
|
|
265
|
-
const _this$_config4 = this._config
|
|
274
|
+
const _this$_config4 = this._config;
|
|
275
|
+
const _onLongPress = _this$_config4.onLongPress;
|
|
276
|
+
const onPress = _this$_config4.onPress;
|
|
266
277
|
if (onPress != null) {
|
|
267
278
|
const isPressCanceledByLongPress = _onLongPress != null && prevState === RESPONDER_ACTIVE_LONG_PRESS_START;
|
|
268
279
|
if (!isPressCanceledByLongPress) {
|
|
269
|
-
if (!isNextActive
|
|
280
|
+
if (!(isNextActive || isPrevActive)) {
|
|
270
281
|
this._activate(event);
|
|
271
282
|
this._deactivate(event);
|
|
272
283
|
}
|
|
@@ -276,7 +287,9 @@ class PressResponder {
|
|
|
276
287
|
this._cancelPressDelayTimeout();
|
|
277
288
|
}
|
|
278
289
|
_activate(event) {
|
|
279
|
-
const _this$_config5 = this._config
|
|
290
|
+
const _this$_config5 = this._config;
|
|
291
|
+
const onPressChange = _this$_config5.onPressChange;
|
|
292
|
+
const onPressStart = _this$_config5.onPressStart;
|
|
280
293
|
const touch = getTouchFromResponderEvent(event);
|
|
281
294
|
this._touchActivatePosition = {
|
|
282
295
|
pageX: touch.pageX,
|
|
@@ -290,7 +303,9 @@ class PressResponder {
|
|
|
290
303
|
}
|
|
291
304
|
}
|
|
292
305
|
_deactivate(event) {
|
|
293
|
-
const _this$_config6 = this._config
|
|
306
|
+
const _this$_config6 = this._config;
|
|
307
|
+
const onPressChange = _this$_config6.onPressChange;
|
|
308
|
+
const onPressEnd = _this$_config6.onPressEnd;
|
|
294
309
|
function end() {
|
|
295
310
|
if (onPressEnd != null) {
|
|
296
311
|
onPressEnd(event);
|
|
@@ -342,7 +357,9 @@ function normalizeDelay(delay, min, fallback) {
|
|
|
342
357
|
return Math.max(min, delay !== null && delay !== void 0 ? delay : fallback);
|
|
343
358
|
}
|
|
344
359
|
function getTouchFromResponderEvent(event) {
|
|
345
|
-
const _event$nativeEvent = event.nativeEvent
|
|
360
|
+
const _event$nativeEvent = event.nativeEvent;
|
|
361
|
+
const changedTouches = _event$nativeEvent.changedTouches;
|
|
362
|
+
const touches = _event$nativeEvent.touches;
|
|
346
363
|
if (touches != null && touches.length > 0) {
|
|
347
364
|
return touches[0];
|
|
348
365
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/PressResponder.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n *\n * @format\n */\n'use strict'\n\nconst DELAY = 'DELAY'\nconst ERROR = 'ERROR'\nconst LONG_PRESS_DETECTED = 'LONG_PRESS_DETECTED'\nconst NOT_RESPONDER = 'NOT_RESPONDER'\nconst RESPONDER_ACTIVE_LONG_PRESS_START = 'RESPONDER_ACTIVE_LONG_PRESS_START'\nconst RESPONDER_ACTIVE_PRESS_START = 'RESPONDER_ACTIVE_PRESS_START'\nconst RESPONDER_INACTIVE_PRESS_START = 'RESPONDER_INACTIVE_PRESS_START'\nconst RESPONDER_GRANT = 'RESPONDER_GRANT'\nconst RESPONDER_RELEASE = 'RESPONDER_RELEASE'\nconst RESPONDER_TERMINATED = 'RESPONDER_TERMINATED'\nconst Transitions = Object.freeze({\n NOT_RESPONDER: {\n DELAY: ERROR,\n RESPONDER_GRANT: RESPONDER_INACTIVE_PRESS_START,\n RESPONDER_RELEASE: ERROR,\n RESPONDER_TERMINATED: ERROR,\n LONG_PRESS_DETECTED: ERROR,\n },\n RESPONDER_INACTIVE_PRESS_START: {\n DELAY: RESPONDER_ACTIVE_PRESS_START,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: ERROR,\n },\n RESPONDER_ACTIVE_PRESS_START: {\n DELAY: ERROR,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: RESPONDER_ACTIVE_LONG_PRESS_START,\n },\n RESPONDER_ACTIVE_LONG_PRESS_START: {\n DELAY: ERROR,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: RESPONDER_ACTIVE_LONG_PRESS_START,\n },\n ERROR: {\n DELAY: NOT_RESPONDER,\n RESPONDER_GRANT: RESPONDER_INACTIVE_PRESS_START,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: NOT_RESPONDER,\n },\n})\n\nconst isActiveSignal = (signal) =>\n signal === RESPONDER_ACTIVE_PRESS_START || signal === RESPONDER_ACTIVE_LONG_PRESS_START\n\nconst isButtonRole = (element) => element.getAttribute('role') === 'button'\n\nconst isPressStartSignal = (signal) =>\n signal === RESPONDER_INACTIVE_PRESS_START ||\n signal === RESPONDER_ACTIVE_PRESS_START ||\n signal === RESPONDER_ACTIVE_LONG_PRESS_START\n\nconst isTerminalSignal = (signal) => signal === RESPONDER_TERMINATED || signal === RESPONDER_RELEASE\n\nconst isValidKeyPress = (event) => {\n const key = event.key,\n target = event.target\n const role = target.getAttribute('role')\n const isSpacebar = key === ' ' || key === 'Spacebar'\n return key === 'Enter' || (isSpacebar && role === 'button')\n}\n\nconst DEFAULT_LONG_PRESS_DELAY_MS = 450 // 500 - 50\n\nconst DEFAULT_PRESS_DELAY_MS = 50\n/**\n * =========================== PressResponder Tutorial ===========================\n *\n * The `PressResponder` class helps you create press interactions by analyzing the\n * geometry of elements and observing when another responder (e.g. ScrollView)\n * has stolen the touch lock. It offers hooks for your component to provide\n * interaction feedback to the user:\n *\n * - When a press has activated (e.g. highlight an element)\n * - When a press has deactivated (e.g. un-highlight an element)\n * - When a press sould trigger an action, meaning it activated and deactivated\n * while within the geometry of the element without the lock being stolen.\n *\n * A high quality interaction isn't as simple as you might think. There should\n * be a slight delay before activation. Moving your finger beyond an element's\n * bounds should trigger deactivation, but moving the same finger back within an\n * element's bounds should trigger reactivation.\n *\n * In order to use `PressResponder`, do the following:\n *\n * const pressResponder = new PressResponder(config);\n *\n * 2. Choose the rendered component who should collect the press events. On that\n * element, spread `pressability.getEventHandlers()` into its props.\n *\n * return (\n * <View {...this.state.pressResponder.getEventHandlers()} />\n * );\n *\n * 3. Reset `PressResponder` when your component unmounts.\n *\n * componentWillUnmount() {\n * this.state.pressResponder.reset();\n * }\n *\n * ==================== Implementation Details ====================\n *\n * `PressResponder` only assumes that there exists a `HitRect` node. The `PressRect`\n * is an abstract box that is extended beyond the `HitRect`.\n *\n * # Geometry\n *\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n * \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 - Presses start anywhere within `HitRect`.\n * \u2502 \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 \u2502\n * \u2502 \u2502 \u2502 VisualRect \u2502 \u2502 \u2502\n * \u2502 \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502 \u2502 - When pressed down for sufficient amount of time\n * \u2502 \u2502 HitRect \u2502 \u2502 before letting up, `VisualRect` activates.\n * \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502\n * \u2502 Out Region o \u2502\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2518\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500 When the press is released outside the `HitRect`,\n * the responder is NOT eligible for a \"press\".\n *\n * # State Machine\n *\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u25C0\u2500\u2500\u2500\u2500 RESPONDER_RELEASE\n * \u2502 NOT_RESPONDER \u2502\n * \u2514\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u25C0\u2500\u2500\u2500\u2500 RESPONDER_TERMINATED\n * \u2502\n * \u2502 RESPONDER_GRANT (HitRect)\n * \u2502\n * \u25BC\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n * \u2502 RESPONDER_INACTIVE_ \u2502 DELAY \u2502 RESPONDER_ACTIVE_ \u2502 T + DELAY \u2502 RESPONDER_ACTIVE_ \u2502\n * \u2502 PRESS_START \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25B6 \u2502 PRESS_START \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25B6 \u2502 LONG_PRESS_START \u2502\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n *\n * T + DELAY => LONG_PRESS_DELAY + DELAY\n *\n * Not drawn are the side effects of each transition. The most important side\n * effect is the invocation of `onLongPress`. Only when the browser produces a\n * `click` event is `onPress` invoked.\n */\n\nexport default class PressResponder {\n _touchActivatePosition = null as any\n _pressDelayTimeout = 0 as any\n _selectionTerminated = false\n _isPointerTouch = false\n _longPressDelayTimeout = 0 as any\n _longPressDispatched = false\n _pressOutDelayTimeout = 0 as any\n _touchState = NOT_RESPONDER\n _config = null as any\n _eventHandlers = null as any\n\n constructor(config) {\n this.configure(config)\n }\n\n configure(config) {\n this._config = config\n }\n /**\n * Resets any pending timers. This should be called on unmount.\n */\n\n reset() {\n this._cancelLongPressDelayTimeout()\n\n this._cancelPressDelayTimeout()\n\n this._cancelPressOutDelayTimeout()\n }\n /**\n * Returns a set of props to spread into the interactive element.\n */\n\n getEventHandlers() {\n if (this._eventHandlers == null) {\n this._eventHandlers = this._createEventHandlers()\n }\n\n return this._eventHandlers\n }\n\n _createEventHandlers() {\n const start = (event, shouldDelay?: boolean) => {\n event.persist()\n\n this._cancelPressOutDelayTimeout()\n\n this._longPressDispatched = false\n this._selectionTerminated = false\n this._touchState = NOT_RESPONDER\n this._isPointerTouch = event.nativeEvent.type === 'touchstart'\n\n this._receiveSignal(RESPONDER_GRANT, event)\n\n const delayPressStart = normalizeDelay(\n this._config.delayPressStart,\n 0,\n DEFAULT_PRESS_DELAY_MS\n )\n\n if (shouldDelay !== false && delayPressStart > 0) {\n this._pressDelayTimeout = setTimeout(() => {\n this._receiveSignal(DELAY, event)\n }, delayPressStart)\n } else {\n this._receiveSignal(DELAY, event)\n }\n\n const delayLongPress = normalizeDelay(\n this._config.delayLongPress,\n 10,\n DEFAULT_LONG_PRESS_DELAY_MS\n )\n this._longPressDelayTimeout = setTimeout(() => {\n this._handleLongPress(event)\n }, delayLongPress + delayPressStart)\n }\n\n const end = (event) => {\n this._receiveSignal(RESPONDER_RELEASE, event)\n }\n\n const keyupHandler = (event) => {\n const onPress = this._config.onPress\n const target = event.target\n\n if (this._touchState !== NOT_RESPONDER && isValidKeyPress(event)) {\n end(event)\n document.removeEventListener('keyup', keyupHandler)\n const role = target.getAttribute('role')\n const elementType = target.tagName.toLowerCase()\n const isNativeInteractiveElement =\n role === 'link' ||\n elementType === 'a' ||\n elementType === 'button' ||\n elementType === 'input' ||\n elementType === 'select' ||\n elementType === 'textarea'\n\n if (onPress != null && !isNativeInteractiveElement) {\n onPress(event)\n }\n }\n }\n\n return {\n onStartShouldSetResponder: (event) => {\n const disabled = this._config.disabled\n\n if (disabled && isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n\n if (disabled == null) {\n return true\n }\n\n return !disabled\n },\n onKeyDown: (event) => {\n const disabled = this._config.disabled\n const key = event.key,\n target = event.target\n\n if (!disabled && isValidKeyPress(event)) {\n if (this._touchState === NOT_RESPONDER) {\n start(event, false) // Listen to 'keyup' on document to account for situations where\n // focus is moved to another element during 'keydown'.\n\n document.addEventListener('keyup', keyupHandler)\n }\n\n const role = target.getAttribute('role')\n const isSpacebarKey = key === ' ' || key === 'Spacebar'\n\n const _isButtonRole = role === 'button' || role === 'menuitem'\n\n if (isSpacebarKey && _isButtonRole) {\n // Prevent spacebar scrolling the window\n event.preventDefault()\n }\n\n event.stopPropagation()\n }\n },\n onResponderGrant: (event) => start(event),\n onResponderMove: (event) => {\n if (this._config.onPressMove != null) {\n this._config.onPressMove(event)\n }\n\n const touch = getTouchFromResponderEvent(event)\n\n if (this._touchActivatePosition != null) {\n const deltaX = this._touchActivatePosition.pageX - touch.pageX\n const deltaY = this._touchActivatePosition.pageY - touch.pageY\n\n if (Math.hypot(deltaX, deltaY) > 10) {\n this._cancelLongPressDelayTimeout()\n }\n }\n },\n onResponderRelease: (event) => end(event),\n onResponderTerminate: (event) => {\n if (event.nativeEvent.type === 'selectionchange') {\n this._selectionTerminated = true\n }\n\n this._receiveSignal(RESPONDER_TERMINATED, event)\n },\n onResponderTerminationRequest: (event) => {\n const _this$_config = this._config,\n cancelable = _this$_config.cancelable,\n disabled = _this$_config.disabled,\n onLongPress = _this$_config.onLongPress // If `onLongPress` is provided, don't terminate on `contextmenu` as default\n // behavior will be prevented for non-mouse pointers.\n\n if (\n !disabled &&\n onLongPress != null &&\n this._isPointerTouch &&\n event.nativeEvent.type === 'contextmenu'\n ) {\n return false\n }\n\n if (cancelable == null) {\n return true\n }\n\n return cancelable\n },\n // NOTE: this diverges from react-native in 3 significant ways:\n // * The `onPress` callback is not connected to the responder system (the native\n // `click` event must be used but is dispatched in many scenarios where no pointers\n // are on the screen.) Therefore, it's possible for `onPress` to be called without\n // `onPress{Start,End}` being called first.\n // * The `onPress` callback is only be called on the first ancestor of the native\n // `click` target that is using the PressResponder.\n // * The event's `nativeEvent` is a `MouseEvent` not a `TouchEvent`.\n onClick: (event) => {\n const _this$_config2 = this._config,\n disabled = _this$_config2.disabled,\n onPress = _this$_config2.onPress\n\n if (!disabled) {\n // If long press dispatched, cancel default click behavior.\n // If the responder terminated because text was selected during the gesture,\n // cancel the default click behavior.\n event.stopPropagation()\n\n if (this._longPressDispatched || this._selectionTerminated) {\n event.preventDefault()\n } else if (onPress != null && event.altKey === false) {\n onPress(event)\n }\n } else {\n if (isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n }\n },\n // If `onLongPress` is provided and a touch pointer is being used, prevent the\n // default context menu from opening.\n onContextMenu: (event) => {\n const _this$_config3 = this._config,\n disabled = _this$_config3.disabled,\n onLongPress = _this$_config3.onLongPress\n\n if (!disabled) {\n if (onLongPress != null && this._isPointerTouch && !event.defaultPrevented) {\n event.preventDefault()\n event.stopPropagation()\n }\n } else {\n if (isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n }\n },\n }\n }\n /**\n * Receives a state machine signal, performs side effects of the transition\n * and stores the new state. Validates the transition as well.\n */\n\n _receiveSignal(signal, event) {\n const prevState = this._touchState\n let nextState = null\n\n if (Transitions[prevState] != null) {\n nextState = Transitions[prevState][signal]\n }\n\n if (this._touchState === NOT_RESPONDER && signal === RESPONDER_RELEASE) {\n return\n }\n\n if (nextState == null || nextState === ERROR) {\n // eslint-disable-next-line no-console\n console.error(\n 'PressResponder: Invalid signal ' + signal + ' for state ' + prevState + ' on responder'\n )\n } else if (prevState !== nextState) {\n this._performTransitionSideEffects(prevState, nextState, signal, event)\n\n this._touchState = nextState\n }\n }\n /**\n * Performs a transition between touchable states and identify any activations\n * or deactivations (and callback invocations).\n */\n\n _performTransitionSideEffects(prevState, nextState, signal, event) {\n if (isTerminalSignal(signal)) {\n // Pressable suppression of contextmenu on windows.\n // On Windows, the contextmenu is displayed after pointerup.\n // https://github.com/necolas/react-native-web/issues/2296\n setTimeout(() => {\n this._isPointerTouch = false\n }, 0)\n this._touchActivatePosition = null\n\n this._cancelLongPressDelayTimeout()\n }\n\n if (isPressStartSignal(prevState) && signal === LONG_PRESS_DETECTED) {\n const onLongPress = this._config.onLongPress // Long press is not supported for keyboards because 'click' can be dispatched\n // immediately (and multiple times) after 'keydown'.\n\n if (onLongPress != null && event.nativeEvent.key == null) {\n onLongPress(event)\n this._longPressDispatched = true\n }\n }\n\n const isPrevActive = isActiveSignal(prevState)\n const isNextActive = isActiveSignal(nextState)\n\n if (!isPrevActive && isNextActive) {\n this._activate(event)\n } else if (isPrevActive && !isNextActive) {\n this._deactivate(event)\n }\n\n if (isPressStartSignal(prevState) && signal === RESPONDER_RELEASE) {\n const _this$_config4 = this._config,\n _onLongPress = _this$_config4.onLongPress,\n onPress = _this$_config4.onPress\n\n if (onPress != null) {\n const isPressCanceledByLongPress =\n _onLongPress != null && prevState === RESPONDER_ACTIVE_LONG_PRESS_START\n\n if (!isPressCanceledByLongPress) {\n // If we never activated (due to delays), activate and deactivate now.\n if (!isNextActive && !isPrevActive) {\n this._activate(event)\n\n this._deactivate(event)\n }\n }\n }\n }\n\n this._cancelPressDelayTimeout()\n }\n\n _activate(event) {\n const _this$_config5 = this._config,\n onPressChange = _this$_config5.onPressChange,\n onPressStart = _this$_config5.onPressStart\n const touch = getTouchFromResponderEvent(event)\n this._touchActivatePosition = {\n pageX: touch.pageX,\n pageY: touch.pageY,\n }\n\n if (onPressStart != null) {\n onPressStart(event)\n }\n\n if (onPressChange != null) {\n onPressChange(true)\n }\n }\n\n _deactivate(event) {\n const _this$_config6 = this._config,\n onPressChange = _this$_config6.onPressChange,\n onPressEnd = _this$_config6.onPressEnd\n\n function end() {\n if (onPressEnd != null) {\n onPressEnd(event)\n }\n\n if (onPressChange != null) {\n onPressChange(false)\n }\n }\n\n const delayPressEnd = normalizeDelay(this._config.delayPressEnd)\n\n if (delayPressEnd > 0) {\n this._pressOutDelayTimeout = setTimeout(() => {\n end()\n }, delayPressEnd)\n } else {\n end()\n }\n }\n\n _handleLongPress(event) {\n if (\n this._touchState === RESPONDER_ACTIVE_PRESS_START ||\n this._touchState === RESPONDER_ACTIVE_LONG_PRESS_START\n ) {\n this._receiveSignal(LONG_PRESS_DETECTED, event)\n }\n }\n\n _cancelLongPressDelayTimeout() {\n if (this._longPressDelayTimeout != null) {\n clearTimeout(this._longPressDelayTimeout)\n this._longPressDelayTimeout = null\n }\n }\n\n _cancelPressDelayTimeout() {\n if (this._pressDelayTimeout != null) {\n clearTimeout(this._pressDelayTimeout)\n this._pressDelayTimeout = null\n }\n }\n\n _cancelPressOutDelayTimeout() {\n if (this._pressOutDelayTimeout != null) {\n clearTimeout(this._pressOutDelayTimeout)\n this._pressOutDelayTimeout = null\n }\n }\n}\n\nfunction normalizeDelay(delay, min?: number, fallback?: any) {\n if (min === void 0) {\n min = 0\n }\n\n if (fallback === void 0) {\n fallback = 0\n }\n\n return Math.max(min, delay !== null && delay !== void 0 ? delay : fallback)\n}\n\nfunction getTouchFromResponderEvent(event) {\n const _event$nativeEvent = event.nativeEvent,\n changedTouches = _event$nativeEvent.changedTouches,\n touches = _event$nativeEvent.touches\n\n if (touches != null && touches.length > 0) {\n return touches[0]\n }\n\n if (changedTouches != null && changedTouches.length > 0) {\n return changedTouches[0]\n }\n\n return event.nativeEvent\n}\n"],
|
|
5
|
-
"mappings": "AAWA,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,sBAAsB;AAC5B,MAAM,gBAAgB;AACtB,MAAM,oCAAoC;AAC1C,MAAM,+BAA+B;AACrC,MAAM,iCAAiC;AACvC,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAC1B,MAAM,uBAAuB;AAC7B,MAAM,cAAc,OAAO,OAAO;AAAA,EAChC,eAAe;AAAA,IACb,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AAAA,EACA,gCAAgC;AAAA,IAC9B,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AAAA,EACA,8BAA8B;AAAA,IAC5B,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AAAA,EACA,mCAAmC;AAAA,IACjC,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AAAA,EACA,OAAO;AAAA,IACL,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AACF,CAAC;AAED,MAAM,iBAAiB,CAAC,WACtB,WAAW,
|
|
4
|
+
"sourcesContent": ["/**\n * Copyright (c) Meta Platforms, Inc. and affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n *\n * @format\n */\n'use strict'\n\nconst DELAY = 'DELAY'\nconst ERROR = 'ERROR'\nconst LONG_PRESS_DETECTED = 'LONG_PRESS_DETECTED'\nconst NOT_RESPONDER = 'NOT_RESPONDER'\nconst RESPONDER_ACTIVE_LONG_PRESS_START = 'RESPONDER_ACTIVE_LONG_PRESS_START'\nconst RESPONDER_ACTIVE_PRESS_START = 'RESPONDER_ACTIVE_PRESS_START'\nconst RESPONDER_INACTIVE_PRESS_START = 'RESPONDER_INACTIVE_PRESS_START'\nconst RESPONDER_GRANT = 'RESPONDER_GRANT'\nconst RESPONDER_RELEASE = 'RESPONDER_RELEASE'\nconst RESPONDER_TERMINATED = 'RESPONDER_TERMINATED'\nconst Transitions = Object.freeze({\n NOT_RESPONDER: {\n DELAY: ERROR,\n RESPONDER_GRANT: RESPONDER_INACTIVE_PRESS_START,\n RESPONDER_RELEASE: ERROR,\n RESPONDER_TERMINATED: ERROR,\n LONG_PRESS_DETECTED: ERROR,\n },\n RESPONDER_INACTIVE_PRESS_START: {\n DELAY: RESPONDER_ACTIVE_PRESS_START,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: ERROR,\n },\n RESPONDER_ACTIVE_PRESS_START: {\n DELAY: ERROR,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: RESPONDER_ACTIVE_LONG_PRESS_START,\n },\n RESPONDER_ACTIVE_LONG_PRESS_START: {\n DELAY: ERROR,\n RESPONDER_GRANT: ERROR,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: RESPONDER_ACTIVE_LONG_PRESS_START,\n },\n ERROR: {\n DELAY: NOT_RESPONDER,\n RESPONDER_GRANT: RESPONDER_INACTIVE_PRESS_START,\n RESPONDER_RELEASE: NOT_RESPONDER,\n RESPONDER_TERMINATED: NOT_RESPONDER,\n LONG_PRESS_DETECTED: NOT_RESPONDER,\n },\n})\n\nconst isActiveSignal = (signal) =>\n signal === RESPONDER_ACTIVE_PRESS_START ||\n signal === RESPONDER_ACTIVE_LONG_PRESS_START\n\nconst isButtonRole = (element) => element.getAttribute('role') === 'button'\n\nconst isPressStartSignal = (signal) =>\n signal === RESPONDER_INACTIVE_PRESS_START ||\n signal === RESPONDER_ACTIVE_PRESS_START ||\n signal === RESPONDER_ACTIVE_LONG_PRESS_START\n\nconst isTerminalSignal = (signal) =>\n signal === RESPONDER_TERMINATED || signal === RESPONDER_RELEASE\n\nconst isValidKeyPress = (event) => {\n const key = event.key\n const target = event.target\n const role = target.getAttribute('role')\n const isSpacebar = key === ' ' || key === 'Spacebar'\n return key === 'Enter' || (isSpacebar && role === 'button')\n}\n\nconst DEFAULT_LONG_PRESS_DELAY_MS = 450 // 500 - 50\n\nconst DEFAULT_PRESS_DELAY_MS = 50\n/**\n * =========================== PressResponder Tutorial ===========================\n *\n * The `PressResponder` class helps you create press interactions by analyzing the\n * geometry of elements and observing when another responder (e.g. ScrollView)\n * has stolen the touch lock. It offers hooks for your component to provide\n * interaction feedback to the user:\n *\n * - When a press has activated (e.g. highlight an element)\n * - When a press has deactivated (e.g. un-highlight an element)\n * - When a press sould trigger an action, meaning it activated and deactivated\n * while within the geometry of the element without the lock being stolen.\n *\n * A high quality interaction isn't as simple as you might think. There should\n * be a slight delay before activation. Moving your finger beyond an element's\n * bounds should trigger deactivation, but moving the same finger back within an\n * element's bounds should trigger reactivation.\n *\n * In order to use `PressResponder`, do the following:\n *\n * const pressResponder = new PressResponder(config);\n *\n * 2. Choose the rendered component who should collect the press events. On that\n * element, spread `pressability.getEventHandlers()` into its props.\n *\n * return (\n * <View {...this.state.pressResponder.getEventHandlers()} />\n * );\n *\n * 3. Reset `PressResponder` when your component unmounts.\n *\n * componentWillUnmount() {\n * this.state.pressResponder.reset();\n * }\n *\n * ==================== Implementation Details ====================\n *\n * `PressResponder` only assumes that there exists a `HitRect` node. The `PressRect`\n * is an abstract box that is extended beyond the `HitRect`.\n *\n * # Geometry\n *\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n * \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 - Presses start anywhere within `HitRect`.\n * \u2502 \u2502 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u2502 \u2502\n * \u2502 \u2502 \u2502 VisualRect \u2502 \u2502 \u2502\n * \u2502 \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502 \u2502 - When pressed down for sufficient amount of time\n * \u2502 \u2502 HitRect \u2502 \u2502 before letting up, `VisualRect` activates.\n * \u2502 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2502\n * \u2502 Out Region o \u2502\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2502\u2500\u2500\u2500\u2518\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500 When the press is released outside the `HitRect`,\n * the responder is NOT eligible for a \"press\".\n *\n * # State Machine\n *\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u25C0\u2500\u2500\u2500\u2500 RESPONDER_RELEASE\n * \u2502 NOT_RESPONDER \u2502\n * \u2514\u2500\u2500\u2500\u252C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u25C0\u2500\u2500\u2500\u2500 RESPONDER_TERMINATED\n * \u2502\n * \u2502 RESPONDER_GRANT (HitRect)\n * \u2502\n * \u25BC\n * \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n * \u2502 RESPONDER_INACTIVE_ \u2502 DELAY \u2502 RESPONDER_ACTIVE_ \u2502 T + DELAY \u2502 RESPONDER_ACTIVE_ \u2502\n * \u2502 PRESS_START \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25B6 \u2502 PRESS_START \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25B6 \u2502 LONG_PRESS_START \u2502\n * \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n *\n * T + DELAY => LONG_PRESS_DELAY + DELAY\n *\n * Not drawn are the side effects of each transition. The most important side\n * effect is the invocation of `onLongPress`. Only when the browser produces a\n * `click` event is `onPress` invoked.\n */\n\nexport default class PressResponder {\n _touchActivatePosition = null as any\n _pressDelayTimeout = 0 as any\n _selectionTerminated = false\n _isPointerTouch = false\n _longPressDelayTimeout = 0 as any\n _longPressDispatched = false\n _pressOutDelayTimeout = 0 as any\n _touchState = NOT_RESPONDER\n _config = null as any\n _eventHandlers = null as any\n\n constructor(config) {\n this.configure(config)\n }\n\n configure(config) {\n this._config = config\n }\n /**\n * Resets any pending timers. This should be called on unmount.\n */\n\n reset() {\n this._cancelLongPressDelayTimeout()\n\n this._cancelPressDelayTimeout()\n\n this._cancelPressOutDelayTimeout()\n }\n /**\n * Returns a set of props to spread into the interactive element.\n */\n\n getEventHandlers() {\n if (this._eventHandlers == null) {\n this._eventHandlers = this._createEventHandlers()\n }\n\n return this._eventHandlers\n }\n\n _createEventHandlers() {\n const start = (event, shouldDelay?: boolean) => {\n event.persist()\n\n this._cancelPressOutDelayTimeout()\n\n this._longPressDispatched = false\n this._selectionTerminated = false\n this._touchState = NOT_RESPONDER\n this._isPointerTouch = event.nativeEvent.type === 'touchstart'\n\n this._receiveSignal(RESPONDER_GRANT, event)\n\n const delayPressStart = normalizeDelay(\n this._config.delayPressStart,\n 0,\n DEFAULT_PRESS_DELAY_MS,\n )\n\n if (shouldDelay !== false && delayPressStart > 0) {\n this._pressDelayTimeout = setTimeout(() => {\n this._receiveSignal(DELAY, event)\n }, delayPressStart)\n } else {\n this._receiveSignal(DELAY, event)\n }\n\n const delayLongPress = normalizeDelay(\n this._config.delayLongPress,\n 10,\n DEFAULT_LONG_PRESS_DELAY_MS,\n )\n this._longPressDelayTimeout = setTimeout(() => {\n this._handleLongPress(event)\n }, delayLongPress + delayPressStart)\n }\n\n const end = (event) => {\n this._receiveSignal(RESPONDER_RELEASE, event)\n }\n\n const keyupHandler = (event) => {\n const onPress = this._config.onPress\n const target = event.target\n\n if (this._touchState !== NOT_RESPONDER && isValidKeyPress(event)) {\n end(event)\n document.removeEventListener('keyup', keyupHandler)\n const role = target.getAttribute('role')\n const elementType = target.tagName.toLowerCase()\n const isNativeInteractiveElement =\n role === 'link' ||\n elementType === 'a' ||\n elementType === 'button' ||\n elementType === 'input' ||\n elementType === 'select' ||\n elementType === 'textarea'\n\n if (onPress != null && !isNativeInteractiveElement) {\n onPress(event)\n }\n }\n }\n\n return {\n onStartShouldSetResponder: (event) => {\n const disabled = this._config.disabled\n\n if (disabled && isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n\n if (disabled == null) {\n return true\n }\n\n return !disabled\n },\n onKeyDown: (event) => {\n const disabled = this._config.disabled\n const key = event.key\n const target = event.target\n\n if (!disabled && isValidKeyPress(event)) {\n if (this._touchState === NOT_RESPONDER) {\n start(event, false) // Listen to 'keyup' on document to account for situations where\n // focus is moved to another element during 'keydown'.\n\n document.addEventListener('keyup', keyupHandler)\n }\n\n const role = target.getAttribute('role')\n const isSpacebarKey = key === ' ' || key === 'Spacebar'\n\n const _isButtonRole = role === 'button' || role === 'menuitem'\n\n if (isSpacebarKey && _isButtonRole) {\n // Prevent spacebar scrolling the window\n event.preventDefault()\n }\n\n event.stopPropagation()\n }\n },\n onResponderGrant: (event) => start(event),\n onResponderMove: (event) => {\n if (this._config.onPressMove != null) {\n this._config.onPressMove(event)\n }\n\n const touch = getTouchFromResponderEvent(event)\n\n if (this._touchActivatePosition != null) {\n const deltaX = this._touchActivatePosition.pageX - touch.pageX\n const deltaY = this._touchActivatePosition.pageY - touch.pageY\n\n if (Math.hypot(deltaX, deltaY) > 10) {\n this._cancelLongPressDelayTimeout()\n }\n }\n },\n onResponderRelease: (event) => end(event),\n onResponderTerminate: (event) => {\n if (event.nativeEvent.type === 'selectionchange') {\n this._selectionTerminated = true\n }\n\n this._receiveSignal(RESPONDER_TERMINATED, event)\n },\n onResponderTerminationRequest: (event) => {\n const _this$_config = this._config\n const cancelable = _this$_config.cancelable\n const disabled = _this$_config.disabled\n const onLongPress = _this$_config.onLongPress // If `onLongPress` is provided, don't terminate on `contextmenu` as default\n // behavior will be prevented for non-mouse pointers.\n\n if (\n !disabled &&\n onLongPress != null &&\n this._isPointerTouch &&\n event.nativeEvent.type === 'contextmenu'\n ) {\n return false\n }\n\n if (cancelable == null) {\n return true\n }\n\n return cancelable\n },\n // NOTE: this diverges from react-native in 3 significant ways:\n // * The `onPress` callback is not connected to the responder system (the native\n // `click` event must be used but is dispatched in many scenarios where no pointers\n // are on the screen.) Therefore, it's possible for `onPress` to be called without\n // `onPress{Start,End}` being called first.\n // * The `onPress` callback is only be called on the first ancestor of the native\n // `click` target that is using the PressResponder.\n // * The event's `nativeEvent` is a `MouseEvent` not a `TouchEvent`.\n onClick: (event) => {\n const _this$_config2 = this._config\n const disabled = _this$_config2.disabled\n const onPress = _this$_config2.onPress\n\n if (!disabled) {\n // If long press dispatched, cancel default click behavior.\n // If the responder terminated because text was selected during the gesture,\n // cancel the default click behavior.\n event.stopPropagation()\n\n if (this._longPressDispatched || this._selectionTerminated) {\n event.preventDefault()\n } else if (onPress != null && event.altKey === false) {\n onPress(event)\n }\n } else {\n if (isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n }\n },\n // If `onLongPress` is provided and a touch pointer is being used, prevent the\n // default context menu from opening.\n onContextMenu: (event) => {\n const _this$_config3 = this._config\n const disabled = _this$_config3.disabled\n const onLongPress = _this$_config3.onLongPress\n\n if (!disabled) {\n if (\n onLongPress != null &&\n this._isPointerTouch &&\n !event.defaultPrevented\n ) {\n event.preventDefault()\n event.stopPropagation()\n }\n } else {\n if (isButtonRole(event.currentTarget)) {\n event.stopPropagation()\n }\n }\n },\n }\n }\n /**\n * Receives a state machine signal, performs side effects of the transition\n * and stores the new state. Validates the transition as well.\n */\n\n _receiveSignal(signal, event) {\n const prevState = this._touchState\n let nextState = null\n\n if (Transitions[prevState] != null) {\n nextState = Transitions[prevState][signal]\n }\n\n if (this._touchState === NOT_RESPONDER && signal === RESPONDER_RELEASE) {\n return\n }\n\n if (nextState == null || nextState === ERROR) {\n // eslint-disable-next-line no-console\n console.error(\n `PressResponder: Invalid signal ${signal} for state ${prevState} on responder`,\n )\n } else if (prevState !== nextState) {\n this._performTransitionSideEffects(prevState, nextState, signal, event)\n\n this._touchState = nextState\n }\n }\n /**\n * Performs a transition between touchable states and identify any activations\n * or deactivations (and callback invocations).\n */\n\n _performTransitionSideEffects(prevState, nextState, signal, event) {\n if (isTerminalSignal(signal)) {\n // Pressable suppression of contextmenu on windows.\n // On Windows, the contextmenu is displayed after pointerup.\n // https://github.com/necolas/react-native-web/issues/2296\n setTimeout(() => {\n this._isPointerTouch = false\n }, 0)\n this._touchActivatePosition = null\n\n this._cancelLongPressDelayTimeout()\n }\n\n if (isPressStartSignal(prevState) && signal === LONG_PRESS_DETECTED) {\n const onLongPress = this._config.onLongPress // Long press is not supported for keyboards because 'click' can be dispatched\n // immediately (and multiple times) after 'keydown'.\n\n if (onLongPress != null && event.nativeEvent.key == null) {\n onLongPress(event)\n this._longPressDispatched = true\n }\n }\n\n const isPrevActive = isActiveSignal(prevState)\n const isNextActive = isActiveSignal(nextState)\n\n if (!isPrevActive && isNextActive) {\n this._activate(event)\n } else if (isPrevActive && !isNextActive) {\n this._deactivate(event)\n }\n\n if (isPressStartSignal(prevState) && signal === RESPONDER_RELEASE) {\n const _this$_config4 = this._config\n const _onLongPress = _this$_config4.onLongPress\n const onPress = _this$_config4.onPress\n\n if (onPress != null) {\n const isPressCanceledByLongPress =\n _onLongPress != null && prevState === RESPONDER_ACTIVE_LONG_PRESS_START\n\n if (!isPressCanceledByLongPress) {\n // If we never activated (due to delays), activate and deactivate now.\n if (!(isNextActive || isPrevActive)) {\n this._activate(event)\n\n this._deactivate(event)\n }\n }\n }\n }\n\n this._cancelPressDelayTimeout()\n }\n\n _activate(event) {\n const _this$_config5 = this._config\n const onPressChange = _this$_config5.onPressChange\n const onPressStart = _this$_config5.onPressStart\n const touch = getTouchFromResponderEvent(event)\n this._touchActivatePosition = {\n pageX: touch.pageX,\n pageY: touch.pageY,\n }\n\n if (onPressStart != null) {\n onPressStart(event)\n }\n\n if (onPressChange != null) {\n onPressChange(true)\n }\n }\n\n _deactivate(event) {\n const _this$_config6 = this._config\n const onPressChange = _this$_config6.onPressChange\n const onPressEnd = _this$_config6.onPressEnd\n\n function end() {\n if (onPressEnd != null) {\n onPressEnd(event)\n }\n\n if (onPressChange != null) {\n onPressChange(false)\n }\n }\n\n const delayPressEnd = normalizeDelay(this._config.delayPressEnd)\n\n if (delayPressEnd > 0) {\n this._pressOutDelayTimeout = setTimeout(() => {\n end()\n }, delayPressEnd)\n } else {\n end()\n }\n }\n\n _handleLongPress(event) {\n if (\n this._touchState === RESPONDER_ACTIVE_PRESS_START ||\n this._touchState === RESPONDER_ACTIVE_LONG_PRESS_START\n ) {\n this._receiveSignal(LONG_PRESS_DETECTED, event)\n }\n }\n\n _cancelLongPressDelayTimeout() {\n if (this._longPressDelayTimeout != null) {\n clearTimeout(this._longPressDelayTimeout)\n this._longPressDelayTimeout = null\n }\n }\n\n _cancelPressDelayTimeout() {\n if (this._pressDelayTimeout != null) {\n clearTimeout(this._pressDelayTimeout)\n this._pressDelayTimeout = null\n }\n }\n\n _cancelPressOutDelayTimeout() {\n if (this._pressOutDelayTimeout != null) {\n clearTimeout(this._pressOutDelayTimeout)\n this._pressOutDelayTimeout = null\n }\n }\n}\n\nfunction normalizeDelay(delay, min?: number, fallback?: any) {\n if (min === void 0) {\n min = 0\n }\n\n if (fallback === void 0) {\n fallback = 0\n }\n\n return Math.max(min, delay !== null && delay !== void 0 ? delay : fallback)\n}\n\nfunction getTouchFromResponderEvent(event) {\n const _event$nativeEvent = event.nativeEvent\n const changedTouches = _event$nativeEvent.changedTouches\n const touches = _event$nativeEvent.touches\n\n if (touches != null && touches.length > 0) {\n return touches[0]\n }\n\n if (changedTouches != null && changedTouches.length > 0) {\n return changedTouches[0]\n }\n\n return event.nativeEvent\n}\n"],
|
|
5
|
+
"mappings": "AAWA,MAAM,QAAQ;AACd,MAAM,QAAQ;AACd,MAAM,sBAAsB;AAC5B,MAAM,gBAAgB;AACtB,MAAM,oCAAoC;AAC1C,MAAM,+BAA+B;AACrC,MAAM,iCAAiC;AACvC,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AAC1B,MAAM,uBAAuB;AAC7B,MAAM,cAAc,OAAO,OAAO;AAAA,EAChC,eAAe;AAAA,IACb,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AAAA,EACA,gCAAgC;AAAA,IAC9B,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAsB;AAAA,IACtB,qBAAqB;AAAA,EACvB;AAAA,EACA,8BAA8B;AAAA,IAC5B,OAAO;AAAA,IACP,iBAAiB;AAAA,IACjB,mBAAmB;AAAA,IACnB,sBAAs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;AAAA,IAC5B;AAAA,EACF;AAAA,EAEA,8BAA8B;AAC5B,QAAI,KAAK,yBAAyB,MAAM;AACtC,mBAAa,KAAK,qBAAqB;AACvC,WAAK,wBAAwB;AAAA,IAC/B;AAAA,EACF;AACF;AAEA,SAAS,eAAe,OAAO,KAAc,UAAgB;AAC3D,MAAI,QAAQ,QAAQ;AAClB,UAAM;AAAA,EACR;AAEA,MAAI,aAAa,QAAQ;AACvB,eAAW;AAAA,EACb;AAEA,SAAO,KAAK,IAAI,KAAK,UAAU,QAAQ,UAAU,SAAS,QAAQ,QAAQ;AAC5E;AAEA,SAAS,2BAA2B,OAAO;AACzC,QAAM,qBAAqB,MAAM;AACjC,QAAM,iBAAiB,mBAAmB;AAC1C,QAAM,UAAU,mBAAmB;AAEnC,MAAI,WAAW,QAAQ,QAAQ,SAAS,GAAG;AACzC,WAAO,QAAQ;AAAA,EACjB;AAEA,MAAI,kBAAkB,QAAQ,eAAe,SAAS,GAAG;AACvD,WAAO,eAAe;AAAA,EACxB;AAEA,SAAO,MAAM;AACf;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/react-native-use-pressable",
|
|
3
|
-
"version": "1.0.1-rc.
|
|
3
|
+
"version": "1.0.1-rc.6",
|
|
4
4
|
"types": "./types/index.d.ts",
|
|
5
5
|
"main": "dist/cjs",
|
|
6
6
|
"module": "dist/esm",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "tamagui-build",
|
|
14
14
|
"watch": "tamagui-build --watch",
|
|
15
|
-
"lint": "
|
|
16
|
-
"lint:fix": "
|
|
15
|
+
"lint": "../../node_modules/.bin/rome check src",
|
|
16
|
+
"lint:fix": "../../node_modules/.bin/rome check --apply-suggested src",
|
|
17
17
|
"clean": "tamagui-build clean",
|
|
18
18
|
"clean:build": "tamagui-build clean:build"
|
|
19
19
|
},
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"react": "^18.2.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@tamagui/build": "^1.0.1-rc.
|
|
24
|
+
"@tamagui/build": "^1.0.1-rc.6",
|
|
25
25
|
"@types/react": "^18.0.15"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
package/src/PressResponder.ts
CHANGED
|
@@ -58,7 +58,8 @@ const Transitions = Object.freeze({
|
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
const isActiveSignal = (signal) =>
|
|
61
|
-
signal === RESPONDER_ACTIVE_PRESS_START ||
|
|
61
|
+
signal === RESPONDER_ACTIVE_PRESS_START ||
|
|
62
|
+
signal === RESPONDER_ACTIVE_LONG_PRESS_START
|
|
62
63
|
|
|
63
64
|
const isButtonRole = (element) => element.getAttribute('role') === 'button'
|
|
64
65
|
|
|
@@ -67,11 +68,12 @@ const isPressStartSignal = (signal) =>
|
|
|
67
68
|
signal === RESPONDER_ACTIVE_PRESS_START ||
|
|
68
69
|
signal === RESPONDER_ACTIVE_LONG_PRESS_START
|
|
69
70
|
|
|
70
|
-
const isTerminalSignal = (signal) =>
|
|
71
|
+
const isTerminalSignal = (signal) =>
|
|
72
|
+
signal === RESPONDER_TERMINATED || signal === RESPONDER_RELEASE
|
|
71
73
|
|
|
72
74
|
const isValidKeyPress = (event) => {
|
|
73
|
-
const key = event.key
|
|
74
|
-
|
|
75
|
+
const key = event.key
|
|
76
|
+
const target = event.target
|
|
75
77
|
const role = target.getAttribute('role')
|
|
76
78
|
const isSpacebar = key === ' ' || key === 'Spacebar'
|
|
77
79
|
return key === 'Enter' || (isSpacebar && role === 'button')
|
|
@@ -213,7 +215,7 @@ export default class PressResponder {
|
|
|
213
215
|
const delayPressStart = normalizeDelay(
|
|
214
216
|
this._config.delayPressStart,
|
|
215
217
|
0,
|
|
216
|
-
DEFAULT_PRESS_DELAY_MS
|
|
218
|
+
DEFAULT_PRESS_DELAY_MS,
|
|
217
219
|
)
|
|
218
220
|
|
|
219
221
|
if (shouldDelay !== false && delayPressStart > 0) {
|
|
@@ -227,7 +229,7 @@ export default class PressResponder {
|
|
|
227
229
|
const delayLongPress = normalizeDelay(
|
|
228
230
|
this._config.delayLongPress,
|
|
229
231
|
10,
|
|
230
|
-
DEFAULT_LONG_PRESS_DELAY_MS
|
|
232
|
+
DEFAULT_LONG_PRESS_DELAY_MS,
|
|
231
233
|
)
|
|
232
234
|
this._longPressDelayTimeout = setTimeout(() => {
|
|
233
235
|
this._handleLongPress(event)
|
|
@@ -277,8 +279,8 @@ export default class PressResponder {
|
|
|
277
279
|
},
|
|
278
280
|
onKeyDown: (event) => {
|
|
279
281
|
const disabled = this._config.disabled
|
|
280
|
-
const key = event.key
|
|
281
|
-
|
|
282
|
+
const key = event.key
|
|
283
|
+
const target = event.target
|
|
282
284
|
|
|
283
285
|
if (!disabled && isValidKeyPress(event)) {
|
|
284
286
|
if (this._touchState === NOT_RESPONDER) {
|
|
@@ -327,10 +329,10 @@ export default class PressResponder {
|
|
|
327
329
|
this._receiveSignal(RESPONDER_TERMINATED, event)
|
|
328
330
|
},
|
|
329
331
|
onResponderTerminationRequest: (event) => {
|
|
330
|
-
const _this$_config = this._config
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
332
|
+
const _this$_config = this._config
|
|
333
|
+
const cancelable = _this$_config.cancelable
|
|
334
|
+
const disabled = _this$_config.disabled
|
|
335
|
+
const onLongPress = _this$_config.onLongPress // If `onLongPress` is provided, don't terminate on `contextmenu` as default
|
|
334
336
|
// behavior will be prevented for non-mouse pointers.
|
|
335
337
|
|
|
336
338
|
if (
|
|
@@ -357,9 +359,9 @@ export default class PressResponder {
|
|
|
357
359
|
// `click` target that is using the PressResponder.
|
|
358
360
|
// * The event's `nativeEvent` is a `MouseEvent` not a `TouchEvent`.
|
|
359
361
|
onClick: (event) => {
|
|
360
|
-
const _this$_config2 = this._config
|
|
361
|
-
|
|
362
|
-
|
|
362
|
+
const _this$_config2 = this._config
|
|
363
|
+
const disabled = _this$_config2.disabled
|
|
364
|
+
const onPress = _this$_config2.onPress
|
|
363
365
|
|
|
364
366
|
if (!disabled) {
|
|
365
367
|
// If long press dispatched, cancel default click behavior.
|
|
@@ -381,12 +383,16 @@ export default class PressResponder {
|
|
|
381
383
|
// If `onLongPress` is provided and a touch pointer is being used, prevent the
|
|
382
384
|
// default context menu from opening.
|
|
383
385
|
onContextMenu: (event) => {
|
|
384
|
-
const _this$_config3 = this._config
|
|
385
|
-
|
|
386
|
-
|
|
386
|
+
const _this$_config3 = this._config
|
|
387
|
+
const disabled = _this$_config3.disabled
|
|
388
|
+
const onLongPress = _this$_config3.onLongPress
|
|
387
389
|
|
|
388
390
|
if (!disabled) {
|
|
389
|
-
if (
|
|
391
|
+
if (
|
|
392
|
+
onLongPress != null &&
|
|
393
|
+
this._isPointerTouch &&
|
|
394
|
+
!event.defaultPrevented
|
|
395
|
+
) {
|
|
390
396
|
event.preventDefault()
|
|
391
397
|
event.stopPropagation()
|
|
392
398
|
}
|
|
@@ -418,7 +424,7 @@ export default class PressResponder {
|
|
|
418
424
|
if (nextState == null || nextState === ERROR) {
|
|
419
425
|
// eslint-disable-next-line no-console
|
|
420
426
|
console.error(
|
|
421
|
-
|
|
427
|
+
`PressResponder: Invalid signal ${signal} for state ${prevState} on responder`,
|
|
422
428
|
)
|
|
423
429
|
} else if (prevState !== nextState) {
|
|
424
430
|
this._performTransitionSideEffects(prevState, nextState, signal, event)
|
|
@@ -464,9 +470,9 @@ export default class PressResponder {
|
|
|
464
470
|
}
|
|
465
471
|
|
|
466
472
|
if (isPressStartSignal(prevState) && signal === RESPONDER_RELEASE) {
|
|
467
|
-
const _this$_config4 = this._config
|
|
468
|
-
|
|
469
|
-
|
|
473
|
+
const _this$_config4 = this._config
|
|
474
|
+
const _onLongPress = _this$_config4.onLongPress
|
|
475
|
+
const onPress = _this$_config4.onPress
|
|
470
476
|
|
|
471
477
|
if (onPress != null) {
|
|
472
478
|
const isPressCanceledByLongPress =
|
|
@@ -474,7 +480,7 @@ export default class PressResponder {
|
|
|
474
480
|
|
|
475
481
|
if (!isPressCanceledByLongPress) {
|
|
476
482
|
// If we never activated (due to delays), activate and deactivate now.
|
|
477
|
-
if (!isNextActive
|
|
483
|
+
if (!(isNextActive || isPrevActive)) {
|
|
478
484
|
this._activate(event)
|
|
479
485
|
|
|
480
486
|
this._deactivate(event)
|
|
@@ -487,9 +493,9 @@ export default class PressResponder {
|
|
|
487
493
|
}
|
|
488
494
|
|
|
489
495
|
_activate(event) {
|
|
490
|
-
const _this$_config5 = this._config
|
|
491
|
-
|
|
492
|
-
|
|
496
|
+
const _this$_config5 = this._config
|
|
497
|
+
const onPressChange = _this$_config5.onPressChange
|
|
498
|
+
const onPressStart = _this$_config5.onPressStart
|
|
493
499
|
const touch = getTouchFromResponderEvent(event)
|
|
494
500
|
this._touchActivatePosition = {
|
|
495
501
|
pageX: touch.pageX,
|
|
@@ -506,9 +512,9 @@ export default class PressResponder {
|
|
|
506
512
|
}
|
|
507
513
|
|
|
508
514
|
_deactivate(event) {
|
|
509
|
-
const _this$_config6 = this._config
|
|
510
|
-
|
|
511
|
-
|
|
515
|
+
const _this$_config6 = this._config
|
|
516
|
+
const onPressChange = _this$_config6.onPressChange
|
|
517
|
+
const onPressEnd = _this$_config6.onPressEnd
|
|
512
518
|
|
|
513
519
|
function end() {
|
|
514
520
|
if (onPressEnd != null) {
|
|
@@ -575,9 +581,9 @@ function normalizeDelay(delay, min?: number, fallback?: any) {
|
|
|
575
581
|
}
|
|
576
582
|
|
|
577
583
|
function getTouchFromResponderEvent(event) {
|
|
578
|
-
const _event$nativeEvent = event.nativeEvent
|
|
579
|
-
|
|
580
|
-
|
|
584
|
+
const _event$nativeEvent = event.nativeEvent
|
|
585
|
+
const changedTouches = _event$nativeEvent.changedTouches
|
|
586
|
+
const touches = _event$nativeEvent.touches
|
|
581
587
|
|
|
582
588
|
if (touches != null && touches.length > 0) {
|
|
583
589
|
return touches[0]
|