@btndprojects/loam-ui-native 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/dist/accordion/index.js +3 -0
- package/dist/adaptive/index.js +2 -0
- package/dist/alert/index.js +3 -0
- package/dist/analyzer/index.js +6 -0
- package/dist/announcement/index.js +6 -0
- package/dist/audio-player/index.js +3 -0
- package/dist/avatar/index.js +3 -0
- package/dist/avatar-group/index.js +3 -0
- package/dist/badge/index.js +5 -0
- package/dist/banner/index.js +2 -0
- package/dist/board/index.js +7 -0
- package/dist/button/index.js +5 -0
- package/dist/camera-permission/index.js +13 -0
- package/dist/capture-result/index.js +18 -0
- package/dist/card/index.js +4 -0
- package/dist/card-form/index.js +10 -0
- package/dist/carousel/index.js +2 -0
- package/dist/chart/index.js +6 -0
- package/dist/charts/index.js +7 -0
- package/dist/checkbox/index.js +7 -0
- package/dist/checklist/index.js +10 -0
- package/dist/checkout/index.js +13 -0
- package/dist/chip/index.js +7 -0
- package/dist/chunk-223Q2T2Q.js +229 -0
- package/dist/chunk-2A5NIQAK.js +254 -0
- package/dist/chunk-2GK6PHGE.js +363 -0
- package/dist/chunk-2WUTXHMU.js +1 -0
- package/dist/chunk-2ZZ7TDJ4.js +324 -0
- package/dist/chunk-35OFI3JG.js +499 -0
- package/dist/chunk-3ARE4TES.js +195 -0
- package/dist/chunk-3ECPOSKO.js +1 -0
- package/dist/chunk-3ENTMPQY.js +229 -0
- package/dist/chunk-3HJH6FF4.js +98 -0
- package/dist/chunk-3NMD74ZU.js +4 -0
- package/dist/chunk-3WPW4KUN.js +182 -0
- package/dist/chunk-47FWHGUN.js +394 -0
- package/dist/chunk-4BXMXBJO.js +141 -0
- package/dist/chunk-4DS5ZWVC.js +83 -0
- package/dist/chunk-4GBOGOTV.js +295 -0
- package/dist/chunk-4SZYY6AN.js +99 -0
- package/dist/chunk-4YIP3CWS.js +237 -0
- package/dist/chunk-4YQOR7JM.js +204 -0
- package/dist/chunk-4ZAHCY44.js +177 -0
- package/dist/chunk-52X2VYTD.js +228 -0
- package/dist/chunk-5P26LBDL.js +1 -0
- package/dist/chunk-5XLRYDAX.js +1 -0
- package/dist/chunk-5YNTNN5A.js +177 -0
- package/dist/chunk-66SG2H23.js +129 -0
- package/dist/chunk-6HT2LP62.js +504 -0
- package/dist/chunk-6N33LFQA.js +35 -0
- package/dist/chunk-6X6PQ443.js +432 -0
- package/dist/chunk-7CFF4HXS.js +126 -0
- package/dist/chunk-7O2FMUPT.js +755 -0
- package/dist/chunk-AI4DWZCD.js +162 -0
- package/dist/chunk-AWJOCGFZ.js +213 -0
- package/dist/chunk-AZRX6SAC.js +285 -0
- package/dist/chunk-B54QE2FN.js +1 -0
- package/dist/chunk-BC475SJH.js +1 -0
- package/dist/chunk-BEDBFJND.js +202 -0
- package/dist/chunk-BTTFCMKG.js +166 -0
- package/dist/chunk-BV3B2HYZ.js +1635 -0
- package/dist/chunk-C2NTXVWM.js +98 -0
- package/dist/chunk-CDRZHT42.js +424 -0
- package/dist/chunk-CJ5EOYZE.js +62 -0
- package/dist/chunk-CUMUNPXY.js +128 -0
- package/dist/chunk-CUS3ZSCU.js +1 -0
- package/dist/chunk-CYRBHQQZ.js +411 -0
- package/dist/chunk-DHWADYZX.js +144 -0
- package/dist/chunk-DKCSPATL.js +1 -0
- package/dist/chunk-DM5QUKKO.js +326 -0
- package/dist/chunk-DSJBXLUG.js +845 -0
- package/dist/chunk-DYBH2I6W.js +1 -0
- package/dist/chunk-DZ255O2F.js +1 -0
- package/dist/chunk-E35BPSGW.js +1 -0
- package/dist/chunk-EJBDRVIH.js +166 -0
- package/dist/chunk-F43NP42L.js +1 -0
- package/dist/chunk-F5XNPWS7.js +1024 -0
- package/dist/chunk-FIF2M24N.js +1521 -0
- package/dist/chunk-FOKG57CR.js +993 -0
- package/dist/chunk-G3HOYSF7.js +1 -0
- package/dist/chunk-GDKZTW34.js +395 -0
- package/dist/chunk-GL7B2DOW.js +134 -0
- package/dist/chunk-GNNJ4GCC.js +471 -0
- package/dist/chunk-GNZ56EUI.js +1 -0
- package/dist/chunk-H6NIOQHK.js +346 -0
- package/dist/chunk-H6PC7RDA.js +1 -0
- package/dist/chunk-HPPW424V.js +334 -0
- package/dist/chunk-HQOQIBJI.js +1 -0
- package/dist/chunk-HU2EQNRZ.js +44 -0
- package/dist/chunk-IIQTAY3J.js +715 -0
- package/dist/chunk-ITTYJZWX.js +271 -0
- package/dist/chunk-IVNRBPGC.js +1018 -0
- package/dist/chunk-J4KLDGI4.js +1 -0
- package/dist/chunk-J7Q7VCVC.js +254 -0
- package/dist/chunk-JDEOITQ2.js +1 -0
- package/dist/chunk-JNH2TYIN.js +96 -0
- package/dist/chunk-JRLTGLN4.js +1 -0
- package/dist/chunk-JTRJJLKL.js +1 -0
- package/dist/chunk-JUAMLEHX.js +379 -0
- package/dist/chunk-JXJB2X6M.js +131 -0
- package/dist/chunk-KMI5ML5I.js +262 -0
- package/dist/chunk-KTAC4MGE.js +4 -0
- package/dist/chunk-LAECSR4H.js +178 -0
- package/dist/chunk-LK4BCSGX.js +1 -0
- package/dist/chunk-LOE5YNN3.js +470 -0
- package/dist/chunk-LRJNDEIA.js +302 -0
- package/dist/chunk-LSS54GLJ.js +116 -0
- package/dist/chunk-LZLHELAG.js +137 -0
- package/dist/chunk-M2LUXGKZ.js +1 -0
- package/dist/chunk-MOUJOP55.js +425 -0
- package/dist/chunk-N32RGOA5.js +159 -0
- package/dist/chunk-N5ZNE2YE.js +1 -0
- package/dist/chunk-NBNCBML6.js +1 -0
- package/dist/chunk-NKB7BZYK.js +167 -0
- package/dist/chunk-NQYBUO3K.js +1795 -0
- package/dist/chunk-NY2U3PBI.js +59 -0
- package/dist/chunk-O4AEHWII.js +464 -0
- package/dist/chunk-O7AE6DAF.js +146 -0
- package/dist/chunk-OETCUXQP.js +134 -0
- package/dist/chunk-OOPPQH27.js +179 -0
- package/dist/chunk-OPXFZ4Y5.js +204 -0
- package/dist/chunk-P23EQNRQ.js +338 -0
- package/dist/chunk-PJXUJYS6.js +248 -0
- package/dist/chunk-PNWUWOBF.js +1 -0
- package/dist/chunk-PUPM2YGF.js +376 -0
- package/dist/chunk-PZXZJBMP.js +620 -0
- package/dist/chunk-Q72LJOVE.js +169 -0
- package/dist/chunk-QCDXZBC5.js +247 -0
- package/dist/chunk-QDYDBCFP.js +197 -0
- package/dist/chunk-QJJ6MADV.js +274 -0
- package/dist/chunk-QKXCPTFS.js +349 -0
- package/dist/chunk-QWCMU5B2.js +860 -0
- package/dist/chunk-RGQWWKLA.js +634 -0
- package/dist/chunk-RIBDXGUG.js +108 -0
- package/dist/chunk-RJQOOHT2.js +214 -0
- package/dist/chunk-RNGLIHFA.js +191 -0
- package/dist/chunk-RQ3HASCC.js +6 -0
- package/dist/chunk-RSOJT5YW.js +124 -0
- package/dist/chunk-RTIKSY6A.js +1 -0
- package/dist/chunk-RUZHTGKB.js +237 -0
- package/dist/chunk-RW6ZL2FQ.js +284 -0
- package/dist/chunk-S7F6XLTK.js +540 -0
- package/dist/chunk-SBMNWWBV.js +155 -0
- package/dist/chunk-SDTQPRRB.js +1 -0
- package/dist/chunk-SYNOJOQO.js +377 -0
- package/dist/chunk-T753XT36.js +1 -0
- package/dist/chunk-TKQYWZ5V.js +196 -0
- package/dist/chunk-TKVFVF5D.js +95 -0
- package/dist/chunk-TOXAGRDQ.js +144 -0
- package/dist/chunk-TUTI5HOZ.js +112 -0
- package/dist/chunk-U7TFM2JA.js +140 -0
- package/dist/chunk-UC2WGUP3.js +627 -0
- package/dist/chunk-UWFLYMAR.js +1126 -0
- package/dist/chunk-UWSZB7BJ.js +1 -0
- package/dist/chunk-UYG5L34B.js +87 -0
- package/dist/chunk-VBOXAEPI.js +336 -0
- package/dist/chunk-VCDBXW5H.js +188 -0
- package/dist/chunk-VCXPHHDS.js +1 -0
- package/dist/chunk-VEAYTRPX.js +414 -0
- package/dist/chunk-VFCUIDRT.js +1 -0
- package/dist/chunk-VQHPQEUH.js +273 -0
- package/dist/chunk-VXDZFJGP.js +874 -0
- package/dist/chunk-WS56BL3D.js +1 -0
- package/dist/chunk-WSW6ZFAQ.js +98 -0
- package/dist/chunk-WVKKJA6U.js +870 -0
- package/dist/chunk-XNUVB5OL.js +375 -0
- package/dist/chunk-XOSCY2CW.js +242 -0
- package/dist/chunk-XXXEFXY5.js +99 -0
- package/dist/chunk-Y5CSSPV4.js +1 -0
- package/dist/chunk-Y6DU4J47.js +1 -0
- package/dist/chunk-YC6WORFL.js +535 -0
- package/dist/chunk-YDGVJETP.js +60 -0
- package/dist/chunk-YF4NSSMT.js +366 -0
- package/dist/chunk-YG3ZJHGU.js +223 -0
- package/dist/chunk-YIJ55TBC.js +1 -0
- package/dist/chunk-YKZ4RZZF.js +1 -0
- package/dist/chunk-YLLCXTMC.js +37 -0
- package/dist/chunk-YTA74UZR.js +1 -0
- package/dist/chunk-Z7H7VSFZ.js +323 -0
- package/dist/chunk-ZK2H4O5P.js +1 -0
- package/dist/chunk-ZVFE5QGU.js +524 -0
- package/dist/coachmark/index.js +4 -0
- package/dist/code-block/index.js +4 -0
- package/dist/color-field/index.js +7 -0
- package/dist/commerce/index.js +20 -0
- package/dist/connectivity/index.js +2 -0
- package/dist/context-menu/index.js +5 -0
- package/dist/copy-button/index.js +3 -0
- package/dist/data-grid/index.js +24 -0
- package/dist/date-range-picker/index.js +13 -0
- package/dist/description-list/index.js +2 -0
- package/dist/dialog/index.js +3 -0
- package/dist/empty-state/index.js +3 -0
- package/dist/error-summary/index.js +3 -0
- package/dist/fab/index.js +2 -0
- package/dist/file-upload/index.js +9 -0
- package/dist/filter-bar/index.js +8 -0
- package/dist/flow-run/index.js +14 -0
- package/dist/form/index.js +3 -0
- package/dist/gallery/index.js +2 -0
- package/dist/header/index.js +5 -0
- package/dist/hold-to-confirm/index.js +4 -0
- package/dist/index.d.ts +22883 -0
- package/dist/index.js +158 -0
- package/dist/infinite-list/index.js +2 -0
- package/dist/inline-edit/index.js +5 -0
- package/dist/input/index.js +5 -0
- package/dist/interactions/index.js +2 -0
- package/dist/invoice/index.js +10 -0
- package/dist/kbd/index.js +1 -0
- package/dist/keyboard/index.js +3 -0
- package/dist/list-row/index.js +7 -0
- package/dist/log-viewer/index.js +2 -0
- package/dist/map-view/index.js +3 -0
- package/dist/markdown/index.js +6 -0
- package/dist/metric/index.js +4 -0
- package/dist/money/index.js +3 -0
- package/dist/nav-drawer/index.js +2 -0
- package/dist/navigation/index.js +2 -0
- package/dist/notification-center/index.js +16 -0
- package/dist/number-roll/index.js +3 -0
- package/dist/one-handed/index.js +5 -0
- package/dist/os-surfaces/index.js +3 -0
- package/dist/otp/index.js +7 -0
- package/dist/page-header/index.js +1 -0
- package/dist/payment-method/index.js +12 -0
- package/dist/payment-status/index.js +16 -0
- package/dist/permission/index.js +2 -0
- package/dist/picker/index.js +7 -0
- package/dist/progress/index.js +5 -0
- package/dist/pull-to-refresh/index.js +4 -0
- package/dist/radio-group/index.js +6 -0
- package/dist/rating/index.js +2 -0
- package/dist/receivables/index.js +20 -0
- package/dist/refund/index.js +16 -0
- package/dist/save-status/index.js +3 -0
- package/dist/scroll-area/index.js +1 -0
- package/dist/search-bar/index.js +5 -0
- package/dist/segmented-control/index.js +5 -0
- package/dist/sheet/index.js +4 -0
- package/dist/skeleton/index.js +2 -0
- package/dist/slider/index.js +5 -0
- package/dist/spinner/index.js +2 -0
- package/dist/split-button/index.js +7 -0
- package/dist/spotlight/index.js +2 -0
- package/dist/stage-timeline/index.js +4 -0
- package/dist/status-dot/index.js +2 -0
- package/dist/stepper/index.js +6 -0
- package/dist/streaming-text/index.js +3 -0
- package/dist/survey/index.js +19 -0
- package/dist/switch/index.js +5 -0
- package/dist/system-state/index.js +4 -0
- package/dist/tab-bar/index.js +2 -0
- package/dist/tabs/index.js +2 -0
- package/dist/textarea/index.js +6 -0
- package/dist/thinking/index.js +2 -0
- package/dist/timeline/index.js +4 -0
- package/dist/toast/index.js +2 -0
- package/dist/toolbar/index.js +2 -0
- package/dist/tour/index.js +11 -0
- package/dist/truncation-notice/index.js +2 -0
- package/dist/update-notice/index.js +11 -0
- package/dist/video-player/index.js +2 -0
- package/dist/viewfinder/index.js +5 -0
- package/dist/widget/index.js +4 -0
- package/dist/wizard/index.js +6 -0
- package/package.json +76 -3
- package/README.md +0 -3
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
import { expandedProps } from './chunk-RQ3HASCC.js';
|
|
2
|
+
import { haptics } from './chunk-NY2U3PBI.js';
|
|
3
|
+
import { Icon } from './chunk-TKVFVF5D.js';
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useWindowDimensions, Animated, Easing, Modal, View, StyleSheet, Pressable, Text, Platform } from 'react-native';
|
|
6
|
+
import { createStyleSheet, useLoamTheme, useStyles } from '@btndprojects/loam-theme-native';
|
|
7
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
8
|
+
|
|
9
|
+
var LONG_PRESS_DELAY_MS = 360;
|
|
10
|
+
var PRE_PRESS_SCALE = 0.95;
|
|
11
|
+
var LIFT_SCALE = 1.06;
|
|
12
|
+
var MOVE_CANCEL_PX = 10;
|
|
13
|
+
var MENU_WIDTH_IOS = 210;
|
|
14
|
+
var MENU_WIDTH_ANDROID = 196;
|
|
15
|
+
var MENU_HEIGHT_ESTIMATE = 210;
|
|
16
|
+
var MENU_EDGE_PAD = 8;
|
|
17
|
+
var MENU_MIN_TOP = 50;
|
|
18
|
+
var MENU_OFFSET_Y_IOS = 10;
|
|
19
|
+
var MENU_OFFSET_Y_ANDROID = -6;
|
|
20
|
+
var MENU_OFFSET_X_IOS = 0;
|
|
21
|
+
var MENU_OFFSET_X_ANDROID = 10;
|
|
22
|
+
var MENU_FROM_SCALE_IOS = 0.7;
|
|
23
|
+
var MENU_FROM_SCALE_ANDROID = 0.85;
|
|
24
|
+
var IOS_MENU_TRANSLUCENCY = 0.82;
|
|
25
|
+
var IOS_FROST_OPACITY = 0.22;
|
|
26
|
+
var ANDROID_ITEM_ICON_OPACITY = 0.55;
|
|
27
|
+
var RIPPLE_DIAMETER_FACTOR = 2.2;
|
|
28
|
+
var RIPPLE_OPACITY = 0.18;
|
|
29
|
+
function touchPoint(e) {
|
|
30
|
+
const ne = e.nativeEvent;
|
|
31
|
+
if (typeof ne.pageX === "number" && typeof ne.pageY === "number") {
|
|
32
|
+
return { x: ne.pageX, y: ne.pageY };
|
|
33
|
+
}
|
|
34
|
+
const t = ne.touches?.[0];
|
|
35
|
+
if (t && typeof t.pageX === "number" && typeof t.pageY === "number") {
|
|
36
|
+
return { x: t.pageX, y: t.pageY };
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
function orderContextMenuItems(items) {
|
|
41
|
+
const safe = items.filter((i) => !i.destructive);
|
|
42
|
+
const destructive = items.filter((i) => i.destructive);
|
|
43
|
+
return destructive.length === 0 ? items : [...safe, ...destructive];
|
|
44
|
+
}
|
|
45
|
+
function placeContextMenu(anchor, screen, platform) {
|
|
46
|
+
const ios = platform === "ios";
|
|
47
|
+
const width = ios ? MENU_WIDTH_IOS : MENU_WIDTH_ANDROID;
|
|
48
|
+
let left = anchor.x + (ios ? MENU_OFFSET_X_IOS : MENU_OFFSET_X_ANDROID);
|
|
49
|
+
let top = anchor.y + anchor.height + (ios ? MENU_OFFSET_Y_IOS : MENU_OFFSET_Y_ANDROID);
|
|
50
|
+
if (left + width > screen.width - MENU_EDGE_PAD) left = screen.width - width - MENU_EDGE_PAD;
|
|
51
|
+
if (top + MENU_HEIGHT_ESTIMATE > screen.height) {
|
|
52
|
+
top = Math.max(MENU_MIN_TOP, anchor.y - MENU_HEIGHT_ESTIMATE);
|
|
53
|
+
}
|
|
54
|
+
return { left, top, width };
|
|
55
|
+
}
|
|
56
|
+
function useResolvedPlatform(explicit) {
|
|
57
|
+
const theme = useLoamTheme();
|
|
58
|
+
if (explicit) return explicit;
|
|
59
|
+
if (Platform.OS === "ios") return "ios";
|
|
60
|
+
if (Platform.OS === "android") return "android";
|
|
61
|
+
return theme.platform === "iOS" ? "ios" : "android";
|
|
62
|
+
}
|
|
63
|
+
function ContextMenuOverlay({
|
|
64
|
+
open,
|
|
65
|
+
onClose,
|
|
66
|
+
items,
|
|
67
|
+
anchor,
|
|
68
|
+
platform,
|
|
69
|
+
lift,
|
|
70
|
+
radius,
|
|
71
|
+
accessibilityLabel = "Actions",
|
|
72
|
+
closeLabel = "Close menu",
|
|
73
|
+
motion = "full"
|
|
74
|
+
}) {
|
|
75
|
+
const theme = useLoamTheme();
|
|
76
|
+
const os = useResolvedPlatform(platform);
|
|
77
|
+
const ios = os === "ios";
|
|
78
|
+
const { styles } = useStyles(sheet, { platform: os });
|
|
79
|
+
const window = useWindowDimensions();
|
|
80
|
+
const reducedMotion = theme.reduceMotion || motion === "reduced";
|
|
81
|
+
const instantMotion = motion === "none";
|
|
82
|
+
const [visible, setVisible] = React.useState(open);
|
|
83
|
+
const fromScale = ios ? MENU_FROM_SCALE_IOS : MENU_FROM_SCALE_ANDROID;
|
|
84
|
+
const backdropOpacity = React.useRef(new Animated.Value(0)).current;
|
|
85
|
+
const menuOpacity = React.useRef(new Animated.Value(0)).current;
|
|
86
|
+
const menuScale = React.useRef(new Animated.Value(fromScale)).current;
|
|
87
|
+
const liftScale = React.useRef(new Animated.Value(1)).current;
|
|
88
|
+
const enter = theme.motion.enter;
|
|
89
|
+
const exit = theme.motion.exit;
|
|
90
|
+
const scaleIn = ios ? { duration: theme.duration.base, easing: theme.easing.spring } : theme.motion.expand;
|
|
91
|
+
const animateIn = React.useCallback(() => {
|
|
92
|
+
if (instantMotion) {
|
|
93
|
+
backdropOpacity.setValue(1);
|
|
94
|
+
menuOpacity.setValue(1);
|
|
95
|
+
menuScale.setValue(1);
|
|
96
|
+
liftScale.setValue(1);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (reducedMotion) {
|
|
100
|
+
backdropOpacity.setValue(0);
|
|
101
|
+
menuOpacity.setValue(0);
|
|
102
|
+
menuScale.setValue(1);
|
|
103
|
+
liftScale.setValue(1);
|
|
104
|
+
Animated.parallel([
|
|
105
|
+
Animated.timing(backdropOpacity, {
|
|
106
|
+
toValue: 1,
|
|
107
|
+
duration: enter.duration,
|
|
108
|
+
easing: Easing.bezier(...enter.easing),
|
|
109
|
+
useNativeDriver: true
|
|
110
|
+
}),
|
|
111
|
+
Animated.timing(menuOpacity, {
|
|
112
|
+
toValue: 1,
|
|
113
|
+
duration: enter.duration,
|
|
114
|
+
easing: Easing.bezier(...enter.easing),
|
|
115
|
+
useNativeDriver: true
|
|
116
|
+
})
|
|
117
|
+
]).start();
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
backdropOpacity.setValue(0);
|
|
121
|
+
menuOpacity.setValue(0);
|
|
122
|
+
menuScale.setValue(fromScale);
|
|
123
|
+
liftScale.setValue(1);
|
|
124
|
+
Animated.parallel([
|
|
125
|
+
Animated.timing(backdropOpacity, {
|
|
126
|
+
toValue: 1,
|
|
127
|
+
duration: enter.duration,
|
|
128
|
+
easing: Easing.bezier(...enter.easing),
|
|
129
|
+
useNativeDriver: true
|
|
130
|
+
}),
|
|
131
|
+
Animated.timing(menuOpacity, {
|
|
132
|
+
toValue: 1,
|
|
133
|
+
duration: enter.duration,
|
|
134
|
+
easing: Easing.bezier(...enter.easing),
|
|
135
|
+
useNativeDriver: true
|
|
136
|
+
}),
|
|
137
|
+
Animated.timing(menuScale, {
|
|
138
|
+
toValue: 1,
|
|
139
|
+
duration: scaleIn.duration,
|
|
140
|
+
easing: Easing.bezier(...scaleIn.easing),
|
|
141
|
+
useNativeDriver: true
|
|
142
|
+
}),
|
|
143
|
+
Animated.timing(liftScale, {
|
|
144
|
+
toValue: LIFT_SCALE,
|
|
145
|
+
duration: scaleIn.duration,
|
|
146
|
+
easing: Easing.bezier(...scaleIn.easing),
|
|
147
|
+
useNativeDriver: true
|
|
148
|
+
})
|
|
149
|
+
]).start();
|
|
150
|
+
}, [
|
|
151
|
+
backdropOpacity,
|
|
152
|
+
menuOpacity,
|
|
153
|
+
menuScale,
|
|
154
|
+
liftScale,
|
|
155
|
+
fromScale,
|
|
156
|
+
enter.duration,
|
|
157
|
+
enter.easing,
|
|
158
|
+
scaleIn.duration,
|
|
159
|
+
scaleIn.easing,
|
|
160
|
+
reducedMotion,
|
|
161
|
+
instantMotion
|
|
162
|
+
]);
|
|
163
|
+
const animateOut = React.useCallback(() => {
|
|
164
|
+
if (instantMotion) {
|
|
165
|
+
backdropOpacity.setValue(0);
|
|
166
|
+
menuOpacity.setValue(0);
|
|
167
|
+
liftScale.setValue(1);
|
|
168
|
+
setVisible(false);
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
const spec = {
|
|
172
|
+
duration: exit.duration,
|
|
173
|
+
easing: Easing.bezier(...exit.easing),
|
|
174
|
+
useNativeDriver: true
|
|
175
|
+
};
|
|
176
|
+
if (reducedMotion) {
|
|
177
|
+
Animated.parallel([
|
|
178
|
+
Animated.timing(backdropOpacity, { toValue: 0, ...spec }),
|
|
179
|
+
Animated.timing(menuOpacity, { toValue: 0, ...spec })
|
|
180
|
+
]).start(({ finished }) => {
|
|
181
|
+
if (finished) setVisible(false);
|
|
182
|
+
});
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
Animated.parallel([
|
|
186
|
+
Animated.timing(backdropOpacity, { toValue: 0, ...spec }),
|
|
187
|
+
Animated.timing(menuOpacity, { toValue: 0, ...spec }),
|
|
188
|
+
Animated.timing(menuScale, { toValue: fromScale, ...spec }),
|
|
189
|
+
Animated.timing(liftScale, { toValue: 1, ...spec })
|
|
190
|
+
]).start(({ finished }) => {
|
|
191
|
+
if (finished) setVisible(false);
|
|
192
|
+
});
|
|
193
|
+
}, [
|
|
194
|
+
backdropOpacity,
|
|
195
|
+
menuOpacity,
|
|
196
|
+
menuScale,
|
|
197
|
+
liftScale,
|
|
198
|
+
fromScale,
|
|
199
|
+
exit.duration,
|
|
200
|
+
exit.easing,
|
|
201
|
+
reducedMotion,
|
|
202
|
+
instantMotion
|
|
203
|
+
]);
|
|
204
|
+
React.useEffect(() => {
|
|
205
|
+
if (open) setVisible(true);
|
|
206
|
+
else if (visible) animateOut();
|
|
207
|
+
}, [open]);
|
|
208
|
+
React.useEffect(() => {
|
|
209
|
+
if (visible && open) animateIn();
|
|
210
|
+
}, [visible]);
|
|
211
|
+
const rect = anchor ?? { x: 0, y: 0, width: 0, height: 0 };
|
|
212
|
+
const place = placeContextMenu(rect, window, os);
|
|
213
|
+
const ordered = orderContextMenuItems(items);
|
|
214
|
+
const liftRadius = radius ?? theme.radius.lg;
|
|
215
|
+
return /* @__PURE__ */ jsx(
|
|
216
|
+
Modal,
|
|
217
|
+
{
|
|
218
|
+
visible,
|
|
219
|
+
transparent: true,
|
|
220
|
+
animationType: "none",
|
|
221
|
+
onRequestClose: onClose,
|
|
222
|
+
statusBarTranslucent: true,
|
|
223
|
+
children: /* @__PURE__ */ jsxs(View, { style: StyleSheet.absoluteFill, children: [
|
|
224
|
+
/* @__PURE__ */ jsxs(Animated.View, { style: [StyleSheet.absoluteFill, { opacity: backdropOpacity }], children: [
|
|
225
|
+
/* @__PURE__ */ jsx(View, { style: [StyleSheet.absoluteFill, styles.dim] }),
|
|
226
|
+
ios ? /* @__PURE__ */ jsx(View, { style: [StyleSheet.absoluteFill, styles.frost] }) : null,
|
|
227
|
+
/* @__PURE__ */ jsx(
|
|
228
|
+
Pressable,
|
|
229
|
+
{
|
|
230
|
+
style: StyleSheet.absoluteFill,
|
|
231
|
+
accessibilityRole: "button",
|
|
232
|
+
accessibilityLabel: closeLabel,
|
|
233
|
+
onPress: onClose
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
] }),
|
|
237
|
+
ios && lift != null ? /* @__PURE__ */ jsx(
|
|
238
|
+
Animated.View,
|
|
239
|
+
{
|
|
240
|
+
pointerEvents: "none",
|
|
241
|
+
style: [
|
|
242
|
+
styles.lift,
|
|
243
|
+
{
|
|
244
|
+
left: rect.x,
|
|
245
|
+
top: rect.y,
|
|
246
|
+
width: rect.width,
|
|
247
|
+
height: rect.height,
|
|
248
|
+
// The shadow is painted from the view's own shape, so the radius
|
|
249
|
+
// has to travel with the copy or `shadow.lg` reads as a hard
|
|
250
|
+
// square block behind a rounded tile.
|
|
251
|
+
borderRadius: liftRadius,
|
|
252
|
+
transform: [{ scale: liftScale }]
|
|
253
|
+
}
|
|
254
|
+
],
|
|
255
|
+
children: lift
|
|
256
|
+
}
|
|
257
|
+
) : null,
|
|
258
|
+
/* @__PURE__ */ jsxs(
|
|
259
|
+
Animated.View,
|
|
260
|
+
{
|
|
261
|
+
accessibilityRole: "menu",
|
|
262
|
+
accessibilityLabel,
|
|
263
|
+
style: [
|
|
264
|
+
styles.menu,
|
|
265
|
+
{
|
|
266
|
+
left: place.left,
|
|
267
|
+
top: place.top,
|
|
268
|
+
width: place.width,
|
|
269
|
+
opacity: menuOpacity,
|
|
270
|
+
transform: [{ scale: menuScale }]
|
|
271
|
+
}
|
|
272
|
+
],
|
|
273
|
+
children: [
|
|
274
|
+
ios ? /* @__PURE__ */ jsx(View, { style: [StyleSheet.absoluteFill, styles.translucency] }) : null,
|
|
275
|
+
ordered.map((item, i) => /* @__PURE__ */ jsx(
|
|
276
|
+
MenuItem,
|
|
277
|
+
{
|
|
278
|
+
item,
|
|
279
|
+
platform: os,
|
|
280
|
+
last: i === ordered.length - 1,
|
|
281
|
+
onClose
|
|
282
|
+
},
|
|
283
|
+
item.key
|
|
284
|
+
))
|
|
285
|
+
]
|
|
286
|
+
}
|
|
287
|
+
)
|
|
288
|
+
] })
|
|
289
|
+
}
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
function MenuItem({
|
|
293
|
+
item,
|
|
294
|
+
platform,
|
|
295
|
+
last,
|
|
296
|
+
onClose
|
|
297
|
+
}) {
|
|
298
|
+
const theme = useLoamTheme();
|
|
299
|
+
const ios = platform === "ios";
|
|
300
|
+
const { styles } = useStyles(sheet, { platform, separated: ios && !last });
|
|
301
|
+
const size = React.useRef({ width: 0, height: 0 });
|
|
302
|
+
const [ripple, setRipple] = React.useState(
|
|
303
|
+
null
|
|
304
|
+
);
|
|
305
|
+
const rippleScale = React.useRef(new Animated.Value(0)).current;
|
|
306
|
+
const rippleOpacity = React.useRef(new Animated.Value(0)).current;
|
|
307
|
+
const timer = React.useRef(null);
|
|
308
|
+
React.useEffect(
|
|
309
|
+
() => () => {
|
|
310
|
+
if (timer.current) clearTimeout(timer.current);
|
|
311
|
+
},
|
|
312
|
+
[]
|
|
313
|
+
);
|
|
314
|
+
const onLayout = (e) => {
|
|
315
|
+
size.current = {
|
|
316
|
+
width: e.nativeEvent.layout.width,
|
|
317
|
+
height: e.nativeEvent.layout.height
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
const onPress = (e) => {
|
|
321
|
+
if (!ios) {
|
|
322
|
+
const { width, height } = size.current;
|
|
323
|
+
const d = Math.max(width, height) * RIPPLE_DIAMETER_FACTOR;
|
|
324
|
+
const lx = e.nativeEvent.locationX ?? width / 2;
|
|
325
|
+
const ly = e.nativeEvent.locationY ?? height / 2;
|
|
326
|
+
setRipple({ left: lx - d / 2, top: ly - d / 2, size: d });
|
|
327
|
+
rippleScale.setValue(0);
|
|
328
|
+
rippleOpacity.setValue(RIPPLE_OPACITY);
|
|
329
|
+
Animated.parallel([
|
|
330
|
+
// Reference: `scale(0) → scale(1)` over 480ms `ease-out` → the `decel`
|
|
331
|
+
// token, timed by `duration.slow` (500) so `reduceMotion` still applies.
|
|
332
|
+
Animated.timing(rippleScale, {
|
|
333
|
+
toValue: 1,
|
|
334
|
+
duration: theme.duration.slow,
|
|
335
|
+
easing: Easing.bezier(...theme.easing.out),
|
|
336
|
+
useNativeDriver: true
|
|
337
|
+
}),
|
|
338
|
+
Animated.timing(rippleOpacity, {
|
|
339
|
+
toValue: 0,
|
|
340
|
+
duration: theme.duration.slow,
|
|
341
|
+
easing: Easing.bezier(...theme.easing.out),
|
|
342
|
+
useNativeDriver: true
|
|
343
|
+
})
|
|
344
|
+
]).start(() => setRipple(null));
|
|
345
|
+
}
|
|
346
|
+
haptics.impact("light");
|
|
347
|
+
item.onSelect?.();
|
|
348
|
+
if (ios) onClose();
|
|
349
|
+
else timer.current = setTimeout(onClose, theme.duration.fast);
|
|
350
|
+
};
|
|
351
|
+
const tint = item.destructive === true ? theme.color.danger : theme.color.text;
|
|
352
|
+
const glyph = item.icon == null ? null : /* @__PURE__ */ jsx(
|
|
353
|
+
Icon,
|
|
354
|
+
{
|
|
355
|
+
name: item.icon,
|
|
356
|
+
size: theme.icon.sm,
|
|
357
|
+
color: item.destructive === true ? theme.color.danger : theme.color.text3
|
|
358
|
+
}
|
|
359
|
+
);
|
|
360
|
+
return /* @__PURE__ */ jsxs(
|
|
361
|
+
Pressable,
|
|
362
|
+
{
|
|
363
|
+
accessibilityRole: "menuitem",
|
|
364
|
+
accessibilityLabel: item.label,
|
|
365
|
+
onLayout,
|
|
366
|
+
onPress,
|
|
367
|
+
style: ({ pressed }) => [
|
|
368
|
+
styles.item,
|
|
369
|
+
// iOS has no ripple, so it gets the state layer instead.
|
|
370
|
+
pressed && ios ? styles.itemPressed : null
|
|
371
|
+
],
|
|
372
|
+
children: [
|
|
373
|
+
ios ? null : /* @__PURE__ */ jsx(View, { style: styles.androidGlyph, children: glyph }),
|
|
374
|
+
/* @__PURE__ */ jsx(Text, { style: [styles.itemLabel, { color: tint }], numberOfLines: 1, children: item.label }),
|
|
375
|
+
ios ? glyph : null,
|
|
376
|
+
ripple ? /* @__PURE__ */ jsx(
|
|
377
|
+
Animated.View,
|
|
378
|
+
{
|
|
379
|
+
pointerEvents: "none",
|
|
380
|
+
style: [
|
|
381
|
+
styles.ripple,
|
|
382
|
+
{
|
|
383
|
+
left: ripple.left,
|
|
384
|
+
top: ripple.top,
|
|
385
|
+
width: ripple.size,
|
|
386
|
+
height: ripple.size,
|
|
387
|
+
borderRadius: ripple.size / 2,
|
|
388
|
+
opacity: rippleOpacity,
|
|
389
|
+
transform: [{ scale: rippleScale }]
|
|
390
|
+
}
|
|
391
|
+
]
|
|
392
|
+
}
|
|
393
|
+
) : null
|
|
394
|
+
]
|
|
395
|
+
}
|
|
396
|
+
);
|
|
397
|
+
}
|
|
398
|
+
function ContextMenu({
|
|
399
|
+
items,
|
|
400
|
+
children,
|
|
401
|
+
onPress,
|
|
402
|
+
disabled = false,
|
|
403
|
+
platform,
|
|
404
|
+
accessibilityLabel,
|
|
405
|
+
radius,
|
|
406
|
+
style,
|
|
407
|
+
onOpen,
|
|
408
|
+
onClose,
|
|
409
|
+
motion = "full"
|
|
410
|
+
}) {
|
|
411
|
+
const theme = useLoamTheme();
|
|
412
|
+
const os = useResolvedPlatform(platform);
|
|
413
|
+
const ios = os === "ios";
|
|
414
|
+
const { styles } = useStyles(sheet, { platform: os });
|
|
415
|
+
const [open, setOpen] = React.useState(false);
|
|
416
|
+
const [anchor, setAnchor] = React.useState(null);
|
|
417
|
+
const triggerRef = React.useRef(null);
|
|
418
|
+
const start = React.useRef(null);
|
|
419
|
+
const moved = React.useRef(false);
|
|
420
|
+
const scale = React.useRef(new Animated.Value(1)).current;
|
|
421
|
+
const springTo = React.useCallback(
|
|
422
|
+
(to) => {
|
|
423
|
+
Animated.timing(scale, {
|
|
424
|
+
toValue: to,
|
|
425
|
+
duration: theme.duration.base,
|
|
426
|
+
easing: Easing.bezier(...theme.easing.spring),
|
|
427
|
+
useNativeDriver: true
|
|
428
|
+
}).start();
|
|
429
|
+
},
|
|
430
|
+
[scale, theme.duration.base, theme.easing.spring]
|
|
431
|
+
);
|
|
432
|
+
const openMenu = () => {
|
|
433
|
+
if (disabled || moved.current) return;
|
|
434
|
+
haptics.impact("heavy");
|
|
435
|
+
scale.setValue(1);
|
|
436
|
+
const node = triggerRef.current;
|
|
437
|
+
if (node && typeof node.measureInWindow === "function") {
|
|
438
|
+
node.measureInWindow((x, y, width, height) => setAnchor({ x, y, width, height }));
|
|
439
|
+
}
|
|
440
|
+
setOpen(true);
|
|
441
|
+
onOpen?.();
|
|
442
|
+
};
|
|
443
|
+
const closeMenu = () => {
|
|
444
|
+
setOpen(false);
|
|
445
|
+
onClose?.();
|
|
446
|
+
};
|
|
447
|
+
const flatStyle = StyleSheet.flatten(style);
|
|
448
|
+
const styleRadius = typeof flatStyle?.borderRadius === "number" ? flatStyle.borderRadius : void 0;
|
|
449
|
+
const triggerRadius = radius ?? styleRadius ?? theme.radius.lg;
|
|
450
|
+
return /* @__PURE__ */ jsxs(View, { ref: triggerRef, style, collapsable: false, children: [
|
|
451
|
+
/* @__PURE__ */ jsx(
|
|
452
|
+
Animated.View,
|
|
453
|
+
{
|
|
454
|
+
style: [
|
|
455
|
+
// iOS hides the in-place trigger while its lifted copy is on screen.
|
|
456
|
+
ios && open ? styles.liftedAway : null,
|
|
457
|
+
{ borderRadius: triggerRadius, transform: [{ scale }] }
|
|
458
|
+
],
|
|
459
|
+
children: /* @__PURE__ */ jsx(
|
|
460
|
+
Pressable,
|
|
461
|
+
{
|
|
462
|
+
style: { borderRadius: triggerRadius },
|
|
463
|
+
accessibilityRole: "button",
|
|
464
|
+
accessibilityLabel,
|
|
465
|
+
accessibilityState: { disabled, expanded: open },
|
|
466
|
+
...expandedProps(open),
|
|
467
|
+
accessibilityActions: [{ name: "longpress", label: "Show actions" }],
|
|
468
|
+
onAccessibilityAction: (e) => {
|
|
469
|
+
if (e.nativeEvent.actionName === "longpress") openMenu();
|
|
470
|
+
},
|
|
471
|
+
disabled,
|
|
472
|
+
delayLongPress: LONG_PRESS_DELAY_MS,
|
|
473
|
+
onLongPress: disabled ? void 0 : openMenu,
|
|
474
|
+
onPress: disabled ? void 0 : onPress,
|
|
475
|
+
onPressIn: () => {
|
|
476
|
+
if (start.current === null) moved.current = false;
|
|
477
|
+
if (!disabled) springTo(PRE_PRESS_SCALE);
|
|
478
|
+
},
|
|
479
|
+
onPressOut: () => {
|
|
480
|
+
start.current = null;
|
|
481
|
+
springTo(1);
|
|
482
|
+
},
|
|
483
|
+
onTouchStart: (e) => {
|
|
484
|
+
moved.current = false;
|
|
485
|
+
start.current = touchPoint(e);
|
|
486
|
+
},
|
|
487
|
+
onTouchMove: (e) => {
|
|
488
|
+
const s = start.current;
|
|
489
|
+
const t = touchPoint(e);
|
|
490
|
+
if (!s || !t) return;
|
|
491
|
+
if (Math.abs(t.x - s.x) + Math.abs(t.y - s.y) > MOVE_CANCEL_PX) {
|
|
492
|
+
moved.current = true;
|
|
493
|
+
springTo(1);
|
|
494
|
+
}
|
|
495
|
+
},
|
|
496
|
+
children
|
|
497
|
+
}
|
|
498
|
+
)
|
|
499
|
+
}
|
|
500
|
+
),
|
|
501
|
+
/* @__PURE__ */ jsx(
|
|
502
|
+
ContextMenuOverlay,
|
|
503
|
+
{
|
|
504
|
+
open,
|
|
505
|
+
onClose: closeMenu,
|
|
506
|
+
items,
|
|
507
|
+
anchor,
|
|
508
|
+
platform: os,
|
|
509
|
+
lift: children,
|
|
510
|
+
radius: triggerRadius,
|
|
511
|
+
accessibilityLabel,
|
|
512
|
+
motion
|
|
513
|
+
}
|
|
514
|
+
)
|
|
515
|
+
] });
|
|
516
|
+
}
|
|
517
|
+
var sheet = createStyleSheet((theme) => ({
|
|
518
|
+
/** The dim behind the menu. iOS whispers (`scrimLight`), Android commits (`scrim`). */
|
|
519
|
+
dim: {
|
|
520
|
+
variants: {
|
|
521
|
+
platform: {
|
|
522
|
+
ios: { backgroundColor: theme.color.scrimLight },
|
|
523
|
+
android: { backgroundColor: theme.color.scrim }
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
/** Stand-in for `backdrop-filter: blur(7px)` — a translucent `surface` veil. */
|
|
528
|
+
frost: {
|
|
529
|
+
backgroundColor: theme.color.surface,
|
|
530
|
+
opacity: IOS_FROST_OPACITY
|
|
531
|
+
},
|
|
532
|
+
/** The lifted copy of the trigger (iOS). */
|
|
533
|
+
lift: {
|
|
534
|
+
position: "absolute",
|
|
535
|
+
...theme.shadow.lg
|
|
536
|
+
},
|
|
537
|
+
/** The in-place trigger while its copy is lifted. */
|
|
538
|
+
liftedAway: { opacity: 0 },
|
|
539
|
+
menu: {
|
|
540
|
+
position: "absolute",
|
|
541
|
+
overflow: "hidden",
|
|
542
|
+
// The reference sets `transform-origin: top left` so the menu grows out of
|
|
543
|
+
// the anchor's corner. RN 0.74+ supports `transformOrigin`.
|
|
544
|
+
transformOrigin: "top left",
|
|
545
|
+
...theme.shadow.lg,
|
|
546
|
+
variants: {
|
|
547
|
+
platform: {
|
|
548
|
+
// Reference radius 16 → `radius.lg` (19); 12 → `radius.md` (13).
|
|
549
|
+
ios: { borderRadius: theme.radius.lg },
|
|
550
|
+
android: {
|
|
551
|
+
borderRadius: theme.radius.md,
|
|
552
|
+
backgroundColor: theme.color.surface,
|
|
553
|
+
// Reference `padding:8px 0` — `space.s2` is exactly 8.
|
|
554
|
+
paddingVertical: theme.space.s2
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
},
|
|
559
|
+
/** iOS: `color-mix(in srgb, var(--surface) 82%, transparent)`, as a fill layer. */
|
|
560
|
+
translucency: {
|
|
561
|
+
backgroundColor: theme.color.surface,
|
|
562
|
+
opacity: IOS_MENU_TRANSLUCENCY
|
|
563
|
+
},
|
|
564
|
+
item: {
|
|
565
|
+
flexDirection: "row",
|
|
566
|
+
alignItems: "center",
|
|
567
|
+
overflow: "hidden",
|
|
568
|
+
minHeight: theme.tapMin,
|
|
569
|
+
variants: {
|
|
570
|
+
platform: {
|
|
571
|
+
ios: {
|
|
572
|
+
justifyContent: "space-between",
|
|
573
|
+
// Reference `padding:13px 16px`.
|
|
574
|
+
paddingVertical: theme.space.s3,
|
|
575
|
+
paddingHorizontal: theme.space.s4
|
|
576
|
+
},
|
|
577
|
+
android: {
|
|
578
|
+
// Reference `padding:12px 18px` and `gap:14px`.
|
|
579
|
+
paddingVertical: theme.space.s3,
|
|
580
|
+
paddingHorizontal: theme.space.s4,
|
|
581
|
+
gap: theme.space.s3
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
separated: {
|
|
585
|
+
// iOS draws a `.5px` hairline between rows — the static `hair` weight,
|
|
586
|
+
// which must stay a true hairline rather than thicken with contrast.
|
|
587
|
+
true: { borderBottomWidth: theme.borderWidth.hair, borderBottomColor: theme.color.border },
|
|
588
|
+
false: {}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
itemPressed: { backgroundColor: theme.state.pressed },
|
|
593
|
+
itemLabel: {
|
|
594
|
+
flexShrink: 1,
|
|
595
|
+
fontFamily: theme.font.sans,
|
|
596
|
+
fontWeight: theme.fontWeight.medium,
|
|
597
|
+
variants: {
|
|
598
|
+
platform: {
|
|
599
|
+
// Reference 16px (iOS) / 15px (Android) → `callout` / `subheadline`.
|
|
600
|
+
ios: {
|
|
601
|
+
fontSize: theme.type.callout.fontSize,
|
|
602
|
+
lineHeight: theme.type.callout.lineHeight,
|
|
603
|
+
letterSpacing: theme.type.callout.letterSpacing
|
|
604
|
+
},
|
|
605
|
+
android: {
|
|
606
|
+
fontSize: theme.type.subheadline.fontSize,
|
|
607
|
+
lineHeight: theme.type.subheadline.lineHeight,
|
|
608
|
+
letterSpacing: theme.type.subheadline.letterSpacing
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
},
|
|
613
|
+
androidGlyph: { opacity: ANDROID_ITEM_ICON_OPACITY },
|
|
614
|
+
ripple: {
|
|
615
|
+
position: "absolute",
|
|
616
|
+
backgroundColor: theme.color.text
|
|
617
|
+
}
|
|
618
|
+
}));
|
|
619
|
+
|
|
620
|
+
export { ContextMenu, ContextMenuOverlay, LONG_PRESS_DELAY_MS, orderContextMenuItems, placeContextMenu };
|