@vvedantb/native-ui 0.24.1 → 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.
@@ -0,0 +1,386 @@
1
+ import { c as _c } from "react/compiler-runtime";
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 } 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(t0) {
24
+ const $ = _c(102);
25
+ const {
26
+ open,
27
+ onClose,
28
+ anchor,
29
+ align,
30
+ preview,
31
+ menu,
32
+ testID: t1
33
+ } = t0;
34
+ const testID = t1 === undefined ? "message-context-menu" : t1;
35
+ const scheme = useScheme();
36
+ const window = useWindowDimensions();
37
+ const insets = useSafeAreaInsets();
38
+ const largerText = useLargerText();
39
+ const reduceMotion = useReduceMotion();
40
+ const rowHeight = largerText ? 56 : 48;
41
+ let T0;
42
+ let T1;
43
+ let T2;
44
+ let t10;
45
+ let t11;
46
+ let t12;
47
+ let t13;
48
+ let t14;
49
+ let t15;
50
+ let t16;
51
+ let t17;
52
+ let t2;
53
+ let t3;
54
+ let t4;
55
+ let t5;
56
+ let t6;
57
+ let t7;
58
+ let t8;
59
+ let t9;
60
+ if ($[0] !== align || $[1] !== anchor || $[2] !== insets || $[3] !== largerText || $[4] !== menu || $[5] !== onClose || $[6] !== open || $[7] !== preview || $[8] !== reduceMotion || $[9] !== rowHeight || $[10] !== scheme || $[11] !== testID || $[12] !== window) {
61
+ t17 = Symbol.for("react.early_return_sentinel");
62
+ bb0: {
63
+ const body = chatTextSize("body", largerText);
64
+ if (!open || anchor === null) {
65
+ t17 = null;
66
+ break bb0;
67
+ }
68
+ const t18 = menu.actions.length * rowHeight;
69
+ const t19 = menu.reactions !== undefined;
70
+ let t20;
71
+ if ($[32] !== anchor || $[33] !== insets || $[34] !== t18 || $[35] !== t19 || $[36] !== window) {
72
+ t20 = messageContextMenuLayout({
73
+ anchor,
74
+ window,
75
+ insets,
76
+ menuHeight: t18,
77
+ hasReactions: t19
78
+ });
79
+ $[32] = anchor;
80
+ $[33] = insets;
81
+ $[34] = t18;
82
+ $[35] = t19;
83
+ $[36] = window;
84
+ $[37] = t20;
85
+ } else {
86
+ t20 = $[37];
87
+ }
88
+ const layout = t20;
89
+ let t21;
90
+ if ($[38] !== onClose) {
91
+ t21 = action => {
92
+ onClose();
93
+ action();
94
+ };
95
+ $[38] = onClose;
96
+ $[39] = t21;
97
+ } else {
98
+ t21 = $[39];
99
+ }
100
+ const run = t21;
101
+ let t22;
102
+ if ($[40] !== align || $[41] !== anchor.width || $[42] !== anchor.x || $[43] !== window.width) {
103
+ t22 = width => align === "end" ? {
104
+ left: Math.max(MESSAGE_MENU.edge, Math.min(anchor.x + anchor.width, window.width - MESSAGE_MENU.edge) - width)
105
+ } : {
106
+ left: Math.max(MESSAGE_MENU.edge, Math.min(anchor.x, window.width - MESSAGE_MENU.edge - width))
107
+ };
108
+ $[40] = align;
109
+ $[41] = anchor.width;
110
+ $[42] = anchor.x;
111
+ $[43] = window.width;
112
+ $[44] = t22;
113
+ } else {
114
+ t22 = $[44];
115
+ }
116
+ const side = t22;
117
+ const surface = tokens.color.surface[scheme];
118
+ let t23;
119
+ if ($[45] === Symbol.for("react.memo_cache_sentinel")) {
120
+ t23 = {
121
+ shadowColor: "#000",
122
+ shadowOpacity: 0.18,
123
+ shadowRadius: 16,
124
+ shadowOffset: {
125
+ width: 0,
126
+ height: 6
127
+ },
128
+ elevation: 8
129
+ };
130
+ $[45] = t23;
131
+ } else {
132
+ t23 = $[45];
133
+ }
134
+ const shadow = t23;
135
+ const pillWidth = Math.min(window.width - 2 * MESSAGE_MENU.edge, (menu.reactions?.items.length ?? 0) * 48 + 16);
136
+ T2 = Modal;
137
+ t12 = true;
138
+ t13 = true;
139
+ t14 = reduceMotion ? "none" : "fade";
140
+ t15 = true;
141
+ t16 = onClose;
142
+ T1 = View;
143
+ if ($[46] === Symbol.for("react.memo_cache_sentinel")) {
144
+ t5 = {
145
+ flex: 1
146
+ };
147
+ $[46] = t5;
148
+ } else {
149
+ t5 = $[46];
150
+ }
151
+ t6 = testID;
152
+ t7 = true;
153
+ t8 = onClose;
154
+ const t24 = `${testID}-backdrop`;
155
+ const t25 = tokens.color.background[scheme];
156
+ let t26;
157
+ if ($[47] !== t25) {
158
+ t26 = withAlpha(t25, 0.85);
159
+ $[47] = t25;
160
+ $[48] = t26;
161
+ } else {
162
+ t26 = $[48];
163
+ }
164
+ let t27;
165
+ if ($[49] !== t26) {
166
+ t27 = [StyleSheet.absoluteFill, {
167
+ backgroundColor: t26
168
+ }];
169
+ $[49] = t26;
170
+ $[50] = t27;
171
+ } else {
172
+ t27 = $[50];
173
+ }
174
+ if ($[51] !== onClose || $[52] !== t24 || $[53] !== t27) {
175
+ t9 = <View style={StyleSheet.absoluteFill}><Pressable testID={t24} accessibilityRole="button" accessibilityLabel="Close menu" onPress={onClose} style={t27} /></View>;
176
+ $[51] = onClose;
177
+ $[52] = t24;
178
+ $[53] = t27;
179
+ $[54] = t9;
180
+ } else {
181
+ t9 = $[54];
182
+ }
183
+ let t28;
184
+ if ($[55] !== anchor.width || $[56] !== anchor.x || $[57] !== layout.previewHeight || $[58] !== layout.previewTop) {
185
+ t28 = {
186
+ position: "absolute",
187
+ top: layout.previewTop,
188
+ left: anchor.x,
189
+ width: anchor.width,
190
+ height: layout.previewHeight,
191
+ overflow: "hidden",
192
+ ...shadow
193
+ };
194
+ $[55] = anchor.width;
195
+ $[56] = anchor.x;
196
+ $[57] = layout.previewHeight;
197
+ $[58] = layout.previewTop;
198
+ $[59] = t28;
199
+ } else {
200
+ t28 = $[59];
201
+ }
202
+ if ($[60] !== preview || $[61] !== t28) {
203
+ t10 = <View pointerEvents="none" style={t28}>{preview}</View>;
204
+ $[60] = preview;
205
+ $[61] = t28;
206
+ $[62] = t10;
207
+ } else {
208
+ t10 = $[62];
209
+ }
210
+ if ($[63] !== layout.pillTop || $[64] !== menu.reactions || $[65] !== pillWidth || $[66] !== run || $[67] !== scheme || $[68] !== side || $[69] !== surface || $[70] !== testID) {
211
+ t11 = menu.reactions ? <View accessibilityRole="toolbar" style={{
212
+ position: "absolute",
213
+ top: layout.pillTop,
214
+ ...side(pillWidth),
215
+ height: MESSAGE_MENU.pillHeight,
216
+ borderRadius: MESSAGE_MENU.pillHeight / 2,
217
+ backgroundColor: surface,
218
+ ...shadow
219
+ }} className="flex-row items-center px-2">{menu.reactions.items.map(item => {
220
+ const selected = item.selected === true;
221
+ return <Pressable key={item.key} testID={`${testID}-reaction-${item.key}`} accessibilityRole="button" accessibilityLabel={item.label} accessibilityState={{
222
+ selected
223
+ }} onPress={() => run(() => menu.reactions?.onPress(item.key))} className="size-11 items-center justify-center rounded-full active:opacity-70" style={{
224
+ marginHorizontal: 2,
225
+ backgroundColor: selected ? withAlpha(palette.primary[scheme], 0.12) : "transparent"
226
+ }}>{item.render(selected)}</Pressable>;
227
+ })}</View> : null;
228
+ $[63] = layout.pillTop;
229
+ $[64] = menu.reactions;
230
+ $[65] = pillWidth;
231
+ $[66] = run;
232
+ $[67] = scheme;
233
+ $[68] = side;
234
+ $[69] = surface;
235
+ $[70] = testID;
236
+ $[71] = t11;
237
+ } else {
238
+ t11 = $[71];
239
+ }
240
+ T0 = View;
241
+ t2 = "menu";
242
+ const t29 = layout.menuTop;
243
+ let t30;
244
+ if ($[72] !== side) {
245
+ t30 = side(MESSAGE_MENU.menuWidth);
246
+ $[72] = side;
247
+ $[73] = t30;
248
+ } else {
249
+ t30 = $[73];
250
+ }
251
+ const t31 = window.width - 2 * MESSAGE_MENU.edge;
252
+ if ($[74] !== layout.menuTop || $[75] !== surface || $[76] !== t30 || $[77] !== t31) {
253
+ t3 = {
254
+ position: "absolute",
255
+ top: t29,
256
+ ...t30,
257
+ width: MESSAGE_MENU.menuWidth,
258
+ maxWidth: t31,
259
+ borderRadius: tokens.radius.card,
260
+ backgroundColor: surface,
261
+ overflow: "hidden",
262
+ ...shadow
263
+ };
264
+ $[74] = layout.menuTop;
265
+ $[75] = surface;
266
+ $[76] = t30;
267
+ $[77] = t31;
268
+ $[78] = t3;
269
+ } else {
270
+ t3 = $[78];
271
+ }
272
+ t4 = menu.actions.map((action_0, index) => {
273
+ const Icon = action_0.icon;
274
+ const color = action_0.destructive ? palette.danger[scheme] : tokens.color.foreground[scheme];
275
+ return <Pressable key={action_0.key} testID={`${testID}-action-${action_0.key}`} accessibilityRole="menuitem" accessibilityLabel={action_0.label} accessibilityState={{
276
+ disabled: action_0.disabled === true
277
+ }} disabled={action_0.disabled === true} onPress={() => run(action_0.onPress)} className="flex-row items-center gap-3 px-4 active:opacity-70" style={[{
278
+ minHeight: rowHeight,
279
+ opacity: action_0.disabled ? 0.5 : 1
280
+ }, index > 0 && {
281
+ borderTopWidth: StyleSheet.hairlineWidth,
282
+ borderTopColor: tokens.color.separator[scheme]
283
+ }]}><Text numberOfLines={1} className={cn(body, "min-w-0 flex-1 font-instrument-sans")} style={[sizeStyle(body), typeStyle("medium"), {
284
+ color
285
+ }]}>{action_0.label}</Text>{Icon ? <Icon size={largerText ? 22 : 20} color={color} /> : null}</Pressable>;
286
+ });
287
+ }
288
+ $[0] = align;
289
+ $[1] = anchor;
290
+ $[2] = insets;
291
+ $[3] = largerText;
292
+ $[4] = menu;
293
+ $[5] = onClose;
294
+ $[6] = open;
295
+ $[7] = preview;
296
+ $[8] = reduceMotion;
297
+ $[9] = rowHeight;
298
+ $[10] = scheme;
299
+ $[11] = testID;
300
+ $[12] = window;
301
+ $[13] = T0;
302
+ $[14] = T1;
303
+ $[15] = T2;
304
+ $[16] = t10;
305
+ $[17] = t11;
306
+ $[18] = t12;
307
+ $[19] = t13;
308
+ $[20] = t14;
309
+ $[21] = t15;
310
+ $[22] = t16;
311
+ $[23] = t17;
312
+ $[24] = t2;
313
+ $[25] = t3;
314
+ $[26] = t4;
315
+ $[27] = t5;
316
+ $[28] = t6;
317
+ $[29] = t7;
318
+ $[30] = t8;
319
+ $[31] = t9;
320
+ } else {
321
+ T0 = $[13];
322
+ T1 = $[14];
323
+ T2 = $[15];
324
+ t10 = $[16];
325
+ t11 = $[17];
326
+ t12 = $[18];
327
+ t13 = $[19];
328
+ t14 = $[20];
329
+ t15 = $[21];
330
+ t16 = $[22];
331
+ t17 = $[23];
332
+ t2 = $[24];
333
+ t3 = $[25];
334
+ t4 = $[26];
335
+ t5 = $[27];
336
+ t6 = $[28];
337
+ t7 = $[29];
338
+ t8 = $[30];
339
+ t9 = $[31];
340
+ }
341
+ if (t17 !== Symbol.for("react.early_return_sentinel")) {
342
+ return t17;
343
+ }
344
+ let t18;
345
+ if ($[79] !== T0 || $[80] !== t2 || $[81] !== t3 || $[82] !== t4) {
346
+ t18 = <T0 accessibilityRole={t2} style={t3}>{t4}</T0>;
347
+ $[79] = T0;
348
+ $[80] = t2;
349
+ $[81] = t3;
350
+ $[82] = t4;
351
+ $[83] = t18;
352
+ } else {
353
+ t18 = $[83];
354
+ }
355
+ let t19;
356
+ if ($[84] !== T1 || $[85] !== t10 || $[86] !== t11 || $[87] !== t18 || $[88] !== t5 || $[89] !== t6 || $[90] !== t7 || $[91] !== t8 || $[92] !== t9) {
357
+ t19 = <T1 style={t5} testID={t6} accessibilityViewIsModal={t7} onAccessibilityEscape={t8}>{t9}{t10}{t11}{t18}</T1>;
358
+ $[84] = T1;
359
+ $[85] = t10;
360
+ $[86] = t11;
361
+ $[87] = t18;
362
+ $[88] = t5;
363
+ $[89] = t6;
364
+ $[90] = t7;
365
+ $[91] = t8;
366
+ $[92] = t9;
367
+ $[93] = t19;
368
+ } else {
369
+ t19 = $[93];
370
+ }
371
+ let t20;
372
+ if ($[94] !== T2 || $[95] !== t12 || $[96] !== t13 || $[97] !== t14 || $[98] !== t15 || $[99] !== t16 || $[100] !== t19) {
373
+ t20 = <T2 visible={t12} transparent={t13} animationType={t14} statusBarTranslucent={t15} onRequestClose={t16}>{t19}</T2>;
374
+ $[94] = T2;
375
+ $[95] = t12;
376
+ $[96] = t13;
377
+ $[97] = t14;
378
+ $[98] = t15;
379
+ $[99] = t16;
380
+ $[100] = t19;
381
+ $[101] = t20;
382
+ } else {
383
+ t20 = $[101];
384
+ }
385
+ return t20;
386
+ }
@@ -0,0 +1,46 @@
1
+ /** A view's box in window coordinates, from `measureInWindow`. */
2
+
3
+ /** What a held message offers: quick reactions above it, actions below it. */
4
+
5
+ /** The pill's height, the gap between the parts, the menu's width and the margin from the screen edges. */
6
+ export const MESSAGE_MENU = {
7
+ pillHeight: 52,
8
+ gap: 8,
9
+ menuWidth: 250,
10
+ edge: 12,
11
+ maxPreviewRatio: 0.4
12
+ };
13
+
14
+ /**
15
+ * Where the parts go: the message stays where it was held when the pill fits
16
+ * above it and the menu below it; else it moves just enough, and a message
17
+ * taller than `maxPreviewRatio` of the screen shows its top part only.
18
+ */
19
+ export function messageContextMenuLayout({
20
+ anchor,
21
+ window,
22
+ insets,
23
+ menuHeight,
24
+ hasReactions
25
+ }) {
26
+ const {
27
+ pillHeight,
28
+ gap,
29
+ edge,
30
+ maxPreviewRatio
31
+ } = MESSAGE_MENU;
32
+ const above = hasReactions ? pillHeight + gap : 0;
33
+ const below = gap + menuHeight;
34
+ const top = insets.top + edge;
35
+ const bottom = window.height - insets.bottom - edge;
36
+ const previewHeight = Math.max(0, Math.min(anchor.height, window.height * maxPreviewRatio, bottom - top - above - below));
37
+ const minTop = top + above;
38
+ const maxTop = bottom - below - previewHeight;
39
+ const previewTop = Math.min(Math.max(anchor.y, minTop), Math.max(minTop, maxTop));
40
+ return {
41
+ previewTop,
42
+ previewHeight,
43
+ pillTop: previewTop - above,
44
+ menuTop: previewTop + previewHeight + gap
45
+ };
46
+ }