@vvedantb/native-ui 0.24.0 → 0.24.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.
@@ -1,8 +1,9 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
- import { Pressable, Text, View } from "react-native";
2
+ import { Text, View } from "react-native";
3
3
  import { IconFile } from "@tabler/icons-react-native";
4
4
  import { cn } from "../cn";
5
5
  import { MIN_TOUCH_TARGET, sizeStyle, textStyle, touchSlop } from "../controlStyles";
6
+ import { AnimatedPressable, usePressScale } from "../pressScale";
6
7
  import { palette } from "../palette";
7
8
  import { useLargerText } from "../theme";
8
9
  import { tokens } from "../tokens";
@@ -142,7 +143,7 @@ function FileChipLabel(t0) {
142
143
  * otherwise. Long names are cut in the middle, so the extension shows.
143
144
  */
144
145
  export function FileChip(t0) {
145
- const $ = _c(13);
146
+ const $ = _c(6);
146
147
  const {
147
148
  name,
148
149
  path,
@@ -160,39 +161,62 @@ export function FileChip(t0) {
160
161
  return t1;
161
162
  }
162
163
  let t1;
163
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
164
+ if ($[2] !== name || $[3] !== onOpenFile || $[4] !== path) {
165
+ t1 = <FileChipButton name={name} path={path} onOpenFile={onOpenFile} />;
166
+ $[2] = name;
167
+ $[3] = onOpenFile;
168
+ $[4] = path;
169
+ $[5] = t1;
170
+ } else {
171
+ t1 = $[5];
172
+ }
173
+ return t1;
174
+ }
175
+ function FileChipButton(t0) {
176
+ const $ = _c(14);
177
+ const {
178
+ name,
179
+ path,
180
+ onOpenFile
181
+ } = t0;
182
+ const press = usePressScale();
183
+ let t1;
184
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
164
185
  t1 = touchSlop(MIN_TOUCH_TARGET, CHIP_HEIGHT);
165
- $[2] = t1;
186
+ $[0] = t1;
166
187
  } else {
167
- t1 = $[2];
188
+ t1 = $[0];
168
189
  }
169
190
  let t2;
170
- if ($[3] !== onOpenFile || $[4] !== path) {
191
+ if ($[1] !== onOpenFile || $[2] !== path) {
171
192
  t2 = () => onOpenFile(path);
172
- $[3] = onOpenFile;
173
- $[4] = path;
174
- $[5] = t2;
193
+ $[1] = onOpenFile;
194
+ $[2] = path;
195
+ $[3] = t2;
175
196
  } else {
176
- t2 = $[5];
197
+ t2 = $[3];
177
198
  }
178
199
  let t3;
179
- if ($[6] !== name) {
200
+ if ($[4] !== name) {
180
201
  t3 = <FileChipLabel name={name} />;
181
- $[6] = name;
182
- $[7] = t3;
202
+ $[4] = name;
203
+ $[5] = t3;
183
204
  } else {
184
- t3 = $[7];
205
+ t3 = $[5];
185
206
  }
186
207
  let t4;
187
- if ($[8] !== name || $[9] !== path || $[10] !== t2 || $[11] !== t3) {
188
- t4 = <Pressable accessibilityRole="button" accessibilityLabel={name} accessibilityHint={path} hitSlop={t1} onPress={t2} className="min-w-0 max-w-full active:opacity-70">{t3}</Pressable>;
189
- $[8] = name;
190
- $[9] = path;
191
- $[10] = t2;
192
- $[11] = t3;
193
- $[12] = t4;
208
+ if ($[6] !== name || $[7] !== path || $[8] !== press.onPressIn || $[9] !== press.onPressOut || $[10] !== press.style || $[11] !== t2 || $[12] !== t3) {
209
+ t4 = <AnimatedPressable accessibilityRole="button" accessibilityLabel={name} accessibilityHint={path} hitSlop={t1} onPress={t2} onPressIn={press.onPressIn} onPressOut={press.onPressOut} style={press.style} className="min-w-0 max-w-full">{t3}</AnimatedPressable>;
210
+ $[6] = name;
211
+ $[7] = path;
212
+ $[8] = press.onPressIn;
213
+ $[9] = press.onPressOut;
214
+ $[10] = press.style;
215
+ $[11] = t2;
216
+ $[12] = t3;
217
+ $[13] = t4;
194
218
  } else {
195
- t4 = $[12];
219
+ t4 = $[13];
196
220
  }
197
221
  return t4;
198
222
  }
@@ -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
+ }
@@ -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.1",
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
  }
@@ -1,8 +1,9 @@
1
- import { Pressable, View } from "react-native";
1
+ import { View } from "react-native";
2
2
  import { IconCheck } from "@tabler/icons-react-native";
3
3
  import { cn } from "./cn";
4
4
  import { touchSlop } from "./controlStyles";
5
5
  import { selectionHaptic } from "./haptics";
6
+ import { AnimatedPressable, usePressScale } from "./pressScale";
6
7
  import { withAlpha } from "./palette";
7
8
  import { useLargerText } from "./theme";
8
9
  import { tokens } from "./tokens";
@@ -91,43 +92,87 @@ export function ColorSwatches({
91
92
  const isSelected = color.toLowerCase() === selected;
92
93
  const check = isSelected ? swatchCheckColor(color) : null;
93
94
  return (
94
- <Pressable
95
+ <Swatch
95
96
  key={`${color}-${index}`}
96
97
  testID={testID ? `${testID}-${index}` : undefined}
97
- accessibilityRole="radio"
98
- accessibilityLabel={labels?.[index] ?? color}
99
- accessibilityState={{ checked: isSelected, disabled }}
100
- hitSlop={touchSlop(outer)}
98
+ label={labels?.[index] ?? color}
99
+ color={color}
100
+ selected={isSelected}
101
+ check={check}
101
102
  disabled={disabled}
103
+ diameter={diameter}
104
+ outer={outer}
102
105
  onPress={() => {
103
106
  selectionHaptic();
104
107
  onChange(color);
105
108
  }}
106
- className="items-center justify-center active:opacity-70"
107
- style={{
108
- width: outer,
109
- height: outer,
110
- borderRadius: outer / 2,
111
- borderWidth: RING,
112
- borderColor: isSelected ? tokens.color.foreground[scheme] : "transparent",
113
- }}
114
- >
115
- <View
116
- className="items-center justify-center"
117
- style={{
118
- width: diameter,
119
- height: diameter,
120
- borderRadius: diameter / 2,
121
- backgroundColor: color,
122
- borderWidth: 1,
123
- borderColor: withAlpha(tokens.color.foreground[scheme], 0.12),
124
- }}
125
- >
126
- {check ? <IconCheck size={Math.round(diameter / 2)} color={check} strokeWidth={2} /> : null}
127
- </View>
128
- </Pressable>
109
+ />
129
110
  );
130
111
  })}
131
112
  </View>
132
113
  );
