@ng-native/components 0.0.1 → 0.1.1

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.
Files changed (144) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +78 -1
  3. package/dist/activity-indicator.d.ts +41 -0
  4. package/dist/activity-indicator.js +66 -0
  5. package/dist/activity-indicator.js.map +1 -0
  6. package/dist/animated-style.d.ts +31 -0
  7. package/dist/animated-style.js +102 -0
  8. package/dist/animated-style.js.map +1 -0
  9. package/dist/animated.d.ts +125 -0
  10. package/dist/animated.js +538 -0
  11. package/dist/animated.js.map +1 -0
  12. package/dist/animation.d.ts +40 -0
  13. package/dist/animation.js +20 -0
  14. package/dist/animation.js.map +1 -0
  15. package/dist/animations-web.d.ts +8 -0
  16. package/dist/animations-web.js +31 -0
  17. package/dist/animations-web.js.map +1 -0
  18. package/dist/animations.d.ts +7 -0
  19. package/dist/animations.js +58 -0
  20. package/dist/animations.js.map +1 -0
  21. package/dist/controlled-model.d.ts +33 -0
  22. package/dist/controlled-model.js +47 -0
  23. package/dist/controlled-model.js.map +1 -0
  24. package/dist/easing.d.ts +21 -0
  25. package/dist/easing.js +50 -0
  26. package/dist/easing.js.map +1 -0
  27. package/dist/events.d.ts +169 -0
  28. package/dist/events.js +2 -0
  29. package/dist/events.js.map +1 -0
  30. package/dist/gesture-backend.d.ts +26 -0
  31. package/dist/gesture-backend.js +14 -0
  32. package/dist/gesture-backend.js.map +1 -0
  33. package/dist/gesture-dispatch.d.ts +67 -0
  34. package/dist/gesture-dispatch.js +106 -0
  35. package/dist/gesture-dispatch.js.map +1 -0
  36. package/dist/gestures.d.ts +23 -0
  37. package/dist/gestures.js +164 -0
  38. package/dist/gestures.js.map +1 -0
  39. package/dist/height-index.d.ts +31 -0
  40. package/dist/height-index.js +80 -0
  41. package/dist/height-index.js.map +1 -0
  42. package/dist/image-background.d.ts +32 -0
  43. package/dist/image-background.js +80 -0
  44. package/dist/image-background.js.map +1 -0
  45. package/dist/image.d.ts +79 -0
  46. package/dist/image.js +155 -0
  47. package/dist/image.js.map +1 -0
  48. package/dist/index.d.ts +38 -0
  49. package/dist/index.js +39 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/input-accessory-view.d.ts +16 -0
  52. package/dist/input-accessory-view.js +29 -0
  53. package/dist/input-accessory-view.js.map +1 -0
  54. package/dist/keyboard-avoiding-view.d.ts +79 -0
  55. package/dist/keyboard-avoiding-view.js +172 -0
  56. package/dist/keyboard-avoiding-view.js.map +1 -0
  57. package/dist/keyboard-dock.d.ts +126 -0
  58. package/dist/keyboard-dock.js +327 -0
  59. package/dist/keyboard-dock.js.map +1 -0
  60. package/dist/keyboard-taps.d.ts +12 -0
  61. package/dist/keyboard-taps.js +51 -0
  62. package/dist/keyboard-taps.js.map +1 -0
  63. package/dist/modal.d.ts +56 -0
  64. package/dist/modal.js +102 -0
  65. package/dist/modal.js.map +1 -0
  66. package/dist/native-gesture.d.ts +21 -0
  67. package/dist/native-gesture.js +56 -0
  68. package/dist/native-gesture.js.map +1 -0
  69. package/dist/native-ref.d.ts +7 -0
  70. package/dist/native-ref.js +13 -0
  71. package/dist/native-ref.js.map +1 -0
  72. package/dist/pressable.d.ts +220 -0
  73. package/dist/pressable.js +484 -0
  74. package/dist/pressable.js.map +1 -0
  75. package/dist/reanimated.d.ts +19 -0
  76. package/dist/reanimated.js +111 -0
  77. package/dist/reanimated.js.map +1 -0
  78. package/dist/refresh-control.d.ts +50 -0
  79. package/dist/refresh-control.js +103 -0
  80. package/dist/refresh-control.js.map +1 -0
  81. package/dist/safe-area-provider.d.ts +11 -0
  82. package/dist/safe-area-provider.js +70 -0
  83. package/dist/safe-area-provider.js.map +1 -0
  84. package/dist/safe-area-view.d.ts +22 -0
  85. package/dist/safe-area-view.js +77 -0
  86. package/dist/safe-area-view.js.map +1 -0
  87. package/dist/safe-area.d.ts +12 -0
  88. package/dist/safe-area.js +27 -0
  89. package/dist/safe-area.js.map +1 -0
  90. package/dist/scroll-view-props.d.ts +89 -0
  91. package/dist/scroll-view-props.js +153 -0
  92. package/dist/scroll-view-props.js.map +1 -0
  93. package/dist/scroll-view.d.ts +95 -0
  94. package/dist/scroll-view.js +181 -0
  95. package/dist/scroll-view.js.map +1 -0
  96. package/dist/section-list.d.ts +146 -0
  97. package/dist/section-list.js +300 -0
  98. package/dist/section-list.js.map +1 -0
  99. package/dist/sticky-headers.d.ts +41 -0
  100. package/dist/sticky-headers.js +118 -0
  101. package/dist/sticky-headers.js.map +1 -0
  102. package/dist/swipe-refresh-layout.d.ts +51 -0
  103. package/dist/swipe-refresh-layout.js +162 -0
  104. package/dist/swipe-refresh-layout.js.map +1 -0
  105. package/dist/switch.d.ts +54 -0
  106. package/dist/switch.js +110 -0
  107. package/dist/switch.js.map +1 -0
  108. package/dist/template-slot.d.ts +18 -0
  109. package/dist/template-slot.js +30 -0
  110. package/dist/template-slot.js.map +1 -0
  111. package/dist/text-input.d.ts +168 -0
  112. package/dist/text-input.js +312 -0
  113. package/dist/text-input.js.map +1 -0
  114. package/dist/text.d.ts +70 -0
  115. package/dist/text.js +111 -0
  116. package/dist/text.js.map +1 -0
  117. package/dist/touchable-opacity.d.ts +36 -0
  118. package/dist/touchable-opacity.js +76 -0
  119. package/dist/touchable-opacity.js.map +1 -0
  120. package/dist/transforms.d.ts +2 -0
  121. package/dist/transforms.js +17 -0
  122. package/dist/transforms.js.map +1 -0
  123. package/dist/view-base.d.ts +332 -0
  124. package/dist/view-base.js +534 -0
  125. package/dist/view-base.js.map +1 -0
  126. package/dist/view.d.ts +12 -0
  127. package/dist/view.js +18 -0
  128. package/dist/view.js.map +1 -0
  129. package/dist/virtual-list.d.ts +530 -0
  130. package/dist/virtual-list.js +1150 -0
  131. package/dist/virtual-list.js.map +1 -0
  132. package/dist/worklet-scroll.d.ts +13 -0
  133. package/dist/worklet-scroll.js +49 -0
  134. package/dist/worklet-scroll.js.map +1 -0
  135. package/dist/worklet-style.d.ts +13 -0
  136. package/dist/worklet-style.js +47 -0
  137. package/dist/worklet-style.js.map +1 -0
  138. package/dist/worklets.d.ts +89 -0
  139. package/dist/worklets.js +42 -0
  140. package/dist/worklets.js.map +1 -0
  141. package/dist/written-props.d.ts +6 -0
  142. package/dist/written-props.js +180 -0
  143. package/dist/written-props.js.map +1 -0
  144. package/package.json +88 -3
