@vvedantb/native-ui 0.25.1 → 0.25.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.
@@ -14,6 +14,7 @@ import { useScheme } from "../useScheme";
14
14
  import { META_TEXT_STYLE, chatTextSize } from "./chat-text";
15
15
  import { ChatIconButton } from "./icon-button";
16
16
  import { MESSAGE_ACTIONS_TITLE, MessageActionSheet } from "./message-action-sheet";
17
+ import { useOptionalConversation } from "./conversation-context";
17
18
  import { MessageContextMenu } from "./message-context-menu";
18
19
  import { ChatTextColorContext, ResponseText } from "./response-text";
19
20
  const MessageContext = createContext("assistant");
@@ -123,7 +124,7 @@ const HELD_STYLE = {
123
124
  opacity: 0.9
124
125
  };
125
126
  export function Message(t0) {
126
- const $ = _c(52);
127
+ const $ = _c(57);
127
128
  let actionSheetTitle;
128
129
  let actions;
129
130
  let bot;
@@ -182,13 +183,15 @@ export function Message(t0) {
182
183
  const pressable = useRef(null);
183
184
  const hasActions = actions != null && actions.length > 0;
184
185
  const longPressable = onLongPress != null || hasActions || menu != null;
186
+ const conversation = useOptionalConversation();
185
187
  let t2;
186
- if ($[12] !== hasActions || $[13] !== menu || $[14] !== onLongPress) {
188
+ if ($[12] !== conversation || $[13] !== hasActions || $[14] !== menu || $[15] !== onLongPress) {
187
189
  t2 = () => {
188
190
  impactHaptic("medium");
189
191
  onLongPress?.();
190
192
  if (menu) {
191
193
  const built = menu();
194
+ conversation?.openOverlay();
192
195
  pressable.current?.measureInWindow((x, y, width, height) => setHeld({
193
196
  anchor: {
194
197
  x,
@@ -204,119 +207,134 @@ export function Message(t0) {
204
207
  }
205
208
  }
206
209
  };
207
- $[12] = hasActions;
208
- $[13] = menu;
209
- $[14] = onLongPress;
210
- $[15] = t2;
210
+ $[12] = conversation;
211
+ $[13] = hasActions;
212
+ $[14] = menu;
213
+ $[15] = onLongPress;
214
+ $[16] = t2;
211
215
  } else {
212
- t2 = $[15];
216
+ t2 = $[16];
213
217
  }
214
218
  const longPress = t2;
215
- const t3 = user ? "flex-end" : "flex-start";
216
- const t4 = user ? "flex-end" : "stretch";
217
- let t5;
218
- if ($[16] !== t3 || $[17] !== t4) {
219
- t5 = {
220
- alignSelf: t3,
221
- alignItems: t4
219
+ let t3;
220
+ if ($[17] !== conversation) {
221
+ t3 = () => {
222
+ setHeld(null);
223
+ conversation?.closeOverlay();
222
224
  };
223
- $[16] = t3;
224
- $[17] = t4;
225
- $[18] = t5;
225
+ $[17] = conversation;
226
+ $[18] = t3;
226
227
  } else {
227
- t5 = $[18];
228
+ t3 = $[18];
228
229
  }
230
+ const closeMenu = t3;
231
+ const t4 = user ? "flex-end" : "flex-start";
232
+ const t5 = user ? "flex-end" : "stretch";
229
233
  let t6;
230
- if ($[19] !== style || $[20] !== t5) {
231
- t6 = [t5, style];
232
- $[19] = style;
234
+ if ($[19] !== t4 || $[20] !== t5) {
235
+ t6 = {
236
+ alignSelf: t4,
237
+ alignItems: t5
238
+ };
239
+ $[19] = t4;
233
240
  $[20] = t5;
234
241
  $[21] = t6;
235
242
  } else {
236
243
  t6 = $[21];
237
244
  }
238
- const layout = t6;
239
245
  let t7;
240
- if ($[22] !== className) {
241
- t7 = cn("w-full max-w-[95%] gap-2", className);
242
- $[22] = className;
243
- $[23] = t7;
246
+ if ($[22] !== style || $[23] !== t6) {
247
+ t7 = [t6, style];
248
+ $[22] = style;
249
+ $[23] = t6;
250
+ $[24] = t7;
244
251
  } else {
245
- t7 = $[23];
252
+ t7 = $[24];
246
253
  }
247
- const merged = t7;
254
+ const layout = t7;
248
255
  let t8;
249
- if ($[24] !== bot || $[25] !== user) {
250
- t8 = bot && !user ? <MessageBotLabel name={bot.name} avatar={bot.avatar} /> : null;
251
- $[24] = bot;
252
- $[25] = user;
256
+ if ($[25] !== className) {
257
+ t8 = cn("w-full max-w-[95%] gap-2", className);
258
+ $[25] = className;
253
259
  $[26] = t8;
254
260
  } else {
255
261
  t8 = $[26];
256
262
  }
263
+ const merged = t8;
257
264
  let t9;
258
- if ($[27] !== highlighted) {
259
- t9 = highlighted ? <MessageHighlight /> : null;
260
- $[27] = highlighted;
261
- $[28] = t9;
265
+ if ($[27] !== bot || $[28] !== user) {
266
+ t9 = bot && !user ? <MessageBotLabel name={bot.name} avatar={bot.avatar} /> : null;
267
+ $[27] = bot;
268
+ $[28] = user;
269
+ $[29] = t9;
262
270
  } else {
263
- t9 = $[28];
271
+ t9 = $[29];
264
272
  }
265
273
  let t10;
266
- if ($[29] !== children || $[30] !== t8 || $[31] !== t9) {
267
- t10 = <>{t8}{children}{t9}</>;
268
- $[29] = children;
269
- $[30] = t8;
270
- $[31] = t9;
271
- $[32] = t10;
274
+ if ($[30] !== highlighted) {
275
+ t10 = highlighted ? <MessageHighlight /> : null;
276
+ $[30] = highlighted;
277
+ $[31] = t10;
272
278
  } else {
273
- t10 = $[32];
279
+ t10 = $[31];
274
280
  }
275
- const parts = t10;
276
281
  let t11;
277
- if ($[33] !== actionSheetTitle || $[34] !== actions || $[35] !== from || $[36] !== hasActions || $[37] !== held || $[38] !== layout || $[39] !== longPress || $[40] !== longPressable || $[41] !== menu || $[42] !== merged || $[43] !== parts || $[44] !== pressing || $[45] !== props || $[46] !== sheetOpen || $[47] !== user) {
278
- t11 = 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={[{
282
+ if ($[32] !== children || $[33] !== t10 || $[34] !== t9) {
283
+ t11 = <>{t9}{children}{t10}</>;
284
+ $[32] = children;
285
+ $[33] = t10;
286
+ $[34] = t9;
287
+ $[35] = t11;
288
+ } else {
289
+ t11 = $[35];
290
+ }
291
+ const parts = t11;
292
+ 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={[{
279
295
  name: "longpress",
280
296
  label: actionSheetTitle ?? MESSAGE_ACTIONS_TITLE
281
297
  }]} onAccessibilityAction={event => {
282
298
  if (event.nativeEvent.actionName === "longpress") {
283
299
  longPress();
284
300
  }
285
- }} {...props}>{parts}</Pressable>{menu ? <MessageContextMenu open={held !== null} onClose={() => setHeld(null)} anchor={held?.anchor ?? null} align={user ? "end" : "start"} preview={<MessageContext.Provider value={from}><View className={merged} style={[layout, {
301
+ }} {...props}>{parts}</Pressable>{menu ? <MessageContextMenu open={held !== null} onClose={closeMenu} onDismissed={conversation?.settleOverlay} anchor={held?.anchor ?? null} align={user ? "end" : "start"} preview={<MessageContext.Provider value={from}><View className={merged} style={[layout, {
286
302
  maxWidth: "100%",
287
303
  width: "100%"
288
304
  }]}>{parts}</View></MessageContext.Provider>} menu={held?.menu ?? {
289
305
  actions: []
290
306
  }} /> : hasActions ? <MessageActionSheet open={sheetOpen} onClose={() => setSheetOpen(false)} actions={actions} title={actionSheetTitle} /> : null}</> : <View className={merged} style={layout} {...props}>{parts}</View>;
291
- $[33] = actionSheetTitle;
292
- $[34] = actions;
293
- $[35] = from;
294
- $[36] = hasActions;
295
- $[37] = held;
296
- $[38] = layout;
297
- $[39] = longPress;
298
- $[40] = longPressable;
299
- $[41] = menu;
300
- $[42] = merged;
301
- $[43] = parts;
302
- $[44] = pressing;
303
- $[45] = props;
304
- $[46] = sheetOpen;
305
- $[47] = user;
306
- $[48] = t11;
307
- } else {
308
- t11 = $[48];
307
+ $[36] = actionSheetTitle;
308
+ $[37] = actions;
309
+ $[38] = closeMenu;
310
+ $[39] = conversation?.settleOverlay;
311
+ $[40] = from;
312
+ $[41] = hasActions;
313
+ $[42] = held;
314
+ $[43] = layout;
315
+ $[44] = longPress;
316
+ $[45] = longPressable;
317
+ $[46] = menu;
318
+ $[47] = merged;
319
+ $[48] = parts;
320
+ $[49] = pressing;
321
+ $[50] = props;
322
+ $[51] = sheetOpen;
323
+ $[52] = user;
324
+ $[53] = t12;
325
+ } else {
326
+ t12 = $[53];
309
327
  }
310
- let t12;
311
- if ($[49] !== from || $[50] !== t11) {
312
- t12 = <MessageContext.Provider value={from}>{t11}</MessageContext.Provider>;
313
- $[49] = from;
314
- $[50] = t11;
315
- $[51] = t12;
328
+ let t13;
329
+ if ($[54] !== from || $[55] !== t12) {
330
+ t13 = <MessageContext.Provider value={from}>{t12}</MessageContext.Provider>;
331
+ $[54] = from;
332
+ $[55] = t12;
333
+ $[56] = t13;
316
334
  } else {
317
- t12 = $[51];
335
+ t13 = $[56];
318
336
  }
319
- return t12;
337
+ return t13;
320
338
  }
321
339
 
322
340
  /**
@@ -76,16 +76,18 @@ function StickyView(t0) {
76
76
  * end on either platform.
77
77
  */
78
78
  function ChatScrollView(t0) {
79
- const $ = _c(17);
79
+ const $ = _c(19);
80
80
  let bottomOffset;
81
81
  let onInsetChange;
82
82
  let onKeyboardMove;
83
83
  let props;
84
84
  let t1;
85
+ let t2;
85
86
  if ($[0] !== t0) {
86
87
  ({
87
88
  bottomOffset,
88
89
  inverted: t1,
90
+ freeze: t2,
89
91
  onInsetChange,
90
92
  onKeyboardMove,
91
93
  ...props
@@ -96,18 +98,21 @@ function ChatScrollView(t0) {
96
98
  $[3] = onKeyboardMove;
97
99
  $[4] = props;
98
100
  $[5] = t1;
101
+ $[6] = t2;
99
102
  } else {
100
103
  bottomOffset = $[1];
101
104
  onInsetChange = $[2];
102
105
  onKeyboardMove = $[3];
103
106
  props = $[4];
104
107
  t1 = $[5];
108
+ t2 = $[6];
105
109
  }
106
110
  const inverted = t1 === undefined ? false : t1;
107
- let t2;
111
+ const freeze = t2 === undefined ? false : t2;
108
112
  let t3;
109
- if ($[6] !== onKeyboardMove) {
110
- t2 = {
113
+ let t4;
114
+ if ($[7] !== onKeyboardMove) {
115
+ t3 = {
111
116
  onStart: () => {
112
117
  "worklet";
113
118
 
@@ -119,36 +124,37 @@ function ChatScrollView(t0) {
119
124
  runOnJS(onKeyboardMove)(false);
120
125
  }
121
126
  };
122
- t3 = [onKeyboardMove];
123
- $[6] = onKeyboardMove;
124
- $[7] = t2;
127
+ t4 = [onKeyboardMove];
128
+ $[7] = onKeyboardMove;
125
129
  $[8] = t3;
130
+ $[9] = t4;
126
131
  } else {
127
- t2 = $[7];
128
132
  t3 = $[8];
133
+ t4 = $[9];
129
134
  }
130
- useKeyboardHandler(t2, t3);
131
- let t4;
132
- if ($[9] !== inverted || $[10] !== onInsetChange) {
133
- t4 = insets => onInsetChange(inverted ? Platform.OS === "ios" ? insets.top : 0 : insets.bottom);
134
- $[9] = inverted;
135
- $[10] = onInsetChange;
136
- $[11] = t4;
135
+ useKeyboardHandler(t3, t4);
136
+ let t5;
137
+ if ($[10] !== inverted || $[11] !== onInsetChange) {
138
+ t5 = insets => onInsetChange(inverted ? Platform.OS === "ios" ? insets.top : 0 : insets.bottom);
139
+ $[10] = inverted;
140
+ $[11] = onInsetChange;
141
+ $[12] = t5;
137
142
  } else {
138
- t4 = $[11];
143
+ t5 = $[12];
139
144
  }
140
- let t5;
141
- if ($[12] !== bottomOffset || $[13] !== inverted || $[14] !== props || $[15] !== t4) {
142
- t5 = <KeyboardChatScrollView {...props} inverted={inverted} offset={bottomOffset} keyboardLiftBehavior="always" onContentInsetChange={t4} />;
143
- $[12] = bottomOffset;
144
- $[13] = inverted;
145
- $[14] = props;
146
- $[15] = t4;
147
- $[16] = t5;
145
+ let t6;
146
+ if ($[13] !== bottomOffset || $[14] !== freeze || $[15] !== inverted || $[16] !== props || $[17] !== t5) {
147
+ t6 = <KeyboardChatScrollView {...props} inverted={inverted} freeze={freeze} offset={bottomOffset} keyboardLiftBehavior="always" onContentInsetChange={t5} />;
148
+ $[13] = bottomOffset;
149
+ $[14] = freeze;
150
+ $[15] = inverted;
151
+ $[16] = props;
152
+ $[17] = t5;
153
+ $[18] = t6;
148
154
  } else {
149
- t5 = $[16];
155
+ t6 = $[18];
150
156
  }
151
- return t5;
157
+ return t6;
152
158
  }
153
159
 
154
160
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vvedantb/native-ui",
3
- "version": "0.25.1",
3
+ "version": "0.25.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",
@@ -0,0 +1,56 @@
1
+ import { createContext, useContext, type RefObject } from "react";
2
+ import type { NativeScrollEvent } from "react-native";
3
+
4
+ // The `Conversation` context on its own, so a message can reach it without the
5
+ // thread's components (`message.tsx` sets `overlay`).
6
+
7
+ /**
8
+ * What the thread scrolls with: the `ScrollView` of `ConversationContent` or
9
+ * the `FlatList` of `ConversationList`. `scrollToEnd` goes to the newest
10
+ * message, which is offset 0 in an inverted list. `scrollTo` goes to an
11
+ * offset; only the `ScrollView` has it, so call it as `scrollTo?.(...)`.
12
+ */
13
+ export type ConversationScroller = {
14
+ scrollToEnd: (options?: { animated?: boolean }) => void;
15
+ scrollTo?: (options: { y: number; animated?: boolean }) => void;
16
+ };
17
+
18
+ export type ConversationContextValue = {
19
+ isAtBottom: boolean;
20
+ scrollToBottom: () => void;
21
+ scrollRef: RefObject<ConversationScroller | null>;
22
+ /** `bottomInset` and `inverted`, as `isScrolledToBottom`. */
23
+ onScroll: (event: NativeScrollEvent, bottomInset?: number, inverted?: boolean) => void;
24
+ onUserScroll: () => void;
25
+ followContent: () => void;
26
+ /** The height of the `ConversationDock` under the thread, 0 without one. */
27
+ dockHeight: number;
28
+ setDockHeight: (height: number) => void;
29
+ /**
30
+ * A message's hold menu over the thread. Its window takes the focus on
31
+ * Android, as it opens and again as it closes, and the keyboard handler of
32
+ * `ConversationList` would scroll the thread to its end each time. The list
33
+ * ignores the keyboard from `openOverlay` until the close has settled:
34
+ * `closeOverlay` marks it `closing`, and `settleOverlay` ends that on the
35
+ * close's last keyboard event (Android), the menu's dismiss (iOS) or the
36
+ * reader's next drag. Android gives no dismiss callback for a `Modal`.
37
+ */
38
+ overlay: "none" | "open" | "closing";
39
+ openOverlay: () => void;
40
+ closeOverlay: () => void;
41
+ settleOverlay: () => void;
42
+ };
43
+
44
+ export const ConversationContext = createContext<ConversationContextValue | null>(null);
45
+
46
+ /** `isAtBottom` and `scrollToBottom` of the enclosing `Conversation`, for a custom scroll button. */
47
+ export function useConversation() {
48
+ const context = useContext(ConversationContext);
49
+ if (!context) throw new Error("Conversation parts must be used within Conversation");
50
+ return context;
51
+ }
52
+
53
+ /** The enclosing `Conversation`, or null for a message drawn outside one. */
54
+ export function useOptionalConversation() {
55
+ return useContext(ConversationContext);
56
+ }
@@ -1,13 +1,4 @@
1
- import {
2
- createContext,
3
- isValidElement,
4
- useContext,
5
- useRef,
6
- useState,
7
- type ComponentType,
8
- type ReactNode,
9
- type RefObject,
10
- } from "react";
1
+ import { isValidElement, useRef, useState, type ComponentType, type ReactNode } from "react";
11
2
  import {
12
3
  FlatList,
13
4
  Platform,
@@ -38,6 +29,7 @@ import { tokens } from "../tokens";
38
29
  import { useReduceMotion } from "../useReduceMotion";
39
30
  import { useScheme } from "../useScheme";
40
31
  import { chatTextSize } from "./chat-text";
32
+ import { ConversationContext, useConversation, type ConversationContextValue, type ConversationScroller } from "./conversation-context";
41
33
 
42
34
  /** Within this many points of the end, the thread counts as at the bottom and keeps following new content. */
43
35
  export const AT_BOTTOM_THRESHOLD = 70;
@@ -59,38 +51,7 @@ export function isScrolledToBottom(
59
51
  return contentSize.height + bottomInset - layoutMeasurement.height - contentOffset.y <= AT_BOTTOM_THRESHOLD;
60
52
  }
61
53
 
62
- /**
63
- * What the thread scrolls with: the `ScrollView` of `ConversationContent` or
64
- * the `FlatList` of `ConversationList`. `scrollToEnd` goes to the newest
65
- * message, which is offset 0 in an inverted list. `scrollTo` goes to an
66
- * offset; only the `ScrollView` has it, so call it as `scrollTo?.(...)`.
67
- */
68
- export type ConversationScroller = {
69
- scrollToEnd: (options?: { animated?: boolean }) => void;
70
- scrollTo?: (options: { y: number; animated?: boolean }) => void;
71
- };
72
-
73
- type ConversationContextValue = {
74
- isAtBottom: boolean;
75
- scrollToBottom: () => void;
76
- scrollRef: RefObject<ConversationScroller | null>;
77
- /** `bottomInset` and `inverted`, as `isScrolledToBottom`. */
78
- onScroll: (event: NativeScrollEvent, bottomInset?: number, inverted?: boolean) => void;
79
- onUserScroll: () => void;
80
- followContent: () => void;
81
- /** The height of the `ConversationDock` under the thread, 0 without one. */
82
- dockHeight: number;
83
- setDockHeight: (height: number) => void;
84
- };
85
-
86
- const ConversationContext = createContext<ConversationContextValue | null>(null);
87
-
88
- /** `isAtBottom` and `scrollToBottom` of the enclosing `Conversation`, for a custom scroll button. */
89
- export function useConversation() {
90
- const context = useContext(ConversationContext);
91
- if (!context) throw new Error("Conversation parts must be used within Conversation");
92
- return context;
93
- }
54
+ export { useConversation, useOptionalConversation, type ConversationScroller } from "./conversation-context";
94
55
 
95
56
  export type ConversationProps = ViewProps & { className?: string };
96
57
 
@@ -108,6 +69,7 @@ export function Conversation({ className, ...props }: ConversationProps) {
108
69
  const autoScrolling = useRef(false);
109
70
  const [isAtBottom, setIsAtBottom] = useState(true);
110
71
  const [dockHeight, setDockHeight] = useState(0);
72
+ const [overlay, setOverlay] = useState<ConversationContextValue["overlay"]>("none");
111
73
 
112
74
  const update = (next: boolean) => {
113
75
  atBottom.current = next;
@@ -137,6 +99,10 @@ export function Conversation({ className, ...props }: ConversationProps) {
137
99
  },
138
100
  dockHeight,
139
101
  setDockHeight,
102
+ overlay,
103
+ openOverlay: () => setOverlay("open"),
104
+ closeOverlay: () => setOverlay("closing"),
105
+ settleOverlay: () => setOverlay((current) => (current === "closing" ? "none" : current)),
140
106
  };
141
107
 
142
108
  return (
@@ -201,6 +167,7 @@ function useConversationScroll<P extends ConversationScrollHandlers>(
201
167
  },
202
168
  onScrollBeginDrag: (event: NativeSyntheticEvent<NativeScrollEvent>) => {
203
169
  conversation.onUserScroll();
170
+ conversation.settleOverlay();
204
171
  onScrollBeginDrag?.(event);
205
172
  },
206
173
  // The app's handler first, so a scroller that measures itself (`ConversationList`) has the new size to follow.
@@ -346,6 +313,7 @@ export function ConversationList<T>({
346
313
  <keyboard.ChatScrollView
347
314
  {...scrollProps}
348
315
  inverted={inverted}
316
+ freeze={conversation.overlay !== "none"}
349
317
  // The composer pads the bottom inset, which the keyboard covers: the content rises by the rest.
350
318
  bottomOffset={insets.bottom}
351
319
  onInsetChange={(inset) => {
@@ -353,6 +321,8 @@ export function ConversationList<T>({
353
321
  }}
354
322
  onKeyboardMove={(moving) => {
355
323
  size.current.keyboardMoving = moving;
324
+ // The closing menu's window hands the focus back with a keyboard event: frozen until it ends.
325
+ if (!moving) conversation.settleOverlay();
356
326
  }}
357
327
  />
358
328
  )
@@ -1,4 +1,4 @@
1
- import type { ReactNode } from "react";
1
+ import { useState, 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";
@@ -23,6 +23,7 @@ import { MESSAGE_MENU, messageContextMenuLayout, type MessageMenu, type MessageM
23
23
  export function MessageContextMenu({
24
24
  open,
25
25
  onClose,
26
+ onDismissed,
26
27
  anchor,
27
28
  align,
28
29
  preview,
@@ -31,6 +32,8 @@ export function MessageContextMenu({
31
32
  }: {
32
33
  open: boolean;
33
34
  onClose: () => void;
35
+ /** After the menu has gone from the screen (iOS; Android gives no such callback for a `Modal`). */
36
+ onDismissed?: () => void;
34
37
  /** The held message's box; the menu stays shut without one. */
35
38
  anchor: MessageMenuRect | null;
36
39
  /** Which side the pill and the card line up with: the message's (`end` for the user's). */
@@ -71,7 +74,7 @@ export function MessageContextMenu({
71
74
 
72
75
  return (
73
76
  // The Modal's own fade: Reanimated entering animations do not run inside a Modal on Android.
74
- <Modal visible transparent animationType={reduceMotion ? "none" : "fade"} statusBarTranslucent onRequestClose={onClose}>
77
+ <Modal visible transparent animationType={reduceMotion ? "none" : "fade"} statusBarTranslucent onRequestClose={onClose} onDismiss={onDismissed}>
75
78
  <View style={{ flex: 1 }} testID={testID} accessibilityViewIsModal onAccessibilityEscape={onClose}>
76
79
  <View style={StyleSheet.absoluteFill}>
77
80
  <Pressable
@@ -149,38 +152,79 @@ export function MessageContextMenu({
149
152
  ...shadow,
150
153
  }}
151
154
  >
152
- {menu.actions.map((action, index) => {
153
- const Icon = action.icon;
154
- const color = action.destructive ? palette.danger[scheme] : tokens.color.foreground[scheme];
155
- return (
156
- <Pressable
157
- key={action.key}
158
- testID={`${testID}-action-${action.key}`}
159
- accessibilityRole="menuitem"
160
- accessibilityLabel={action.label}
161
- accessibilityState={{ disabled: action.disabled === true }}
162
- disabled={action.disabled === true}
163
- onPress={() => run(action.onPress)}
164
- // A static style: with a `className`, NativeWind drops a style function.
165
- className="flex-row items-center gap-3 px-4 active:opacity-70"
166
- style={[
167
- { minHeight: rowHeight, opacity: action.disabled ? 0.5 : 1 },
168
- index > 0 && { borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: tokens.color.separator[scheme] },
169
- ]}
170
- >
171
- <Text
172
- numberOfLines={1}
173
- className={cn(body, "min-w-0 flex-1 font-instrument-sans")}
174
- style={[sizeStyle(body), typeStyle("medium"), { color }]}
175
- >
176
- {action.label}
177
- </Text>
178
- {Icon ? <Icon size={largerText ? 22 : 20} color={color} /> : null}
179
- </Pressable>
180
- );
181
- })}
155
+ {menu.actions.map((action, index) => (
156
+ <MenuCardRow
157
+ key={action.key}
158
+ testID={`${testID}-action-${action.key}`}
159
+ action={action}
160
+ first={index === 0}
161
+ rowHeight={rowHeight}
162
+ body={body}
163
+ iconSize={largerText ? 22 : 20}
164
+ onPress={() => run(action.onPress)}
165
+ />
166
+ ))}
182
167
  </View>
183
168
  </View>
184
169
  </Modal>
185
170
  );
186
171
  }
172
+
173
+ /**
174
+ * One card row: label first, icon last. While pressed it takes the
175
+ * `SheetRow` pressed fill, so the finger sees which row it is on.
176
+ */
177
+ function MenuCardRow({
178
+ testID,
179
+ action,
180
+ first,
181
+ rowHeight,
182
+ body,
183
+ iconSize,
184
+ onPress,
185
+ }: {
186
+ testID: string;
187
+ action: MessageMenu["actions"][number];
188
+ first: boolean;
189
+ rowHeight: number;
190
+ body: ReturnType<typeof chatTextSize>;
191
+ iconSize: number;
192
+ onPress: () => void;
193
+ }) {
194
+ const scheme = useScheme();
195
+ // A state, not a style function: with a `className`, NativeWind drops a style function.
196
+ const [pressed, setPressed] = useState(false);
197
+ const disabled = action.disabled === true;
198
+ const Icon = action.icon;
199
+ const color = action.destructive ? palette.danger[scheme] : tokens.color.foreground[scheme];
200
+ return (
201
+ <Pressable
202
+ testID={testID}
203
+ accessibilityRole="menuitem"
204
+ accessibilityLabel={action.label}
205
+ accessibilityState={{ disabled }}
206
+ disabled={disabled}
207
+ onPress={onPress}
208
+ onPressIn={() => setPressed(true)}
209
+ onPressOut={() => setPressed(false)}
210
+ className="flex-row items-center gap-3 px-4"
211
+ style={[
212
+ {
213
+ minHeight: rowHeight,
214
+ opacity: disabled ? 0.5 : 1,
215
+ backgroundColor: pressed && !disabled ? palette.default[scheme] : "transparent",
216
+ },
217
+ !first && { borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: tokens.color.separator[scheme] },
218
+ ]}
219
+ >
220
+ <Text
221
+ numberOfLines={1}
222
+ className={cn(body, "min-w-0 flex-1 font-instrument-sans")}
223
+ style={[sizeStyle(body), typeStyle("medium"), { color }]}
224
+ >
225
+ {action.label}
226
+ </Text>
227
+ {Icon ? <Icon size={iconSize} color={color} /> : null}
228
+ </Pressable>
229
+ );
230
+ }