133
114
  }
115
+
116
+ /** One swatch: a radio that scales a little on press. The slop does not scale. */
117
+ function Swatch({
118
+ testID,
119
+ label,
120
+ color,
121
+ selected,
122
+ check,
123
+ disabled,
124
+ diameter,
125
+ outer,
126
+ onPress,
127
+ }: {
128
+ testID?: string;
129
+ label: string;
130
+ color: string;
131
+ selected: boolean;
132
+ check: string | null;
133
+ disabled: boolean;
134
+ diameter: number;
135
+ outer: number;
136
+ onPress: () => void;
137
+ }) {
138
+ const scheme = useScheme();
139
+ const press = usePressScale({ disabled });
140
+ return (
141
+ <AnimatedPressable
142
+ testID={testID}
143
+ accessibilityRole="radio"
144
+ accessibilityLabel={label}
145
+ accessibilityState={{ checked: selected, disabled }}
146
+ hitSlop={touchSlop(outer)}
147
+ disabled={disabled}
148
+ onPress={onPress}
149
+ onPressIn={press.onPressIn}
150
+ onPressOut={press.onPressOut}
151
+ className="items-center justify-center"
152
+ style={[
153
+ {
154
+ width: outer,
155
+ height: outer,
156
+ borderRadius: outer / 2,
157
+ borderWidth: RING,
158
+ borderColor: selected ? tokens.color.foreground[scheme] : "transparent",
159
+ },
160
+ press.style,
161
+ ]}
162
+ >
163
+ <View
164
+ className="items-center justify-center"
165
+ style={{
166
+ width: diameter,
167
+ height: diameter,
168
+ borderRadius: diameter / 2,
169
+ backgroundColor: color,
170
+ borderWidth: 1,
171
+ borderColor: withAlpha(tokens.color.foreground[scheme], 0.12),
172
+ }}
173
+ >
174
+ {check ? <IconCheck size={Math.round(diameter / 2)} color={check} strokeWidth={2} /> : null}
175
+ </View>
176
+ </AnimatedPressable>
177
+ );
178
+ }
package/src/Dialog.tsx CHANGED
@@ -10,6 +10,7 @@ import { useSafeAreaInsets } from "react-native-safe-area-context";
10
10
  import { IconX } from "@tabler/icons-react-native";
