@vvedantb/native-ui 0.24.2 → 0.25.0
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.
- package/dist/MenuSheet.jsx +164 -0
- package/dist/ReactionRow.jsx +84 -0
- package/dist/ai/index.js +2 -0
- package/dist/ai/message-context-menu.jsx +386 -0
- package/dist/ai/message-menu-layout.js +46 -0
- package/dist/ai/message.jsx +113 -69
- package/dist/entries/primitives.js +2 -0
- package/dist/index.js +2 -0
- package/package.json +1 -1
- package/src/MenuSheet.tsx +80 -0
- package/src/ReactionRow.tsx +70 -0
- package/src/ai/index.ts +3 -0
- package/src/ai/message-action-sheet.tsx +2 -0
- package/src/ai/message-context-menu.tsx +183 -0
- package/src/ai/message-menu-layout.ts +44 -0
- package/src/ai/message.tsx +52 -6
- package/src/entries/primitives.ts +4 -0
- package/src/index.ts +4 -0
package/dist/ai/message.jsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
2
|
+
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
4
4
|
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
5
5
|
import { IconArrowBackUp, IconCopy, IconRefresh, IconThumbDown, IconThumbUp } from "@tabler/icons-react-native";
|
|
6
6
|
import { cn } from "../cn";
|
|
7
|
+
import { impactHaptic } from "../haptics";
|
|
7
8
|
import { sizeStyle, typeStyle } from "../controlStyles";
|
|
8
9
|
import { palette, withAlpha } from "../palette";
|
|
9
10
|
import { useLargerText } from "../theme";
|
|
@@ -13,6 +14,7 @@ import { useScheme } from "../useScheme";
|
|
|
13
14
|
import { META_TEXT_STYLE, chatTextSize } from "./chat-text";
|
|
14
15
|
import { ChatIconButton } from "./icon-button";
|
|
15
16
|
import { MESSAGE_ACTIONS_TITLE, MessageActionSheet } from "./message-action-sheet";
|
|
17
|
+
import { MessageContextMenu } from "./message-context-menu";
|
|
16
18
|
import { ChatTextColorContext, ResponseText } from "./response-text";
|
|
17
19
|
const MessageContext = createContext("assistant");
|
|
18
20
|
|
|
@@ -104,19 +106,30 @@ function MessageHighlight() {
|
|
|
104
106
|
* at the start, its parts full width.
|
|
105
107
|
*
|
|
106
108
|
* With `onLongPress` or `actions` the message is a `Pressable` (same layout,
|
|
107
|
-
* `className`, `style` and view props)
|
|
109
|
+
* `className`, `style` and view props): a 350 ms hold shrinks it a little,
|
|
110
|
+
* fires a medium haptic, runs `onLongPress` and opens the
|
|
108
111
|
* `MessageActionSheet`; TalkBack reaches it as the `longpress` action. It stays
|
|
109
112
|
* a non-accessible container so its buttons and links keep their own focus:
|
|
110
113
|
* also offer the actions in a `MessageActionsBar` for screen reader users. `highlighted` draws the quote-jump highlight.
|
|
111
114
|
*/
|
|
115
|
+
/** How long a hold takes, in ms: shorter than React Native's 500, as iMessage. */
|
|
116
|
+
const HOLD_DELAY_MS = 350;
|
|
117
|
+
/** A held message: a little smaller and dimmer. */
|
|
118
|
+
const HELD_STYLE = {
|
|
119
|
+
transform: [{
|
|
120
|
+
scale: 0.98
|
|
121
|
+
}],
|
|
122
|
+
opacity: 0.9
|
|
123
|
+
};
|
|
112
124
|
export function Message(t0) {
|
|
113
|
-
const $ = _c(
|
|
125
|
+
const $ = _c(52);
|
|
114
126
|
let actionSheetTitle;
|
|
115
127
|
let actions;
|
|
116
128
|
let bot;
|
|
117
129
|
let children;
|
|
118
130
|
let className;
|
|
119
131
|
let from;
|
|
132
|
+
let menu;
|
|
120
133
|
let onLongPress;
|
|
121
134
|
let props;
|
|
122
135
|
let style;
|
|
@@ -127,6 +140,7 @@ export function Message(t0) {
|
|
|
127
140
|
className,
|
|
128
141
|
style,
|
|
129
142
|
onLongPress,
|
|
143
|
+
menu,
|
|
130
144
|
actions,
|
|
131
145
|
actionSheetTitle,
|
|
132
146
|
highlighted: t1,
|
|
@@ -141,10 +155,11 @@ export function Message(t0) {
|
|
|
141
155
|
$[4] = children;
|
|
142
156
|
$[5] = className;
|
|
143
157
|
$[6] = from;
|
|
144
|
-
$[7] =
|
|
145
|
-
$[8] =
|
|
146
|
-
$[9] =
|
|
147
|
-
$[10] =
|
|
158
|
+
$[7] = menu;
|
|
159
|
+
$[8] = onLongPress;
|
|
160
|
+
$[9] = props;
|
|
161
|
+
$[10] = style;
|
|
162
|
+
$[11] = t1;
|
|
148
163
|
} else {
|
|
149
164
|
actionSheetTitle = $[1];
|
|
150
165
|
actions = $[2];
|
|
@@ -152,124 +167,153 @@ export function Message(t0) {
|
|
|
152
167
|
children = $[4];
|
|
153
168
|
className = $[5];
|
|
154
169
|
from = $[6];
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
menu = $[7];
|
|
171
|
+
onLongPress = $[8];
|
|
172
|
+
props = $[9];
|
|
173
|
+
style = $[10];
|
|
174
|
+
t1 = $[11];
|
|
159
175
|
}
|
|
160
176
|
const highlighted = t1 === undefined ? false : t1;
|
|
161
177
|
const user = from === "user";
|
|
162
178
|
const [sheetOpen, setSheetOpen] = useState(false);
|
|
179
|
+
const [pressing, setPressing] = useState(false);
|
|
180
|
+
const [held, setHeld] = useState(null);
|
|
181
|
+
const pressable = useRef(null);
|
|
163
182
|
const hasActions = actions != null && actions.length > 0;
|
|
164
|
-
const longPressable = onLongPress != null || hasActions;
|
|
183
|
+
const longPressable = onLongPress != null || hasActions || menu != null;
|
|
165
184
|
let t2;
|
|
166
|
-
if ($[
|
|
185
|
+
if ($[12] !== hasActions || $[13] !== menu || $[14] !== onLongPress) {
|
|
167
186
|
t2 = () => {
|
|
187
|
+
impactHaptic("medium");
|
|
168
188
|
onLongPress?.();
|
|
169
|
-
if (
|
|
170
|
-
|
|
189
|
+
if (menu) {
|
|
190
|
+
const built = menu();
|
|
191
|
+
pressable.current?.measureInWindow((x, y, width, height) => setHeld({
|
|
192
|
+
anchor: {
|
|
193
|
+
x,
|
|
194
|
+
y,
|
|
195
|
+
width,
|
|
196
|
+
height
|
|
197
|
+
},
|
|
198
|
+
menu: built
|
|
199
|
+
}));
|
|
200
|
+
} else {
|
|
201
|
+
if (hasActions) {
|
|
202
|
+
setSheetOpen(true);
|
|
203
|
+
}
|
|
171
204
|
}
|
|
172
205
|
};
|
|
173
|
-
$[
|
|
174
|
-
$[
|
|
175
|
-
$[
|
|
206
|
+
$[12] = hasActions;
|
|
207
|
+
$[13] = menu;
|
|
208
|
+
$[14] = onLongPress;
|
|
209
|
+
$[15] = t2;
|
|
176
210
|
} else {
|
|
177
|
-
t2 = $[
|
|
211
|
+
t2 = $[15];
|
|
178
212
|
}
|
|
179
213
|
const longPress = t2;
|
|
180
214
|
const t3 = user ? "flex-end" : "flex-start";
|
|
181
215
|
const t4 = user ? "flex-end" : "stretch";
|
|
182
216
|
let t5;
|
|
183
|
-
if ($[
|
|
217
|
+
if ($[16] !== t3 || $[17] !== t4) {
|
|
184
218
|
t5 = {
|
|
185
219
|
alignSelf: t3,
|
|
186
220
|
alignItems: t4
|
|
187
221
|
};
|
|
188
|
-
$[
|
|
189
|
-
$[
|
|
190
|
-
$[
|
|
222
|
+
$[16] = t3;
|
|
223
|
+
$[17] = t4;
|
|
224
|
+
$[18] = t5;
|
|
191
225
|
} else {
|
|
192
|
-
t5 = $[
|
|
226
|
+
t5 = $[18];
|
|
193
227
|
}
|
|
194
228
|
let t6;
|
|
195
|
-
if ($[
|
|
229
|
+
if ($[19] !== style || $[20] !== t5) {
|
|
196
230
|
t6 = [t5, style];
|
|
197
|
-
$[
|
|
198
|
-
$[
|
|
199
|
-
$[
|
|
231
|
+
$[19] = style;
|
|
232
|
+
$[20] = t5;
|
|
233
|
+
$[21] = t6;
|
|
200
234
|
} else {
|
|
201
|
-
t6 = $[
|
|
235
|
+
t6 = $[21];
|
|
202
236
|
}
|
|
203
237
|
const layout = t6;
|
|
204
238
|
let t7;
|
|
205
|
-
if ($[
|
|
239
|
+
if ($[22] !== className) {
|
|
206
240
|
t7 = cn("w-full max-w-[95%] gap-2", className);
|
|
207
|
-
$[
|
|
208
|
-
$[
|
|
241
|
+
$[22] = className;
|
|
242
|
+
$[23] = t7;
|
|
209
243
|
} else {
|
|
210
|
-
t7 = $[
|
|
244
|
+
t7 = $[23];
|
|
211
245
|
}
|
|
212
246
|
const merged = t7;
|
|
213
247
|
let t8;
|
|
214
|
-
if ($[
|
|
248
|
+
if ($[24] !== bot || $[25] !== user) {
|
|
215
249
|
t8 = bot && !user ? <MessageBotLabel name={bot.name} avatar={bot.avatar} /> : null;
|
|
216
|
-
$[
|
|
217
|
-
$[
|
|
218
|
-
$[
|
|
250
|
+
$[24] = bot;
|
|
251
|
+
$[25] = user;
|
|
252
|
+
$[26] = t8;
|
|
219
253
|
} else {
|
|
220
|
-
t8 = $[
|
|
254
|
+
t8 = $[26];
|
|
221
255
|
}
|
|
222
256
|
let t9;
|
|
223
|
-
if ($[
|
|
257
|
+
if ($[27] !== highlighted) {
|
|
224
258
|
t9 = highlighted ? <MessageHighlight /> : null;
|
|
225
|
-
$[
|
|
226
|
-
$[
|
|
259
|
+
$[27] = highlighted;
|
|
260
|
+
$[28] = t9;
|
|
227
261
|
} else {
|
|
228
|
-
t9 = $[
|
|
262
|
+
t9 = $[28];
|
|
229
263
|
}
|
|
230
264
|
let t10;
|
|
231
|
-
if ($[
|
|
265
|
+
if ($[29] !== children || $[30] !== t8 || $[31] !== t9) {
|
|
232
266
|
t10 = <>{t8}{children}{t9}</>;
|
|
233
|
-
$[
|
|
234
|
-
$[
|
|
235
|
-
$[
|
|
236
|
-
$[
|
|
267
|
+
$[29] = children;
|
|
268
|
+
$[30] = t8;
|
|
269
|
+
$[31] = t9;
|
|
270
|
+
$[32] = t10;
|
|
237
271
|
} else {
|
|
238
|
-
t10 = $[
|
|
272
|
+
t10 = $[32];
|
|
239
273
|
}
|
|
240
274
|
const parts = t10;
|
|
241
275
|
let t11;
|
|
242
|
-
if ($[
|
|
243
|
-
t11 = longPressable ? <><Pressable accessible={false} className={merged} style={layout} onLongPress={longPress} accessibilityActions={[{
|
|
276
|
+
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) {
|
|
277
|
+
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={[{
|
|
244
278
|
name: "longpress",
|
|
245
279
|
label: actionSheetTitle ?? MESSAGE_ACTIONS_TITLE
|
|
246
280
|
}]} onAccessibilityAction={event => {
|
|
247
281
|
if (event.nativeEvent.actionName === "longpress") {
|
|
248
282
|
longPress();
|
|
249
283
|
}
|
|
250
|
-
}} {...props}>{parts}</Pressable>{
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
$[
|
|
257
|
-
$[
|
|
258
|
-
$[
|
|
259
|
-
$[
|
|
260
|
-
$[
|
|
261
|
-
$[
|
|
262
|
-
|
|
263
|
-
|
|
284
|
+
}} {...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, {
|
|
285
|
+
maxWidth: "100%",
|
|
286
|
+
width: "100%"
|
|
287
|
+
}]}>{parts}</View></MessageContext.Provider>} menu={held?.menu ?? {
|
|
288
|
+
actions: []
|
|
289
|
+
}} /> : hasActions ? <MessageActionSheet open={sheetOpen} onClose={() => setSheetOpen(false)} actions={actions} title={actionSheetTitle} /> : null}</> : <View className={merged} style={layout} {...props}>{parts}</View>;
|
|
290
|
+
$[33] = actionSheetTitle;
|
|
291
|
+
$[34] = actions;
|
|
292
|
+
$[35] = from;
|
|
293
|
+
$[36] = hasActions;
|
|
294
|
+
$[37] = held;
|
|
295
|
+
$[38] = layout;
|
|
296
|
+
$[39] = longPress;
|
|
297
|
+
$[40] = longPressable;
|
|
298
|
+
$[41] = menu;
|
|
299
|
+
$[42] = merged;
|
|
300
|
+
$[43] = parts;
|
|
301
|
+
$[44] = pressing;
|
|
302
|
+
$[45] = props;
|
|
303
|
+
$[46] = sheetOpen;
|
|
304
|
+
$[47] = user;
|
|
305
|
+
$[48] = t11;
|
|
306
|
+
} else {
|
|
307
|
+
t11 = $[48];
|
|
264
308
|
}
|
|
265
309
|
let t12;
|
|
266
|
-
if ($[
|
|
310
|
+
if ($[49] !== from || $[50] !== t11) {
|
|
267
311
|
t12 = <MessageContext.Provider value={from}>{t11}</MessageContext.Provider>;
|
|
268
|
-
$[
|
|
269
|
-
$[
|
|
270
|
-
$[
|
|
312
|
+
$[49] = from;
|
|
313
|
+
$[50] = t11;
|
|
314
|
+
$[51] = t12;
|
|
271
315
|
} else {
|
|
272
|
-
t12 = $[
|
|
316
|
+
t12 = $[51];
|
|
273
317
|
}
|
|
274
318
|
return t12;
|
|
275
319
|
}
|
|
@@ -19,6 +19,8 @@ export { ColorSwatches } from "../ColorSwatches";
|
|
|
19
19
|
export { StatGrid } from "../StatGrid";
|
|
20
20
|
export { SectionLabel } from "../SectionLabel";
|
|
21
21
|
export { SheetRow } from "../SheetRow";
|
|
22
|
+
export { MenuSheet, SubmenuRow, MenuDivider } from "../MenuSheet";
|
|
23
|
+
export { ReactionRow } from "../ReactionRow";
|
|
22
24
|
export { PageIndicator } from "../PageIndicator";
|
|
23
25
|
export { IconButton } from "../IconButton";
|
|
24
26
|
export { Stepper } from "../Stepper";
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,8 @@ export { ColorSwatches } from "./ColorSwatches";
|
|
|
27
27
|
export { StatGrid } from "./StatGrid";
|
|
28
28
|
export { SectionLabel } from "./SectionLabel";
|
|
29
29
|
export { SheetRow } from "./SheetRow";
|
|
30
|
+
export { MenuSheet, SubmenuRow, MenuDivider } from "./MenuSheet";
|
|
31
|
+
export { ReactionRow } from "./ReactionRow";
|
|
30
32
|
export { PageIndicator } from "./PageIndicator";
|
|
31
33
|
export { IconButton } from "./IconButton";
|
|
32
34
|
export { Stepper } from "./Stepper";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/native-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
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,80 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
import { Pressable, View } from "react-native";
|
|
3
|
+
import { IconChevronLeft, IconChevronRight, type IconProps } from "@tabler/icons-react-native";
|
|
4
|
+
import { Sheet, SheetBody, SheetContent, SheetHeader, SheetTitle } from "./Sheet";
|
|
5
|
+
import { SheetRow } from "./SheetRow";
|
|
6
|
+
import { tokens } from "./tokens";
|
|
7
|
+
import { useScheme } from "./useScheme";
|
|
8
|
+
|
|
9
|
+
export type MenuSheetProps = {
|
|
10
|
+
open: boolean;
|
|
11
|
+
onOpenChange: (open: boolean) => void;
|
|
12
|
+
title: string;
|
|
13
|
+
/** Set on a submenu page: the header gets a 44 back button to the root page. */
|
|
14
|
+
onBack?: () => void;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
testID?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A dropdown or context menu as one bottom sheet: a title, then `SheetRow`s
|
|
21
|
+
* with no gap between them, `MenuDivider`s between groups. With submenus, the
|
|
22
|
+
* root page lists the items, a `SubmenuRow` swaps the sheet to its page, and
|
|
23
|
+
* that page's header has a back button (`onBack`) to the root.
|
|
24
|
+
*/
|
|
25
|
+
export function MenuSheet({ open, onOpenChange, title, onBack, children, testID }: MenuSheetProps) {
|
|
26
|
+
const muted = tokens.color.muted[useScheme()];
|
|
27
|
+
return (
|
|
28
|
+
<Sheet open={open} onOpenChange={onOpenChange}>
|
|
29
|
+
<SheetContent className="gap-3 px-3" testID={testID}>
|
|
30
|
+
<SheetHeader className="min-h-11 flex-row items-center gap-1 px-2">
|
|
31
|
+
{onBack ? (
|
|
32
|
+
<Pressable
|
|
33
|
+
accessibilityRole="button"
|
|
34
|
+
accessibilityLabel="Back"
|
|
35
|
+
onPress={onBack}
|
|
36
|
+
className="-ml-2 h-11 w-11 items-center justify-center rounded-lg active:opacity-70"
|
|
37
|
+
>
|
|
38
|
+
<IconChevronLeft size={20} color={muted} />
|
|
39
|
+
</Pressable>
|
|
40
|
+
) : null}
|
|
41
|
+
<SheetTitle numberOfLines={1} className="min-w-0 flex-1">
|
|
42
|
+
{title}
|
|
43
|
+
</SheetTitle>
|
|
44
|
+
</SheetHeader>
|
|
45
|
+
<SheetBody>{children}</SheetBody>
|
|
46
|
+
</SheetContent>
|
|
47
|
+
</Sheet>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type SubmenuRowProps = {
|
|
52
|
+
icon?: ComponentType<IconProps>;
|
|
53
|
+
/** At the start in place of `icon`, such as a coloured status mark. */
|
|
54
|
+
leading?: ReactNode;
|
|
55
|
+
title: string;
|
|
56
|
+
detail?: string;
|
|
57
|
+
disabled?: boolean;
|
|
58
|
+
onPress: () => void;
|
|
59
|
+
testID?: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** A root-page item that opens a submenu: a `SheetRow` with a chevron at the end. */
|
|
63
|
+
export function SubmenuRow({ icon, leading, title, detail, disabled, onPress, testID }: SubmenuRowProps) {
|
|
64
|
+
const muted = tokens.color.muted[useScheme()];
|
|
65
|
+
return (
|
|
66
|
+
<View className="flex-row items-center">
|
|
67
|
+
<View className="min-w-0 flex-1">
|
|
68
|
+
<SheetRow icon={icon} leading={leading} title={title} detail={detail} disabled={disabled} onPress={onPress} testID={testID} />
|
|
69
|
+
</View>
|
|
70
|
+
<View className="absolute right-4" style={{ pointerEvents: "none", opacity: disabled ? 0.5 : 1 }}>
|
|
71
|
+
<IconChevronRight size={16} color={muted} />
|
|
72
|
+
</View>
|
|
73
|
+
</View>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** The web `DropdownMenuSeparator` between groups of menu rows. */
|
|
78
|
+
export function MenuDivider() {
|
|
79
|
+
return <View className="mx-4 my-1 h-px" style={{ backgroundColor: tokens.color.border[useScheme()] }} />;
|
|
80
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { Pressable, View } from "react-native";
|
|
3
|
+
import { palette, withAlpha } from "./palette";
|
|
4
|
+
import { useScheme } from "./useScheme";
|
|
5
|
+
|
|
6
|
+
/** One round toggle: its key, its screen-reader label, its content (an emoji `Text` or an icon) and whether it is on. */
|
|
7
|
+
export type ReactionRowItem = {
|
|
8
|
+
key: string;
|
|
9
|
+
label: string;
|
|
10
|
+
selected?: boolean;
|
|
11
|
+
/** The content, given whether it is on, so an icon can switch to its filled form or colour. */
|
|
12
|
+
render: (selected: boolean) => ReactNode;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ReactionRowProps = {
|
|
16
|
+
items: readonly ReactionRowItem[];
|
|
17
|
+
onPress: (key: string) => void;
|
|
18
|
+
/**
|
|
19
|
+
* How an item that is on looks. `"tint"` (default): the primary at 12%,
|
|
20
|
+
* for emoji, which a dark fill would hide. `"solid"`: the primary fill,
|
|
21
|
+
* for icons, whose colour the caller sets with `render`.
|
|
22
|
+
*/
|
|
23
|
+
selectedStyle?: "tint" | "solid";
|
|
24
|
+
/** `"spread"` (default) shares the width, as a reaction bar; `"start"` packs them at the start. */
|
|
25
|
+
layout?: "spread" | "start";
|
|
26
|
+
/** After the items: a round button with the same look, such as "More reactions". */
|
|
27
|
+
trailing?: { label: string; icon: ReactNode; onPress: () => void };
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The quick reactions at the top of a hold menu (`MenuSheet`): round 44
|
|
32
|
+
* toggles, each one on or off. Emoji reactions use the tint, a reply's
|
|
33
|
+
* thumbs the solid fill.
|
|
34
|
+
*/
|
|
35
|
+
export function ReactionRow({ items, onPress, selectedStyle = "tint", layout = "spread", trailing }: ReactionRowProps) {
|
|
36
|
+
const scheme = useScheme();
|
|
37
|
+
const fill = (selected: boolean) =>
|
|
38
|
+
!selected ? palette.default[scheme] : selectedStyle === "solid" ? palette.primary[scheme] : withAlpha(palette.primary[scheme], 0.12);
|
|
39
|
+
return (
|
|
40
|
+
<View className={layout === "spread" ? "flex-row justify-between px-2 pb-2" : "flex-row gap-3 px-4 py-2"}>
|
|
41
|
+
{items.map((item) => {
|
|
42
|
+
const selected = item.selected === true;
|
|
43
|
+
return (
|
|
44
|
+
<Pressable
|
|
45
|
+
key={item.key}
|
|
46
|
+
accessibilityRole="button"
|
|
47
|
+
accessibilityLabel={item.label}
|
|
48
|
+
accessibilityState={{ selected }}
|
|
49
|
+
onPress={() => onPress(item.key)}
|
|
50
|
+
className="size-11 items-center justify-center rounded-full active:opacity-70"
|
|
51
|
+
style={{ backgroundColor: fill(selected) }}
|
|
52
|
+
>
|
|
53
|
+
{item.render(selected)}
|
|
54
|
+
</Pressable>
|
|
55
|
+
);
|
|
56
|
+
})}
|
|
57
|
+
{trailing ? (
|
|
58
|
+
<Pressable
|
|
59
|
+
accessibilityRole="button"
|
|
60
|
+
accessibilityLabel={trailing.label}
|
|
61
|
+
onPress={trailing.onPress}
|
|
62
|
+
className="size-11 items-center justify-center rounded-full active:opacity-70"
|
|
63
|
+
style={{ backgroundColor: fill(false) }}
|
|
64
|
+
>
|
|
65
|
+
{trailing.icon}
|
|
66
|
+
</Pressable>
|
|
67
|
+
) : null}
|
|
68
|
+
</View>
|
|
69
|
+
);
|
|
70
|
+
}
|
package/src/ai/index.ts
CHANGED
|
@@ -60,6 +60,9 @@ export type {
|
|
|
60
60
|
} from "./message";
|
|
61
61
|
export { MessageActionSheet } from "./message-action-sheet";
|
|
62
62
|
export type { MessageActionSheetProps, MessageSheetAction } from "./message-action-sheet";
|
|
63
|
+
export { MessageContextMenu } from "./message-context-menu";
|
|
64
|
+
export { messageContextMenuLayout, MESSAGE_MENU } from "./message-menu-layout";
|
|
65
|
+
export type { MessageMenu, MessageMenuRect } from "./message-menu-layout";
|
|
63
66
|
export { ReplyQuoteChip } from "./reply-quote-chip";
|
|
64
67
|
export type { ReplyQuoteChipProps } from "./reply-quote-chip";
|
|
65
68
|
export { MessageQuote, QUOTE_MAX_LINES } from "./message-quote";
|
|
@@ -20,6 +20,8 @@ export type MessageSheetAction = {
|
|
|
20
20
|
icon?: ComponentType<IconProps>;
|
|
21
21
|
/** Draws the row in the danger colour, such as Delete. */
|
|
22
22
|
destructive?: boolean;
|
|
23
|
+
/** Dims the row and ignores presses (the context menu's rows; the sheet leaves a disabled action out). */
|
|
24
|
+
disabled?: boolean;
|
|
23
25
|
onPress: () => void;
|
|
24
26
|
};
|
|
25
27
|
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { Modal, Pressable, StyleSheet, Text, View, useWindowDimensions } from "react-native";
|
|
3
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
4
|
+
import { cn } from "../cn";
|
|
5
|
+
import { sizeStyle, typeStyle } from "../controlStyles";
|
|
6
|
+
import { palette, withAlpha } from "../palette";
|
|
7
|
+
import { useLargerText } from "../theme";
|
|
8
|
+
import { tokens } from "../tokens";
|
|
9
|
+
import { useReduceMotion } from "../useReduceMotion";
|
|
10
|
+
import { useScheme } from "../useScheme";
|
|
11
|
+
import { chatTextSize } from "./chat-text";
|
|
12
|
+
import { MESSAGE_MENU, messageContextMenuLayout, type MessageMenu, type MessageMenuRect } from "./message-menu-layout";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The iMessage hold menu for a chat message: the chat fades under a frosted
|
|
16
|
+
* wash of the screen colour, the held message stays in place,
|
|
17
|
+
* lifted, with the quick reactions in a pill above it and the actions in a
|
|
18
|
+
* card below it, label first and icon last. It fades in and out as one (the
|
|
19
|
+
* Modal's own fade; with Reduce Motion on, it appears at once). A tap outside, Android back
|
|
20
|
+
* or the VoiceOver escape closes it; an action or a reaction closes it, then
|
|
21
|
+
* runs. `Message` opens it with `menu`.
|
|
22
|
+
*/
|
|
23
|
+
export function MessageContextMenu({
|
|
24
|
+
open,
|
|
25
|
+
onClose,
|
|
26
|
+
anchor,
|
|
27
|
+
align,
|
|
28
|
+
preview,
|
|
29
|
+
menu,
|
|
30
|
+
testID = "message-context-menu",
|
|
31
|
+
}: {
|
|
32
|
+
open: boolean;
|
|
33
|
+
onClose: () => void;
|
|
34
|
+
/** The held message's box; the menu stays shut without one. */
|
|
35
|
+
anchor: MessageMenuRect | null;
|
|
36
|
+
/** Which side the pill and the card line up with: the message's (`end` for the user's). */
|
|
37
|
+
align: "start" | "end";
|
|
38
|
+
/** The message, drawn again over the blur. */
|
|
39
|
+
preview: ReactNode;
|
|
40
|
+
menu: MessageMenu;
|
|
41
|
+
testID?: string;
|
|
42
|
+
}) {
|
|
43
|
+
const scheme = useScheme();
|
|
44
|
+
const window = useWindowDimensions();
|
|
45
|
+
const insets = useSafeAreaInsets();
|
|
46
|
+
const largerText = useLargerText();
|
|
47
|
+
const reduceMotion = useReduceMotion();
|
|
48
|
+
const rowHeight = largerText ? 56 : 48;
|
|
49
|
+
const body = chatTextSize("body", largerText);
|
|
50
|
+
if (!open || anchor === null) return null;
|
|
51
|
+
|
|
52
|
+
const layout = messageContextMenuLayout({
|
|
53
|
+
anchor,
|
|
54
|
+
window,
|
|
55
|
+
insets,
|
|
56
|
+
menuHeight: menu.actions.length * rowHeight,
|
|
57
|
+
hasReactions: menu.reactions !== undefined,
|
|
58
|
+
});
|
|
59
|
+
const run = (action: () => void) => {
|
|
60
|
+
onClose();
|
|
61
|
+
action();
|
|
62
|
+
};
|
|
63
|
+
// The pill and the card line up with the message's side, kept on screen.
|
|
64
|
+
const side = (width: number) =>
|
|
65
|
+
align === "end"
|
|
66
|
+
? { left: Math.max(MESSAGE_MENU.edge, Math.min(anchor.x + anchor.width, window.width - MESSAGE_MENU.edge) - width) }
|
|
67
|
+
: { left: Math.max(MESSAGE_MENU.edge, Math.min(anchor.x, window.width - MESSAGE_MENU.edge - width)) };
|
|
68
|
+
const surface = tokens.color.surface[scheme];
|
|
69
|
+
const shadow = { shadowColor: "#000", shadowOpacity: 0.18, shadowRadius: 16, shadowOffset: { width: 0, height: 6 }, elevation: 8 };
|
|
70
|
+
const pillWidth = Math.min(window.width - 2 * MESSAGE_MENU.edge, (menu.reactions?.items.length ?? 0) * 48 + 16);
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
// 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}>
|
|
75
|
+
<View style={{ flex: 1 }} testID={testID} accessibilityViewIsModal onAccessibilityEscape={onClose}>
|
|
76
|
+
<View style={StyleSheet.absoluteFill}>
|
|
77
|
+
<Pressable
|
|
78
|
+
testID={`${testID}-backdrop`}
|
|
79
|
+
accessibilityRole="button"
|
|
80
|
+
accessibilityLabel="Close menu"
|
|
81
|
+
onPress={onClose}
|
|
82
|
+
// A frosted wash of the screen colour over the chat, as iMessage's blur reads: the `ai`
|
|
83
|
+
// entry reaches no optional peer, so it draws no `expo-blur`.
|
|
84
|
+
style={[StyleSheet.absoluteFill, { backgroundColor: withAlpha(tokens.color.background[scheme], 0.85) }]}
|
|
85
|
+
/>
|
|
86
|
+
</View>
|
|
87
|
+
{/* The held message, lifted: in place, a shadow under it, clipped when it is taller than the room. */}
|
|
88
|
+
<View
|
|
89
|
+
pointerEvents="none"
|
|
90
|
+
style={{
|
|
91
|
+
position: "absolute",
|
|
92
|
+
top: layout.previewTop,
|
|
93
|
+
left: anchor.x,
|
|
94
|
+
width: anchor.width,
|
|
95
|
+
height: layout.previewHeight,
|
|
96
|
+
overflow: "hidden",
|
|
97
|
+
...shadow,
|
|
98
|
+
}}
|
|
99
|
+
>
|
|
100
|
+
{preview}
|
|
101
|
+
</View>
|
|
102
|
+
{menu.reactions ? (
|
|
103
|
+
<View
|
|
104
|
+
accessibilityRole="toolbar"
|
|
105
|
+
style={{
|
|
106
|
+
position: "absolute",
|
|
107
|
+
top: layout.pillTop,
|
|
108
|
+
...side(pillWidth),
|
|
109
|
+
height: MESSAGE_MENU.pillHeight,
|
|
110
|
+
borderRadius: MESSAGE_MENU.pillHeight / 2,
|
|
111
|
+
backgroundColor: surface,
|
|
112
|
+
...shadow,
|
|
113
|
+
}}
|
|
114
|
+
className="flex-row items-center px-2"
|
|
115
|
+
>
|
|
116
|
+
{menu.reactions.items.map((item) => {
|
|
117
|
+
const selected = item.selected === true;
|
|
118
|
+
return (
|
|
119
|
+
<Pressable
|
|
120
|
+
key={item.key}
|
|
121
|
+
testID={`${testID}-reaction-${item.key}`}
|
|
122
|
+
accessibilityRole="button"
|
|
123
|
+
accessibilityLabel={item.label}
|
|
124
|
+
accessibilityState={{ selected }}
|
|
125
|
+
onPress={() => run(() => menu.reactions?.onPress(item.key))}
|
|
126
|
+
className="size-11 items-center justify-center rounded-full active:opacity-70"
|
|
127
|
+
style={{ marginHorizontal: 2, backgroundColor: selected ? withAlpha(palette.primary[scheme], 0.12) : "transparent" }}
|
|
128
|
+
>
|
|
129
|
+
{item.render(selected)}
|
|
130
|
+
</Pressable>
|
|
131
|
+
);
|
|
132
|
+
})}
|
|
133
|
+
</View>
|
|
134
|
+
) : null}
|
|
135
|
+
<View
|
|
136
|
+
accessibilityRole="menu"
|
|
137
|
+
style={{
|
|
138
|
+
position: "absolute",
|
|
139
|
+
top: layout.menuTop,
|
|
140
|
+
...side(MESSAGE_MENU.menuWidth),
|
|
141
|
+
width: MESSAGE_MENU.menuWidth,
|
|
142
|
+
maxWidth: window.width - 2 * MESSAGE_MENU.edge,
|
|
143
|
+
borderRadius: tokens.radius.card,
|
|
144
|
+
backgroundColor: surface,
|
|
145
|
+
overflow: "hidden",
|
|
146
|
+
...shadow,
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
{menu.actions.map((action, index) => {
|
|
150
|
+
const Icon = action.icon;
|
|
151
|
+
const color = action.destructive ? palette.danger[scheme] : tokens.color.foreground[scheme];
|
|
152
|
+
return (
|
|
153
|
+
<Pressable
|
|
154
|
+
key={action.key}
|
|
155
|
+
testID={`${testID}-action-${action.key}`}
|
|
156
|
+
accessibilityRole="menuitem"
|
|
157
|
+
accessibilityLabel={action.label}
|
|
158
|
+
accessibilityState={{ disabled: action.disabled === true }}
|
|
159
|
+
disabled={action.disabled === true}
|
|
160
|
+
onPress={() => run(action.onPress)}
|
|
161
|
+
// A static style: with a `className`, NativeWind drops a style function.
|
|
162
|
+
className="flex-row items-center gap-3 px-4 active:opacity-70"
|
|
163
|
+
style={[
|
|
164
|
+
{ minHeight: rowHeight, opacity: action.disabled ? 0.5 : 1 },
|
|
165
|
+
index > 0 && { borderTopWidth: StyleSheet.hairlineWidth, borderTopColor: tokens.color.separator[scheme] },
|
|
166
|
+
]}
|
|
167
|
+
>
|
|
168
|
+
<Text
|
|
169
|
+
numberOfLines={1}
|
|
170
|
+
className={cn(body, "min-w-0 flex-1 font-instrument-sans")}
|
|
171
|
+
style={[sizeStyle(body), typeStyle("medium"), { color }]}
|
|
172
|
+
>
|
|
173
|
+
{action.label}
|
|
174
|
+
</Text>
|
|
175
|
+
{Icon ? <Icon size={largerText ? 22 : 20} color={color} /> : null}
|
|
176
|
+
</Pressable>
|
|
177
|
+
);
|
|
178
|
+
})}
|
|
179
|
+
</View>
|
|
180
|
+
</View>
|
|
181
|
+
</Modal>
|
|
182
|
+
);
|
|
183
|
+
}
|