@tamagui/react-native-use-pressable 1.0.1-beta.194
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.
- package/dist/cjs/PressResponder.js +379 -0
- package/dist/cjs/PressResponder.js.map +7 -0
- package/dist/cjs/index.js +53 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/esm/PressResponder.js +357 -0
- package/dist/esm/PressResponder.js.map +7 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/index.js.map +7 -0
- package/package.json +30 -0
- package/src/PressResponder.ts +591 -0
- package/src/index.ts +40 -0
- package/types/PressResponder.d.ts +124 -0
- package/types/index.d.ts +3 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* =========================== PressResponder Tutorial ===========================
|
|
3
|
+
*
|
|
4
|
+
* The `PressResponder` class helps you create press interactions by analyzing the
|
|
5
|
+
* geometry of elements and observing when another responder (e.g. ScrollView)
|
|
6
|
+
* has stolen the touch lock. It offers hooks for your component to provide
|
|
7
|
+
* interaction feedback to the user:
|
|
8
|
+
*
|
|
9
|
+
* - When a press has activated (e.g. highlight an element)
|
|
10
|
+
* - When a press has deactivated (e.g. un-highlight an element)
|
|
11
|
+
* - When a press sould trigger an action, meaning it activated and deactivated
|
|
12
|
+
* while within the geometry of the element without the lock being stolen.
|
|
13
|
+
*
|
|
14
|
+
* A high quality interaction isn't as simple as you might think. There should
|
|
15
|
+
* be a slight delay before activation. Moving your finger beyond an element's
|
|
16
|
+
* bounds should trigger deactivation, but moving the same finger back within an
|
|
17
|
+
* element's bounds should trigger reactivation.
|
|
18
|
+
*
|
|
19
|
+
* In order to use `PressResponder`, do the following:
|
|
20
|
+
*
|
|
21
|
+
* const pressResponder = new PressResponder(config);
|
|
22
|
+
*
|
|
23
|
+
* 2. Choose the rendered component who should collect the press events. On that
|
|
24
|
+
* element, spread `pressability.getEventHandlers()` into its props.
|
|
25
|
+
*
|
|
26
|
+
* return (
|
|
27
|
+
* <View {...this.state.pressResponder.getEventHandlers()} />
|
|
28
|
+
* );
|
|
29
|
+
*
|
|
30
|
+
* 3. Reset `PressResponder` when your component unmounts.
|
|
31
|
+
*
|
|
32
|
+
* componentWillUnmount() {
|
|
33
|
+
* this.state.pressResponder.reset();
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* ==================== Implementation Details ====================
|
|
37
|
+
*
|
|
38
|
+
* `PressResponder` only assumes that there exists a `HitRect` node. The `PressRect`
|
|
39
|
+
* is an abstract box that is extended beyond the `HitRect`.
|
|
40
|
+
*
|
|
41
|
+
* # Geometry
|
|
42
|
+
*
|
|
43
|
+
* ┌────────────────────────┐
|
|
44
|
+
* │ ┌──────────────────┐ │ - Presses start anywhere within `HitRect`.
|
|
45
|
+
* │ │ ┌────────────┐ │ │
|
|
46
|
+
* │ │ │ VisualRect │ │ │
|
|
47
|
+
* │ │ └────────────┘ │ │ - When pressed down for sufficient amount of time
|
|
48
|
+
* │ │ HitRect │ │ before letting up, `VisualRect` activates.
|
|
49
|
+
* │ └──────────────────┘ │
|
|
50
|
+
* │ Out Region o │
|
|
51
|
+
* └────────────────────│───┘
|
|
52
|
+
* └────── When the press is released outside the `HitRect`,
|
|
53
|
+
* the responder is NOT eligible for a "press".
|
|
54
|
+
*
|
|
55
|
+
* # State Machine
|
|
56
|
+
*
|
|
57
|
+
* ┌───────────────┐ ◀──── RESPONDER_RELEASE
|
|
58
|
+
* │ NOT_RESPONDER │
|
|
59
|
+
* └───┬───────────┘ ◀──── RESPONDER_TERMINATED
|
|
60
|
+
* │
|
|
61
|
+
* │ RESPONDER_GRANT (HitRect)
|
|
62
|
+
* │
|
|
63
|
+
* ▼
|
|
64
|
+
* ┌─────────────────────┐ ┌───────────────────┐ ┌───────────────────┐
|
|
65
|
+
* │ RESPONDER_INACTIVE_ │ DELAY │ RESPONDER_ACTIVE_ │ T + DELAY │ RESPONDER_ACTIVE_ │
|
|
66
|
+
* │ PRESS_START ├────────▶ │ PRESS_START ├────────────▶ │ LONG_PRESS_START │
|
|
67
|
+
* └─────────────────────┘ └───────────────────┘ └───────────────────┘
|
|
68
|
+
*
|
|
69
|
+
* T + DELAY => LONG_PRESS_DELAY + DELAY
|
|
70
|
+
*
|
|
71
|
+
* Not drawn are the side effects of each transition. The most important side
|
|
72
|
+
* effect is the invocation of `onLongPress`. Only when the browser produces a
|
|
73
|
+
* `click` event is `onPress` invoked.
|
|
74
|
+
*/
|
|
75
|
+
export default class PressResponder {
|
|
76
|
+
_touchActivatePosition: any;
|
|
77
|
+
_pressDelayTimeout: any;
|
|
78
|
+
_selectionTerminated: boolean;
|
|
79
|
+
_isPointerTouch: boolean;
|
|
80
|
+
_longPressDelayTimeout: any;
|
|
81
|
+
_longPressDispatched: boolean;
|
|
82
|
+
_pressOutDelayTimeout: any;
|
|
83
|
+
_touchState: string;
|
|
84
|
+
_config: any;
|
|
85
|
+
_eventHandlers: any;
|
|
86
|
+
constructor(config: any);
|
|
87
|
+
configure(config: any): void;
|
|
88
|
+
/**
|
|
89
|
+
* Resets any pending timers. This should be called on unmount.
|
|
90
|
+
*/
|
|
91
|
+
reset(): void;
|
|
92
|
+
/**
|
|
93
|
+
* Returns a set of props to spread into the interactive element.
|
|
94
|
+
*/
|
|
95
|
+
getEventHandlers(): any;
|
|
96
|
+
_createEventHandlers(): {
|
|
97
|
+
onStartShouldSetResponder: (event: any) => boolean;
|
|
98
|
+
onKeyDown: (event: any) => void;
|
|
99
|
+
onResponderGrant: (event: any) => void;
|
|
100
|
+
onResponderMove: (event: any) => void;
|
|
101
|
+
onResponderRelease: (event: any) => void;
|
|
102
|
+
onResponderTerminate: (event: any) => void;
|
|
103
|
+
onResponderTerminationRequest: (event: any) => any;
|
|
104
|
+
onClick: (event: any) => void;
|
|
105
|
+
onContextMenu: (event: any) => void;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Receives a state machine signal, performs side effects of the transition
|
|
109
|
+
* and stores the new state. Validates the transition as well.
|
|
110
|
+
*/
|
|
111
|
+
_receiveSignal(signal: any, event: any): void;
|
|
112
|
+
/**
|
|
113
|
+
* Performs a transition between touchable states and identify any activations
|
|
114
|
+
* or deactivations (and callback invocations).
|
|
115
|
+
*/
|
|
116
|
+
_performTransitionSideEffects(prevState: any, nextState: any, signal: any, event: any): void;
|
|
117
|
+
_activate(event: any): void;
|
|
118
|
+
_deactivate(event: any): void;
|
|
119
|
+
_handleLongPress(event: any): void;
|
|
120
|
+
_cancelLongPressDelayTimeout(): void;
|
|
121
|
+
_cancelPressDelayTimeout(): void;
|
|
122
|
+
_cancelPressOutDelayTimeout(): void;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=PressResponder.d.ts.map
|
package/types/index.d.ts
ADDED