11
11
  import { FloatingSurface } from "./FloatingSurface";
12
12
  import { cn } from "./cn";
13
+ import { AnimatedPressable, usePressScale } from "./pressScale";
13
14
  import { isCompactOverlay, textStyle, typeStyle } from "./controlStyles";
14
15
  import { DialogLayoutContext, useDialogLayout, type DialogLayout } from "./dialogLayout";
15
16
  import { palette } from "./palette";
@@ -162,14 +163,22 @@ function DialogHandle() {
162
163
  function DialogCloseButton() {
163
164
  const largerText = useLargerText();
164
165
  const scheme = useScheme();
166
+ const press = usePressScale();
167
+ // `asChild`: the close press goes into this animated `Pressable`, so the
168
+ // button scales while `overlay.tsx` stays as it is.
165
169
  return (
166
- <DialogClose
167
- testID="dialog-close"
168
- accessibilityLabel="Close"
169
- hitSlop={8}
170
- className="absolute right-2 top-2 h-11 w-11 items-center justify-center rounded-lg active:opacity-70"
171
- >
172
- <IconX size={largerText ? 26 : 16} color={tokens.color.muted[scheme]} />
170
+ <DialogClose asChild>
171
+ <AnimatedPressable
172
+ testID="dialog-close"
173
+ accessibilityLabel="Close"
174
+ hitSlop={8}
175
+ onPressIn={press.onPressIn}
176
+ onPressOut={press.onPressOut}
177
+ style={press.style}
178
+ className="absolute right-2 top-2 h-11 w-11 items-center justify-center rounded-lg"
179
+ >
180
+ <IconX size={largerText ? 26 : 16} color={tokens.color.muted[scheme]} />
181
+ </AnimatedPressable>
173
182
  </DialogClose>
174
183
  );
175
184
  }
@@ -1,8 +1,9 @@
1
1
  import type { ReactNode } from "react";
2
- import { Platform, Pressable, View } from "react-native";
2
+ import { Platform, View } from "react-native";
3
3
  import { cn } from "./cn";
4
4
  import { useSafeAreaInsets } from "react-native-safe-area-context";
5
5
  import { FloatingSurface } from "./FloatingSurface";
6
+ import { AnimatedPressable, usePressScale } from "./pressScale";
6
7
  import { useAccentColor, useLargerText } from "./theme";
7
8
  import {
8
9
  FLOATING_INSET,
@@ -24,6 +25,7 @@ export function FloatingFAB({
24
25
  const insets = useSafeAreaInsets();
25
26
  const largerText = useLargerText();
26
27
  const accentColor = useAccentColor();
28
+ const press = usePressScale({ scale: 0.95 });
27
29
  const size = largerText ? 64 : 56;
28
30
  const tabBar = largerText
29
31
  ? FLOATING_TAB_BAR_HEIGHT_LARGE
@@ -39,24 +41,29 @@ export function FloatingFAB({
39
41
  }}
40
42
  >
41
43
  <FloatingSurface radius={size / 2} blur={false}>
42
- <Pressable
44
+ <AnimatedPressable
43
45
  testID={testID}
44
46
  accessibilityRole="button"
45
47
  accessibilityLabel={label}
46
48
  onPress={onPress}
47
- // Layout in the function style and no `className`: NativeWind drops a
48
- // function `style` next to a `className`.
49
- style={({ pressed }) => ({
50
- alignItems: "center",
51
- justifyContent: "center",
52
- width: size,
53
- height: size,
54
- backgroundColor: accentColor,
55
- opacity: pressed ? 0.7 : 1,
56
- })}
49
+ onPressIn={press.onPressIn}
50
+ onPressOut={press.onPressOut}
51
+ // Layout in `style` and no `className`: NativeWind drops a function
52
+ // `style` next to a `className`, and the press scale and dim come
53
+ // from the animated style, not a function style.
54
+ style={[
55
+ {
56
+ alignItems: "center",
57
+ justifyContent: "center",
58
+ width: size,
59
+ height: size,
60
+ backgroundColor: accentColor,
61
+ },
62
+ press.style,
63
+ ]}
57
64
  >
58
65
  {children}
59
- </Pressable>
66
+ </AnimatedPressable>
60
67
  </FloatingSurface>
61
68
  </View>
62
69
  );
@@ -1,8 +1,7 @@
1
1
  import type { ComponentType } from "react";
2
- import { Pressable } from "react-native";
3
2
  import type { IconProps } from "@tabler/icons-react-native";
4
- import { cn } from "./cn";
5
3
  import { touchSlop } from "./controlStyles";
4
+ import { AnimatedPressable, usePressScale } from "./pressScale";
6
5
  import { withAlpha } from "./palette";
7
6
  import { useLargerText } from "./theme";
8
7
  import { tokens } from "./tokens";
@@ -69,8 +68,9 @@ export function IconButton({
69
68
  const largerText = useLargerText();
70
69
  const [diameter, iconSize] = METRICS[largerText ? "larger" : "regular"][size];
71
70
  const { color, ...frame } = iconButtonColors(variant, scheme);
71
+ const press = usePressScale({ restOpacity: disabled ? 0.5 : 1, disabled });
72
72
  return (
73
- <Pressable
73
+ <AnimatedPressable
74
74
  testID={testID}
75
75
  accessibilityRole="button"
76
76
  accessibilityLabel={label}
@@ -78,10 +78,12 @@ export function IconButton({
78
78
  hitSlop={touchSlop(diameter)}
79
79
  disabled={disabled}
80
80
  onPress={onPress}
81
- className={cn("items-center justify-center active:opacity-70", disabled && "opacity-50")}
82
- style={{ width: diameter, height: diameter, borderRadius: diameter / 2, borderWidth: 1, ...frame }}
81
+ onPressIn={press.onPressIn}
82
+ onPressOut={press.onPressOut}
83
+ className="items-center justify-center"
84
+ style={[{ width: diameter, height: diameter, borderRadius: diameter / 2, borderWidth: 1, ...frame }, press.style]}
83
85
  >
84
86
  <Icon size={iconSize} color={iconColor ?? color} />
85
- </Pressable>
87
+ </AnimatedPressable>
86
88
  );
87
89
  }
@@ -1,7 +1,8 @@
1
1
  import { Children, type ReactNode } from "react";
2
- import { Pressable, Text, View, type ViewProps } from "react-native";
2
+ import { Text, View, type ViewProps } from "react-native";
3
3
  import { cn } from "./cn";
4
4
  import { cardStyle, textStyle, typeStyle } from "./controlStyles";
5
+ import { AnimatedPressable, usePressScale } from "./pressScale";
5
6
  import { StatusDot } from "./StatusDot";
6
7
  import { Spinner } from "./Spinner";
7
8
  import { useLargerText } from "./theme";
@@ -31,16 +32,19 @@ export type PinnedBotTileProps = {
31
32
  export function PinnedBotTile({ title, leading, unread = false, generating = false, onPress, onLongPress, testID }: PinnedBotTileProps) {
32
33
  const scheme = useScheme();
33
34
  const largerText = useLargerText();
35
+ const press = usePressScale();
34
36
  const state = [unread ? "unread" : null, generating ? "generating" : null].filter(Boolean).join(", ");
35
37
  return (
36
- <Pressable
38
+ <AnimatedPressable
37
39
  testID={testID}
38
40
  accessibilityRole="button"
39
41
  accessibilityLabel={state ? `${title}, ${state}` : title}
40
42
  onPress={onPress}
41
43
  onLongPress={onLongPress}
42
- className={cn("min-w-0 items-center justify-center gap-2 px-3 py-4 active:opacity-70", largerText ? "min-h-36" : "min-h-28")}
43
- style={cardStyle(scheme)}
44
+ onPressIn={press.onPressIn}
45
+ onPressOut={press.onPressOut}
46
+ className={cn("min-w-0 items-center justify-center gap-2 px-3 py-4", largerText ? "min-h-36" : "min-h-28")}
47
+ style={[cardStyle(scheme), press.style]}
44
48
  >
45
49
  {leading}
46
50
  <Text
@@ -60,7 +64,7 @@ export function PinnedBotTile({ title, leading, unread = false, generating = fal
60
64
  <Spinner size="sm" decorative />
61
65
  </View>
62
66
  ) : null}
63
- </Pressable>
67
+ </AnimatedPressable>
64
68
  );
65
69
  }
66
70