@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.
- package/dist/DropdownMenu.jsx +245 -116
- package/dist/MenuSheet.jsx +164 -0
- package/dist/ReactionRow.jsx +84 -0
- package/dist/ai/index.js +2 -0
- package/dist/ai/message-action-sheet.jsx +182 -202
- 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/dist/motion.js +31 -0
- package/dist/primitives/overlay.jsx +162 -101
- package/package.json +1 -1
- package/src/DropdownMenu.tsx +71 -16
- 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 +92 -97
- 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/src/motion.ts +15 -0
- package/src/primitives/overlay.tsx +48 -8
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import * as Slot from "@rn-primitives/slot";
|
|
3
3
|
import { createContext, Fragment, useContext, useEffect, useState } from "react";
|
|
4
|
-
import { Modal, Pressable, StyleSheet
|
|
5
|
-
import Animated from "react-native-reanimated";
|
|
4
|
+
import { Modal, Pressable, StyleSheet } from "react-native";
|
|
5
|
+
import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
6
6
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
7
7
|
import { palette } from "../palette";
|
|
8
8
|
import { KeyboardAvoidingView, KeyboardLiftContext } from "./keyboard-parts";
|
|
9
|
+
import { DIALOG_ENTER, DIALOG_EXIT, PANEL_SCALE_FROM } from "../motion";
|
|
9
10
|
import { useReduceMotion } from "../useReduceMotion";
|
|
10
11
|
import { useScheme } from "../useScheme";
|
|
11
12
|
import { SheetDragProvider, SheetGestureContext, slideSheetIn, slideSheetOut, useSheetBackdropStyle, useSheetDragState } from "./sheet-drag";
|
|
@@ -152,7 +153,9 @@ export function OverlayClose(props) {
|
|
|
152
153
|
* RN `Modal` with a tinted backdrop, safe-area padding and keyboard avoidance
|
|
153
154
|
* (`KeyboardAvoidingView`: frame by frame with `KeyboardControllerProvider`).
|
|
154
155
|
* `placement="center"` centres the child (dialogs) inside the insets on every
|
|
155
|
-
* side
|
|
156
|
+
* side: the backdrop fades while the panel scales from 0.96 and fades in (200
|
|
157
|
+
* ms on open, 150 ms on close), and the `Modal` stays up until it is out of
|
|
158
|
+
* sight. `"bottom"` pins it to the bottom
|
|
156
159
|
* edge (sheets), which pad their own bottom inset: the sheet slides up on
|
|
157
160
|
* open and back down on close, however it closes, and may be dragged down to
|
|
158
161
|
* close (`SheetDragView`); the backdrop fades with the sheet's position. The
|
|
@@ -179,11 +182,12 @@ export function OverlayModal(t0) {
|
|
|
179
182
|
} = useOverlay(part);
|
|
180
183
|
const reduceMotion = useReduceMotion();
|
|
181
184
|
const slides = placement === "bottom" && !reduceMotion;
|
|
185
|
+
const scales = placement === "center" && !reduceMotion;
|
|
182
186
|
const [shown, setShown] = useState(open);
|
|
183
187
|
if (open && !shown) {
|
|
184
188
|
setShown(true);
|
|
185
189
|
}
|
|
186
|
-
if (!open && shown && !slides) {
|
|
190
|
+
if (!open && shown && !slides && !scales) {
|
|
187
191
|
setShown(false);
|
|
188
192
|
}
|
|
189
193
|
let t1;
|
|
@@ -196,61 +200,61 @@ export function OverlayModal(t0) {
|
|
|
196
200
|
}
|
|
197
201
|
const close = t1;
|
|
198
202
|
const ModalRoot = useContext(SheetGestureContext)?.ModalRoot ?? Fragment;
|
|
199
|
-
|
|
200
|
-
let t3;
|
|
203
|
+
let t2;
|
|
201
204
|
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
202
|
-
|
|
203
|
-
$[2] =
|
|
205
|
+
t2 = () => setShown(false);
|
|
206
|
+
$[2] = t2;
|
|
204
207
|
} else {
|
|
205
|
-
|
|
208
|
+
t2 = $[2];
|
|
206
209
|
}
|
|
207
|
-
let
|
|
208
|
-
if ($[3] !== children || $[4] !== close || $[5] !== dismissible || $[6] !== open || $[7] !== part || $[8] !== placement || $[9] !== slides) {
|
|
209
|
-
|
|
210
|
+
let t3;
|
|
211
|
+
if ($[3] !== children || $[4] !== close || $[5] !== dismissible || $[6] !== open || $[7] !== part || $[8] !== placement || $[9] !== scales || $[10] !== slides) {
|
|
212
|
+
t3 = <OverlayModalBody placement={placement} dismissible={dismissible} open={open} slides={slides} scales={scales} close={close} onHidden={t2} part={part}>{children}</OverlayModalBody>;
|
|
210
213
|
$[3] = children;
|
|
211
214
|
$[4] = close;
|
|
212
215
|
$[5] = dismissible;
|
|
213
216
|
$[6] = open;
|
|
214
217
|
$[7] = part;
|
|
215
218
|
$[8] = placement;
|
|
216
|
-
$[9] =
|
|
217
|
-
$[10] =
|
|
219
|
+
$[9] = scales;
|
|
220
|
+
$[10] = slides;
|
|
221
|
+
$[11] = t3;
|
|
218
222
|
} else {
|
|
219
|
-
|
|
223
|
+
t3 = $[11];
|
|
220
224
|
}
|
|
221
|
-
let
|
|
222
|
-
if ($[
|
|
223
|
-
|
|
224
|
-
$[
|
|
225
|
-
$[
|
|
226
|
-
$[
|
|
225
|
+
let t4;
|
|
226
|
+
if ($[12] !== ModalRoot || $[13] !== t3) {
|
|
227
|
+
t4 = <ModalRoot>{t3}</ModalRoot>;
|
|
228
|
+
$[12] = ModalRoot;
|
|
229
|
+
$[13] = t3;
|
|
230
|
+
$[14] = t4;
|
|
227
231
|
} else {
|
|
228
|
-
|
|
232
|
+
t4 = $[14];
|
|
229
233
|
}
|
|
230
|
-
let
|
|
231
|
-
if ($[
|
|
232
|
-
|
|
233
|
-
$[
|
|
234
|
-
$[
|
|
235
|
-
$[
|
|
236
|
-
$[
|
|
237
|
-
$[
|
|
238
|
-
$[19] = t6;
|
|
234
|
+
let t5;
|
|
235
|
+
if ($[15] !== close || $[16] !== onShow || $[17] !== shown || $[18] !== t4) {
|
|
236
|
+
t5 = <Modal visible={shown} transparent={true} animationType="none" statusBarTranslucent={true} onRequestClose={close} onShow={onShow}>{t4}</Modal>;
|
|
237
|
+
$[15] = close;
|
|
238
|
+
$[16] = onShow;
|
|
239
|
+
$[17] = shown;
|
|
240
|
+
$[18] = t4;
|
|
241
|
+
$[19] = t5;
|
|
239
242
|
} else {
|
|
240
|
-
|
|
243
|
+
t5 = $[19];
|
|
241
244
|
}
|
|
242
|
-
return
|
|
245
|
+
return t5;
|
|
243
246
|
}
|
|
244
247
|
|
|
245
248
|
/** The `Modal`'s content: mounted with each opening, so a sheet starts below the screen (or at rest). */
|
|
246
249
|
function OverlayModalBody(t0) {
|
|
247
|
-
const $ = _c(
|
|
250
|
+
const $ = _c(48);
|
|
248
251
|
const {
|
|
249
252
|
part,
|
|
250
253
|
placement,
|
|
251
254
|
dismissible,
|
|
252
255
|
open,
|
|
253
256
|
slides,
|
|
257
|
+
scales,
|
|
254
258
|
close,
|
|
255
259
|
onHidden,
|
|
256
260
|
children
|
|
@@ -258,7 +262,18 @@ function OverlayModalBody(t0) {
|
|
|
258
262
|
const scheme = useScheme();
|
|
259
263
|
const insets = useSafeAreaInsets();
|
|
260
264
|
const drag = useSheetDragState(close, slides);
|
|
261
|
-
const
|
|
265
|
+
const sheetBackdropStyle = useSheetBackdropStyle(drag);
|
|
266
|
+
const progress = useSharedValue(scales ? 0 : 1);
|
|
267
|
+
const centreBackdropStyle = useAnimatedStyle(() => ({
|
|
268
|
+
opacity: progress.get()
|
|
269
|
+
}));
|
|
270
|
+
const centrePanelStyle = useAnimatedStyle(() => ({
|
|
271
|
+
opacity: progress.get(),
|
|
272
|
+
transform: [{
|
|
273
|
+
scale: PANEL_SCALE_FROM + (1 - PANEL_SCALE_FROM) * progress.get()
|
|
274
|
+
}]
|
|
275
|
+
}));
|
|
276
|
+
const backdropStyle = placement === "center" ? centreBackdropStyle : sheetBackdropStyle;
|
|
262
277
|
let t1;
|
|
263
278
|
if ($[0] !== drag || $[1] !== onHidden || $[2] !== open || $[3] !== slides) {
|
|
264
279
|
t1 = () => {
|
|
@@ -289,51 +304,87 @@ function OverlayModalBody(t0) {
|
|
|
289
304
|
t2 = $[7];
|
|
290
305
|
}
|
|
291
306
|
useEffect(t1, t2);
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
307
|
+
let t3;
|
|
308
|
+
if ($[8] !== onHidden || $[9] !== open || $[10] !== progress || $[11] !== scales) {
|
|
309
|
+
t3 = () => {
|
|
310
|
+
if (!scales) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (open) {
|
|
314
|
+
progress.set(withTiming(1, DIALOG_ENTER));
|
|
315
|
+
} else {
|
|
316
|
+
progress.set(withTiming(0, DIALOG_EXIT, finished => {
|
|
317
|
+
"worklet";
|
|
318
|
+
|
|
319
|
+
if (finished) {
|
|
320
|
+
runOnJS(onHidden)();
|
|
321
|
+
}
|
|
322
|
+
}));
|
|
323
|
+
}
|
|
297
324
|
};
|
|
298
|
-
$[8] =
|
|
299
|
-
$[9] =
|
|
325
|
+
$[8] = onHidden;
|
|
326
|
+
$[9] = open;
|
|
327
|
+
$[10] = progress;
|
|
328
|
+
$[11] = scales;
|
|
329
|
+
$[12] = t3;
|
|
300
330
|
} else {
|
|
301
|
-
|
|
331
|
+
t3 = $[12];
|
|
302
332
|
}
|
|
303
|
-
let
|
|
304
|
-
if ($[
|
|
305
|
-
|
|
306
|
-
$[
|
|
307
|
-
$[
|
|
308
|
-
$[
|
|
333
|
+
let t4;
|
|
334
|
+
if ($[13] !== open || $[14] !== scales) {
|
|
335
|
+
t4 = [open, scales];
|
|
336
|
+
$[13] = open;
|
|
337
|
+
$[14] = scales;
|
|
338
|
+
$[15] = t4;
|
|
309
339
|
} else {
|
|
310
|
-
|
|
340
|
+
t4 = $[15];
|
|
311
341
|
}
|
|
312
|
-
|
|
313
|
-
const
|
|
314
|
-
let
|
|
315
|
-
if ($[
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
$[
|
|
320
|
-
$[
|
|
321
|
-
$[17] = t8;
|
|
342
|
+
useEffect(t3, t4);
|
|
343
|
+
const t5 = palette.backdrop[scheme];
|
|
344
|
+
let t6;
|
|
345
|
+
if ($[16] !== t5) {
|
|
346
|
+
t6 = {
|
|
347
|
+
backgroundColor: t5
|
|
348
|
+
};
|
|
349
|
+
$[16] = t5;
|
|
350
|
+
$[17] = t6;
|
|
322
351
|
} else {
|
|
323
|
-
|
|
352
|
+
t6 = $[17];
|
|
324
353
|
}
|
|
325
|
-
let
|
|
326
|
-
if ($[18] !==
|
|
327
|
-
|
|
328
|
-
$[18] =
|
|
329
|
-
$[19] =
|
|
330
|
-
$[20] =
|
|
354
|
+
let t7;
|
|
355
|
+
if ($[18] !== backdropStyle || $[19] !== t6) {
|
|
356
|
+
t7 = [StyleSheet.absoluteFill, t6, backdropStyle];
|
|
357
|
+
$[18] = backdropStyle;
|
|
358
|
+
$[19] = t6;
|
|
359
|
+
$[20] = t7;
|
|
331
360
|
} else {
|
|
332
|
-
|
|
361
|
+
t7 = $[20];
|
|
333
362
|
}
|
|
363
|
+
const t8 = `${part}-backdrop`;
|
|
364
|
+
const t9 = !dismissible;
|
|
334
365
|
let t10;
|
|
335
|
-
if ($[21] !==
|
|
336
|
-
t10 =
|
|
366
|
+
if ($[21] !== close || $[22] !== dismissible || $[23] !== t8 || $[24] !== t9) {
|
|
367
|
+
t10 = <Pressable testID={t8} accessible={dismissible} accessibilityRole="button" accessibilityLabel="Close" disabled={t9} onPress={close} style={StyleSheet.absoluteFill} />;
|
|
368
|
+
$[21] = close;
|
|
369
|
+
$[22] = dismissible;
|
|
370
|
+
$[23] = t8;
|
|
371
|
+
$[24] = t9;
|
|
372
|
+
$[25] = t10;
|
|
373
|
+
} else {
|
|
374
|
+
t10 = $[25];
|
|
375
|
+
}
|
|
376
|
+
let t11;
|
|
377
|
+
if ($[26] !== t10 || $[27] !== t7) {
|
|
378
|
+
t11 = <Animated.View pointerEvents="box-none" style={t7}>{t10}</Animated.View>;
|
|
379
|
+
$[26] = t10;
|
|
380
|
+
$[27] = t7;
|
|
381
|
+
$[28] = t11;
|
|
382
|
+
} else {
|
|
383
|
+
t11 = $[28];
|
|
384
|
+
}
|
|
385
|
+
let t12;
|
|
386
|
+
if ($[29] !== insets.bottom || $[30] !== insets.left || $[31] !== insets.right || $[32] !== insets.top || $[33] !== placement) {
|
|
387
|
+
t12 = placement === "bottom" ? {
|
|
337
388
|
justifyContent: "flex-end",
|
|
338
389
|
paddingTop: insets.top + 16,
|
|
339
390
|
paddingLeft: insets.left,
|
|
@@ -344,45 +395,55 @@ function OverlayModalBody(t0) {
|
|
|
344
395
|
paddingBottom: insets.bottom + 16,
|
|
345
396
|
paddingLeft: insets.left + 16,
|
|
346
397
|
paddingRight: insets.right + 16
|
|
347
|
-
}
|
|
348
|
-
$[
|
|
349
|
-
$[
|
|
350
|
-
$[
|
|
351
|
-
$[
|
|
352
|
-
$[
|
|
353
|
-
$[
|
|
398
|
+
};
|
|
399
|
+
$[29] = insets.bottom;
|
|
400
|
+
$[30] = insets.left;
|
|
401
|
+
$[31] = insets.right;
|
|
402
|
+
$[32] = insets.top;
|
|
403
|
+
$[33] = placement;
|
|
404
|
+
$[34] = t12;
|
|
354
405
|
} else {
|
|
355
|
-
|
|
406
|
+
t12 = $[34];
|
|
356
407
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
$[
|
|
362
|
-
$[
|
|
363
|
-
$[
|
|
408
|
+
const t13 = placement === "center" ? centrePanelStyle : null;
|
|
409
|
+
let t14;
|
|
410
|
+
if ($[35] !== t12 || $[36] !== t13) {
|
|
411
|
+
t14 = [styles.fill, t12, t13];
|
|
412
|
+
$[35] = t12;
|
|
413
|
+
$[36] = t13;
|
|
414
|
+
$[37] = t14;
|
|
364
415
|
} else {
|
|
365
|
-
|
|
416
|
+
t14 = $[37];
|
|
366
417
|
}
|
|
367
|
-
let
|
|
368
|
-
if ($[
|
|
369
|
-
|
|
370
|
-
$[
|
|
371
|
-
$[
|
|
372
|
-
$[
|
|
418
|
+
let t15;
|
|
419
|
+
if ($[38] !== children || $[39] !== close || $[40] !== t14) {
|
|
420
|
+
t15 = <Animated.View pointerEvents="box-none" onAccessibilityEscape={close} style={t14}>{children}</Animated.View>;
|
|
421
|
+
$[38] = children;
|
|
422
|
+
$[39] = close;
|
|
423
|
+
$[40] = t14;
|
|
424
|
+
$[41] = t15;
|
|
373
425
|
} else {
|
|
374
|
-
|
|
426
|
+
t15 = $[41];
|
|
375
427
|
}
|
|
376
|
-
let
|
|
377
|
-
if ($[
|
|
378
|
-
|
|
379
|
-
$[
|
|
380
|
-
$[
|
|
381
|
-
$[
|
|
428
|
+
let t16;
|
|
429
|
+
if ($[42] !== t11 || $[43] !== t15) {
|
|
430
|
+
t16 = <KeyboardAvoidingView style={styles.fill}><KeyboardLiftContext.Provider value={false}>{t11}{t15}</KeyboardLiftContext.Provider></KeyboardAvoidingView>;
|
|
431
|
+
$[42] = t11;
|
|
432
|
+
$[43] = t15;
|
|
433
|
+
$[44] = t16;
|
|
434
|
+
} else {
|
|
435
|
+
t16 = $[44];
|
|
436
|
+
}
|
|
437
|
+
let t17;
|
|
438
|
+
if ($[45] !== drag || $[46] !== t16) {
|
|
439
|
+
t17 = <SheetDragProvider value={drag}>{t16}</SheetDragProvider>;
|
|
440
|
+
$[45] = drag;
|
|
441
|
+
$[46] = t16;
|
|
442
|
+
$[47] = t17;
|
|
382
443
|
} else {
|
|
383
|
-
|
|
444
|
+
t17 = $[47];
|
|
384
445
|
}
|
|
385
|
-
return
|
|
446
|
+
return t17;
|
|
386
447
|
}
|
|
387
448
|
const styles = StyleSheet.create({
|
|
388
449
|
fill: {
|
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",
|
package/src/DropdownMenu.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Slot from "@rn-primitives/slot";
|
|
2
|
-
import { createContext, useContext, useRef, useState, type ComponentType, type ReactNode } from "react";
|
|
2
|
+
import { createContext, useContext, useEffect, useRef, useState, type ComponentType, type ReactNode } from "react";
|
|
3
3
|
import {
|
|
4
4
|
Modal,
|
|
5
5
|
Pressable,
|
|
@@ -12,12 +12,14 @@ import {
|
|
|
12
12
|
type PressableProps,
|
|
13
13
|
type ViewProps,
|
|
14
14
|
} from "react-native";
|
|
15
|
+
import Animated, { runOnJS, useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
15
16
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
16
17
|
import { IconCheck, type IconProps } from "@tabler/icons-react-native";
|
|
17
18
|
import { FloatingSurface } from "./FloatingSurface";
|
|
18
19
|
import { cn } from "./cn";
|
|
19
20
|
import { sizeStyle, typeStyle } from "./controlStyles";
|
|
20
21
|
import { selectionHaptic } from "./haptics";
|
|
22
|
+
import { PANEL_SCALE_FROM, POPOVER_ENTER, POPOVER_EXIT } from "./motion";
|
|
21
23
|
import { palette } from "./palette";
|
|
22
24
|
import { useLargerText } from "./theme";
|
|
23
25
|
import { tokens } from "./tokens";
|
|
@@ -195,7 +197,9 @@ export type DropdownMenuContentProps = ViewProps & {
|
|
|
195
197
|
* `Dialog` and `Sheet` (`FloatingSurface` without blur, with the floating
|
|
196
198
|
* shadow) at radius 16, at least 192 wide, `p-1.5`, scrolling when taller than
|
|
197
199
|
* the room. A tap outside, Android back and the VoiceOver escape gesture close
|
|
198
|
-
* it.
|
|
200
|
+
* it. The panel (not the backdrop) fades in and scales from 0.96 over 150 ms
|
|
201
|
+
* once it is measured, from the corner nearest the trigger, and fades out in
|
|
202
|
+
* 100 ms. With Reduce Motion on, it appears and leaves at once.
|
|
199
203
|
*/
|
|
200
204
|
export function DropdownMenuContent({
|
|
201
205
|
align = "start",
|
|
@@ -212,13 +216,60 @@ export function DropdownMenuContent({
|
|
|
212
216
|
// `null` until the content is measured: only then is it known whether the
|
|
213
217
|
// menu fits below the trigger or flips above, so it stays hidden till then.
|
|
214
218
|
const [contentHeight, setContentHeight] = useState<number | null>(null);
|
|
219
|
+
// Up while open, and after a close until the panel has faded out.
|
|
220
|
+
const [shown, setShown] = useState(open);
|
|
221
|
+
if (open && !shown) setShown(true);
|
|
222
|
+
if (!open && shown && reduceMotion) setShown(false);
|
|
223
|
+
const openRef = useRef(open);
|
|
224
|
+
useEffect(() => {
|
|
225
|
+
openRef.current = open;
|
|
226
|
+
}, [open]);
|
|
227
|
+
// The panel's motion, on the UI thread. At rest (1, 1) under Reduce Motion.
|
|
228
|
+
const opacity = useSharedValue(reduceMotion ? 1 : 0);
|
|
229
|
+
const scale = useSharedValue(reduceMotion ? 1 : PANEL_SCALE_FROM);
|
|
230
|
+
const measured = contentHeight !== null;
|
|
231
|
+
const hide = () => {
|
|
232
|
+
// Opened again in the moment the fade ended: stay up.
|
|
233
|
+
if (openRef.current) return;
|
|
234
|
+
setShown(false);
|
|
235
|
+
setContentHeight(null);
|
|
236
|
+
scale.set(PANEL_SCALE_FROM);
|
|
237
|
+
};
|
|
238
|
+
useEffect(() => {
|
|
239
|
+
if (reduceMotion) {
|
|
240
|
+
opacity.set(1);
|
|
241
|
+
scale.set(1);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (open) {
|
|
245
|
+
if (!measured) return;
|
|
246
|
+
opacity.set(withTiming(1, POPOVER_ENTER));
|
|
247
|
+
scale.set(withTiming(1, POPOVER_ENTER));
|
|
248
|
+
} else if (shown) {
|
|
249
|
+
// A fade only: the scale stays where it is.
|
|
250
|
+
opacity.set(
|
|
251
|
+
withTiming(0, POPOVER_EXIT, (finished) => {
|
|
252
|
+
"worklet";
|
|
253
|
+
if (finished) runOnJS(hide)();
|
|
254
|
+
}),
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
// Only opening, measuring and closing start the motion.
|
|
258
|
+
}, [open, measured, reduceMotion]);
|
|
259
|
+
const panelStyle = useAnimatedStyle(() => ({
|
|
260
|
+
opacity: opacity.get(),
|
|
261
|
+
transform: [{ scale: scale.get() }],
|
|
262
|
+
}));
|
|
215
263
|
const close = () => setOpen(false);
|
|
216
264
|
const position = dropdownMenuPosition({ trigger, window, insets, align, sideOffset, contentHeight: contentHeight ?? 0 });
|
|
265
|
+
// The scale grows from the corner nearest the trigger: its edge on the
|
|
266
|
+
// trigger's (`align`), and the top, or the bottom when the menu flipped above.
|
|
267
|
+
const transformOrigin = `${align === "end" ? 100 : 0}% ${position.bottom === undefined ? 0 : 100}%`;
|
|
217
268
|
return (
|
|
218
269
|
<Modal
|
|
219
|
-
visible={
|
|
270
|
+
visible={shown}
|
|
220
271
|
transparent
|
|
221
|
-
animationType=
|
|
272
|
+
animationType="none"
|
|
222
273
|
statusBarTranslucent
|
|
223
274
|
onRequestClose={close}
|
|
224
275
|
>
|
|
@@ -237,6 +288,8 @@ export function DropdownMenuContent({
|
|
|
237
288
|
accessibilityRole="menu"
|
|
238
289
|
accessibilityViewIsModal
|
|
239
290
|
onAccessibilityEscape={close}
|
|
291
|
+
// Leaving: a late tap on a row must not select twice.
|
|
292
|
+
pointerEvents={open ? "auto" : "none"}
|
|
240
293
|
style={{
|
|
241
294
|
position: "absolute",
|
|
242
295
|
...position,
|
|
@@ -245,18 +298,20 @@ export function DropdownMenuContent({
|
|
|
245
298
|
opacity: contentHeight === null ? 0 : 1,
|
|
246
299
|
}}
|
|
247
300
|
>
|
|
248
|
-
<
|
|
249
|
-
<
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
{
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
301
|
+
<Animated.View style={[{ transformOrigin }, panelStyle]}>
|
|
302
|
+
<FloatingSurface blur={false} radius={DROPDOWN_MENU.radius} style={{ maxHeight: position.maxHeight }}>
|
|
303
|
+
<ScrollView
|
|
304
|
+
bounces={false}
|
|
305
|
+
showsVerticalScrollIndicator={false}
|
|
306
|
+
onContentSizeChange={(_width, height) => setContentHeight(height)}
|
|
307
|
+
contentContainerStyle={{ padding: DROPDOWN_MENU.padding }}
|
|
308
|
+
>
|
|
309
|
+
<View className={cn(className)} style={style} {...props}>
|
|
310
|
+
{children}
|
|
311
|
+
</View>
|
|
312
|
+
</ScrollView>
|
|
313
|
+
</FloatingSurface>
|
|
314
|
+
</Animated.View>
|
|
260
315
|
</View>
|
|
261
316
|
</View>
|
|
262
317
|
</Modal>
|
|
@@ -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";
|