@vvedantb/native-ui 0.25.2 → 0.25.3

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.
@@ -11,6 +11,7 @@ import { useLargerText } from "./theme";
11
11
  import { useReduceMotion } from "./useReduceMotion";
12
12
  import { useScheme } from "./useScheme";
13
13
  import { FLOATING_PILL_RADIUS, tabBarHeight, tabBarSlotStyle } from "./floating";
14
+ import { usePressed } from "./usePressed";
14
15
 
15
16
  /**
16
17
  * Space between the bar edge and the tabs, on every side of the active pill,
@@ -192,7 +193,7 @@ export function FloatingTabBar(t0) {
192
193
  * the caller's function.
193
194
  */
194
195
  function TabBarItem(t0) {
195
- const $ = _c(29);
196
+ const $ = _c(34);
196
197
  const {
197
198
  route,
198
199
  navigation,
@@ -204,6 +205,7 @@ function TabBarItem(t0) {
204
205
  testID,
205
206
  accessibilityLabel
206
207
  } = t0;
208
+ const press = usePressed();
207
209
  let t1;
208
210
  if ($[0] !== focused || $[1] !== navigation || $[2] !== route.key || $[3] !== route.name || $[4] !== route.params) {
209
211
  t1 = () => {
@@ -237,71 +239,87 @@ function TabBarItem(t0) {
237
239
  } else {
238
240
  t2 = $[7];
239
241
  }
240
- let t3;
241
- if ($[8] !== color || $[9] !== focused || $[10] !== largerText || $[11] !== renderIcon) {
242
- t3 = renderIcon ? renderIcon({
242
+ const t3 = press.onPressIn;
243
+ const t4 = press.onPressOut;
244
+ const t5 = press.pressed ? 0.7 : 1;
245
+ let t6;
246
+ if ($[8] !== t5) {
247
+ t6 = {
248
+ opacity: t5
249
+ };
250
+ $[8] = t5;
251
+ $[9] = t6;
252
+ } else {
253
+ t6 = $[9];
254
+ }
255
+ let t7;
256
+ if ($[10] !== color || $[11] !== focused || $[12] !== largerText || $[13] !== renderIcon) {
257
+ t7 = renderIcon ? renderIcon({
243
258
  focused,
244
259
  color,
245
260
  size: largerText ? 28 : 24
246
261
  }) : null;
247
- $[8] = color;
248
- $[9] = focused;
249
- $[10] = largerText;
250
- $[11] = renderIcon;
251
- $[12] = t3;
262
+ $[10] = color;
263
+ $[11] = focused;
264
+ $[12] = largerText;
265
+ $[13] = renderIcon;
266
+ $[14] = t7;
252
267
  } else {
253
- t3 = $[12];
268
+ t7 = $[14];
254
269
  }
255
- const t4 = `font-instrument-sans-semibold ${largerText ? "text-base" : "text-sm"}`;
256
- let t5;
257
- if ($[13] !== color) {
258
- t5 = {
270
+ const t8 = `font-instrument-sans-semibold ${largerText ? "text-base" : "text-sm"}`;
271
+ let t9;
272
+ if ($[15] !== color) {
273
+ t9 = {
259
274
  color
260
275
  };
261
- $[13] = color;
262
- $[14] = t5;
276
+ $[15] = color;
277
+ $[16] = t9;
263
278
  } else {
264
- t5 = $[14];
279
+ t9 = $[16];
265
280
  }
266
- let t6;
267
- if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
268
- t6 = typeStyle("semibold");
269
- $[15] = t6;
281
+ let t10;
282
+ if ($[17] === Symbol.for("react.memo_cache_sentinel")) {
283
+ t10 = typeStyle("semibold");
284
+ $[17] = t10;
270
285
  } else {
271
- t6 = $[15];
286
+ t10 = $[17];
272
287
  }
273
- let t7;
274
- if ($[16] !== t5) {
275
- t7 = [t5, t6];
276
- $[16] = t5;
277
- $[17] = t7;
288
+ let t11;
289
+ if ($[18] !== t9) {
290
+ t11 = [t9, t10];
291
+ $[18] = t9;
292
+ $[19] = t11;
278
293
  } else {
279
- t7 = $[17];
294
+ t11 = $[19];
280
295
  }
281
- let t8;
282
- if ($[18] !== label || $[19] !== t4 || $[20] !== t7) {
283
- t8 = <Text numberOfLines={1} maxFontSizeMultiplier={1.5} className={t4} style={t7}>{label}</Text>;
284
- $[18] = label;
285
- $[19] = t4;
286
- $[20] = t7;
287
- $[21] = t8;
296
+ let t12;
297
+ if ($[20] !== label || $[21] !== t11 || $[22] !== t8) {
298
+ t12 = <Text numberOfLines={1} maxFontSizeMultiplier={1.5} className={t8} style={t11}>{label}</Text>;
299
+ $[20] = label;
300
+ $[21] = t11;
301
+ $[22] = t8;
302
+ $[23] = t12;
288
303
  } else {
289
- t8 = $[21];
304
+ t12 = $[23];
290
305
  }
291
- let t9;
292
- if ($[22] !== accessibilityLabel || $[23] !== onPress || $[24] !== t2 || $[25] !== t3 || $[26] !== t8 || $[27] !== testID) {
293
- t9 = <Pressable testID={testID} accessibilityRole="tab" accessibilityState={t2} accessibilityLabel={accessibilityLabel} onPress={onPress} className="min-h-12 min-w-12 flex-1 items-center justify-center gap-1" style={_temp}>{t3}{t8}</Pressable>;
294
- $[22] = accessibilityLabel;
295
- $[23] = onPress;
296
- $[24] = t2;
297
- $[25] = t3;
298
- $[26] = t8;
299
- $[27] = testID;
300
- $[28] = t9;
306
+ let t13;
307
+ if ($[24] !== accessibilityLabel || $[25] !== onPress || $[26] !== press.onPressIn || $[27] !== press.onPressOut || $[28] !== t12 || $[29] !== t2 || $[30] !== t6 || $[31] !== t7 || $[32] !== testID) {
308
+ t13 = <Pressable testID={testID} accessibilityRole="tab" accessibilityState={t2} accessibilityLabel={accessibilityLabel} onPress={onPress} onPressIn={t3} onPressOut={t4} className="min-h-12 min-w-12 flex-1 items-center justify-center gap-1" style={t6}>{t7}{t12}</Pressable>;
309
+ $[24] = accessibilityLabel;
310
+ $[25] = onPress;
311
+ $[26] = press.onPressIn;
312
+ $[27] = press.onPressOut;
313
+ $[28] = t12;
314
+ $[29] = t2;
315
+ $[30] = t6;
316
+ $[31] = t7;
317
+ $[32] = testID;
318
+ $[33] = t13;
301
319
  } else {
302
- t9 = $[28];
320
+ t13 = $[33];
303
321
  }
304
- return t9;
322
+ return t13;
305
323
  }
306
324
 
307
325
  /**
@@ -313,14 +331,6 @@ function TabBarItem(t0) {
313
331
  * and moves at once with Reduce Motion. Behind the tablist, so assistive tech
314
332
  * reads only the tabs.
315
333
  */
316
- function _temp(t0) {
317
- const {
318
- pressed
319
- } = t0;
320
- return {
321
- opacity: pressed ? 0.7 : 1
322
- };
323
- }
324
334
  function ActiveTabPill(t0) {
325
335
  const $ = _c(14);
326
336
  const {
package/dist/SheetRow.jsx CHANGED
@@ -7,6 +7,7 @@ import { palette } from "./palette";
7
7
  import { useLargerText } from "./theme";
8
8
  import { tokens } from "./tokens";
9
9
  import { useScheme } from "./useScheme";
10
+ import { usePressed } from "./usePressed";
10
11
  /**
11
12
  * One action in a `Sheet` or bottom sheet, a touch size of the web menu item:
12
13
  * icon (or another `leading` mark), title and optional detail, at least 56 high (64 with larger text) with
@@ -16,7 +17,7 @@ import { useScheme } from "./useScheme";
16
17
  * item, and ignores presses.
17
18
  */
18
19
  export function SheetRow(t0) {
19
- const $ = _c(52);
20
+ const $ = _c(53);
20
21
  const {
21
22
  icon: Icon,
22
23
  leading,
@@ -34,6 +35,7 @@ export function SheetRow(t0) {
34
35
  const danger = t2 === undefined ? false : t2;
35
36
  const warning = t3 === undefined ? false : t3;
36
37
  const disabled = t4 === undefined ? false : t4;
38
+ const press = usePressed();
37
39
  const scheme = useScheme();
38
40
  const largerText = useLargerText();
39
41
  const color = danger ? palette.danger[scheme] : warning ? palette.warning[scheme] : tokens.color.foreground[scheme];
@@ -66,133 +68,132 @@ export function SheetRow(t0) {
66
68
  } else {
67
69
  t9 = $[5];
68
70
  }
69
- let t10;
70
- if ($[6] !== disabled || $[7] !== scheme) {
71
- t10 = t11 => {
72
- const {
73
- pressed
74
- } = t11;
75
- return {
76
- borderRadius: tokens.radius.sm,
77
- backgroundColor: pressed && !disabled ? palette.default[scheme] : "transparent"
78
- };
79
- };
80
- $[6] = disabled;
81
- $[7] = scheme;
82
- $[8] = t10;
83
- } else {
84
- t10 = $[8];
85
- }
86
- let t11;
87
- if ($[9] !== Icon || $[10] !== color || $[11] !== iconSize || $[12] !== leading) {
88
- t11 = leading ?? (Icon ? <Icon size={iconSize} color={color} /> : null);
89
- $[9] = Icon;
90
- $[10] = color;
91
- $[11] = iconSize;
92
- $[12] = leading;
93
- $[13] = t11;
94
- } else {
95
- t11 = $[13];
96
- }
97
- let t12;
98
- if ($[14] !== titleSize) {
99
- t12 = cn("font-instrument-sans-medium", titleSize);
100
- $[14] = titleSize;
101
- $[15] = t12;
102
- } else {
103
- t12 = $[15];
104
- }
71
+ const t10 = press.onPressIn;
72
+ const t11 = press.onPressOut;
73
+ const t12 = press.pressed && !disabled ? palette.default[scheme] : "transparent";
105
74
  let t13;
106
- if ($[16] !== color) {
75
+ if ($[6] !== t12) {
107
76
  t13 = {
108
- color
77
+ borderRadius: tokens.radius.sm,
78
+ backgroundColor: t12
109
79
  };
110
- $[16] = color;
111
- $[17] = t13;
80
+ $[6] = t12;
81
+ $[7] = t13;
112
82
  } else {
113
- t13 = $[17];
83
+ t13 = $[7];
114
84
  }
115
85
  let t14;
116
- if ($[18] !== titleSize) {
117
- t14 = sizeStyle(titleSize);
118
- $[18] = titleSize;
119
- $[19] = t14;
86
+ if ($[8] !== Icon || $[9] !== color || $[10] !== iconSize || $[11] !== leading) {
87
+ t14 = leading ?? (Icon ? <Icon size={iconSize} color={color} /> : null);
88
+ $[8] = Icon;
89
+ $[9] = color;
90
+ $[10] = iconSize;
91
+ $[11] = leading;
92
+ $[12] = t14;
120
93
  } else {
121
- t14 = $[19];
94
+ t14 = $[12];
122
95
  }
123
96
  let t15;
124
- if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
125
- t15 = typeStyle("medium");
126
- $[20] = t15;
97
+ if ($[13] !== titleSize) {
98
+ t15 = cn("font-instrument-sans-medium", titleSize);
99
+ $[13] = titleSize;
100
+ $[14] = t15;
127
101
  } else {
128
- t15 = $[20];
102
+ t15 = $[14];
129
103
  }
130
104
  let t16;
131
- if ($[21] !== t13 || $[22] !== t14) {
132
- t16 = [t13, t14, t15];
133
- $[21] = t13;
134
- $[22] = t14;
135
- $[23] = t16;
105
+ if ($[15] !== color) {
106
+ t16 = {
107
+ color
108
+ };
109
+ $[15] = color;
110
+ $[16] = t16;
136
111
  } else {
137
- t16 = $[23];
112
+ t16 = $[16];
138
113
  }
139
114
  let t17;
140
- if ($[24] !== t12 || $[25] !== t16 || $[26] !== title) {
141
- t17 = <Text className={t12} style={t16}>{title}</Text>;
142
- $[24] = t12;
143
- $[25] = t16;
144
- $[26] = title;
145
- $[27] = t17;
115
+ if ($[17] !== titleSize) {
116
+ t17 = sizeStyle(titleSize);
117
+ $[17] = titleSize;
118
+ $[18] = t17;
146
119
  } else {
147
- t17 = $[27];
120
+ t17 = $[18];
148
121
  }
149
122
  let t18;
150
- if ($[28] !== detail || $[29] !== detailSize || $[30] !== scheme) {
151
- t18 = detail ? <Text className={cn("font-instrument-sans", detailSize)} style={[textStyle("muted", scheme), sizeStyle(detailSize)]}>{detail}</Text> : null;
152
- $[28] = detail;
153
- $[29] = detailSize;
154
- $[30] = scheme;
155
- $[31] = t18;
123
+ if ($[19] === Symbol.for("react.memo_cache_sentinel")) {
124
+ t18 = typeStyle("medium");
125
+ $[19] = t18;
156
126
  } else {
157
- t18 = $[31];
127
+ t18 = $[19];
158
128
  }
159
129
  let t19;
160
- if ($[32] !== t17 || $[33] !== t18) {
161
- t19 = <View className="min-w-0 flex-1">{t17}{t18}</View>;
162
- $[32] = t17;
163
- $[33] = t18;
164
- $[34] = t19;
130
+ if ($[20] !== t16 || $[21] !== t17) {
131
+ t19 = [t16, t17, t18];
132
+ $[20] = t16;
133
+ $[21] = t17;
134
+ $[22] = t19;
165
135
  } else {
166
- t19 = $[34];
136
+ t19 = $[22];
167
137
  }
168
138
  let t20;
169
- if ($[35] !== active || $[36] !== color || $[37] !== iconSize) {
170
- t20 = active ? <IconCheck size={iconSize} color={color} strokeWidth={2} /> : null;
171
- $[35] = active;
172
- $[36] = color;
173
- $[37] = iconSize;
174
- $[38] = t20;
139
+ if ($[23] !== t15 || $[24] !== t19 || $[25] !== title) {
140
+ t20 = <Text className={t15} style={t19}>{title}</Text>;
141
+ $[23] = t15;
142
+ $[24] = t19;
143
+ $[25] = title;
144
+ $[26] = t20;
175
145
  } else {
176
- t20 = $[38];
146
+ t20 = $[26];
177
147
  }
178
148
  let t21;
179
- if ($[39] !== detail || $[40] !== disabled || $[41] !== onPress || $[42] !== t10 || $[43] !== t11 || $[44] !== t19 || $[45] !== t20 || $[46] !== t5 || $[47] !== t6 || $[48] !== t9 || $[49] !== testID || $[50] !== title) {
180
- t21 = <Pressable testID={testID} accessibilityRole={t5} accessibilityLabel={title} accessibilityHint={detail} accessibilityState={t6} disabled={disabled} onPress={onPress} className={t9} style={t10}>{t11}{t19}{t20}</Pressable>;
181
- $[39] = detail;
182
- $[40] = disabled;
183
- $[41] = onPress;
184
- $[42] = t10;
185
- $[43] = t11;
186
- $[44] = t19;
187
- $[45] = t20;
188
- $[46] = t5;
189
- $[47] = t6;
190
- $[48] = t9;
191
- $[49] = testID;
192
- $[50] = title;
193
- $[51] = t21;
149
+ if ($[27] !== detail || $[28] !== detailSize || $[29] !== scheme) {
150
+ t21 = detail ? <Text className={cn("font-instrument-sans", detailSize)} style={[textStyle("muted", scheme), sizeStyle(detailSize)]}>{detail}</Text> : null;
151
+ $[27] = detail;
152
+ $[28] = detailSize;
153
+ $[29] = scheme;
154
+ $[30] = t21;
155
+ } else {
156
+ t21 = $[30];
157
+ }
158
+ let t22;
159
+ if ($[31] !== t20 || $[32] !== t21) {
160
+ t22 = <View className="min-w-0 flex-1">{t20}{t21}</View>;
161
+ $[31] = t20;
162
+ $[32] = t21;
163
+ $[33] = t22;
164
+ } else {
165
+ t22 = $[33];
166
+ }
167
+ let t23;
168
+ if ($[34] !== active || $[35] !== color || $[36] !== iconSize) {
169
+ t23 = active ? <IconCheck size={iconSize} color={color} strokeWidth={2} /> : null;
170
+ $[34] = active;
171
+ $[35] = color;
172
+ $[36] = iconSize;
173
+ $[37] = t23;
174
+ } else {
175
+ t23 = $[37];
176
+ }
177
+ let t24;
178
+ if ($[38] !== detail || $[39] !== disabled || $[40] !== onPress || $[41] !== press.onPressIn || $[42] !== press.onPressOut || $[43] !== t13 || $[44] !== t14 || $[45] !== t22 || $[46] !== t23 || $[47] !== t5 || $[48] !== t6 || $[49] !== t9 || $[50] !== testID || $[51] !== title) {
179
+ t24 = <Pressable testID={testID} accessibilityRole={t5} accessibilityLabel={title} accessibilityHint={detail} accessibilityState={t6} disabled={disabled} onPress={onPress} className={t9} onPressIn={t10} onPressOut={t11} style={t13}>{t14}{t22}{t23}</Pressable>;
180
+ $[38] = detail;
181
+ $[39] = disabled;
182
+ $[40] = onPress;
183
+ $[41] = press.onPressIn;
184
+ $[42] = press.onPressOut;
185
+ $[43] = t13;
186
+ $[44] = t14;
187
+ $[45] = t22;
188
+ $[46] = t23;
189
+ $[47] = t5;
190
+ $[48] = t6;
191
+ $[49] = t9;
192
+ $[50] = testID;
193
+ $[51] = title;
194
+ $[52] = t24;
194
195
  } else {
195
- t21 = $[51];
196
+ t24 = $[52];
196
197
  }
197
- return t21;
198
+ return t24;
198
199
  }
@@ -1,5 +1,4 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
- import { useState } from "react";
3
2
  import { Modal, Pressable, StyleSheet, Text, View, useWindowDimensions } from "react-native";
4
3
  import { useSafeAreaInsets } from "react-native-safe-area-context";
5
4
  import { cn } from "../cn";
@@ -11,6 +10,7 @@ import { useReduceMotion } from "../useReduceMotion";
11
10
  import { useScheme } from "../useScheme";
12
11
  import { chatTextSize } from "./chat-text";
13
12
  import { MESSAGE_MENU, messageContextMenuLayout } from "./message-menu-layout";
13
+ import { usePressed } from "../usePressed";
14
14
 
15
15
  /**
16
16
  * The iMessage hold menu for a chat message: the chat fades under a frosted
@@ -331,7 +331,7 @@ function MenuCardRow(t0) {
331
331
  onPress
332
332
  } = t0;
333
333
  const scheme = useScheme();
334
- const [pressed, setPressed] = useState(false);
334
+ const press = usePressed();
335
335
  const disabled = action.disabled === true;
336
336
  const Icon = action.icon;
337
337
  const color = action.destructive ? palette.danger[scheme] : tokens.color.foreground[scheme];
@@ -346,122 +346,115 @@ function MenuCardRow(t0) {
346
346
  } else {
347
347
  t2 = $[1];
348
348
  }
349
- let t3;
350
- let t4;
351
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
352
- t3 = () => setPressed(true);
353
- t4 = () => setPressed(false);
354
- $[2] = t3;
355
- $[3] = t4;
356
- } else {
357
- t3 = $[2];
358
- t4 = $[3];
359
- }
349
+ const t3 = press.onPressIn;
350
+ const t4 = press.onPressOut;
360
351
  const t5 = disabled ? 0.5 : 1;
361
- const t6 = pressed && !disabled ? palette.default[scheme] : "transparent";
352
+ const t6 = press.pressed && !disabled ? palette.default[scheme] : "transparent";
362
353
  let t7;
363
- if ($[4] !== rowHeight || $[5] !== t5 || $[6] !== t6) {
354
+ if ($[2] !== rowHeight || $[3] !== t5 || $[4] !== t6) {
364
355
  t7 = {
365
356
  minHeight: rowHeight,
366
357
  opacity: t5,
367
358
  backgroundColor: t6
368
359
  };
369
- $[4] = rowHeight;
370
- $[5] = t5;
371
- $[6] = t6;
372
- $[7] = t7;
360
+ $[2] = rowHeight;
361
+ $[3] = t5;
362
+ $[4] = t6;
363
+ $[5] = t7;
373
364
  } else {
374
- t7 = $[7];
365
+ t7 = $[5];
375
366
  }
376
367
  let t8;
377
- if ($[8] !== first || $[9] !== scheme) {
368
+ if ($[6] !== first || $[7] !== scheme) {
378
369
  t8 = !first && {
379
370
  borderTopWidth: StyleSheet.hairlineWidth,
380
371
  borderTopColor: tokens.color.separator[scheme]
381
372
  };
382
- $[8] = first;
383
- $[9] = scheme;
384
- $[10] = t8;
373
+ $[6] = first;
374
+ $[7] = scheme;
375
+ $[8] = t8;
385
376
  } else {
386
- t8 = $[10];
377
+ t8 = $[8];
387
378
  }
388
379
  let t9;
389
- if ($[11] !== t7 || $[12] !== t8) {
380
+ if ($[9] !== t7 || $[10] !== t8) {
390
381
  t9 = [t7, t8];
391
- $[11] = t7;
392
- $[12] = t8;
393
- $[13] = t9;
382
+ $[9] = t7;
383
+ $[10] = t8;
384
+ $[11] = t9;
394
385
  } else {
395
- t9 = $[13];
386
+ t9 = $[11];
396
387
  }
397
388
  let t10;
398
- if ($[14] !== body) {
389
+ if ($[12] !== body) {
399
390
  t10 = cn(body, "min-w-0 flex-1 font-instrument-sans");
400
- $[14] = body;
401
- $[15] = t10;
391
+ $[12] = body;
392
+ $[13] = t10;
402
393
  } else {
403
- t10 = $[15];
394
+ t10 = $[13];
404
395
  }
405
396
  let t11;
406
- if ($[16] !== body) {
397
+ if ($[14] !== body) {
407
398
  t11 = sizeStyle(body);
408
- $[16] = body;
409
- $[17] = t11;
399
+ $[14] = body;
400
+ $[15] = t11;
410
401
  } else {
411
- t11 = $[17];
402
+ t11 = $[15];
412
403
  }
413
404
  let t12;
414
- if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
405
+ if ($[16] === Symbol.for("react.memo_cache_sentinel")) {
415
406
  t12 = typeStyle("medium");
416
- $[18] = t12;
407
+ $[16] = t12;
417
408
  } else {
418
- t12 = $[18];
409
+ t12 = $[16];
419
410
  }
420
411
  let t13;
421
- if ($[19] !== color) {
412
+ if ($[17] !== color) {
422
413
  t13 = {
423
414
  color
424
415
  };
425
- $[19] = color;
426
- $[20] = t13;
416
+ $[17] = color;
417
+ $[18] = t13;
427
418
  } else {
428
- t13 = $[20];
419
+ t13 = $[18];
429
420
  }
430
421
  let t14;
431
- if ($[21] !== t11 || $[22] !== t13) {
422
+ if ($[19] !== t11 || $[20] !== t13) {
432
423
  t14 = [t11, t12, t13];
433
- $[21] = t11;
434
- $[22] = t13;
435
- $[23] = t14;
424
+ $[19] = t11;
425
+ $[20] = t13;
426
+ $[21] = t14;
436
427
  } else {
437
- t14 = $[23];
428
+ t14 = $[21];
438
429
  }
439
430
  let t15;
440
- if ($[24] !== action.label || $[25] !== t10 || $[26] !== t14) {
431
+ if ($[22] !== action.label || $[23] !== t10 || $[24] !== t14) {
441
432
  t15 = <Text numberOfLines={1} className={t10} style={t14}>{action.label}</Text>;
442
- $[24] = action.label;
443
- $[25] = t10;
444
- $[26] = t14;
445
- $[27] = t15;
433
+ $[22] = action.label;
434
+ $[23] = t10;
435
+ $[24] = t14;
436
+ $[25] = t15;
446
437
  } else {
447
- t15 = $[27];
438
+ t15 = $[25];
448
439
  }
449
440
  let t16;
450
- if ($[28] !== Icon || $[29] !== color || $[30] !== iconSize) {
441
+ if ($[26] !== Icon || $[27] !== color || $[28] !== iconSize) {
451
442
  t16 = Icon ? <Icon size={iconSize} color={color} /> : null;
452
- $[28] = Icon;
453
- $[29] = color;
454
- $[30] = iconSize;
455
- $[31] = t16;
443
+ $[26] = Icon;
444
+ $[27] = color;
445
+ $[28] = iconSize;
446
+ $[29] = t16;
456
447
  } else {
457
- t16 = $[31];
448
+ t16 = $[29];
458
449
  }
459
450
  let t17;
460
- if ($[32] !== action.label || $[33] !== disabled || $[34] !== onPress || $[35] !== t15 || $[36] !== t16 || $[37] !== t2 || $[38] !== t9 || $[39] !== testID) {
451
+ if ($[30] !== action.label || $[31] !== disabled || $[32] !== onPress || $[33] !== press.onPressIn || $[34] !== press.onPressOut || $[35] !== t15 || $[36] !== t16 || $[37] !== t2 || $[38] !== t9 || $[39] !== testID) {
461
452
  t17 = <Pressable testID={testID} accessibilityRole="menuitem" accessibilityLabel={t1} accessibilityState={t2} disabled={disabled} onPress={onPress} onPressIn={t3} onPressOut={t4} className="flex-row items-center gap-3 px-4" style={t9}>{t15}{t16}</Pressable>;
462
- $[32] = action.label;
463
- $[33] = disabled;
464
- $[34] = onPress;
453
+ $[30] = action.label;
454
+ $[31] = disabled;
455
+ $[32] = onPress;
456
+ $[33] = press.onPressIn;
457
+ $[34] = press.onPressOut;
465
458
  $[35] = t15;
466
459
  $[36] = t16;
467
460
  $[37] = t2;
@@ -17,6 +17,7 @@ import { MESSAGE_ACTIONS_TITLE, MessageActionSheet } from "./message-action-shee
17
17
  import { useOptionalConversation } from "./conversation-context";
18
18
  import { MessageContextMenu } from "./message-context-menu";
19
19
  import { ChatTextColorContext, ResponseText } from "./response-text";
20
+ import { usePressed } from "../usePressed";
20
21
  const MessageContext = createContext("assistant");
21
22
 
22
23
  /** The bot behind an incoming message in a group chat. */
@@ -178,7 +179,7 @@ export function Message(t0) {
178
179
  const highlighted = t1 === undefined ? false : t1;
179
180
  const user = from === "user";
180
181
  const [sheetOpen, setSheetOpen] = useState(false);
181
- const [pressing, setPressing] = useState(false);
182
+ const press = usePressed();
182
183
  const [held, setHeld] = useState(null);
183
184
  const pressable = useRef(null);
184
185
  const hasActions = actions != null && actions.length > 0;
@@ -290,8 +291,8 @@ export function Message(t0) {
290
291
  }
291
292
  const parts = t11;
292
293
  let t12;
293
- if ($[36] !== actionSheetTitle || $[37] !== actions || $[38] !== closeMenu || $[39] !== conversation?.settleOverlay || $[40] !== from || $[41] !== hasActions || $[42] !== held || $[43] !== layout || $[44] !== longPress || $[45] !== longPressable || $[46] !== menu || $[47] !== merged || $[48] !== parts || $[49] !== pressing || $[50] !== props || $[51] !== sheetOpen || $[52] !== user) {
294
- t12 = longPressable ? <><Pressable ref={pressable} accessible={false} className={merged} style={[layout, pressing ? HELD_STYLE : null]} onPressIn={() => setPressing(true)} onPressOut={() => setPressing(false)} onLongPress={longPress} delayLongPress={HOLD_DELAY_MS} accessibilityActions={[{
294
+ if ($[36] !== actionSheetTitle || $[37] !== actions || $[38] !== closeMenu || $[39] !== conversation?.settleOverlay || $[40] !== from || $[41] !== hasActions || $[42] !== held || $[43] !== layout || $[44] !== longPress || $[45] !== longPressable || $[46] !== menu || $[47] !== merged || $[48] !== parts || $[49] !== press || $[50] !== props || $[51] !== sheetOpen || $[52] !== user) {
295
+ t12 = longPressable ? <><Pressable ref={pressable} accessible={false} className={merged} style={[layout, press.pressed ? HELD_STYLE : null]} onPressIn={press.onPressIn} onPressOut={press.onPressOut} onLongPress={longPress} delayLongPress={HOLD_DELAY_MS} accessibilityActions={[{
295
296
  name: "longpress",
296
297
  label: actionSheetTitle ?? MESSAGE_ACTIONS_TITLE
297
298
  }]} onAccessibilityAction={event => {
@@ -317,7 +318,7 @@ export function Message(t0) {
317
318
  $[46] = menu;
318
319
  $[47] = merged;
319
320
  $[48] = parts;
320
- $[49] = pressing;
321
+ $[49] = press;
321
322
  $[50] = props;
322
323
  $[51] = sheetOpen;
323
324
  $[52] = user;
@@ -8,6 +8,7 @@ import { tokens } from "../tokens";
8
8
  import { useScheme } from "../useScheme";
9
9
  import { Collapsible, CollapsibleChevron, CollapsibleContent, CollapsibleTrigger, useCollapsible } from "./collapsible";
10
10
  import { ResponseText } from "./response-text";
11
+ import { usePressed } from "../usePressed";
11
12
 
12
13
  /** The sources a reply used, folded (default closed). */
13
14
  export function Sources(t0) {
@@ -182,13 +183,14 @@ const ROW_HEIGHT = 36;
182
183
  * Pressed, it takes the web hover fill (`bg-surface-secondary`).
183
184
  */
184
185
  export function Source(t0) {
185
- const $ = _c(18);
186
+ const $ = _c(20);
186
187
  const {
187
188
  href,
188
189
  title,
189
190
  onPress,
190
191
  testID
191
192
  } = t0;
193
+ const press = usePressed();
192
194
  const scheme = useScheme();
193
195
  const largerText = useLargerText();
194
196
  const label = title ?? href;
@@ -208,53 +210,51 @@ export function Source(t0) {
208
210
  } else {
209
211
  t2 = $[3];
210
212
  }
211
- let t3;
212
- if ($[4] !== scheme) {
213
- t3 = t4 => {
214
- const {
215
- pressed
216
- } = t4;
217
- return {
218
- borderRadius: tokens.radius.md,
219
- backgroundColor: pressed ? tokens.color.surfaceSecondary[scheme] : "transparent"
220
- };
213
+ const t3 = press.pressed ? tokens.color.surfaceSecondary[scheme] : "transparent";
214
+ let t4;
215
+ if ($[4] !== t3) {
216
+ t4 = {
217
+ borderRadius: tokens.radius.md,
218
+ backgroundColor: t3
221
219
  };
222
- $[4] = scheme;
223
- $[5] = t3;
220
+ $[4] = t3;
221
+ $[5] = t4;
224
222
  } else {
225
- t3 = $[5];
223
+ t4 = $[5];
226
224
  }
227
- let t4;
225
+ let t5;
228
226
  if ($[6] !== label) {
229
- t4 = <ResponseText size="small" tone="muted" selectable={false} numberOfLines={1} className="shrink">{label}</ResponseText>;
227
+ t5 = <ResponseText size="small" tone="muted" selectable={false} numberOfLines={1} className="shrink">{label}</ResponseText>;
230
228
  $[6] = label;
231
- $[7] = t4;
229
+ $[7] = t5;
232
230
  } else {
233
- t4 = $[7];
231
+ t5 = $[7];
234
232
  }
235
- const t5 = largerText ? 18 : 14;
236
- const t6 = tokens.color.muted[scheme];
237
- let t7;
238
- if ($[8] !== t5 || $[9] !== t6) {
239
- t7 = <IconBook size={t5} color={t6} strokeWidth={1.5} />;
240
- $[8] = t5;
241
- $[9] = t6;
242
- $[10] = t7;
233
+ const t6 = largerText ? 18 : 14;
234
+ const t7 = tokens.color.muted[scheme];
235
+ let t8;
236
+ if ($[8] !== t6 || $[9] !== t7) {
237
+ t8 = <IconBook size={t6} color={t7} strokeWidth={1.5} />;
238
+ $[8] = t6;
239
+ $[9] = t7;
240
+ $[10] = t8;
243
241
  } else {
244
- t7 = $[10];
242
+ t8 = $[10];
245
243
  }
246
- let t8;
247
- if ($[11] !== label || $[12] !== t2 || $[13] !== t3 || $[14] !== t4 || $[15] !== t7 || $[16] !== testID) {
248
- t8 = <Pressable testID={testID} accessibilityRole="link" accessibilityLabel={label} hitSlop={t1} onPress={t2} className="flex-row items-center justify-between gap-2 px-3 py-2" style={t3}>{t4}{t7}</Pressable>;
244
+ let t9;
245
+ if ($[11] !== label || $[12] !== press.onPressIn || $[13] !== press.onPressOut || $[14] !== t2 || $[15] !== t4 || $[16] !== t5 || $[17] !== t8 || $[18] !== testID) {
246
+ t9 = <Pressable testID={testID} accessibilityRole="link" accessibilityLabel={label} hitSlop={t1} onPress={t2} onPressIn={press.onPressIn} onPressOut={press.onPressOut} className="flex-row items-center justify-between gap-2 px-3 py-2" style={t4}>{t5}{t8}</Pressable>;
249
247
  $[11] = label;
250
- $[12] = t2;
251
- $[13] = t3;
252
- $[14] = t4;
253
- $[15] = t7;
254
- $[16] = testID;
248
+ $[12] = press.onPressIn;
249
+ $[13] = press.onPressOut;
250
+ $[14] = t2;
251
+ $[15] = t4;
252
+ $[16] = t5;
255
253
  $[17] = t8;
254
+ $[18] = testID;
255
+ $[19] = t9;
256
256
  } else {
257
- t8 = $[17];
257
+ t9 = $[19];
258
258
  }
259
- return t8;
259
+ return t9;
260
260
  }
@@ -7,6 +7,7 @@ import { useLargerText } from "../theme";
7
7
  import { tokens } from "../tokens";
8
8
  import { useScheme } from "../useScheme";
9
9
  import { chatTextSize } from "./chat-text";
10
+ import { usePressed } from "../usePressed";
10
11
  /**
11
12
  * Prompt suggestions. Horizontal is a `ScrollView` with no scroll bar (the web
12
13
  * row with its scroll arrows; a phone swipes instead).
@@ -77,7 +78,7 @@ const CHIP_HEIGHT = 32;
77
78
  * it takes the web hover (`bg-surface-tertiary text-foreground`).
78
79
  */
79
80
  export function Suggestion(t0) {
80
- const $ = _c(27);
81
+ const $ = _c(30);
81
82
  const {
82
83
  suggestion,
83
84
  onPress,
@@ -85,6 +86,7 @@ export function Suggestion(t0) {
85
86
  disabled,
86
87
  testID
87
88
  } = t0;
89
+ const press = usePressed();
88
90
  const scheme = useScheme();
89
91
  const largerText = useLargerText();
90
92
  let t1;
@@ -134,53 +136,53 @@ export function Suggestion(t0) {
134
136
  } else {
135
137
  t8 = $[10];
136
138
  }
137
- let t9;
138
- if ($[11] !== scheme) {
139
- t9 = t10 => {
140
- const {
141
- pressed
142
- } = t10;
143
- return {
144
- borderRadius: tokens.radius.pill,
145
- borderColor: tokens.color.border[scheme],
146
- backgroundColor: pressed ? palette.surfaceTertiary[scheme] : tokens.color.surfaceSecondary[scheme]
147
- };
139
+ const t9 = tokens.color.border[scheme];
140
+ const t10 = press.pressed ? palette.surfaceTertiary[scheme] : tokens.color.surfaceSecondary[scheme];
141
+ let t11;
142
+ if ($[11] !== t10 || $[12] !== t9) {
143
+ t11 = {
144
+ borderRadius: tokens.radius.pill,
145
+ borderColor: t9,
146
+ backgroundColor: t10
148
147
  };
149
- $[11] = scheme;
148
+ $[11] = t10;
150
149
  $[12] = t9;
150
+ $[13] = t11;
151
151
  } else {
152
- t9 = $[12];
152
+ t11 = $[13];
153
153
  }
154
- let t10;
155
- if ($[13] !== children || $[14] !== scheme || $[15] !== size || $[16] !== suggestion) {
156
- t10 = t11 => {
154
+ let t12;
155
+ if ($[14] !== children || $[15] !== scheme || $[16] !== size || $[17] !== suggestion) {
156
+ t12 = t13 => {
157
157
  const {
158
- pressed: pressed_0
159
- } = t11;
160
- return <Text className={cn(size, "font-instrument-sans")} style={[sizeStyle(size), textStyle(pressed_0 ? "foreground" : "muted", scheme)]}>{children ?? suggestion}</Text>;
158
+ pressed
159
+ } = t13;
160
+ return <Text className={cn(size, "font-instrument-sans")} style={[sizeStyle(size), textStyle(pressed ? "foreground" : "muted", scheme)]}>{children ?? suggestion}</Text>;
161
161
  };
162
- $[13] = children;
163
- $[14] = scheme;
164
- $[15] = size;
165
- $[16] = suggestion;
166
- $[17] = t10;
162
+ $[14] = children;
163
+ $[15] = scheme;
164
+ $[16] = size;
165
+ $[17] = suggestion;
166
+ $[18] = t12;
167
167
  } else {
168
- t10 = $[17];
168
+ t12 = $[18];
169
169
  }
170
- let t11;
171
- if ($[18] !== disabled || $[19] !== suggestion || $[20] !== t10 || $[21] !== t3 || $[22] !== t5 || $[23] !== t8 || $[24] !== t9 || $[25] !== testID) {
172
- t11 = <Pressable testID={testID} accessibilityRole="button" accessibilityLabel={suggestion} accessibilityState={t3} disabled={disabled} hitSlop={t4} onPress={t5} className={t8} style={t9}>{t10}</Pressable>;
173
- $[18] = disabled;
174
- $[19] = suggestion;
175
- $[20] = t10;
176
- $[21] = t3;
177
- $[22] = t5;
178
- $[23] = t8;
179
- $[24] = t9;
180
- $[25] = testID;
181
- $[26] = t11;
170
+ let t13;
171
+ if ($[19] !== disabled || $[20] !== press.onPressIn || $[21] !== press.onPressOut || $[22] !== suggestion || $[23] !== t11 || $[24] !== t12 || $[25] !== t3 || $[26] !== t5 || $[27] !== t8 || $[28] !== testID) {
172
+ t13 = <Pressable testID={testID} accessibilityRole="button" accessibilityLabel={suggestion} accessibilityState={t3} disabled={disabled} hitSlop={t4} onPress={t5} className={t8} onPressIn={press.onPressIn} onPressOut={press.onPressOut} style={t11}>{t12}</Pressable>;
173
+ $[19] = disabled;
174
+ $[20] = press.onPressIn;
175
+ $[21] = press.onPressOut;
176
+ $[22] = suggestion;
177
+ $[23] = t11;
178
+ $[24] = t12;
179
+ $[25] = t3;
180
+ $[26] = t5;
181
+ $[27] = t8;
182
+ $[28] = testID;
183
+ $[29] = t13;
182
184
  } else {
183
- t11 = $[26];
185
+ t13 = $[29];
184
186
  }
185
- return t11;
187
+ return t13;
186
188
  }
@@ -0,0 +1,38 @@
1
+ import { c as _c } from "react/compiler-runtime";
2
+ import { useState } from "react";
3
+
4
+ /**
5
+ * Whether a `Pressable` is held down, as state, for a pressed look. With a
6
+ * `className`, NativeWind drops a `Pressable` style function (`({ pressed })
7
+ * => ...`), and with it the radius, border and fill it sets; so a pressable
8
+ * with classes reads `pressed` from here and passes a plain style. Spread
9
+ * `onPressIn` and `onPressOut` on the `Pressable`.
10
+ */
11
+ export function usePressed() {
12
+ const $ = _c(4);
13
+ const [pressed, setPressed] = useState(false);
14
+ let t0;
15
+ let t1;
16
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
17
+ t0 = () => setPressed(true);
18
+ t1 = () => setPressed(false);
19
+ $[0] = t0;
20
+ $[1] = t1;
21
+ } else {
22
+ t0 = $[0];
23
+ t1 = $[1];
24
+ }
25
+ let t2;
26
+ if ($[2] !== pressed) {
27
+ t2 = {
28
+ pressed,
29
+ onPressIn: t0,
30
+ onPressOut: t1
31
+ };
32
+ $[2] = pressed;
33
+ $[3] = t2;
34
+ } else {
35
+ t2 = $[3];
36
+ }
37
+ return t2;
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/native-ui",
3
- "version": "0.25.2",
3
+ "version": "0.25.3",
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",
@@ -310,8 +310,8 @@
310
310
  "check:exports": "node scripts/check-exports.mjs",
311
311
  "check:hermes": "node scripts/check-hermes-compat.mjs",
312
312
  "test": "vitest run",
313
- "typecheck": "tsc -p tsconfig.typecheck.json && pnpm run typecheck:consumer",
314
- "typecheck:consumer": "tsc -p tsconfig.consumer.json",
313
+ "typecheck": "tsrs --noEmit --fast -p tsconfig.typecheck.json && pnpm run typecheck:consumer",
314
+ "typecheck:consumer": "tsrs --noEmit --fast -p tsconfig.consumer.json",
315
315
  "build:baseline": "node scripts/build-dist.mjs --update"
316
316
  }
317
317
  }
@@ -15,6 +15,7 @@ import { useLargerText } from "./theme";
15
15
  import { useReduceMotion } from "./useReduceMotion";
16
16
  import { useScheme } from "./useScheme";
17
17
  import { FLOATING_PILL_RADIUS, tabBarHeight, tabBarSlotStyle } from "./floating";
18
+ import { usePressed } from "./usePressed";
18
19
 
19
20
  /**
20
21
  * Space between the bar edge and the tabs, on every side of the active pill,
@@ -158,6 +159,7 @@ function TabBarItem({
158
159
  testID,
159
160
  accessibilityLabel,
160
161
  }: TabBarItemProps) {
162
+ const press = usePressed();
161
163
  const onPress = () => {
162
164
  const event = navigation.emit({
163
165
  type: "tabPress",
@@ -177,8 +179,10 @@ function TabBarItem({
177
179
  accessibilityState={{ selected: focused }}
178
180
  accessibilityLabel={accessibilityLabel}
179
181
  onPress={onPress}
182
+ onPressIn={press.onPressIn}
183
+ onPressOut={press.onPressOut}
180
184
  className="min-h-12 min-w-12 flex-1 items-center justify-center gap-1"
181
- style={({ pressed }) => ({ opacity: pressed ? 0.7 : 1 })}
185
+ style={{ opacity: press.pressed ? 0.7 : 1 }}
182
186
  >
183
187
  {renderIcon ? renderIcon({ focused, color, size: largerText ? 28 : 24 }) : null}
184
188
  <Text
package/src/SheetRow.tsx CHANGED
@@ -7,6 +7,7 @@ import { palette } from "./palette";
7
7
  import { useLargerText } from "./theme";
8
8
  import { tokens } from "./tokens";
9
9
  import { useScheme } from "./useScheme";
10
+ import { usePressed } from "./usePressed";
10
11
 
11
12
  export type SheetRowProps = {
12
13
  /** A Tabler icon at the start. */
@@ -55,6 +56,7 @@ export function SheetRow({
55
56
  onPress,
56
57
  testID,
57
58
  }: SheetRowProps) {
59
+ const press = usePressed();
58
60
  const scheme = useScheme();
59
61
  const largerText = useLargerText();
60
62
  const color = danger
@@ -79,10 +81,12 @@ export function SheetRow({
79
81
  largerText ? "min-h-16" : "min-h-14",
80
82
  disabled && "opacity-50",
81
83
  )}
82
- style={({ pressed }) => ({
84
+ onPressIn={press.onPressIn}
85
+ onPressOut={press.onPressOut}
86
+ style={{
83
87
  borderRadius: tokens.radius.sm,
84
- backgroundColor: pressed && !disabled ? palette.default[scheme] : "transparent",
85
- })}
88
+ backgroundColor: press.pressed && !disabled ? palette.default[scheme] : "transparent",
89
+ }}
86
90
  >
87
91
  {leading ?? (Icon ? <Icon size={iconSize} color={color} /> : null)}
88
92
  <View className="min-w-0 flex-1">
@@ -1,4 +1,4 @@
1
- import { useState, type ReactNode } from "react";
1
+ import type { ReactNode } from "react";
2
2
  import { Modal, Pressable, StyleSheet, Text, View, useWindowDimensions } from "react-native";
3
3
  import { useSafeAreaInsets } from "react-native-safe-area-context";
4
4
  import { cn } from "../cn";
@@ -10,6 +10,7 @@ import { useReduceMotion } from "../useReduceMotion";
10
10
  import { useScheme } from "../useScheme";
11
11
  import { chatTextSize } from "./chat-text";
12
12
  import { MESSAGE_MENU, messageContextMenuLayout, type MessageMenu, type MessageMenuRect } from "./message-menu-layout";
13
+ import { usePressed } from "../usePressed";
13
14
 
14
15
  /**
15
16
  * The iMessage hold menu for a chat message: the chat fades under a frosted
@@ -193,7 +194,7 @@ function MenuCardRow({
193
194
  }) {
194
195
  const scheme = useScheme();
195
196
  // A state, not a style function: with a `className`, NativeWind drops a style function.
196
- const [pressed, setPressed] = useState(false);
197
+ const press = usePressed();
197
198
  const disabled = action.disabled === true;
198
199
  const Icon = action.icon;
199
200
  const color = action.destructive ? palette.danger[scheme] : tokens.color.foreground[scheme];
@@ -205,14 +206,14 @@ function MenuCardRow({
205
206
  accessibilityState={{ disabled }}
206
207
  disabled={disabled}
207
208
  onPress={onPress}
208
- onPressIn={() => setPressed(true)}
209
- onPressOut={() => setPressed(false)}
209
+ onPressIn={press.onPressIn}
210
+ onPressOut={press.onPressOut}
210
211
  className="flex-row items-center gap-3 px-4"
211
212
  style={[
212
213
  {
213
214
  minHeight: rowHeight,
214
215
  opacity: disabled ? 0.5 : 1,
215
- backgroundColor: pressed && !disabled ? palette.default[scheme] : "transparent",
216
+ backgroundColor: press.pressed && !disabled ? palette.default[scheme] : "transparent",
216
217
  },
217
218
  !first && { borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: tokens.color.separator[scheme] },
218
219
  ]}
@@ -24,6 +24,7 @@ import { useOptionalConversation } from "./conversation-context";
24
24
  import { MessageContextMenu } from "./message-context-menu";
25
25
  import type { MessageMenu, MessageMenuRect } from "./message-menu-layout";
26
26
  import { ChatTextColorContext, ResponseText } from "./response-text";
27
+ import { usePressed } from "../usePressed";
27
28
 
28
29
  export type MessageRole = "user" | "assistant" | "system";
29
30
 
@@ -138,7 +139,7 @@ export function Message({
138
139
  }: MessageProps) {
139
140
  const user = from === "user";
140
141
  const [sheetOpen, setSheetOpen] = useState(false);
141
- const [pressing, setPressing] = useState(false);
142
+ const press = usePressed();
142
143
  // The open context menu: where the message was and what it offers, read at the hold.
143
144
  const [held, setHeld] = useState<{ anchor: MessageMenuRect; menu: MessageMenu } | null>(null);
144
145
  // Measured at the hold: the menu draws the message again where it is on screen.
@@ -183,9 +184,9 @@ export function Message({
183
184
  className={merged}
184
185
  // While held it dims a little: the feedback before the menu opens. A state, not a
185
186
  // style function: with a `className`, NativeWind drops a style function, layout and all.
186
- style={[layout, pressing ? HELD_STYLE : null]}
187
- onPressIn={() => setPressing(true)}
188
- onPressOut={() => setPressing(false)}
187
+ style={[layout, press.pressed ? HELD_STYLE : null]}
188
+ onPressIn={press.onPressIn}
189
+ onPressOut={press.onPressOut}
189
190
  onLongPress={longPress}
190
191
  delayLongPress={HOLD_DELAY_MS}
191
192
  // TalkBack's actions menu reaches the same sheet as a long press.
@@ -15,6 +15,7 @@ import {
15
15
  type CollapsibleTriggerProps,
16
16
  } from "./collapsible";
17
17
  import { ResponseText } from "./response-text";
18
+ import { usePressed } from "../usePressed";
18
19
 
19
20
  /** The sources a reply used, folded (default closed). */
20
21
  export function Sources({ className, ...props }: CollapsibleProps) {
@@ -75,6 +76,7 @@ const ROW_HEIGHT = 36;
75
76
  * Pressed, it takes the web hover fill (`bg-surface-secondary`).
76
77
  */
77
78
  export function Source({ href, title, onPress, testID }: SourceProps) {
79
+ const press = usePressed();
78
80
  const scheme = useScheme();
79
81
  const largerText = useLargerText();
80
82
  const label = title ?? href;
@@ -85,11 +87,13 @@ export function Source({ href, title, onPress, testID }: SourceProps) {
85
87
  accessibilityLabel={label}
86
88
  hitSlop={touchSlop(MIN_TOUCH_TARGET, ROW_HEIGHT)}
87
89
  onPress={() => (onPress ? onPress(href) : void Linking.openURL(href))}
90
+ onPressIn={press.onPressIn}
91
+ onPressOut={press.onPressOut}
88
92
  className="flex-row items-center justify-between gap-2 px-3 py-2"
89
- style={({ pressed }) => ({
93
+ style={{
90
94
  borderRadius: tokens.radius.md,
91
- backgroundColor: pressed ? tokens.color.surfaceSecondary[scheme] : "transparent",
92
- })}
95
+ backgroundColor: press.pressed ? tokens.color.surfaceSecondary[scheme] : "transparent",
96
+ }}
93
97
  >
94
98
  <ResponseText size="small" tone="muted" selectable={false} numberOfLines={1} className="shrink">
95
99
  {label}
@@ -7,6 +7,7 @@ import { useLargerText } from "../theme";
7
7
  import { tokens } from "../tokens";
8
8
  import { useScheme } from "../useScheme";
9
9
  import { chatTextSize } from "./chat-text";
10
+ import { usePressed } from "../usePressed";
10
11
 
11
12
  export type SuggestionsProps = {
12
13
  /** `horizontal` (default) scrolls one row of chips; `vertical` stacks them full width. */
@@ -61,6 +62,7 @@ const CHIP_HEIGHT = 32;
61
62
  * it takes the web hover (`bg-surface-tertiary text-foreground`).
62
63
  */
63
64
  export function Suggestion({ suggestion, onPress, children, disabled, testID }: SuggestionProps) {
65
+ const press = usePressed();
64
66
  const scheme = useScheme();
65
67
  const largerText = useLargerText();
66
68
  const size = chatTextSize("small", largerText);
@@ -74,11 +76,13 @@ export function Suggestion({ suggestion, onPress, children, disabled, testID }:
74
76
  hitSlop={touchSlop(MIN_TOUCH_TARGET, CHIP_HEIGHT)}
75
77
  onPress={() => onPress?.(suggestion)}
76
78
  className={cn("justify-center border", largerText ? "min-h-12 px-4 py-2" : "min-h-8 px-3 py-1.5", disabled && "opacity-45")}
77
- style={({ pressed }) => ({
79
+ onPressIn={press.onPressIn}
80
+ onPressOut={press.onPressOut}
81
+ style={{
78
82
  borderRadius: tokens.radius.pill,
79
83
  borderColor: tokens.color.border[scheme],
80
- backgroundColor: pressed ? palette.surfaceTertiary[scheme] : tokens.color.surfaceSecondary[scheme],
81
- })}
84
+ backgroundColor: press.pressed ? palette.surfaceTertiary[scheme] : tokens.color.surfaceSecondary[scheme],
85
+ }}
82
86
  >
83
87
  {({ pressed }) => (
84
88
  <Text
@@ -0,0 +1,13 @@
1
+ import { useState } from "react";
2
+
3
+ /**
4
+ * Whether a `Pressable` is held down, as state, for a pressed look. With a
5
+ * `className`, NativeWind drops a `Pressable` style function (`({ pressed })
6
+ * => ...`), and with it the radius, border and fill it sets; so a pressable
7
+ * with classes reads `pressed` from here and passes a plain style. Spread
8
+ * `onPressIn` and `onPressOut` on the `Pressable`.
9
+ */
10
+ export function usePressed() {
11
+ const [pressed, setPressed] = useState(false);
12
+ return { pressed, onPressIn: () => setPressed(true), onPressOut: () => setPressed(false) };
13
+ }