glacia-native 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +29 -4
- package/README.md +27 -0
- package/lib/module/Bars.js +103 -9
- package/lib/module/Button.js +11 -8
- package/lib/module/Card.js +2 -2
- package/lib/module/Dialog.js +16 -17
- package/lib/module/Display.js +86 -8
- package/lib/module/Feedback.js +244 -21
- package/lib/module/Form.js +29 -33
- package/lib/module/Forms2.js +257 -13
- package/lib/module/Glass.js +2 -2
- package/lib/module/Input.js +12 -10
- package/lib/module/Message.js +84 -0
- package/lib/module/Overlays.js +195 -17
- package/lib/module/Pickers.js +16 -16
- package/lib/module/SegmentedControl.js +24 -11
- package/lib/module/Slider.js +24 -10
- package/lib/module/Switch.js +25 -10
- package/lib/module/TabBar.js +23 -13
- package/lib/module/Table.js +4 -3
- package/lib/module/Tabs.js +3 -2
- package/lib/module/ai.js +26 -18
- package/lib/module/charts/BarChart.js +11 -3
- package/lib/module/index.js +23 -2
- package/lib/module/internal/GlassContainer.js +54 -0
- package/lib/module/internal/GlassView.js +10 -2
- package/lib/module/internal/a11y.js +94 -0
- package/lib/module/internal/blur.js +78 -0
- package/lib/module/internal/fallback.js +120 -19
- package/lib/module/internal/glass-routing.js +7 -0
- package/lib/module/internal/glow.js +36 -0
- package/lib/module/internal/haptics.js +54 -0
- package/lib/module/internal/lens.js +70 -0
- package/lib/module/internal/material.js +64 -0
- package/lib/module/internal/motion.js +10 -1
- package/lib/module/internal/primitives.js +70 -4
- package/lib/module/internal/rim.js +35 -0
- package/lib/module/internal/tokens.js +80 -2
- package/lib/typescript/Bars.d.ts +67 -0
- package/lib/typescript/Display.d.ts +59 -0
- package/lib/typescript/Feedback.d.ts +58 -0
- package/lib/typescript/Forms2.d.ts +81 -0
- package/lib/typescript/Message.d.ts +67 -0
- package/lib/typescript/Overlays.d.ts +41 -0
- package/lib/typescript/SegmentedControl.d.ts +2 -0
- package/lib/typescript/Slider.d.ts +2 -0
- package/lib/typescript/Switch.d.ts +2 -0
- package/lib/typescript/TabBar.d.ts +2 -0
- package/lib/typescript/index.d.ts +9 -6
- package/lib/typescript/internal/GlassContainer.d.ts +37 -0
- package/lib/typescript/internal/GlassView.d.ts +21 -0
- package/lib/typescript/internal/a11y.d.ts +19 -0
- package/lib/typescript/internal/blur.d.ts +24 -0
- package/lib/typescript/internal/fallback.d.ts +32 -2
- package/lib/typescript/internal/glass-routing.d.ts +10 -0
- package/lib/typescript/internal/glow.d.ts +11 -0
- package/lib/typescript/internal/haptics.d.ts +7 -0
- package/lib/typescript/internal/lens.d.ts +47 -0
- package/lib/typescript/internal/material.d.ts +27 -0
- package/lib/typescript/internal/motion.d.ts +4 -0
- package/lib/typescript/internal/primitives.d.ts +23 -0
- package/lib/typescript/internal/rim.d.ts +16 -0
- package/lib/typescript/internal/tokens.d.ts +89 -0
- package/package.json +12 -3
- package/src/Bars.tsx +239 -2
- package/src/Button.tsx +16 -9
- package/src/Card.tsx +2 -2
- package/src/Dialog.tsx +37 -26
- package/src/Display.tsx +237 -6
- package/src/Feedback.tsx +448 -35
- package/src/Form.tsx +60 -40
- package/src/Forms2.tsx +455 -8
- package/src/Glass.tsx +4 -0
- package/src/Input.tsx +15 -11
- package/src/Message.tsx +218 -0
- package/src/Overlays.tsx +269 -39
- package/src/Pickers.tsx +11 -6
- package/src/SegmentedControl.tsx +39 -9
- package/src/Slider.tsx +26 -10
- package/src/Switch.tsx +29 -10
- package/src/TabBar.tsx +39 -12
- package/src/Table.tsx +4 -3
- package/src/Tabs.tsx +5 -0
- package/src/ai.tsx +37 -23
- package/src/charts/BarChart.tsx +41 -3
- package/src/index.ts +43 -1
- package/src/internal/GlassContainer.tsx +82 -0
- package/src/internal/GlassView.tsx +25 -0
- package/src/internal/a11y.ts +105 -0
- package/src/internal/blur.ts +90 -0
- package/src/internal/fallback.tsx +170 -15
- package/src/internal/glass-routing.ts +17 -0
- package/src/internal/glow.tsx +62 -0
- package/src/internal/haptics.ts +59 -0
- package/src/internal/lens.tsx +105 -0
- package/src/internal/material.ts +92 -0
- package/src/internal/motion.ts +10 -1
- package/src/internal/primitives.ts +83 -4
- package/src/internal/rim.tsx +79 -0
- package/src/internal/tokens.ts +82 -1
package/src/Feedback.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { forwardRef, useEffect, useRef, useState, type ReactNode } from "react";
|
|
1
|
+
import { createContext, forwardRef, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
|
|
2
2
|
import type { StyleProp, ViewStyle } from "react-native";
|
|
3
3
|
|
|
4
4
|
import { Glass } from "./Glass";
|
|
@@ -6,6 +6,8 @@ import { Separator } from "./Display";
|
|
|
6
6
|
import { colors, radii, toneColor, type Tone } from "./internal/tokens";
|
|
7
7
|
import { primitives } from "./internal/primitives";
|
|
8
8
|
import { useIsDark, useSpring } from "./internal/motion";
|
|
9
|
+
import { SelectedLens, rowLensStyle } from "./internal/lens";
|
|
10
|
+
import { hapticSelection } from "./internal/haptics";
|
|
9
11
|
|
|
10
12
|
// ---------------------------------------------------------------------------
|
|
11
13
|
// Toast
|
|
@@ -104,15 +106,21 @@ export const Toast = forwardRef<any, ToastProps>(function Toast(
|
|
|
104
106
|
<Entrance animated={animated} rise={rise} fade={fade}>
|
|
105
107
|
<Glass
|
|
106
108
|
effect="regular"
|
|
109
|
+
surface="overlay"
|
|
107
110
|
isDark={isDark}
|
|
108
111
|
style={{
|
|
109
112
|
flexDirection: "row",
|
|
110
113
|
alignItems: "center",
|
|
111
114
|
gap: 10,
|
|
112
|
-
paddingVertical:
|
|
113
|
-
paddingHorizontal:
|
|
114
|
-
borderRadius: radii.
|
|
115
|
-
maxWidth:
|
|
115
|
+
paddingVertical: 12,
|
|
116
|
+
paddingHorizontal: 16,
|
|
117
|
+
borderRadius: radii.lg,
|
|
118
|
+
maxWidth: 400,
|
|
119
|
+
minWidth: 280,
|
|
120
|
+
// A toast floats above everything; without a shadow it is a label.
|
|
121
|
+
shadowOpacity: 0.12,
|
|
122
|
+
shadowRadius: 30,
|
|
123
|
+
shadowOffset: { width: 0, height: 10 },
|
|
116
124
|
borderColor: tone === "neutral" ? theme.edge : accent,
|
|
117
125
|
}}
|
|
118
126
|
>
|
|
@@ -120,7 +128,7 @@ export const Toast = forwardRef<any, ToastProps>(function Toast(
|
|
|
120
128
|
<RNText
|
|
121
129
|
accessibilityRole="alert"
|
|
122
130
|
accessibilityLiveRegion="polite"
|
|
123
|
-
style={{ fontSize:
|
|
131
|
+
style={{ fontSize: 13, color: theme.foreground, flexShrink: 1 }}
|
|
124
132
|
>
|
|
125
133
|
{message}
|
|
126
134
|
</RNText>
|
|
@@ -168,6 +176,197 @@ function Entrance({
|
|
|
168
176
|
);
|
|
169
177
|
}
|
|
170
178
|
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
// ToastViewport
|
|
181
|
+
|
|
182
|
+
/** One message in a ToastViewport's queue. */
|
|
183
|
+
export interface ToastItem {
|
|
184
|
+
/** A stable identity. Required, because the queue reorders and dismisses. */
|
|
185
|
+
id: string;
|
|
186
|
+
message: string;
|
|
187
|
+
action?: ToastAction;
|
|
188
|
+
icon?: ReactNode;
|
|
189
|
+
tone?: Tone | "neutral";
|
|
190
|
+
/** Milliseconds before it dismisses itself. 0 keeps it until dismissed. */
|
|
191
|
+
duration?: number;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export interface ToastViewportProps {
|
|
195
|
+
/** The messages to show. The oldest are dropped when more than 3 arrive. */
|
|
196
|
+
toasts: ToastItem[];
|
|
197
|
+
/** Called when one leaves, by timer, by swipe or by its action. */
|
|
198
|
+
onDismiss: (id: string) => void;
|
|
199
|
+
/** How many are visible at once. Extras wait in order. Defaults to 3. */
|
|
200
|
+
max?: number;
|
|
201
|
+
/** Where the stack sits. */
|
|
202
|
+
position?: "top" | "bottom";
|
|
203
|
+
style?: StyleProp<ViewStyle>;
|
|
204
|
+
isDark?: boolean;
|
|
205
|
+
testID?: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* A queue of toasts, stacked the way Sonner stacks them.
|
|
210
|
+
*
|
|
211
|
+
* Three at a time is the practical limit: beyond that the messages stop being
|
|
212
|
+
* read and start covering the screen. Extras wait in the order they arrived, so
|
|
213
|
+
* no message is lost and the newest is never hidden behind a backlog.
|
|
214
|
+
*
|
|
215
|
+
* Each toast is independently dismissible — its own timer, its own action, and
|
|
216
|
+
* a swipe up. Swiping one up removes only that one.
|
|
217
|
+
*
|
|
218
|
+
* The single `Toast` keeps working unchanged: this is the host for when an app
|
|
219
|
+
* has several messages at once, not a replacement. A caller that shows one
|
|
220
|
+
* message continues to use `Toast` directly.
|
|
221
|
+
*/
|
|
222
|
+
export const ToastViewport = forwardRef<any, ToastViewportProps>(function ToastViewport(
|
|
223
|
+
{ toasts, onDismiss, max = 3, position = "bottom", style, isDark: isDarkProp, testID, ...props },
|
|
224
|
+
ref,
|
|
225
|
+
) {
|
|
226
|
+
const isDark = useIsDark(isDarkProp);
|
|
227
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
228
|
+
const { View, PanResponder } = primitives();
|
|
229
|
+
|
|
230
|
+
// The visible window is the newest `max`, so a burst shows the latest
|
|
231
|
+
// messages rather than a stale backlog. Earlier ones remain queued in the
|
|
232
|
+
// caller's array and appear as the visible ones leave.
|
|
233
|
+
//
|
|
234
|
+
// A host is often rendered for the whole life of a screen and simply has no
|
|
235
|
+
// messages yet, so an absent queue means empty rather than a crash.
|
|
236
|
+
const visible = (toasts ?? []).slice(0, Math.max(0, max));
|
|
237
|
+
|
|
238
|
+
return (
|
|
239
|
+
<View
|
|
240
|
+
ref={ref}
|
|
241
|
+
testID={testID}
|
|
242
|
+
pointerEvents="box-none"
|
|
243
|
+
style={{
|
|
244
|
+
position: "absolute",
|
|
245
|
+
left: 0,
|
|
246
|
+
right: 0,
|
|
247
|
+
alignItems: "center",
|
|
248
|
+
gap: 8,
|
|
249
|
+
...(position === "top" ? { top: 16 } : { bottom: 16 }),
|
|
250
|
+
...(style as ViewStyle),
|
|
251
|
+
}}
|
|
252
|
+
{...props}
|
|
253
|
+
>
|
|
254
|
+
{visible.map((toast) => (
|
|
255
|
+
<SwipeableToast
|
|
256
|
+
key={toast.id}
|
|
257
|
+
toast={toast}
|
|
258
|
+
isDark={isDark}
|
|
259
|
+
onDismiss={() => onDismiss(toast.id)}
|
|
260
|
+
theme={theme}
|
|
261
|
+
/>
|
|
262
|
+
))}
|
|
263
|
+
</View>
|
|
264
|
+
);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* One toast inside the viewport, with the swipe-up dismissal.
|
|
269
|
+
*
|
|
270
|
+
* Wrapping the existing Toast would have meant threading the gesture through
|
|
271
|
+
* its props, so the viewport renders the same pill with the gesture attached —
|
|
272
|
+
* the styling lives in one place (`Toast`), and this adds only the drag.
|
|
273
|
+
*/
|
|
274
|
+
function SwipeableToast({
|
|
275
|
+
toast,
|
|
276
|
+
isDark,
|
|
277
|
+
onDismiss,
|
|
278
|
+
theme,
|
|
279
|
+
}: {
|
|
280
|
+
toast: ToastItem;
|
|
281
|
+
isDark: boolean;
|
|
282
|
+
onDismiss: () => void;
|
|
283
|
+
theme: any;
|
|
284
|
+
}) {
|
|
285
|
+
const { View, Text: RNText, Pressable, PanResponder, Animated } = primitives();
|
|
286
|
+
const [lift, setLift] = useState(0);
|
|
287
|
+
const dismissRef = useRef(onDismiss);
|
|
288
|
+
dismissRef.current = onDismiss;
|
|
289
|
+
|
|
290
|
+
const duration = toast.duration ?? 4000;
|
|
291
|
+
useEffect(() => {
|
|
292
|
+
if (duration <= 0) return;
|
|
293
|
+
const timer = setTimeout(() => dismissRef.current(), duration);
|
|
294
|
+
return () => clearTimeout(timer);
|
|
295
|
+
}, [duration]);
|
|
296
|
+
|
|
297
|
+
const panResponder = useMemo(() => {
|
|
298
|
+
if (!PanResponder?.create) return null;
|
|
299
|
+
return PanResponder.create({
|
|
300
|
+
onMoveShouldSetPanResponder: (_event: any, gesture: any) =>
|
|
301
|
+
// Only an upward swipe removes a toast; downward drags are ignored.
|
|
302
|
+
gesture.dy < -8 && Math.abs(gesture.dy) > Math.abs(gesture.dx),
|
|
303
|
+
onPanResponderMove: (_event: any, gesture: any) => setLift(Math.min(0, gesture.dy)),
|
|
304
|
+
onPanResponderRelease: (_event: any, gesture: any) => {
|
|
305
|
+
// A quick flick or a long drag removes it; anything less springs back.
|
|
306
|
+
if (gesture.dy < -40 || gesture.vy < -0.5) {
|
|
307
|
+
dismissRef.current();
|
|
308
|
+
} else {
|
|
309
|
+
setLift(0);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
onPanResponderTerminate: () => setLift(0),
|
|
313
|
+
});
|
|
314
|
+
}, [PanResponder]);
|
|
315
|
+
|
|
316
|
+
const tone = toast.tone ?? "neutral";
|
|
317
|
+
const accent = tone === "neutral" ? theme.foreground : toneColor(theme, tone);
|
|
318
|
+
|
|
319
|
+
const pill = (
|
|
320
|
+
<Glass
|
|
321
|
+
effect="regular"
|
|
322
|
+
isDark={isDark}
|
|
323
|
+
style={{
|
|
324
|
+
flexDirection: "row",
|
|
325
|
+
alignItems: "center",
|
|
326
|
+
gap: 10,
|
|
327
|
+
paddingVertical: 10,
|
|
328
|
+
paddingHorizontal: 14,
|
|
329
|
+
borderRadius: radii.pill,
|
|
330
|
+
maxWidth: 420,
|
|
331
|
+
borderColor: tone === "neutral" ? theme.edge : accent,
|
|
332
|
+
}}
|
|
333
|
+
>
|
|
334
|
+
{toast.icon ? <View>{toast.icon}</View> : null}
|
|
335
|
+
<RNText
|
|
336
|
+
accessibilityRole="alert"
|
|
337
|
+
accessibilityLiveRegion="polite"
|
|
338
|
+
style={{ fontSize: 14, color: theme.foreground, flexShrink: 1 }}
|
|
339
|
+
>
|
|
340
|
+
{toast.message}
|
|
341
|
+
</RNText>
|
|
342
|
+
{toast.action ? (
|
|
343
|
+
<Pressable
|
|
344
|
+
accessibilityRole="button"
|
|
345
|
+
accessibilityLabel={toast.action.label}
|
|
346
|
+
onPress={() => {
|
|
347
|
+
toast.action?.onPress();
|
|
348
|
+
onDismiss();
|
|
349
|
+
}}
|
|
350
|
+
style={{ paddingHorizontal: 4 }}
|
|
351
|
+
>
|
|
352
|
+
<RNText style={{ fontSize: 14, fontWeight: "600", color: theme.fill }}>
|
|
353
|
+
{toast.action.label}
|
|
354
|
+
</RNText>
|
|
355
|
+
</Pressable>
|
|
356
|
+
) : null}
|
|
357
|
+
</Glass>
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
return (
|
|
361
|
+
<View
|
|
362
|
+
style={{ transform: [{ translateY: lift }], opacity: lift === 0 ? 1 : Math.max(0.4, 1 + lift / 120) }}
|
|
363
|
+
{...(panResponder ? panResponder.panHandlers : {})}
|
|
364
|
+
>
|
|
365
|
+
{pill}
|
|
366
|
+
</View>
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
|
|
171
370
|
// ---------------------------------------------------------------------------
|
|
172
371
|
// Banner
|
|
173
372
|
|
|
@@ -207,6 +406,7 @@ export const Banner = forwardRef<any, BannerProps>(function Banner(
|
|
|
207
406
|
<Glass
|
|
208
407
|
ref={ref}
|
|
209
408
|
effect="regular"
|
|
409
|
+
surface="overlay"
|
|
210
410
|
isDark={isDark}
|
|
211
411
|
testID={testID}
|
|
212
412
|
style={{ borderRadius: radii.md, borderColor: accent, ...(style as ViewStyle) }}
|
|
@@ -258,6 +458,16 @@ export const Banner = forwardRef<any, BannerProps>(function Banner(
|
|
|
258
458
|
// ---------------------------------------------------------------------------
|
|
259
459
|
// List
|
|
260
460
|
|
|
461
|
+
/** One action revealed by swiping a row. */
|
|
462
|
+
export interface ListSwipeAction {
|
|
463
|
+
label: string;
|
|
464
|
+
/** A leading node, typically an SVG icon the caller supplies. */
|
|
465
|
+
icon?: ReactNode;
|
|
466
|
+
/** The action's tint. Defaults to the theme's fill. */
|
|
467
|
+
color?: string;
|
|
468
|
+
onPress: () => void;
|
|
469
|
+
}
|
|
470
|
+
|
|
261
471
|
export interface ListItemProps {
|
|
262
472
|
/** An avatar, icon or other leading node. */
|
|
263
473
|
leading?: ReactNode;
|
|
@@ -272,11 +482,33 @@ export interface ListItemProps {
|
|
|
272
482
|
onPress?: () => void;
|
|
273
483
|
disabled?: boolean;
|
|
274
484
|
selected?: boolean;
|
|
485
|
+
/** Actions revealed by swiping right (towards the trailing edge). */
|
|
486
|
+
swipeActions?: ListSwipeAction[];
|
|
487
|
+
/** Actions revealed by swiping left. */
|
|
488
|
+
leadingSwipeActions?: ListSwipeAction[];
|
|
489
|
+
/** Width allotted to each revealed action button. */
|
|
490
|
+
swipeActionWidth?: number;
|
|
491
|
+
/** Turns the swipe gesture off, leaving the row's `onPress` only. */
|
|
492
|
+
swipeable?: boolean;
|
|
493
|
+
/** Opt out of the selection tick when a swipe opens. */
|
|
494
|
+
haptics?: boolean;
|
|
275
495
|
style?: StyleProp<ViewStyle>;
|
|
276
496
|
isDark?: boolean;
|
|
277
497
|
testID?: string;
|
|
278
498
|
}
|
|
279
499
|
|
|
500
|
+
/**
|
|
501
|
+
* Tracks which row of a List is open, so opening one closes the rest.
|
|
502
|
+
*
|
|
503
|
+
* A list with two open rows looks broken; iOS Mail and every kit that copied
|
|
504
|
+
* it keep at most one. The List provides the registry and each swipeable row
|
|
505
|
+
* registers its own close function.
|
|
506
|
+
*/
|
|
507
|
+
const OpenRowContext = createContext<{
|
|
508
|
+
openId: string | null;
|
|
509
|
+
setOpenId: (id: string | null) => void;
|
|
510
|
+
} | null>(null);
|
|
511
|
+
|
|
280
512
|
/**
|
|
281
513
|
* One row of a List.
|
|
282
514
|
*
|
|
@@ -295,6 +527,11 @@ export const ListItem = forwardRef<any, ListItemProps>(function ListItem(
|
|
|
295
527
|
onPress,
|
|
296
528
|
disabled = false,
|
|
297
529
|
selected = false,
|
|
530
|
+
swipeActions,
|
|
531
|
+
leadingSwipeActions,
|
|
532
|
+
swipeActionWidth = 78,
|
|
533
|
+
swipeable = true,
|
|
534
|
+
haptics = true,
|
|
298
535
|
style,
|
|
299
536
|
isDark: isDarkProp,
|
|
300
537
|
testID,
|
|
@@ -304,11 +541,106 @@ export const ListItem = forwardRef<any, ListItemProps>(function ListItem(
|
|
|
304
541
|
) {
|
|
305
542
|
const isDark = useIsDark(isDarkProp);
|
|
306
543
|
const theme = isDark ? colors.dark : colors.light;
|
|
307
|
-
const { View, Text: RNText, Pressable } = primitives();
|
|
544
|
+
const { View, Text: RNText, Pressable, PanResponder } = primitives();
|
|
545
|
+
const rowGroup = useContext(OpenRowContext);
|
|
308
546
|
|
|
309
547
|
const interactive = Boolean(onPress) && !disabled;
|
|
310
548
|
const showChevron = interactive && chevron !== false && trailing === undefined;
|
|
311
549
|
|
|
550
|
+
const trailActions = swipeActions?.filter(Boolean) ?? [];
|
|
551
|
+
const leadActions = leadingSwipeActions?.filter(Boolean) ?? [];
|
|
552
|
+
const canSwipe = swipeable && !disabled && (trailActions.length > 0 || leadActions.length > 0);
|
|
553
|
+
|
|
554
|
+
// The row's own identity, so a List can close its siblings.
|
|
555
|
+
const rowId = useRef<string>(`row-${Math.random().toString(36).slice(2)}`);
|
|
556
|
+
|
|
557
|
+
// 0 is closed; a positive offset reveals trailing actions, negative leading.
|
|
558
|
+
const [offset, setOffset] = useState(0);
|
|
559
|
+
const offsetRef = useRef(0);
|
|
560
|
+
offsetRef.current = offset;
|
|
561
|
+
// A gesture that moved is a swipe, not a tap: the press that follows the
|
|
562
|
+
// release must not fire the row's onPress.
|
|
563
|
+
const swipedRef = useRef(false);
|
|
564
|
+
|
|
565
|
+
const trailingWidth = trailActions.length * swipeActionWidth;
|
|
566
|
+
const leadingWidth = leadActions.length * swipeActionWidth;
|
|
567
|
+
|
|
568
|
+
const close = () => setOffset(0);
|
|
569
|
+
|
|
570
|
+
// When another row opens, this one closes.
|
|
571
|
+
useEffect(() => {
|
|
572
|
+
if (rowGroup && rowGroup.openId !== rowId.current && offsetRef.current !== 0) {
|
|
573
|
+
setOffset(0);
|
|
574
|
+
}
|
|
575
|
+
}, [rowGroup?.openId]);
|
|
576
|
+
|
|
577
|
+
const settle = (next: number) => {
|
|
578
|
+
setOffset(next);
|
|
579
|
+
if (rowGroup) {
|
|
580
|
+
rowGroup.setOpenId(next !== 0 ? rowId.current : null);
|
|
581
|
+
}
|
|
582
|
+
if (next !== 0 && haptics && offsetRef.current === 0) hapticSelection();
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
const panResponder = useMemo(() => {
|
|
586
|
+
if (!canSwipe || !PanResponder?.create) return null;
|
|
587
|
+
return PanResponder.create({
|
|
588
|
+
// A horizontal drag claims the gesture; a vertical one stays with the
|
|
589
|
+
// surrounding scroll view.
|
|
590
|
+
onMoveShouldSetPanResponder: (_event: any, gesture: any) =>
|
|
591
|
+
Math.abs(gesture.dx) > Math.abs(gesture.dy) && Math.abs(gesture.dx) > 8,
|
|
592
|
+
onPanResponderGrant: () => {
|
|
593
|
+
swipedRef.current = false;
|
|
594
|
+
},
|
|
595
|
+
onPanResponderMove: (_event: any, gesture: any) => {
|
|
596
|
+
if (Math.abs(gesture.dx) > 4) swipedRef.current = true;
|
|
597
|
+
const from = offsetRef.current;
|
|
598
|
+
let next = from + gesture.dx;
|
|
599
|
+
// Do not drag past what the actions actually occupy; a small
|
|
600
|
+
// overshoot makes the edge feel elastic rather than hard.
|
|
601
|
+
next = Math.min(next, trailingWidth + 24);
|
|
602
|
+
next = Math.max(next, -(leadingWidth + 24));
|
|
603
|
+
setOffset(next);
|
|
604
|
+
},
|
|
605
|
+
onPanResponderRelease: (_event: any, gesture: any) => {
|
|
606
|
+
const released = offsetRef.current;
|
|
607
|
+
// Beyond half an action, or with a decisive flick, it stays open;
|
|
608
|
+
// otherwise it falls back closed.
|
|
609
|
+
if (gesture.dx > 0 && trailActions.length > 0) {
|
|
610
|
+
settle(released > trailingWidth / 2 || gesture.vx > 0.5 ? trailingWidth : 0);
|
|
611
|
+
} else if (gesture.dx < 0 && leadActions.length > 0) {
|
|
612
|
+
settle(released < -leadingWidth / 2 || gesture.vx < -0.5 ? -leadingWidth : 0);
|
|
613
|
+
} else {
|
|
614
|
+
settle(offsetRef.current > 0 ? Math.min(offsetRef.current, trailingWidth) : Math.max(offsetRef.current, -leadingWidth));
|
|
615
|
+
}
|
|
616
|
+
},
|
|
617
|
+
onPanResponderTerminate: () => settle(0),
|
|
618
|
+
onPanResponderTerminationRequest: () => false,
|
|
619
|
+
});
|
|
620
|
+
// The responder reads from refs, so it never acts on a stale offset.
|
|
621
|
+
}, [canSwipe, PanResponder, trailingWidth, leadingWidth, trailActions.length, leadActions.length]);
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Runs an action and closes the row.
|
|
625
|
+
*
|
|
626
|
+
* The action is dispatched first so its own feedback is not delayed by the
|
|
627
|
+
* close, then the row resets — the reveal should not outlive the press.
|
|
628
|
+
*/
|
|
629
|
+
const runAction = (action: ListSwipeAction) => {
|
|
630
|
+
action.onPress();
|
|
631
|
+
settle(0);
|
|
632
|
+
if (rowGroup) rowGroup.setOpenId(null);
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
const guardPress = (handler?: () => void) => () => {
|
|
636
|
+
// Swallow the press that ends a swipe.
|
|
637
|
+
if (swipedRef.current) {
|
|
638
|
+
swipedRef.current = false;
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
handler?.();
|
|
642
|
+
};
|
|
643
|
+
|
|
312
644
|
const content = (
|
|
313
645
|
<>
|
|
314
646
|
{leading ? <View style={{ marginRight: 12 }}>{leading}</View> : null}
|
|
@@ -337,36 +669,107 @@ export const ListItem = forwardRef<any, ListItemProps>(function ListItem(
|
|
|
337
669
|
const rowStyle: ViewStyle = {
|
|
338
670
|
flexDirection: "row",
|
|
339
671
|
alignItems: "center",
|
|
340
|
-
minHeight:
|
|
672
|
+
minHeight: 44,
|
|
341
673
|
paddingVertical: 10,
|
|
342
|
-
paddingHorizontal:
|
|
343
|
-
|
|
674
|
+
paddingHorizontal: 16,
|
|
675
|
+
// The selected row is a lens painted behind the content, not a flat wash.
|
|
676
|
+
backgroundColor: "transparent",
|
|
344
677
|
opacity: disabled ? 0.38 : 1,
|
|
345
678
|
...(style as ViewStyle),
|
|
346
679
|
};
|
|
347
680
|
|
|
348
|
-
|
|
681
|
+
const lens = selected ? (
|
|
682
|
+
<SelectedLens
|
|
683
|
+
radius={8}
|
|
684
|
+
isDark={isDark}
|
|
685
|
+
style={rowLensStyle(8)}
|
|
686
|
+
testID={testID ? `${testID}-lens` : undefined}
|
|
687
|
+
/>
|
|
688
|
+
) : null;
|
|
689
|
+
|
|
690
|
+
const rowInner = !interactive ? (
|
|
691
|
+
<View accessibilityRole="text" accessibilityState={{ disabled }} style={rowStyle}>
|
|
692
|
+
{lens}
|
|
693
|
+
{content}
|
|
694
|
+
</View>
|
|
695
|
+
) : (
|
|
696
|
+
<Pressable
|
|
697
|
+
accessibilityRole="button"
|
|
698
|
+
accessibilityLabel={description ? `${title}, ${description}` : title}
|
|
699
|
+
accessibilityState={{ selected, disabled }}
|
|
700
|
+
disabled={disabled}
|
|
701
|
+
onPress={guardPress(onPress)}
|
|
702
|
+
style={({ pressed }: { pressed: boolean }) => ({ ...rowStyle, opacity: pressed ? 0.7 : rowStyle.opacity })}
|
|
703
|
+
>
|
|
704
|
+
{lens}
|
|
705
|
+
{content}
|
|
706
|
+
</Pressable>
|
|
707
|
+
);
|
|
708
|
+
|
|
709
|
+
if (!canSwipe) {
|
|
349
710
|
return (
|
|
350
|
-
<View ref={ref} testID={testID}
|
|
351
|
-
{
|
|
711
|
+
<View ref={ref} testID={testID} style={{ overflow: "hidden" }} {...props}>
|
|
712
|
+
{rowInner}
|
|
352
713
|
</View>
|
|
353
714
|
);
|
|
354
715
|
}
|
|
355
716
|
|
|
717
|
+
/** The tinted tray behind the row: glass-tinted actions, flat not glass. */
|
|
718
|
+
const tray = (actions: ListSwipeAction[], edge: "left" | "right") => (
|
|
719
|
+
<View
|
|
720
|
+
style={{
|
|
721
|
+
position: "absolute",
|
|
722
|
+
top: 0,
|
|
723
|
+
bottom: 0,
|
|
724
|
+
[edge]: 0,
|
|
725
|
+
flexDirection: "row",
|
|
726
|
+
}}
|
|
727
|
+
>
|
|
728
|
+
{actions.map((action, index) => (
|
|
729
|
+
<Pressable
|
|
730
|
+
key={`${action.label}-${index}`}
|
|
731
|
+
accessibilityRole="button"
|
|
732
|
+
accessibilityLabel={action.label}
|
|
733
|
+
onPress={() => runAction(action)}
|
|
734
|
+
style={{
|
|
735
|
+
width: swipeActionWidth,
|
|
736
|
+
alignItems: "center",
|
|
737
|
+
justifyContent: "center",
|
|
738
|
+
gap: 3,
|
|
739
|
+
backgroundColor: action.color ?? theme.glassActive,
|
|
740
|
+
}}
|
|
741
|
+
>
|
|
742
|
+
{action.icon}
|
|
743
|
+
<RNText style={{ fontSize: 12, color: theme.foreground }} numberOfLines={1}>
|
|
744
|
+
{action.label}
|
|
745
|
+
</RNText>
|
|
746
|
+
</Pressable>
|
|
747
|
+
))}
|
|
748
|
+
</View>
|
|
749
|
+
);
|
|
750
|
+
|
|
356
751
|
return (
|
|
357
|
-
<
|
|
752
|
+
<View
|
|
358
753
|
ref={ref}
|
|
359
754
|
testID={testID}
|
|
360
|
-
accessibilityRole="
|
|
361
|
-
|
|
362
|
-
accessibilityState={{ selected, disabled }}
|
|
363
|
-
disabled={disabled}
|
|
364
|
-
onPress={onPress}
|
|
365
|
-
style={({ pressed }: { pressed: boolean }) => ({ ...rowStyle, opacity: pressed ? 0.7 : rowStyle.opacity })}
|
|
755
|
+
accessibilityRole="none"
|
|
756
|
+
style={{ overflow: "hidden" }}
|
|
366
757
|
{...props}
|
|
367
758
|
>
|
|
368
|
-
{
|
|
369
|
-
|
|
759
|
+
{leadActions.length > 0 ? tray(leadActions, "right") : null}
|
|
760
|
+
{trailActions.length > 0 ? tray(trailActions, "left") : null}
|
|
761
|
+
<View
|
|
762
|
+
style={{
|
|
763
|
+
transform: [{ translateX: offset }],
|
|
764
|
+
// The row rides over its tray while it is open, so the actions are
|
|
765
|
+
// uncovered rather than shown alongside.
|
|
766
|
+
backgroundColor: "transparent",
|
|
767
|
+
}}
|
|
768
|
+
{...(panResponder ? panResponder.panHandlers : {})}
|
|
769
|
+
>
|
|
770
|
+
{rowInner}
|
|
771
|
+
</View>
|
|
772
|
+
</View>
|
|
370
773
|
);
|
|
371
774
|
});
|
|
372
775
|
|
|
@@ -395,15 +798,22 @@ export const List = forwardRef<any, ListProps>(function List(
|
|
|
395
798
|
|
|
396
799
|
const rows = Array.isArray(children) ? children.filter(Boolean) : children == null ? [] : [children];
|
|
397
800
|
|
|
801
|
+
// At most one swipeable row is open at a time, so a list never shows two
|
|
802
|
+
// trays at once.
|
|
803
|
+
const [openId, setOpenId] = useState<string | null>(null);
|
|
804
|
+
const group = useMemo(() => ({ openId, setOpenId }), [openId]);
|
|
805
|
+
|
|
398
806
|
const body = (
|
|
399
|
-
<
|
|
400
|
-
{
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
807
|
+
<OpenRowContext.Provider value={group}>
|
|
808
|
+
<View style={{ gap: 2 }}>
|
|
809
|
+
{rows.map((row, index) => (
|
|
810
|
+
<View key={index}>
|
|
811
|
+
{index > 0 ? <Separator isDark={isDark} inset={inset ? 14 : 0} /> : null}
|
|
812
|
+
{row}
|
|
813
|
+
</View>
|
|
814
|
+
))}
|
|
815
|
+
</View>
|
|
816
|
+
</OpenRowContext.Provider>
|
|
407
817
|
);
|
|
408
818
|
|
|
409
819
|
if (!inset) {
|
|
@@ -418,9 +828,10 @@ export const List = forwardRef<any, ListProps>(function List(
|
|
|
418
828
|
<Glass
|
|
419
829
|
ref={ref}
|
|
420
830
|
effect="regular"
|
|
831
|
+
surface="panel"
|
|
421
832
|
isDark={isDark}
|
|
422
833
|
testID={testID}
|
|
423
|
-
style={{ borderRadius: radii.
|
|
834
|
+
style={{ borderRadius: radii.lg, ...(style as ViewStyle) }}
|
|
424
835
|
{...props}
|
|
425
836
|
>
|
|
426
837
|
{body}
|
|
@@ -456,7 +867,8 @@ export const ListSection = forwardRef<any, ListSectionProps>(function ListSectio
|
|
|
456
867
|
letterSpacing: 0.4,
|
|
457
868
|
textTransform: "uppercase",
|
|
458
869
|
color: theme.muted,
|
|
459
|
-
paddingHorizontal:
|
|
870
|
+
paddingHorizontal: 16,
|
|
871
|
+
paddingVertical: 5,
|
|
460
872
|
}}
|
|
461
873
|
>
|
|
462
874
|
{header}
|
|
@@ -535,9 +947,10 @@ export const Accordion = forwardRef<any, AccordionProps>(function Accordion(
|
|
|
535
947
|
<Glass
|
|
536
948
|
ref={ref}
|
|
537
949
|
effect="regular"
|
|
950
|
+
surface="panel"
|
|
538
951
|
isDark={isDark}
|
|
539
952
|
testID={testID}
|
|
540
|
-
style={{ borderRadius: radii.
|
|
953
|
+
style={{ borderRadius: radii.stack, ...(style as ViewStyle) }}
|
|
541
954
|
{...props}
|
|
542
955
|
>
|
|
543
956
|
{sections.map((section, index) => {
|
|
@@ -550,7 +963,7 @@ export const Accordion = forwardRef<any, AccordionProps>(function Accordion(
|
|
|
550
963
|
accessibilityLabel={section.title}
|
|
551
964
|
accessibilityState={{ expanded }}
|
|
552
965
|
onPress={() => toggle(section.value)}
|
|
553
|
-
style={{ paddingVertical:
|
|
966
|
+
style={{ paddingVertical: 16, paddingHorizontal: 20, flexDirection: "row", alignItems: "center" }}
|
|
554
967
|
>
|
|
555
968
|
<View style={{ flex: 1, gap: 2 }}>
|
|
556
969
|
<RNText style={{ fontSize: 15, fontWeight: "500", color: theme.foreground }}>
|
|
@@ -569,7 +982,7 @@ export const Accordion = forwardRef<any, AccordionProps>(function Accordion(
|
|
|
569
982
|
</RNText>
|
|
570
983
|
</Pressable>
|
|
571
984
|
{expanded ? (
|
|
572
|
-
<View style={{ paddingHorizontal:
|
|
985
|
+
<View style={{ paddingHorizontal: 20, paddingBottom: 16 }}>{section.content}</View>
|
|
573
986
|
) : null}
|
|
574
987
|
</View>
|
|
575
988
|
);
|