@@ -0,0 +1,484 @@
1
+ /**
2
+ * Press handling, built on the engine's responder system as RN's `Pressability` is.
3
+ *
4
+ * `onPress` is not a native event: RN synthesises it in JS from the touch primitives, with a
5
+ * press rectangle, delays and a long-press timer around them. This is that machine, on the same
6
+ * responder negotiation, so a button and an enclosing scroll view agree on who owns a drag.
7
+ */
8
+ import { Directive, booleanAttribute, forwardRef, input, numberAttribute, output, signal, } from '@angular/core';
9
+ import { ViewBase } from "./view-base.js";
10
+ import * as i0 from "@angular/core";
11
+ /**
12
+ * How far outside its own bounds a control keeps a press: RN's `DEFAULT_PRESS_RECT_OFFSETS`.
13
+ * More room below, because a thumb rolls downwards as it lifts.
14
+ */
15
+ const DEFAULT_PRESS_RETENTION = { top: 20, left: 20, right: 20, bottom: 30 };
16
+ /** RN's `DEFAULT_LONG_PRESS_DELAY_MS`. */
17
+ const DEFAULT_LONG_PRESS_DELAY = 500;
18
+ /** RN's `DEFAULT_MIN_PRESS_DURATION`: the pressed look stays at least this long on a quick tap. */
19
+ const DEFAULT_MIN_PRESS_DURATION = 130;
20
+ /**
21
+ * Used only until a control has been measured. RN measures the view and cancels when the touch
22
+ * leaves its bounds plus the retention offset; before the first layout arrives there are no
23
+ * bounds to compare against, so fall back to a small movement threshold rather than treating a
24
+ * drag of any length as a tap.
25
+ */
26
+ const PRESS_CANCEL_DISTANCE = 15;
27
+ const insets = (value, fallback) => {
28
+ if (value === undefined)
29
+ return fallback;
30
+ if (typeof value === 'number')
31
+ return { top: value, left: value, right: value, bottom: value };
32
+ return {
33
+ top: value.top ?? 0,
34
+ left: value.left ?? 0,
35
+ right: value.right ?? 0,
36
+ bottom: value.bottom ?? 0,
37
+ };
38
+ };
39
+ /** Page-space touch point, tolerating the several shapes a Fabric touch payload can take. */
40
+ function touchPoint(event) {
41
+ const native = (event.nativeEvent ?? {});
42
+ const touch = native.touches?.[0];
43
+ return {
44
+ x: native.pageX ?? touch?.pageX ?? 0,
45
+ y: native.pageY ?? touch?.pageY ?? 0,
46
+ };
47
+ }
48
+ const now = () => globalThis.performance?.now?.() ?? Date.now();
49
+ /**
50
+ * The press machine, and the base of every primitive that takes a touch.
51
+ *
52
+ * It declares no host bindings of its own, because `Text` extends it and a host binding runs on
53
+ * every element that carries it, on every pass. The controls bind theirs through `ControlBase`.
54
+ */
55
+ export class TouchableBase extends ViewBase {
56
+ /** Ignore touches entirely. */
57
+ disabled = input(false, { ...(ngDevMode ? { debugName: "disabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
58
+ /**
59
+ * How far outside the hit area a touch may wander before the press is cancelled. Native's
60
+ * `hitSlop` grows the area a touch can start in; this grows the area it may move within.
61
+ */
62
+ pressRetentionOffset = input(/* @ts-ignore */
63
+ ...(ngDevMode ? [undefined, { debugName: "pressRetentionOffset" }] : /* istanbul ignore next */ []));
64
+ /** Milliseconds a touch must be held before `(longPress)` fires. */
65
+ delayLongPress = input(DEFAULT_LONG_PRESS_DELAY, { ...(ngDevMode ? { debugName: "delayLongPress" } : /* istanbul ignore next */ {}), transform: numberAttribute });
66
+ /** Milliseconds between the touch landing and `(pressIn)`, so a scroll can start first. */
67
+ delayPressIn = input(0, { ...(ngDevMode ? { debugName: "delayPressIn" } : /* istanbul ignore next */ {}), transform: numberAttribute });
68
+ /** Milliseconds between the touch lifting and `(pressOut)`. */
69
+ delayPressOut = input(0, { ...(ngDevMode ? { debugName: "delayPressOut" } : /* istanbul ignore next */ {}), transform: numberAttribute });
70
+ /** The pressed state lasts at least this long, so a quick tap still shows it. */
71
+ minPressDuration = input(DEFAULT_MIN_PRESS_DURATION, { ...(ngDevMode ? { debugName: "minPressDuration" } : /* istanbul ignore next */ {}), transform: numberAttribute });
72
+ /** Whether a scrolling ancestor may take the gesture away mid-press. */
73
+ cancelable = input(true, { ...(ngDevMode ? { debugName: "cancelable" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
74
+ /** Android: a native ripple on press. */
75
+ androidRipple = input(undefined, { ...(ngDevMode ? { debugName: "androidRipple" } : /* istanbul ignore next */ {}), alias: 'android_ripple' });
76
+ /** The touch lifted inside the press area. Not fired after a `(longPress)` that has a listener. */
77
+ press = output();
78
+ pressIn = output();
79
+ pressOut = output();
80
+ /**
81
+ * The touch has been held for `delayLongPress`. With no listener there is no long press, as in
82
+ * React Native, so a slow tap is still a `press`.
83
+ */
84
+ longPress = output();
85
+ /** Whether a press is in progress, for the pressed look. */
86
+ pressed = signal(false, /* @ts-ignore */
87
+ ...(ngDevMode ? [{ debugName: "pressed" }] : /* istanbul ignore next */ []));
88
+ /**
89
+ * Whether a pointer is over the control, which on this platform means an iPad with a trackpad
90
+ * or a mouse. Always false on a phone, because a phone never sends a pointer event.
91
+ *
92
+ * Opted into by exactly the elements that opt into being measured, which is the same question
93
+ * asked twice: is this a control, or is it a piece of text that merely inherits the machinery.
94
+ * Registering on everything was the first attempt and put two props on every paragraph on
95
+ * screen, which is the most numerous node in an app paying for a state a label cannot use.
96
+ */
97
+ hovered = signal(false, /* @ts-ignore */
98
+ ...(ngDevMode ? [{ debugName: "hovered" }] : /* istanbul ignore next */ []));
99
+ /*
100
+ * Methods rather than `computed()`s, because nearly every instance has no ripple and a computed
101
+ * is an allocation per element whether or not it ever holds anything. The drawable is kept for as
102
+ * long as the ripple it came from, which is the memo the computed was there to provide: a fresh
103
+ * object on every pass would re-send the prop on every pass.
104
+ */
105
+ rippleBackground() {
106
+ const ripple = this.androidRipple();
107
+ return ripple && !ripple.foreground ? this.drawable(ripple) : undefined;
108
+ }
109
+ rippleForeground() {
110
+ const ripple = this.androidRipple();
111
+ return ripple?.foreground ? this.drawable(ripple) : undefined;
112
+ }
113
+ drawn = null;
114
+ drawable(ripple) {
115
+ if (this.drawn?.ripple !== ripple)
116
+ this.drawn = { ripple, drawable: this.rippleDrawable(ripple) };
117
+ return this.drawn.drawable;
118
+ }
119
+ /**
120
+ * The drawable description Android's `ReactDrawableHelper` reads.
121
+ *
122
+ * `color` goes through the engine the way every other colour prop does, and has to: the helper
123
+ * switches on the value's runtime type and takes a number or a platform-colour map, and anything
124
+ * else - a `'#ff0000'` written at the call site, say - falls through to `null` and the ripple
125
+ * draws in the theme's own `colorControlHighlight` instead. Nothing is logged and nothing throws,
126
+ * so the ripple appears and is simply the wrong colour. RN's own `TouchableNativeFeedback.Ripple`
127
+ * calls `processColor` here for the same reason.
128
+ */
129
+ rippleDrawable(ripple) {
130
+ return {
131
+ type: 'RippleAndroid',
132
+ color: this.engine.color(ripple.color),
133
+ borderless: ripple.borderless ?? false,
134
+ rippleRadius: ripple.radius,
135
+ };
136
+ }
137
+ /** Where the touch started, so a drag can be told apart from a tap. */
138
+ origin = null;
139
+ /** The control's own size, from its last layout. Null until it has been measured once. */
140
+ size = null;
141
+ cancelled = false;
142
+ longPressed = false;
143
+ /** How many `(longPress)` listeners there are; the long-press clock only runs with one. */
144
+ longPressListeners = 0;
145
+ pressedAt = 0;
146
+ pressInTimer = null;
147
+ longPressTimer = null;
148
+ pressOutTimer = null;
149
+ constructor() {
150
+ super();
151
+ // output() has to be a member's own initializer for the compiler to see it, so its listeners
152
+ // are counted here, through its public subscribe.
153
+ const subscribe = this.longPress.subscribe.bind(this.longPress);
154
+ this.longPress.subscribe = (callback) => {
155
+ this.longPressListeners++;
156
+ const subscription = subscribe(callback);
157
+ let open = true;
158
+ return {
159
+ unsubscribe: () => {
160
+ if (open)
161
+ this.longPressListeners--;
162
+ open = false;
163
+ subscription.unsubscribe();
164
+ },
165
+ };
166
+ };
167
+ }
168
+ /** Called as a press starts and ends, for a subclass that shows it natively. `Text` does. */
169
+ pressedChanged(_pressed) { }
170
+ /** Whether a touch starting on this node should be claimed. `Text` narrows it. */
171
+ claims() {
172
+ return !this.disabled();
173
+ }
174
+ /**
175
+ * Whether the control's size should be tracked. Native only measures a view that asks, so
176
+ * this must not be true for every `<text>`: a pressable text opts in, a label never does.
177
+ */
178
+ measures() {
179
+ return true;
180
+ }
181
+ /**
182
+ * Whether a touch this far from where it started is still on the control.
183
+ *
184
+ * Distance from the origin is the wrong question on anything large: a thumb tap on a full-width
185
+ * button easily travels twenty points without ever leaving it, and cancelling there reads as
186
+ * "the button doesn't work", intermittently and only for some people. What matters is whether
187
+ * the finger is still within the control plus its hit slop, plus the slop RN allows.
188
+ *
189
+ * The touch began somewhere inside the control but we do not know where, so the bound is the
190
+ * full extent rather than half of it. That errs towards keeping the press, which is the right
191
+ * way to be wrong: a press that survives a drag the user meant as a scroll is a smaller sin
192
+ * than a tap that does nothing.
193
+ */
194
+ stillOnControl(dx, dy) {
195
+ if (!this.size)
196
+ return Math.hypot(dx, dy) <= PRESS_CANCEL_DISTANCE;
197
+ const slop = insets(this.hitSlop(), { top: 0, left: 0, right: 0, bottom: 0 });
198
+ const keep = insets(this.pressRetentionOffset(), DEFAULT_PRESS_RETENTION);
199
+ const horizontal = dx < 0 ? slop.left + keep.left : slop.right + keep.right;
200
+ const vertical = dy < 0 ? slop.top + keep.top : slop.bottom + keep.bottom;
201
+ return (Math.abs(dx) <= this.size.width + horizontal && Math.abs(dy) <= this.size.height + vertical);
202
+ }
203
+ /**
204
+ * A lifecycle hook rather than `inject(DestroyRef).onDestroy`: Angular registers a hook once per
205
+ * directive type, where the callback was a closure and a lookup for every instance - and every
206
+ * `<text>` on screen is one.
207
+ */
208
+ ngOnDestroy() {
209
+ this.clearTimers();
210
+ this.stopResponding?.();
211
+ this.stopLayout?.();
212
+ this.stopHover?.();
213
+ }
214
+ stopResponding = null;
215
+ stopLayout = null;
216
+ stopHover = null;
217
+ ngOnInit() {
218
+ super.ngOnInit();
219
+ this.respondIfNeeded();
220
+ this.measureIfNeeded();
221
+ this.hoverIfNeeded();
222
+ }
223
+ ngOnChanges() {
224
+ super.ngOnChanges();
225
+ this.respondIfNeeded();
226
+ this.measureIfNeeded();
227
+ this.hoverIfNeeded();
228
+ }
229
+ /**
230
+ * Join the responder negotiation, once this is something a touch can press.
231
+ *
232
+ * Behind `measures()` for the same reason as layout and hover: a `<text>` is the commonest node
233
+ * on screen and almost never a control, and registering every one cost a handler object, six
234
+ * closures and a responder entry apiece for a touch it would have refused anyway.
235
+ */
236
+ respondIfNeeded() {
237
+ if (this.stopResponding || !this.measures())
238
+ return;
239
+ this.stopResponding = this.engine.setResponder(this.node, {
240
+ // Claim the gesture on touch down unless disabled. Because this goes through the
241
+ // negotiation, an ancestor can pre-empt us in the capture pass and a nested pressable
242
+ // wins over us in the bubble pass, neither of which raw touch listeners could express.
243
+ onStartShouldSetResponder: () => this.claims(),
244
+ onResponderGrant: (event) => this.onGrant(event),
245
+ onResponderMove: (event) => this.onMove(event),
246
+ onResponderRelease: (event) => this.onRelease(event),
247
+ onResponderTerminate: (event) => this.onTerminate(event),
248
+ // Yield to an enclosing scroll view when it takes over the drag, unless told not to.
249
+ onResponderTerminationRequest: () => this.cancelable(),
250
+ });
251
+ }
252
+ /**
253
+ * `onLayout` is opted into by the engine as soon as something listens for it, which is the only
254
+ * way the native side reports a view's size at all, and the reason it is only asked for once
255
+ * `measures()` says so - a `<text>` answers that from an input, and most of them say no.
256
+ *
257
+ * Called from the lifecycle rather than watched by an effect. An effect per element is an
258
+ * allocation and a scheduler entry for every pressable and every piece of text on screen, to
259
+ * notice a change these two hooks already see.
260
+ */
261
+ /**
262
+ * Hover, on the same terms and behind the same question.
263
+ *
264
+ * Fabric will not dispatch a pointer event to a view whose props have not asked for one, and
265
+ * the engine writes those props when something listens - so listening is the whole opt-in. The
266
+ * gate is `measures()`, which is not what its name is about but is the right question underneath
267
+ * it: is this an actual control, or a piece of text that merely inherits the machinery. A label
268
+ * says no, and two props on every paragraph on screen is not a cost worth paying for a hover
269
+ * state a label has no use for.
270
+ *
271
+ * Never true on a phone, which sends no pointer events at all. This is the one thing an iPad
272
+ * with a trackpad has that a phone does not.
273
+ */
274
+ hoverIfNeeded() {
275
+ if (this.stopHover || !this.measures())
276
+ return;
277
+ const enter = this.engine.setEventListener(this.node, 'topPointerEnter', () => this.hovered.set(true));
278
+ const leave = this.engine.setEventListener(this.node, 'topPointerLeave', () => this.hovered.set(false));
279
+ this.stopHover = () => {
280
+ enter();
281
+ leave();
282
+ };
283
+ }
284
+ measureIfNeeded() {
285
+ if (this.stopLayout || !this.measures())
286
+ return;
287
+ this.stopLayout = this.engine.setEventListener(this.node, 'topLayout', (event) => {
288
+ const layout = event
289
+ .nativeEvent?.layout;
290
+ if (layout)
291
+ this.size = { width: layout.width, height: layout.height };
292
+ });
293
+ }
294
+ onGrant(event) {
295
+ this.origin = touchPoint(event);
296
+ this.cancelled = false;
297
+ this.longPressed = false;
298
+ this.clearTimers();
299
+ if (this.androidRipple()) {
300
+ const { x, y } = this.origin;
301
+ this.engine.dispatchCommand(this.node, 'hotspotUpdate', [x, y]);
302
+ this.engine.dispatchCommand(this.node, 'setPressed', [true]);
303
+ }
304
+ const delay = this.delayPressIn();
305
+ if (delay > 0)
306
+ this.pressInTimer = setTimeout(() => this.activate(event), delay);
307
+ else
308
+ this.activate(event);
309
+ }
310
+ /** `pressIn`, and the long-press clock starts from here. */
311
+ activate(event) {
312
+ this.pressInTimer = null;
313
+ this.pressedAt = now();
314
+ this.pressed.set(true);
315
+ this.pressedChanged(true);
316
+ this.pressIn.emit(event);
317
+ if (!this.longPressListeners)
318
+ return;
319
+ this.longPressTimer = setTimeout(() => {
320
+ this.longPressTimer = null;
321
+ this.longPressed = true;
322
+ this.longPress.emit(event);
323
+ }, this.delayLongPress());
324
+ }
325
+ onMove(event) {
326
+ if (this.cancelled || !this.origin)
327
+ return;
328
+ const point = touchPoint(event);
329
+ if (this.stillOnControl(point.x - this.origin.x, point.y - this.origin.y))
330
+ return;
331
+ // The finger has wandered: this is a drag, not a tap. Give up the press but stay the
332
+ // responder, so a scroll view underneath still gets its gesture.
333
+ this.cancelled = true;
334
+ this.deactivate(event);
335
+ }
336
+ onRelease(event) {
337
+ if (this.androidRipple())
338
+ this.engine.dispatchCommand(this.node, 'setPressed', [false]);
339
+ if (this.cancelled)
340
+ return;
341
+ // Lifted before the press-in delay ran out: RN still reports a full press.
342
+ if (this.pressInTimer) {
343
+ clearTimeout(this.pressInTimer);
344
+ this.activate(event);
345
+ }
346
+ const longPressed = this.longPressed;
347
+ this.deactivate(event);
348
+ if (!longPressed)
349
+ this.press.emit(event);
350
+ }
351
+ onTerminate(event) {
352
+ if (this.androidRipple())
353
+ this.engine.dispatchCommand(this.node, 'setPressed', [false]);
354
+ if (this.cancelled)
355
+ return;
356
+ this.cancelled = true;
357
+ this.deactivate(event);
358
+ }
359
+ /** `pressOut`, no sooner than `minPressDuration` after `pressIn` and after `delayPressOut`. */
360
+ deactivate(event) {
361
+ if (this.pressInTimer) {
362
+ clearTimeout(this.pressInTimer);
363
+ this.pressInTimer = null;
364
+ return;
365
+ }
366
+ if (this.longPressTimer) {
367
+ clearTimeout(this.longPressTimer);
368
+ this.longPressTimer = null;
369
+ }
370
+ if (!this.pressed())
371
+ return;
372
+ const held = now() - this.pressedAt;
373
+ const delay = Math.max(this.delayPressOut(), this.minPressDuration() - held);
374
+ const out = () => {
375
+ this.pressOutTimer = null;
376
+ this.pressed.set(false);
377
+ this.pressedChanged(false);
378
+ this.pressOut.emit(event);
379
+ };
380
+ if (delay > 0)
381
+ this.pressOutTimer = setTimeout(out, delay);
382
+ else
383
+ out();
384
+ }
385
+ clearTimers() {
386
+ // Every touchable is destroyed through here, and nearly all of them were never pressed.
387
+ if (!this.pressInTimer && !this.longPressTimer && !this.pressOutTimer)
388
+ return;
389
+ for (const timer of [this.pressInTimer, this.longPressTimer, this.pressOutTimer]) {
390
+ if (timer)
391
+ clearTimeout(timer);
392
+ }
393
+ this.pressInTimer = this.longPressTimer = this.pressOutTimer = null;
394
+ }
395
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TouchableBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
396
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.0", type: TouchableBase, isStandalone: true, inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, pressRetentionOffset: { classPropertyName: "pressRetentionOffset", publicName: "pressRetentionOffset", isSignal: true, isRequired: false, transformFunction: null }, delayLongPress: { classPropertyName: "delayLongPress", publicName: "delayLongPress", isSignal: true, isRequired: false, transformFunction: null }, delayPressIn: { classPropertyName: "delayPressIn", publicName: "delayPressIn", isSignal: true, isRequired: false, transformFunction: null }, delayPressOut: { classPropertyName: "delayPressOut", publicName: "delayPressOut", isSignal: true, isRequired: false, transformFunction: null }, minPressDuration: { classPropertyName: "minPressDuration", publicName: "minPressDuration", isSignal: true, isRequired: false, transformFunction: null }, cancelable: { classPropertyName: "cancelable", publicName: "cancelable", isSignal: true, isRequired: false, transformFunction: null }, androidRipple: { classPropertyName: "androidRipple", publicName: "android_ripple", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { press: "press", pressIn: "pressIn", pressOut: "pressOut", longPress: "longPress" }, usesInheritance: true, usesOnChanges: true, ngImport: i0 });
397
+ }
398
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: TouchableBase, decorators: [{
399
+ type: Directive
400
+ }], ctorParameters: () => [], propDecorators: { disabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "disabled", required: false }] }], pressRetentionOffset: [{ type: i0.Input, args: [{ isSignal: true, alias: "pressRetentionOffset", required: false }] }], delayLongPress: [{ type: i0.Input, args: [{ isSignal: true, alias: "delayLongPress", required: false }] }], delayPressIn: [{ type: i0.Input, args: [{ isSignal: true, alias: "delayPressIn", required: false }] }], delayPressOut: [{ type: i0.Input, args: [{ isSignal: true, alias: "delayPressOut", required: false }] }], minPressDuration: [{ type: i0.Input, args: [{ isSignal: true, alias: "minPressDuration", required: false }] }], cancelable: [{ type: i0.Input, args: [{ isSignal: true, alias: "cancelable", required: false }] }], androidRipple: [{ type: i0.Input, args: [{ isSignal: true, alias: "android_ripple", required: false }] }], press: [{ type: i0.Output, args: ["press"] }], pressIn: [{ type: i0.Output, args: ["pressIn"] }], pressOut: [{ type: i0.Output, args: ["pressOut"] }], longPress: [{ type: i0.Output, args: ["longPress"] }] } });
401
+ /**
402
+ * A touchable that is a control: `Pressable`, `TouchableOpacity` and `PressBehavior`.
403
+ *
404
+ * The three host bindings every control needs live here rather than on `TouchableBase`, which
405
+ * `Text` extends: the state that follows `disabled`, and the Android ripple. Controls are few
406
+ * enough on a screen to pay for a binding on every pass; texts are not.
407
+ */
408
+ export class ControlBase extends TouchableBase {
409
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ControlBase, deps: null, target: i0.ɵɵFactoryTarget.Directive });
410
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.0", type: ControlBase, isStandalone: true, host: { properties: { "accessibilityState": "accessibilityStateProp()", "nativeBackgroundAndroid": "rippleBackground()", "nativeForegroundAndroid": "rippleForeground()" } }, usesInheritance: true, ngImport: i0 });
411
+ }
412
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ControlBase, decorators: [{
413
+ type: Directive,
414
+ args: [{
415
+ host: {
416
+ // `disabled` is an input of ours, so it cannot reach `ngOnChanges` on the base; this is
417
+ // the one binding that keeps the announced state in step with it.
418
+ '[accessibilityState]': 'accessibilityStateProp()',
419
+ '[nativeBackgroundAndroid]': 'rippleBackground()',
420
+ '[nativeForegroundAndroid]': 'rippleForeground()',
421
+ },
422
+ }]
423
+ }] });
424
+ /**
425
+ * The press machine on its own, for a component that wants to be pressable rather than to
426
+ * contain something that is.
427
+ *
428
+ * No selector: this is only ever a `hostDirectives` entry. A component listing it gets the whole
429
+ * of `TouchableBase` on its own host node - the responder negotiation, the press rectangle, the
430
+ * delays and the long-press timer - instead of wrapping a `<pressable>` and paying for a second
431
+ * native view.
432
+ *
433
+ * It provides `TouchableBase`, so a primitive on the same node can `inject(TouchableBase)` and
434
+ * read `pressed` without caring whether it landed on this or on a real `<pressable>`.
435
+ */
436
+ export class PressBehavior extends ControlBase {
437
+ accessibleByDefault() {
438
+ return true;
439
+ }
440
+ focusableByDefault() {
441
+ return true;
442
+ }
443
+ disabledForAccessibility() {
444
+ return this.disabled();
445
+ }
446
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PressBehavior, deps: null, target: i0.ɵɵFactoryTarget.Directive });
447
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.0", type: PressBehavior, isStandalone: true, providers: [{ provide: TouchableBase, useExisting: forwardRef(() => PressBehavior) }], usesInheritance: true, ngImport: i0 });
448
+ }
449
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PressBehavior, decorators: [{
450
+ type: Directive,
451
+ args: [{
452
+ providers: [{ provide: TouchableBase, useExisting: forwardRef(() => PressBehavior) }],
453
+ }]
454
+ }] });
455
+ /**
456
+ * A view that responds to presses. RN's `Pressable`, with the same configuration: hit slop,
457
+ * retention offset, press-in and press-out delays, long press, and an Android ripple.
458
+ *
459
+ * `pressed` is a public signal, so a template can style from it through a template reference:
460
+ * `<pressable #p [style.opacity]="p.pressed() ? 0.5 : 1">`.
461
+ */
462
+ export class Pressable extends ControlBase {
463
+ /** `Pressable.js`: a control is an accessibility element, and focusable, unless refused. */
464
+ accessibleByDefault() {
465
+ return true;
466
+ }
467
+ focusableByDefault() {
468
+ return true;
469
+ }
470
+ disabledForAccessibility() {
471
+ return this.disabled();
472
+ }
473
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Pressable, deps: null, target: i0.ɵɵFactoryTarget.Directive });
474
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.0", type: Pressable, isStandalone: true, selector: "pressable", providers: [{ provide: TouchableBase, useExisting: forwardRef(() => Pressable) }], exportAs: ["pressable"], usesInheritance: true, ngImport: i0 });
475
+ }
476
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: Pressable, decorators: [{
477
+ type: Directive,
478
+ args: [{
479
+ selector: 'pressable',
480
+ exportAs: 'pressable',
481
+ providers: [{ provide: TouchableBase, useExisting: forwardRef(() => Pressable) }],
482
+ }]
483
+ }] });
484
+ //# sourceMappingURL=pressable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pressable.js","sourceRoot":"","sources":["../src/pressable.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,UAAU,EACV,KAAK,EACL,eAAe,EACf,MAAM,EACN,MAAM,GACP,MAAM,eAAe,CAAC;AAGvB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;;AAe1C;;;GAGG;AACH,MAAM,uBAAuB,GAAqB,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAC/F,0CAA0C;AAC1C,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,mGAAmG;AACnG,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,qBAAqB,GAAG,EAAE,CAAC;AAEjC,MAAM,MAAM,GAAG,CAAC,KAAkC,EAAE,QAA0B,EAAE,EAAE;IAChF,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,EAA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AAG,EAAE,CAAC,aAAa,CAAC,EAAE,CAAC;;2FAE1E,aAAa;kBAHzB,SAAS;mBAAC;oBACT,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,cAAc,CAAC,EAAE,CAAC;iBACtF;;AAeD;;;;;;GAMG;AAMH,MAAM,OAAO,SAAU,SAAQ,WAAW;IACxC,4FAA4F;IACzE,mBAAmB;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;IAEkB,kBAAkB;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAEkB,wBAAwB;QACzC,OAAO,IAAI,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;uGAZU,SAAS;2FAAT,SAAS,wDAFT,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC;;2FAEtE,SAAS;kBALrB,SAAS;mBAAC;oBACT,QAAQ,EAAE,WAAW;oBACrB,QAAQ,EAAE,WAAW;oBACrB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,CAAC;iBAClF","sourcesContent":["/**\n * Press handling, built on the engine's responder system as RN's `Pressability` is.\n *\n * `onPress` is not a native event: RN synthesises it in JS from the touch primitives, with a\n * press rectangle, delays and a long-press timer around them. This is that machine, on the same\n * responder negotiation, so a button and an enclosing scroll view agree on who owns a drag.\n */\nimport {\n Directive,\n booleanAttribute,\n forwardRef,\n input,\n numberAttribute,\n output,\n signal,\n} from '@angular/core';\nimport type { NativeSyntheticEvent } from '@ng-native/fabric';\nimport type { Insets, TouchEvent } from './events.ts';\nimport { ViewBase } from './view-base.ts';\n\n/** What a press handler receives: RN's `{nativeEvent}` shape, passed straight through. */\nexport type PressEvent = TouchEvent;\n\n/**\n * Android's ripple, drawn natively. `foreground` paints it over the content rather than behind.\n */\nexport interface AndroidRipple {\n readonly color?: string | number;\n readonly borderless?: boolean;\n readonly radius?: number;\n readonly foreground?: boolean;\n}\n\n/**\n * How far outside its own bounds a control keeps a press: RN's `DEFAULT_PRESS_RECT_OFFSETS`.\n * More room below, because a thumb rolls downwards as it lifts.\n */\nconst DEFAULT_PRESS_RETENTION: Required<Insets> = { top: 20, left: 20, right: 20, bottom: 30 };\n/** RN's `DEFAULT_LONG_PRESS_DELAY_MS`. */\nconst DEFAULT_LONG_PRESS_DELAY = 500;\n/** RN's `DEFAULT_MIN_PRESS_DURATION`: the pressed look stays at least this long on a quick tap. */\nconst DEFAULT_MIN_PRESS_DURATION = 130;\n\n/**\n * Used only until a control has been measured. RN measures the view and cancels when the touch\n * leaves its bounds plus the retention offset; before the first layout arrives there are no\n * bounds to compare against, so fall back to a small movement threshold rather than treating a\n * drag of any length as a tap.\n */\nconst PRESS_CANCEL_DISTANCE = 15;\n\nconst insets = (value: Insets | number | undefined, fallback: Required<Insets>) => {\n if (value === undefined) return fallback;\n if (typeof value === 'number') return { top: value, left: value, right: value, bottom: value };\n return {\n top: value.top ?? 0,\n left: value.left ?? 0,\n right: value.right ?? 0,\n bottom: value.bottom ?? 0,\n };\n};\n\n/** Page-space touch point, tolerating the several shapes a Fabric touch payload can take. */\nfunction touchPoint(event: NativeSyntheticEvent): { x: number; y: number } {\n const native = (event.nativeEvent ?? {}) as {\n pageX?: number;\n pageY?: number;\n touches?: { pageX?: number; pageY?: number }[];\n };\n const touch = native.touches?.[0];\n return {\n x: native.pageX ?? touch?.pageX ?? 0,\n y: native.pageY ?? touch?.pageY ?? 0,\n };\n}\n\n/** What `rippleDrawable` builds: Android's `RippleAndroid` drawable description. */\ninterface RippleDrawable {\n readonly type: 'RippleAndroid';\n readonly color: unknown;\n readonly borderless: boolean;\n readonly rippleRadius: number | undefined;\n}\n\nconst now = (): number => globalThis.performance?.now?.() ?? Date.now();\n\n/**\n * The press machine, and the base of every primitive that takes a touch.\n *\n * It declares no host bindings of its own, because `Text` extends it and a host binding runs on\n * every element that carries it, on every pass. The controls bind theirs through `ControlBase`.\n */\n@Directive()\nexport abstract class TouchableBase extends ViewBase {\n /** Ignore touches entirely. */\n readonly disabled = input(false, { transform: booleanAttribute });\n\n /**\n * How far outside the hit area a touch may wander before the press is cancelled. Native's\n * `hitSlop` grows the area a touch can start in; this grows the area it may move within.\n */\n readonly pressRetentionOffset = input<Insets | number>();\n /** Milliseconds a touch must be held before `(longPress)` fires. */\n readonly delayLongPress = input(DEFAULT_LONG_PRESS_DELAY, { transform: numberAttribute });\n /** Milliseconds between the touch landing and `(pressIn)`, so a scroll can start first. */\n readonly delayPressIn = input(0, { transform: numberAttribute });\n /** Milliseconds between the touch lifting and `(pressOut)`. */\n readonly delayPressOut = input(0, { transform: numberAttribute });\n /** The pressed state lasts at least this long, so a quick tap still shows it. */\n readonly minPressDuration = input(DEFAULT_MIN_PRESS_DURATION, { transform: numberAttribute });\n /** Whether a scrolling ancestor may take the gesture away mid-press. */\n readonly cancelable = input(true, { transform: booleanAttribute });\n /** Android: a native ripple on press. */\n readonly androidRipple = input<AndroidRipple>(undefined, { alias: 'android_ripple' });\n\n /** The touch lifted inside the press area. Not fired after a `(longPress)` that has a listener. */\n readonly press = output<PressEvent>();\n readonly pressIn = output<PressEvent>();\n readonly pressOut = output<PressEvent>();\n /**\n * The touch has been held for `delayLongPress`. With no listener there is no long press, as in\n * React Native, so a slow tap is still a `press`.\n */\n readonly longPress = output<PressEvent>();\n\n /** Whether a press is in progress, for the pressed look. */\n readonly pressed = signal(false);\n\n /**\n * Whether a pointer is over the control, which on this platform means an iPad with a trackpad\n * or a mouse. Always false on a phone, because a phone never sends a pointer event.\n *\n * Opted into by exactly the elements that opt into being measured, which is the same question\n * asked twice: is this a control, or is it a piece of text that merely inherits the machinery.\n * Registering on everything was the first attempt and put two props on every paragraph on\n * screen, which is the most numerous node in an app paying for a state a label cannot use.\n */\n readonly hovered = signal(false);\n\n /*\n * Methods rather than `computed()`s, because nearly every instance has no ripple and a computed\n * is an allocation per element whether or not it ever holds anything. The drawable is kept for as\n * long as the ripple it came from, which is the memo the computed was there to provide: a fresh\n * object on every pass would re-send the prop on every pass.\n */\n protected rippleBackground(): RippleDrawable | undefined {\n const ripple = this.androidRipple();\n return ripple && !ripple.foreground ? this.drawable(ripple) : undefined;\n }\n\n protected rippleForeground(): RippleDrawable | undefined {\n const ripple = this.androidRipple();\n return ripple?.foreground ? this.drawable(ripple) : undefined;\n }\n\n private drawn: { ripple: AndroidRipple; drawable: RippleDrawable } | null = null;\n\n private drawable(ripple: AndroidRipple): RippleDrawable {\n if (this.drawn?.ripple !== ripple)\n this.drawn = { ripple, drawable: this.rippleDrawable(ripple) };\n return this.drawn.drawable;\n }\n\n /**\n * The drawable description Android's `ReactDrawableHelper` reads.\n *\n * `color` goes through the engine the way every other colour prop does, and has to: the helper\n * switches on the value's runtime type and takes a number or a platform-colour map, and anything\n * else - a `'#ff0000'` written at the call site, say - falls through to `null` and the ripple\n * draws in the theme's own `colorControlHighlight` instead. Nothing is logged and nothing throws,\n * so the ripple appears and is simply the wrong colour. RN's own `TouchableNativeFeedback.Ripple`\n * calls `processColor` here for the same reason.\n */\n private rippleDrawable(ripple: AndroidRipple): RippleDrawable {\n return {\n type: 'RippleAndroid' as const,\n color: this.engine.color(ripple.color),\n borderless: ripple.borderless ?? false,\n rippleRadius: ripple.radius,\n };\n }\n\n /** Where the touch started, so a drag can be told apart from a tap. */\n private origin: { x: number; y: number } | null = null;\n /** The control's own size, from its last layout. Null until it has been measured once. */\n private size: { width: number; height: number } | null = null;\n private cancelled = false;\n private longPressed = false;\n /** How many `(longPress)` listeners there are; the long-press clock only runs with one. */\n private longPressListeners = 0;\n private pressedAt = 0;\n private pressInTimer: ReturnType<typeof setTimeout> | null = null;\n private longPressTimer: ReturnType<typeof setTimeout> | null = null;\n private pressOutTimer: ReturnType<typeof setTimeout> | null = null;\n\n constructor() {\n super();\n // output() has to be a member's own initializer for the compiler to see it, so its listeners\n // are counted here, through its public subscribe.\n const subscribe = this.longPress.subscribe.bind(this.longPress);\n this.longPress.subscribe = (callback) => {\n this.longPressListeners++;\n const subscription = subscribe(callback);\n let open = true;\n return {\n unsubscribe: () => {\n if (open) this.longPressListeners--;\n open = false;\n subscription.unsubscribe();\n },\n };\n };\n }\n\n /** Called as a press starts and ends, for a subclass that shows it natively. `Text` does. */\n protected pressedChanged(_pressed: boolean): void {}\n\n /** Whether a touch starting on this node should be claimed. `Text` narrows it. */\n protected claims(): boolean {\n return !this.disabled();\n }\n\n /**\n * Whether the control's size should be tracked. Native only measures a view that asks, so\n * this must not be true for every `<text>`: a pressable text opts in, a label never does.\n */\n protected measures(): boolean {\n return true;\n }\n\n /**\n * Whether a touch this far from where it started is still on the control.\n *\n * Distance from the origin is the wrong question on anything large: a thumb tap on a full-width\n * button easily travels twenty points without ever leaving it, and cancelling there reads as\n * \"the button doesn't work\", intermittently and only for some people. What matters is whether\n * the finger is still within the control plus its hit slop, plus the slop RN allows.\n *\n * The touch began somewhere inside the control but we do not know where, so the bound is the\n * full extent rather than half of it. That errs towards keeping the press, which is the right\n * way to be wrong: a press that survives a drag the user meant as a scroll is a smaller sin\n * than a tap that does nothing.\n */\n private stillOnControl(dx: number, dy: number): boolean {\n if (!this.size) return Math.hypot(dx, dy) <= PRESS_CANCEL_DISTANCE;\n const slop = insets(this.hitSlop(), { top: 0, left: 0, right: 0, bottom: 0 });\n const keep = insets(this.pressRetentionOffset(), DEFAULT_PRESS_RETENTION);\n const horizontal = dx < 0 ? slop.left + keep.left : slop.right + keep.right;\n const vertical = dy < 0 ? slop.top + keep.top : slop.bottom + keep.bottom;\n return (\n Math.abs(dx) <= this.size.width + horizontal && Math.abs(dy) <= this.size.height + vertical\n );\n }\n\n /**\n * A lifecycle hook rather than `inject(DestroyRef).onDestroy`: Angular registers a hook once per\n * directive type, where the callback was a closure and a lookup for every instance - and every\n * `<text>` on screen is one.\n */\n ngOnDestroy(): void {\n this.clearTimers();\n this.stopResponding?.();\n this.stopLayout?.();\n this.stopHover?.();\n }\n\n private stopResponding: (() => void) | null = null;\n private stopLayout: (() => void) | null = null;\n private stopHover: (() => void) | null = null;\n\n override ngOnInit(): void {\n super.ngOnInit();\n this.respondIfNeeded();\n this.measureIfNeeded();\n this.hoverIfNeeded();\n }\n\n override ngOnChanges(): void {\n super.ngOnChanges();\n this.respondIfNeeded();\n this.measureIfNeeded();\n this.hoverIfNeeded();\n }\n\n /**\n * Join the responder negotiation, once this is something a touch can press.\n *\n * Behind `measures()` for the same reason as layout and hover: a `<text>` is the commonest node\n * on screen and almost never a control, and registering every one cost a handler object, six\n * closures and a responder entry apiece for a touch it would have refused anyway.\n */\n private respondIfNeeded(): void {\n if (this.stopResponding || !this.measures()) return;\n this.stopResponding = this.engine.setResponder(this.node, {\n // Claim the gesture on touch down unless disabled. Because this goes through the\n // negotiation, an ancestor can pre-empt us in the capture pass and a nested pressable\n // wins over us in the bubble pass, neither of which raw touch listeners could express.\n onStartShouldSetResponder: () => this.claims(),\n onResponderGrant: (event) => this.onGrant(event),\n onResponderMove: (event) => this.onMove(event),\n onResponderRelease: (event) => this.onRelease(event),\n onResponderTerminate: (event) => this.onTerminate(event),\n // Yield to an enclosing scroll view when it takes over the drag, unless told not to.\n onResponderTerminationRequest: () => this.cancelable(),\n });\n }\n\n /**\n * `onLayout` is opted into by the engine as soon as something listens for it, which is the only\n * way the native side reports a view's size at all, and the reason it is only asked for once\n * `measures()` says so - a `<text>` answers that from an input, and most of them say no.\n *\n * Called from the lifecycle rather than watched by an effect. An effect per element is an\n * allocation and a scheduler entry for every pressable and every piece of text on screen, to\n * notice a change these two hooks already see.\n */\n /**\n * Hover, on the same terms and behind the same question.\n *\n * Fabric will not dispatch a pointer event to a view whose props have not asked for one, and\n * the engine writes those props when something listens - so listening is the whole opt-in. The\n * gate is `measures()`, which is not what its name is about but is the right question underneath\n * it: is this an actual control, or a piece of text that merely inherits the machinery. A label\n * says no, and two props on every paragraph on screen is not a cost worth paying for a hover\n * state a label has no use for.\n *\n * Never true on a phone, which sends no pointer events at all. This is the one thing an iPad\n * with a trackpad has that a phone does not.\n */\n private hoverIfNeeded(): void {\n if (this.stopHover || !this.measures()) return;\n const enter = this.engine.setEventListener(this.node, 'topPointerEnter', () =>\n this.hovered.set(true),\n );\n const leave = this.engine.setEventListener(this.node, 'topPointerLeave', () =>\n this.hovered.set(false),\n );\n this.stopHover = () => {\n enter();\n leave();\n };\n }\n\n private measureIfNeeded(): void {\n if (this.stopLayout || !this.measures()) return;\n this.stopLayout = this.engine.setEventListener(this.node, 'topLayout', (event) => {\n const layout = (event as NativeSyntheticEvent<{ layout?: { width: number; height: number } }>)\n .nativeEvent?.layout;\n if (layout) this.size = { width: layout.width, height: layout.height };\n });\n }\n\n private onGrant(event: PressEvent): void {\n this.origin = touchPoint(event);\n this.cancelled = false;\n this.longPressed = false;\n this.clearTimers();\n if (this.androidRipple()) {\n const { x, y } = this.origin;\n this.engine.dispatchCommand(this.node, 'hotspotUpdate', [x, y]);\n this.engine.dispatchCommand(this.node, 'setPressed', [true]);\n }\n const delay = this.delayPressIn();\n if (delay > 0) this.pressInTimer = setTimeout(() => this.activate(event), delay);\n else this.activate(event);\n }\n\n /** `pressIn`, and the long-press clock starts from here. */\n private activate(event: PressEvent): void {\n this.pressInTimer = null;\n this.pressedAt = now();\n this.pressed.set(true);\n this.pressedChanged(true);\n this.pressIn.emit(event);\n if (!this.longPressListeners) return;\n this.longPressTimer = setTimeout(() => {\n this.longPressTimer = null;\n this.longPressed = true;\n this.longPress.emit(event);\n }, this.delayLongPress());\n }\n\n private onMove(event: PressEvent): void {\n if (this.cancelled || !this.origin) return;\n const point = touchPoint(event);\n if (this.stillOnControl(point.x - this.origin.x, point.y - this.origin.y)) return;\n // The finger has wandered: this is a drag, not a tap. Give up the press but stay the\n // responder, so a scroll view underneath still gets its gesture.\n this.cancelled = true;\n this.deactivate(event);\n }\n\n private onRelease(event: PressEvent): void {\n if (this.androidRipple()) this.engine.dispatchCommand(this.node, 'setPressed', [false]);\n if (this.cancelled) return;\n // Lifted before the press-in delay ran out: RN still reports a full press.\n if (this.pressInTimer) {\n clearTimeout(this.pressInTimer);\n this.activate(event);\n }\n const longPressed = this.longPressed;\n this.deactivate(event);\n if (!longPressed) this.press.emit(event);\n }\n\n private onTerminate(event: PressEvent): void {\n if (this.androidRipple()) this.engine.dispatchCommand(this.node, 'setPressed', [false]);\n if (this.cancelled) return;\n this.cancelled = true;\n this.deactivate(event);\n }\n\n /** `pressOut`, no sooner than `minPressDuration` after `pressIn` and after `delayPressOut`. */\n private deactivate(event: PressEvent): void {\n if (this.pressInTimer) {\n clearTimeout(this.pressInTimer);\n this.pressInTimer = null;\n return;\n }\n if (this.longPressTimer) {\n clearTimeout(this.longPressTimer);\n this.longPressTimer = null;\n }\n if (!this.pressed()) return;\n const held = now() - this.pressedAt;\n const delay = Math.max(this.delayPressOut(), this.minPressDuration() - held);\n const out = () => {\n this.pressOutTimer = null;\n this.pressed.set(false);\n this.pressedChanged(false);\n this.pressOut.emit(event);\n };\n if (delay > 0) this.pressOutTimer = setTimeout(out, delay);\n else out();\n }\n\n private clearTimers(): void {\n // Every touchable is destroyed through here, and nearly all of them were never pressed.\n if (!this.pressInTimer && !this.longPressTimer && !this.pressOutTimer) return;\n for (const timer of [this.pressInTimer, this.longPressTimer, this.pressOutTimer]) {\n if (timer) clearTimeout(timer);\n }\n this.pressInTimer = this.longPressTimer = this.pressOutTimer = null;\n }\n}\n\n/**\n * A touchable that is a control: `Pressable`, `TouchableOpacity` and `PressBehavior`.\n *\n * The three host bindings every control needs live here rather than on `TouchableBase`, which\n * `Text` extends: the state that follows `disabled`, and the Android ripple. Controls are few\n * enough on a screen to pay for a binding on every pass; texts are not.\n */\n@Directive({\n host: {\n // `disabled` is an input of ours, so it cannot reach `ngOnChanges` on the base; this is\n // the one binding that keeps the announced state in step with it.\n '[accessibilityState]': 'accessibilityStateProp()',\n '[nativeBackgroundAndroid]': 'rippleBackground()',\n '[nativeForegroundAndroid]': 'rippleForeground()',\n },\n})\nexport abstract class ControlBase extends TouchableBase {}\n\n/**\n * The press machine on its own, for a component that wants to be pressable rather than to\n * contain something that is.\n *\n * No selector: this is only ever a `hostDirectives` entry. A component listing it gets the whole\n * of `TouchableBase` on its own host node - the responder negotiation, the press rectangle, the\n * delays and the long-press timer - instead of wrapping a `<pressable>` and paying for a second\n * native view.\n *\n * It provides `TouchableBase`, so a primitive on the same node can `inject(TouchableBase)` and\n * read `pressed` without caring whether it landed on this or on a real `<pressable>`.\n */\n@Directive({\n providers: [{ provide: TouchableBase, useExisting: forwardRef(() => PressBehavior) }],\n})\nexport class PressBehavior extends ControlBase {\n protected override accessibleByDefault(): boolean {\n return true;\n }\n\n protected override focusableByDefault(): boolean {\n return true;\n }\n\n protected override disabledForAccessibility(): boolean {\n return this.disabled();\n }\n}\n\n/**\n * A view that responds to presses. RN's `Pressable`, with the same configuration: hit slop,\n * retention offset, press-in and press-out delays, long press, and an Android ripple.\n *\n * `pressed` is a public signal, so a template can style from it through a template reference:\n * `<pressable #p [style.opacity]=\"p.pressed() ? 0.5 : 1\">`.\n */\n@Directive({\n selector: 'pressable',\n exportAs: 'pressable',\n providers: [{ provide: TouchableBase, useExisting: forwardRef(() => Pressable) }],\n})\nexport class Pressable extends ControlBase {\n /** `Pressable.js`: a control is an accessibility element, and focusable, unless refused. */\n protected override accessibleByDefault(): boolean {\n return true;\n }\n\n protected override focusableByDefault(): boolean {\n return true;\n }\n\n protected override disabledForAccessibility(): boolean {\n return this.disabled();\n }\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { type SharedValue as Mutable } from 'react-native-reanimated';
2
+ import { WorkletScrollBase } from './worklet-scroll.ts';
3
+ import { WorkletStyleBase } from './worklet-style.ts';
4
+ import * as i0 from "@angular/core";
5
+ export { workletScroll, workletStyle, type SharedValue, type WorkletScrollSpec, type WorkletStyleSpec, } from './worklets.ts';
6
+ /**
7
+ * A value both runtimes can see. Reanimated's own `useSharedValue` is this plus a React ref, and
8
+ * the ref is the half that does not apply here. Typed as Reanimated's own, so it goes to
9
+ * `cancelAnimation` and the rest of the library as one of theirs would.
10
+ */
11
+ export declare function sharedValue<T>(initial: T): Mutable<T>;
12
+ export declare class WorkletStyle extends WorkletStyleBase {
13
+ static ɵfac: i0.ɵɵFactoryDeclaration<WorkletStyle, never>;
14
+ static ɵdir: i0.ɵɵDirectiveDeclaration<WorkletStyle, "[workletStyle]", never, {}, {}, never, never, true, never>;
15
+ }
16
+ export declare class WorkletScroll extends WorkletScrollBase {
17
+ static ɵfac: i0.ɵɵFactoryDeclaration<WorkletScroll, never>;
18
+ static ɵdir: i0.ɵɵDirectiveDeclaration<WorkletScroll, "[workletScroll]", never, {}, {}, never, never, true, never>;
19
+ }