@vvedantb/native-ui 0.24.0 → 0.24.2

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.
@@ -0,0 +1,131 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { cssInterop } from "nativewind";
3
+ import { useCallback, useEffect } from "react";
4
+ import { Pressable } from "react-native";
5
+ import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
6
+ import { EASE_OUT } from "./motion";
7
+ import { useReduceMotion } from "./useReduceMotion";
8
+
9
+ /**
10
+ * A `Pressable` whose `style` can take the style from `usePressScale`.
11
+ * NativeWind maps `className` only for components it knows, so it is told
12
+ * about this one, or the classes would be dropped.
13
+ */
14
+ export const AnimatedPressable = Animated.createAnimatedComponent(Pressable);
15
+ cssInterop(AnimatedPressable, {
16
+ className: "style"
17
+ });
18
+ /**
19
+ * Press feedback for a small control: a scale and a light dim that ease in on
20
+ * press-in and ease back on release. Pass `onPressIn` and `onPressOut` to the
21
+ * `Pressable` and `style` to the animated view that should scale (an
22
+ * `AnimatedPressable`, or an `Animated.View` inside the `Pressable`). One
23
+ * shared value on the UI thread drives transform and opacity only. A new press
24
+ * or release starts from the current value, so a fast tap never sticks. With
25
+ * Reduce Motion nothing animates and nothing scales: the dim switches on and
26
+ * off at once.
27
+ */
28
+ export function usePressScale(t0) {
29
+ const $ = _c(18);
30
+ let t1;
31
+ if ($[0] !== t0) {
32
+ t1 = t0 === undefined ? {} : t0;
33
+ $[0] = t0;
34
+ $[1] = t1;
35
+ } else {
36
+ t1 = $[1];
37
+ }
38
+ const {
39
+ scale: t2,
40
+ dim: t3,
41
+ reducedDim: t4,
42
+ restOpacity: t5,
43
+ pressInMs: t6,
44
+ pressOutMs: t7,
45
+ disabled: t8
46
+ } = t1;
47
+ const scale = t2 === undefined ? 0.97 : t2;
48
+ const dim = t3 === undefined ? 0.7 : t3;
49
+ const reducedDim = t4 === undefined ? dim : t4;
50
+ const restOpacity = t5 === undefined ? 1 : t5;
51
+ const pressInMs = t6 === undefined ? 120 : t6;
52
+ const pressOutMs = t7 === undefined ? 160 : t7;
53
+ const disabled = t8 === undefined ? false : t8;
54
+ const reduceMotion = useReduceMotion();
55
+ const progress = useSharedValue(0);
56
+ const target = reduceMotion ? reducedDim : dim;
57
+ let t9;
58
+ if ($[2] !== pressInMs || $[3] !== progress || $[4] !== reduceMotion) {
59
+ t9 = () => {
60
+ progress.set(reduceMotion ? 1 : withTiming(1, {
61
+ duration: pressInMs,
62
+ easing: EASE_OUT
63
+ }));
64
+ };
65
+ $[2] = pressInMs;
66
+ $[3] = progress;
67
+ $[4] = reduceMotion;
68
+ $[5] = t9;
69
+ } else {
70
+ t9 = $[5];
71
+ }
72
+ const onPressIn = t9;
73
+ let t10;
74
+ if ($[6] !== pressOutMs || $[7] !== progress || $[8] !== reduceMotion) {
75
+ t10 = () => {
76
+ progress.set(reduceMotion ? 0 : withTiming(0, {
77
+ duration: pressOutMs,
78
+ easing: EASE_OUT
79
+ }));
80
+ };
81
+ $[6] = pressOutMs;
82
+ $[7] = progress;
83
+ $[8] = reduceMotion;
84
+ $[9] = t10;
85
+ } else {
86
+ t10 = $[9];
87
+ }
88
+ const onPressOut = t10;
89
+ let t11;
90
+ let t12;
91
+ if ($[10] !== disabled || $[11] !== progress) {
92
+ t11 = () => {
93
+ if (disabled) {
94
+ progress.set(0);
95
+ }
96
+ };
97
+ t12 = [disabled, progress];
98
+ $[10] = disabled;
99
+ $[11] = progress;
100
+ $[12] = t11;
101
+ $[13] = t12;
102
+ } else {
103
+ t11 = $[12];
104
+ t12 = $[13];
105
+ }
106
+ useEffect(t11, t12);
107
+ const style = useAnimatedStyle(() => {
108
+ const p = progress.get();
109
+ return {
110
+ opacity: restOpacity * (1 - p * (1 - target)),
111
+ transform: [{
112
+ scale: reduceMotion ? 1 : 1 - p * (1 - scale)
113
+ }]
114
+ };
115
+ });
116
+ let t13;
117
+ if ($[14] !== onPressIn || $[15] !== onPressOut || $[16] !== style) {
118
+ t13 = {
119
+ style,
120
+ onPressIn,
121
+ onPressOut
122
+ };
123
+ $[14] = onPressIn;
124
+ $[15] = onPressOut;
125
+ $[16] = style;
126
+ $[17] = t13;
127
+ } else {
128
+ t13 = $[17];
129
+ }
130
+ return t13;
131
+ }
@@ -1,11 +1,12 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
2
  import * as Slot from "@rn-primitives/slot";
3
3
  import { createContext, Fragment, useContext, useEffect, useState } from "react";
4
- import { Modal, Pressable, StyleSheet, View } from "react-native";
5
- import Animated from "react-native-reanimated";
4
+ import { Modal, Pressable, StyleSheet } from "react-native";
5
+ import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
6
6
  import { useSafeAreaInsets } from "react-native-safe-area-context";
7
7
  import { palette } from "../palette";
8
8
  import { KeyboardAvoidingView, KeyboardLiftContext } from "./keyboard-parts";
9
+ import { DIALOG_ENTER, DIALOG_EXIT, PANEL_SCALE_FROM } from "../motion";
9
10
  import { useReduceMotion } from "../useReduceMotion";
10
11
  import { useScheme } from "../useScheme";
11
12
  import { SheetDragProvider, SheetGestureContext, slideSheetIn, slideSheetOut, useSheetBackdropStyle, useSheetDragState } from "./sheet-drag";
@@ -152,7 +153,9 @@ export function OverlayClose(props) {
152
153
  * RN `Modal` with a tinted backdrop, safe-area padding and keyboard avoidance
153
154
  * (`KeyboardAvoidingView`: frame by frame with `KeyboardControllerProvider`).
154
155
  * `placement="center"` centres the child (dialogs) inside the insets on every
155
- * side, and the `Modal` fades in and out. `"bottom"` pins it to the bottom
156
+ * side: the backdrop fades while the panel scales from 0.96 and fades in (200
157
+ * ms on open, 150 ms on close), and the `Modal` stays up until it is out of
158
+ * sight. `"bottom"` pins it to the bottom
156
159
  * edge (sheets), which pad their own bottom inset: the sheet slides up on
157
160
  * open and back down on close, however it closes, and may be dragged down to
158
161
  * close (`SheetDragView`); the backdrop fades with the sheet's position. The
@@ -179,11 +182,12 @@ export function OverlayModal(t0) {
179
182
  } = useOverlay(part);
180
183
  const reduceMotion = useReduceMotion();
181
184
  const slides = placement === "bottom" && !reduceMotion;
185
+ const scales = placement === "center" && !reduceMotion;
182
186
  const [shown, setShown] = useState(open);
183
187
  if (open && !shown) {
184
188
  setShown(true);
185
189
  }
186
- if (!open && shown && !slides) {
190
+ if (!open && shown && !slides && !scales) {
187
191
  setShown(false);
188
192
  }
189
193
  let t1;
@@ -196,61 +200,61 @@ export function OverlayModal(t0) {
196
200
  }
197
201
  const close = t1;
198
202
  const ModalRoot = useContext(SheetGestureContext)?.ModalRoot ?? Fragment;
199
- const t2 = slides || reduceMotion ? "none" : "fade";
200
- let t3;
203
+ let t2;
201
204
  if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
202
- t3 = () => setShown(false);
203
- $[2] = t3;
205
+ t2 = () => setShown(false);
206
+ $[2] = t2;
204
207
  } else {
205
- t3 = $[2];
208
+ t2 = $[2];
206
209
  }
207
- let t4;
208
- if ($[3] !== children || $[4] !== close || $[5] !== dismissible || $[6] !== open || $[7] !== part || $[8] !== placement || $[9] !== slides) {
209
- t4 = <OverlayModalBody placement={placement} dismissible={dismissible} open={open} slides={slides} close={close} onHidden={t3} part={part}>{children}</OverlayModalBody>;
210
+ let t3;
211
+ if ($[3] !== children || $[4] !== close || $[5] !== dismissible || $[6] !== open || $[7] !== part || $[8] !== placement || $[9] !== scales || $[10] !== slides) {
212
+ t3 = <OverlayModalBody placement={placement} dismissible={dismissible} open={open} slides={slides} scales={scales} close={close} onHidden={t2} part={part}>{children}</OverlayModalBody>;
210
213
  $[3] = children;
211
214
  $[4] = close;
212
215
  $[5] = dismissible;
213
216
  $[6] = open;
214
217
  $[7] = part;
215
218
  $[8] = placement;
216
- $[9] = slides;
217
- $[10] = t4;
219
+ $[9] = scales;
220
+ $[10] = slides;
221
+ $[11] = t3;
218
222
  } else {
219
- t4 = $[10];
223
+ t3 = $[11];
220
224
  }
221
- let t5;
222
- if ($[11] !== ModalRoot || $[12] !== t4) {
223
- t5 = <ModalRoot>{t4}</ModalRoot>;
224
- $[11] = ModalRoot;
225
- $[12] = t4;
226
- $[13] = t5;
225
+ let t4;
226
+ if ($[12] !== ModalRoot || $[13] !== t3) {
227
+ t4 = <ModalRoot>{t3}</ModalRoot>;
228
+ $[12] = ModalRoot;
229
+ $[13] = t3;
230
+ $[14] = t4;
227
231
  } else {
228
- t5 = $[13];
232
+ t4 = $[14];
229
233
  }
230
- let t6;
231
- if ($[14] !== close || $[15] !== onShow || $[16] !== shown || $[17] !== t2 || $[18] !== t5) {
232
- t6 = <Modal visible={shown} transparent={true} animationType={t2} statusBarTranslucent={true} onRequestClose={close} onShow={onShow}>{t5}</Modal>;
233
- $[14] = close;
234
- $[15] = onShow;
235
- $[16] = shown;
236
- $[17] = t2;
237
- $[18] = t5;
238
- $[19] = t6;
234
+ let t5;
235
+ if ($[15] !== close || $[16] !== onShow || $[17] !== shown || $[18] !== t4) {
236
+ t5 = <Modal visible={shown} transparent={true} animationType="none" statusBarTranslucent={true} onRequestClose={close} onShow={onShow}>{t4}</Modal>;
237
+ $[15] = close;
238
+ $[16] = onShow;
239
+ $[17] = shown;
240
+ $[18] = t4;
241
+ $[19] = t5;
239
242
  } else {
240
- t6 = $[19];
243
+ t5 = $[19];
241
244
  }
242
- return t6;
245
+ return t5;
243
246
  }
244
247
 
245
248
  /** The `Modal`'s content: mounted with each opening, so a sheet starts below the screen (or at rest). */
246
249
  function OverlayModalBody(t0) {
247
- const $ = _c(37);
250
+ const $ = _c(48);
248
251
  const {
249
252
  part,
250
253
  placement,
251
254
  dismissible,
252
255
  open,
253
256
  slides,
257
+ scales,
254
258
  close,
255
259
  onHidden,
256
260
  children
@@ -258,7 +262,18 @@ function OverlayModalBody(t0) {
258
262
  const scheme = useScheme();
259
263
  const insets = useSafeAreaInsets();
260
264
  const drag = useSheetDragState(close, slides);
261
- const backdropStyle = useSheetBackdropStyle(drag);
265
+ const sheetBackdropStyle = useSheetBackdropStyle(drag);
266
+ const progress = useSharedValue(scales ? 0 : 1);
267
+ const centreBackdropStyle = useAnimatedStyle(() => ({
268
+ opacity: progress.get()
269
+ }));
270
+ const centrePanelStyle = useAnimatedStyle(() => ({
271
+ opacity: progress.get(),
272
+ transform: [{
273
+ scale: PANEL_SCALE_FROM + (1 - PANEL_SCALE_FROM) * progress.get()
274
+ }]
275
+ }));
276
+ const backdropStyle = placement === "center" ? centreBackdropStyle : sheetBackdropStyle;
262
277
  let t1;
263
278
  if ($[0] !== drag || $[1] !== onHidden || $[2] !== open || $[3] !== slides) {
264
279
  t1 = () => {
@@ -289,51 +304,87 @@ function OverlayModalBody(t0) {
289
304
  t2 = $[7];
290
305
  }
291
306
  useEffect(t1, t2);
292
- const t3 = palette.backdrop[scheme];
293
- let t4;
294
- if ($[8] !== t3) {
295
- t4 = {
296
- backgroundColor: t3
307
+ let t3;
308
+ if ($[8] !== onHidden || $[9] !== open || $[10] !== progress || $[11] !== scales) {
309
+ t3 = () => {
310
+ if (!scales) {
311
+ return;
312
+ }
313
+ if (open) {
314
+ progress.set(withTiming(1, DIALOG_ENTER));
315
+ } else {
316
+ progress.set(withTiming(0, DIALOG_EXIT, finished => {
317
+ "worklet";
318
+
319
+ if (finished) {
320
+ runOnJS(onHidden)();
321
+ }
322
+ }));
323
+ }
297
324
  };
298
- $[8] = t3;
299
- $[9] = t4;
325
+ $[8] = onHidden;
326
+ $[9] = open;
327
+ $[10] = progress;
328
+ $[11] = scales;
329
+ $[12] = t3;
300
330
  } else {
301
- t4 = $[9];
331
+ t3 = $[12];
302
332
  }
303
- let t5;
304
- if ($[10] !== backdropStyle || $[11] !== t4) {
305
- t5 = [StyleSheet.absoluteFill, t4, backdropStyle];
306
- $[10] = backdropStyle;
307
- $[11] = t4;
308
- $[12] = t5;
333
+ let t4;
334
+ if ($[13] !== open || $[14] !== scales) {
335
+ t4 = [open, scales];
336
+ $[13] = open;
337
+ $[14] = scales;
338
+ $[15] = t4;
309
339
  } else {
310
- t5 = $[12];
340
+ t4 = $[15];
311
341
  }
312
- const t6 = `${part}-backdrop`;
313
- const t7 = !dismissible;
314
- let t8;
315
- if ($[13] !== close || $[14] !== dismissible || $[15] !== t6 || $[16] !== t7) {
316
- t8 = <Pressable testID={t6} accessible={dismissible} accessibilityRole="button" accessibilityLabel="Close" disabled={t7} onPress={close} style={StyleSheet.absoluteFill} />;
317
- $[13] = close;
318
- $[14] = dismissible;
319
- $[15] = t6;
320
- $[16] = t7;
321
- $[17] = t8;
342
+ useEffect(t3, t4);
343
+ const t5 = palette.backdrop[scheme];
344
+ let t6;
345
+ if ($[16] !== t5) {
346
+ t6 = {
347
+ backgroundColor: t5
348
+ };
349
+ $[16] = t5;
350
+ $[17] = t6;
322
351
  } else {
323
- t8 = $[17];
352
+ t6 = $[17];
324
353
  }
325
- let t9;
326
- if ($[18] !== t5 || $[19] !== t8) {
327
- t9 = <Animated.View pointerEvents="box-none" style={t5}>{t8}</Animated.View>;
328
- $[18] = t5;
329
- $[19] = t8;
330
- $[20] = t9;
354
+ let t7;
355
+ if ($[18] !== backdropStyle || $[19] !== t6) {
356
+ t7 = [StyleSheet.absoluteFill, t6, backdropStyle];
357
+ $[18] = backdropStyle;
358
+ $[19] = t6;
359
+ $[20] = t7;
331
360
  } else {
332
- t9 = $[20];
361
+ t7 = $[20];
333
362
  }
363
+ const t8 = `${part}-backdrop`;
364
+ const t9 = !dismissible;
334
365
  let t10;
335
- if ($[21] !== insets.bottom || $[22] !== insets.left || $[23] !== insets.right || $[24] !== insets.top || $[25] !== placement) {
336
- t10 = [styles.fill, placement === "bottom" ? {
366
+ if ($[21] !== close || $[22] !== dismissible || $[23] !== t8 || $[24] !== t9) {
367
+ t10 = <Pressable testID={t8} accessible={dismissible} accessibilityRole="button" accessibilityLabel="Close" disabled={t9} onPress={close} style={StyleSheet.absoluteFill} />;
368
+ $[21] = close;
369
+ $[22] = dismissible;
370
+ $[23] = t8;
371
+ $[24] = t9;
372
+ $[25] = t10;
373
+ } else {
374
+ t10 = $[25];
375
+ }
376
+ let t11;
377
+ if ($[26] !== t10 || $[27] !== t7) {
378
+ t11 = <Animated.View pointerEvents="box-none" style={t7}>{t10}</Animated.View>;
379
+ $[26] = t10;
380
+ $[27] = t7;
381
+ $[28] = t11;
382
+ } else {
383
+ t11 = $[28];
384
+ }
385
+ let t12;
386
+ if ($[29] !== insets.bottom || $[30] !== insets.left || $[31] !== insets.right || $[32] !== insets.top || $[33] !== placement) {
387
+ t12 = placement === "bottom" ? {
337
388
  justifyContent: "flex-end",
338
389
  paddingTop: insets.top + 16,
339
390
  paddingLeft: insets.left,
@@ -344,45 +395,55 @@ function OverlayModalBody(t0) {
344
395
  paddingBottom: insets.bottom + 16,
345
396
  paddingLeft: insets.left + 16,
346
397
  paddingRight: insets.right + 16
347
- }];
348
- $[21] = insets.bottom;
349
- $[22] = insets.left;
350
- $[23] = insets.right;
351
- $[24] = insets.top;
352
- $[25] = placement;
353
- $[26] = t10;
398
+ };
399
+ $[29] = insets.bottom;
400
+ $[30] = insets.left;
401
+ $[31] = insets.right;
402
+ $[32] = insets.top;
403
+ $[33] = placement;
404
+ $[34] = t12;
354
405
  } else {
355
- t10 = $[26];
406
+ t12 = $[34];
356
407
  }
357
- let t11;
358
- if ($[27] !== children || $[28] !== close || $[29] !== t10) {
359
- t11 = <View pointerEvents="box-none" onAccessibilityEscape={close} style={t10}>{children}</View>;
360
- $[27] = children;
361
- $[28] = close;
362
- $[29] = t10;
363
- $[30] = t11;
408
+ const t13 = placement === "center" ? centrePanelStyle : null;
409
+ let t14;
410
+ if ($[35] !== t12 || $[36] !== t13) {
411
+ t14 = [styles.fill, t12, t13];
412
+ $[35] = t12;
413
+ $[36] = t13;
414
+ $[37] = t14;
364
415
  } else {
365
- t11 = $[30];
416
+ t14 = $[37];
366
417
  }
367
- let t12;
368
- if ($[31] !== t11 || $[32] !== t9) {
369
- t12 = <KeyboardAvoidingView style={styles.fill}><KeyboardLiftContext.Provider value={false}>{t9}{t11}</KeyboardLiftContext.Provider></KeyboardAvoidingView>;
370
- $[31] = t11;
371
- $[32] = t9;
372
- $[33] = t12;
418
+ let t15;
419
+ if ($[38] !== children || $[39] !== close || $[40] !== t14) {
420
+ t15 = <Animated.View pointerEvents="box-none" onAccessibilityEscape={close} style={t14}>{children}</Animated.View>;
421
+ $[38] = children;
422
+ $[39] = close;
423
+ $[40] = t14;
424
+ $[41] = t15;
373
425
  } else {
374
- t12 = $[33];
426
+ t15 = $[41];
375
427
  }
376
- let t13;
377
- if ($[34] !== drag || $[35] !== t12) {
378
- t13 = <SheetDragProvider value={drag}>{t12}</SheetDragProvider>;
379
- $[34] = drag;
380
- $[35] = t12;
381
- $[36] = t13;
428
+ let t16;
429
+ if ($[42] !== t11 || $[43] !== t15) {
430
+ t16 = <KeyboardAvoidingView style={styles.fill}><KeyboardLiftContext.Provider value={false}>{t11}{t15}</KeyboardLiftContext.Provider></KeyboardAvoidingView>;
431
+ $[42] = t11;
432
+ $[43] = t15;
433
+ $[44] = t16;
434
+ } else {
435
+ t16 = $[44];
436
+ }
437
+ let t17;
438
+ if ($[45] !== drag || $[46] !== t16) {
439
+ t17 = <SheetDragProvider value={drag}>{t16}</SheetDragProvider>;
440
+ $[45] = drag;
441
+ $[46] = t16;
442
+ $[47] = t17;
382
443
  } else {
383
- t13 = $[36];
444
+ t17 = $[47];
384
445
  }
385
- return t13;
446
+ return t17;
386
447
  }
387
448
  const styles = StyleSheet.create({
388
449
  fill: {
@@ -6,6 +6,7 @@ import { IconCheck, IconChevronDown, IconChevronUp } from "@tabler/icons-react-n
6
6
  import * as React from "react";
7
7
  import { Platform, ScrollView, StyleSheet, Text, View } from "react-native";
8
8
  import { FadeIn, FadeOut } from "react-native-reanimated";
9
+ import { EASE_OUT } from "../motion";
9
10
  import { NativeOnlyAnimatedView } from "./native-only-animated-view";
10
11
  import { SelectHost } from "./select-host";
11
12
  import { TextClassContext } from "./text";
@@ -155,6 +156,9 @@ const SelectTrigger = React.forwardRef((t0, ref) => {
155
156
  }
156
157
  return t8;
157
158
  });
159
+ /** The popover fades in and out on the strong ease-out. */
160
+ const SELECT_ENTER = FadeIn.duration(150).easing(EASE_OUT);
161
+ const SELECT_EXIT = FadeOut.duration(100).easing(EASE_OUT);
158
162
  const SelectContent = React.forwardRef((t0, ref) => {
159
163
  const $ = _c(31);
160
164
  let children;
@@ -252,7 +256,7 @@ const SelectContent = React.forwardRef((t0, ref) => {
252
256
  }
253
257
  let t11;
254
258
  if ($[18] !== position || $[19] !== props || $[20] !== ref || $[21] !== t4 || $[22] !== t9) {
255
- t11 = <SelectPrimitive.Overlay style={overlayFill}><TextClassContext.Provider value="text-popover-foreground"><NativeOnlyAnimatedView entering={FadeIn} exiting={FadeOut} className="z-50" style={overlayFill} pointerEvents={t3}><SelectPrimitive.Content ref={ref} position={position} className={t4} {...props}>{t5}{t6}{t9}{t10}</SelectPrimitive.Content></NativeOnlyAnimatedView></TextClassContext.Provider></SelectPrimitive.Overlay>;
259
+ t11 = <SelectPrimitive.Overlay style={overlayFill}><TextClassContext.Provider value="text-popover-foreground"><NativeOnlyAnimatedView entering={SELECT_ENTER} exiting={SELECT_EXIT} className="z-50" style={overlayFill} pointerEvents={t3}><SelectPrimitive.Content ref={ref} position={position} className={t4} {...props}>{t5}{t6}{t9}{t10}</SelectPrimitive.Content></NativeOnlyAnimatedView></TextClassContext.Provider></SelectPrimitive.Overlay>;
256
260
  $[18] = position;
257
261
  $[19] = props;
258
262
  $[20] = ref;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/native-ui",
3
- "version": "0.24.0",
3
+ "version": "0.24.2",
4
4
  "license": "MIT",
5
5
  "description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar, AI chat parts, the family app marks, a NativeWind preset, the Expo web root and Clerk + Convex auth screens.",
6
6
  "type": "module",
@@ -1,5 +1,7 @@
1
- import { Pressable, View } from "react-native";
1
+ import { Pressable } from "react-native";
2
+ import Animated from "react-native-reanimated";
2
3
  import { cn } from "./cn";
4
+ import { usePressScale } from "./pressScale";
3
5
  import { withAlpha } from "./palette";
4
6
  import { tokens } from "./tokens";
5
7
 
@@ -16,7 +18,8 @@ export const CAPTURE_BUTTON = { size: 76, ring: 4, gap: 4 } as const;
16
18
 
17
19
  /**
18
20
  * A camera shutter: a 76 white ring around a white disc, for a live preview in
19
- * light and dark alike. The disc shrinks to 90% while pressed. Larger than the
21
+ * light and dark alike. The disc eases down to 90% in 100 ms while pressed
22
+ * and back in 160 ms; with Reduce Motion it dims instead. Larger than the
20
23
  * 44 target, so it needs no hit slop. A labelled button, dimmed and ignoring
21
24
  * presses when `disabled`.
22
25
  */
@@ -28,6 +31,7 @@ export function CaptureButton({
28
31
  }: CaptureButtonProps) {
29
32
  const { size, ring, gap } = CAPTURE_BUTTON;
30
33
  const inner = size - 2 * (ring + gap);
34
+ const press = usePressScale({ scale: 0.9, dim: 1, reducedDim: 0.7, pressInMs: 100, disabled });
31
35
  return (
32
36
  <Pressable
33
37
  testID={testID}
@@ -36,6 +40,8 @@ export function CaptureButton({
36
40
  accessibilityState={{ disabled }}
37
41
  disabled={disabled}
38
42
  onPress={onPress}
43
+ onPressIn={press.onPressIn}
44
+ onPressOut={press.onPressOut}
39
45
  className={cn("items-center justify-center", disabled && "opacity-50")}
40
46
  style={{
41
47
  width: size,
@@ -46,17 +52,17 @@ export function CaptureButton({
46
52
  backgroundColor: withAlpha(tokens.color.black, 0.15),
47
53
  }}
48
54
  >
49
- {({ pressed }) => (
50
- <View
51
- style={{
55
+ <Animated.View
56
+ style={[
57
+ {
52
58
  width: inner,
53
59
  height: inner,
54
60
  borderRadius: inner / 2,
55
61
  backgroundColor: tokens.color.white,
56
- transform: [{ scale: pressed && !disabled ? 0.9 : 1 }],
57
- }}
58
- />
59
- )}
62
+ },
63
+ press.style,
64
+ ]}
65
+ />
60
66
  </Pressable>
61
67
  );
62
68
  }
package/src/Chip.tsx CHANGED
@@ -1,4 +1,5 @@
1
- import { Pressable, Text } from "react-native";
1
+ import { Text } from "react-native";
2
+ import { AnimatedPressable, usePressScale } from "./pressScale";
2
3
  import { textStyle, typeStyle } from "./controlStyles";
3
4
  import { useLargerText } from "./theme";
4
5
  import { useScheme } from "./useScheme";
@@ -18,6 +19,7 @@ export function Chip({
18
19
  }) {
19
20
  const largerText = useLargerText();
20
21
  const scheme = useScheme();
22
+ const press = usePressScale();
21
23
  const size = round
22
24
  ? largerText
23
25
  ? "h-14 w-14"
@@ -26,13 +28,16 @@ export function Chip({
26
28
  ? "min-h-14 px-5 py-3"
27
29
  : "min-h-12 px-4 py-2";
28
30
  return (
29
- <Pressable
31
+ <AnimatedPressable
30
32
  testID={testID}
31
33
  accessibilityRole="button"
32
34
  accessibilityLabel={label}
33
35
  accessibilityState={{ selected }}
34
36
  onPress={onPress}
35
- className={`items-center justify-center rounded-full border border-white/40 active:opacity-70 dark:border-white/10 ${
37
+ onPressIn={press.onPressIn}
38
+ onPressOut={press.onPressOut}
39
+ style={press.style}
40
+ className={`items-center justify-center rounded-full border border-white/40 dark:border-white/10 ${
36
41
  size
37
42
  } ${selected ? "bg-pink-100 dark:bg-pink-900/40" : "bg-secondary"}`}
38
43
  >
@@ -46,6 +51,6 @@ export function Chip({
46
51
  >
47
52
  {label}
48
53
  </Text>
49
- </Pressable>
54
+ </AnimatedPressable>
50
55
  );
51
56
  }