glacia-native 0.5.0 → 0.5.1
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/lib/module/Bars.js +95 -2
- package/lib/module/Display.js +78 -1
- package/lib/module/Feedback.js +221 -7
- package/lib/module/Forms2.js +228 -1
- package/lib/module/Message.js +88 -0
- package/lib/module/Overlays.js +173 -11
- package/lib/module/SegmentedControl.js +5 -1
- package/lib/module/Slider.js +6 -1
- package/lib/module/Switch.js +4 -1
- package/lib/module/TabBar.js +5 -1
- package/lib/module/ai.js +8 -3
- package/lib/module/index.js +23 -2
- package/lib/module/internal/GlassContainer.js +54 -0
- package/lib/module/internal/GlassView.js +8 -0
- package/lib/module/internal/a11y.js +94 -0
- package/lib/module/internal/fallback.js +19 -8
- package/lib/module/internal/glass-routing.js +7 -0
- package/lib/module/internal/haptics.js +54 -0
- package/lib/module/internal/motion.js +10 -1
- package/lib/module/internal/primitives.js +69 -4
- package/lib/module/internal/tokens.js +47 -1
- 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 +71 -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 +8 -6
- package/lib/typescript/internal/GlassContainer.d.ts +37 -0
- package/lib/typescript/internal/GlassView.d.ts +8 -0
- package/lib/typescript/internal/a11y.d.ts +19 -0
- package/lib/typescript/internal/fallback.d.ts +5 -0
- package/lib/typescript/internal/glass-routing.d.ts +10 -0
- package/lib/typescript/internal/haptics.d.ts +7 -0
- package/lib/typescript/internal/motion.d.ts +4 -0
- package/lib/typescript/internal/primitives.d.ts +21 -0
- package/lib/typescript/internal/tokens.d.ts +53 -0
- package/package.json +2 -2
- package/src/Bars.tsx +227 -0
- package/src/Display.tsx +229 -1
- package/src/Feedback.tsx +412 -22
- package/src/Forms2.tsx +407 -1
- package/src/Message.tsx +219 -0
- package/src/Overlays.tsx +244 -33
- package/src/SegmentedControl.tsx +6 -0
- package/src/Slider.tsx +7 -0
- package/src/Switch.tsx +5 -0
- package/src/TabBar.tsx +6 -0
- package/src/ai.tsx +9 -3
- package/src/index.ts +42 -1
- package/src/internal/GlassContainer.tsx +82 -0
- package/src/internal/GlassView.tsx +8 -0
- package/src/internal/a11y.ts +105 -0
- package/src/internal/fallback.tsx +19 -2
- package/src/internal/glass-routing.ts +17 -0
- package/src/internal/haptics.ts +59 -0
- package/src/internal/motion.ts +10 -1
- package/src/internal/primitives.ts +80 -4
- package/src/internal/tokens.ts +48 -0
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,7 @@ 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 { hapticSelection } from "./internal/haptics";
|
|
9
10
|
|
|
10
11
|
// ---------------------------------------------------------------------------
|
|
11
12
|
// Toast
|
|
@@ -168,6 +169,197 @@ function Entrance({
|
|
|
168
169
|
);
|
|
169
170
|
}
|
|
170
171
|
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
// ToastViewport
|
|
174
|
+
|
|
175
|
+
/** One message in a ToastViewport's queue. */
|
|
176
|
+
export interface ToastItem {
|
|
177
|
+
/** A stable identity. Required, because the queue reorders and dismisses. */
|
|
178
|
+
id: string;
|
|
179
|
+
message: string;
|
|
180
|
+
action?: ToastAction;
|
|
181
|
+
icon?: ReactNode;
|
|
182
|
+
tone?: Tone | "neutral";
|
|
183
|
+
/** Milliseconds before it dismisses itself. 0 keeps it until dismissed. */
|
|
184
|
+
duration?: number;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface ToastViewportProps {
|
|
188
|
+
/** The messages to show. The oldest are dropped when more than 3 arrive. */
|
|
189
|
+
toasts: ToastItem[];
|
|
190
|
+
/** Called when one leaves, by timer, by swipe or by its action. */
|
|
191
|
+
onDismiss: (id: string) => void;
|
|
192
|
+
/** How many are visible at once. Extras wait in order. Defaults to 3. */
|
|
193
|
+
max?: number;
|
|
194
|
+
/** Where the stack sits. */
|
|
195
|
+
position?: "top" | "bottom";
|
|
196
|
+
style?: StyleProp<ViewStyle>;
|
|
197
|
+
isDark?: boolean;
|
|
198
|
+
testID?: string;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* A queue of toasts, stacked the way Sonner stacks them.
|
|
203
|
+
*
|
|
204
|
+
* Three at a time is the practical limit: beyond that the messages stop being
|
|
205
|
+
* read and start covering the screen. Extras wait in the order they arrived, so
|
|
206
|
+
* no message is lost and the newest is never hidden behind a backlog.
|
|
207
|
+
*
|
|
208
|
+
* Each toast is independently dismissible — its own timer, its own action, and
|
|
209
|
+
* a swipe up. Swiping one up removes only that one.
|
|
210
|
+
*
|
|
211
|
+
* The single `Toast` keeps working unchanged: this is the host for when an app
|
|
212
|
+
* has several messages at once, not a replacement. A caller that shows one
|
|
213
|
+
* message continues to use `Toast` directly.
|
|
214
|
+
*/
|
|
215
|
+
export const ToastViewport = forwardRef<any, ToastViewportProps>(function ToastViewport(
|
|
216
|
+
{ toasts, onDismiss, max = 3, position = "bottom", style, isDark: isDarkProp, testID, ...props },
|
|
217
|
+
ref,
|
|
218
|
+
) {
|
|
219
|
+
const isDark = useIsDark(isDarkProp);
|
|
220
|
+
const theme = isDark ? colors.dark : colors.light;
|
|
221
|
+
const { View, PanResponder } = primitives();
|
|
222
|
+
|
|
223
|
+
// The visible window is the newest `max`, so a burst shows the latest
|
|
224
|
+
// messages rather than a stale backlog. Earlier ones remain queued in the
|
|
225
|
+
// caller's array and appear as the visible ones leave.
|
|
226
|
+
//
|
|
227
|
+
// A host is often rendered for the whole life of a screen and simply has no
|
|
228
|
+
// messages yet, so an absent queue means empty rather than a crash.
|
|
229
|
+
const visible = (toasts ?? []).slice(0, Math.max(0, max));
|
|
230
|
+
|
|
231
|
+
return (
|
|
232
|
+
<View
|
|
233
|
+
ref={ref}
|
|
234
|
+
testID={testID}
|
|
235
|
+
pointerEvents="box-none"
|
|
236
|
+
style={{
|
|
237
|
+
position: "absolute",
|
|
238
|
+
left: 0,
|
|
239
|
+
right: 0,
|
|
240
|
+
alignItems: "center",
|
|
241
|
+
gap: 8,
|
|
242
|
+
...(position === "top" ? { top: 16 } : { bottom: 16 }),
|
|
243
|
+
...(style as ViewStyle),
|
|
244
|
+
}}
|
|
245
|
+
{...props}
|
|
246
|
+
>
|
|
247
|
+
{visible.map((toast) => (
|
|
248
|
+
<SwipeableToast
|
|
249
|
+
key={toast.id}
|
|
250
|
+
toast={toast}
|
|
251
|
+
isDark={isDark}
|
|
252
|
+
onDismiss={() => onDismiss(toast.id)}
|
|
253
|
+
theme={theme}
|
|
254
|
+
/>
|
|
255
|
+
))}
|
|
256
|
+
</View>
|
|
257
|
+
);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* One toast inside the viewport, with the swipe-up dismissal.
|
|
262
|
+
*
|
|
263
|
+
* Wrapping the existing Toast would have meant threading the gesture through
|
|
264
|
+
* its props, so the viewport renders the same pill with the gesture attached —
|
|
265
|
+
* the styling lives in one place (`Toast`), and this adds only the drag.
|
|
266
|
+
*/
|
|
267
|
+
function SwipeableToast({
|
|
268
|
+
toast,
|
|
269
|
+
isDark,
|
|
270
|
+
onDismiss,
|
|
271
|
+
theme,
|
|
272
|
+
}: {
|
|
273
|
+
toast: ToastItem;
|
|
274
|
+
isDark: boolean;
|
|
275
|
+
onDismiss: () => void;
|
|
276
|
+
theme: any;
|
|
277
|
+
}) {
|
|
278
|
+
const { View, Text: RNText, Pressable, PanResponder, Animated } = primitives();
|
|
279
|
+
const [lift, setLift] = useState(0);
|
|
280
|
+
const dismissRef = useRef(onDismiss);
|
|
281
|
+
dismissRef.current = onDismiss;
|
|
282
|
+
|
|
283
|
+
const duration = toast.duration ?? 4000;
|
|
284
|
+
useEffect(() => {
|
|
285
|
+
if (duration <= 0) return;
|
|
286
|
+
const timer = setTimeout(() => dismissRef.current(), duration);
|
|
287
|
+
return () => clearTimeout(timer);
|
|
288
|
+
}, [duration]);
|
|
289
|
+
|
|
290
|
+
const panResponder = useMemo(() => {
|
|
291
|
+
if (!PanResponder?.create) return null;
|
|
292
|
+
return PanResponder.create({
|
|
293
|
+
onMoveShouldSetPanResponder: (_event: any, gesture: any) =>
|
|
294
|
+
// Only an upward swipe removes a toast; downward drags are ignored.
|
|
295
|
+
gesture.dy < -8 && Math.abs(gesture.dy) > Math.abs(gesture.dx),
|
|
296
|
+
onPanResponderMove: (_event: any, gesture: any) => setLift(Math.min(0, gesture.dy)),
|
|
297
|
+
onPanResponderRelease: (_event: any, gesture: any) => {
|
|
298
|
+
// A quick flick or a long drag removes it; anything less springs back.
|
|
299
|
+
if (gesture.dy < -40 || gesture.vy < -0.5) {
|
|
300
|
+
dismissRef.current();
|
|
301
|
+
} else {
|
|
302
|
+
setLift(0);
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
onPanResponderTerminate: () => setLift(0),
|
|
306
|
+
});
|
|
307
|
+
}, [PanResponder]);
|
|
308
|
+
|
|
309
|
+
const tone = toast.tone ?? "neutral";
|
|
310
|
+
const accent = tone === "neutral" ? theme.foreground : toneColor(theme, tone);
|
|
311
|
+
|
|
312
|
+
const pill = (
|
|
313
|
+
<Glass
|
|
314
|
+
effect="regular"
|
|
315
|
+
isDark={isDark}
|
|
316
|
+
style={{
|
|
317
|
+
flexDirection: "row",
|
|
318
|
+
alignItems: "center",
|
|
319
|
+
gap: 10,
|
|
320
|
+
paddingVertical: 10,
|
|
321
|
+
paddingHorizontal: 14,
|
|
322
|
+
borderRadius: radii.pill,
|
|
323
|
+
maxWidth: 420,
|
|
324
|
+
borderColor: tone === "neutral" ? theme.edge : accent,
|
|
325
|
+
}}
|
|
326
|
+
>
|
|
327
|
+
{toast.icon ? <View>{toast.icon}</View> : null}
|
|
328
|
+
<RNText
|
|
329
|
+
accessibilityRole="alert"
|
|
330
|
+
accessibilityLiveRegion="polite"
|
|
331
|
+
style={{ fontSize: 14, color: theme.foreground, flexShrink: 1 }}
|
|
332
|
+
>
|
|
333
|
+
{toast.message}
|
|
334
|
+
</RNText>
|
|
335
|
+
{toast.action ? (
|
|
336
|
+
<Pressable
|
|
337
|
+
accessibilityRole="button"
|
|
338
|
+
accessibilityLabel={toast.action.label}
|
|
339
|
+
onPress={() => {
|
|
340
|
+
toast.action?.onPress();
|
|
341
|
+
onDismiss();
|
|
342
|
+
}}
|
|
343
|
+
style={{ paddingHorizontal: 4 }}
|
|
344
|
+
>
|
|
345
|
+
<RNText style={{ fontSize: 14, fontWeight: "600", color: theme.fill }}>
|
|
346
|
+
{toast.action.label}
|
|
347
|
+
</RNText>
|
|
348
|
+
</Pressable>
|
|
349
|
+
) : null}
|
|
350
|
+
</Glass>
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
return (
|
|
354
|
+
<View
|
|
355
|
+
style={{ transform: [{ translateY: lift }], opacity: lift === 0 ? 1 : Math.max(0.4, 1 + lift / 120) }}
|
|
356
|
+
{...(panResponder ? panResponder.panHandlers : {})}
|
|
357
|
+
>
|
|
358
|
+
{pill}
|
|
359
|
+
</View>
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
|
|
171
363
|
// ---------------------------------------------------------------------------
|
|
172
364
|
// Banner
|
|
173
365
|
|
|
@@ -258,6 +450,16 @@ export const Banner = forwardRef<any, BannerProps>(function Banner(
|
|
|
258
450
|
// ---------------------------------------------------------------------------
|
|
259
451
|
// List
|
|
260
452
|
|
|
453
|
+
/** One action revealed by swiping a row. */
|
|
454
|
+
export interface ListSwipeAction {
|
|
455
|
+
label: string;
|
|
456
|
+
/** A leading node, typically an SVG icon the caller supplies. */
|
|
457
|
+
icon?: ReactNode;
|
|
458
|
+
/** The action's tint. Defaults to the theme's fill. */
|
|
459
|
+
color?: string;
|
|
460
|
+
onPress: () => void;
|
|
461
|
+
}
|
|
462
|
+
|
|
261
463
|
export interface ListItemProps {
|
|
262
464
|
/** An avatar, icon or other leading node. */
|
|
263
465
|
leading?: ReactNode;
|
|
@@ -272,11 +474,33 @@ export interface ListItemProps {
|
|
|
272
474
|
onPress?: () => void;
|
|
273
475
|
disabled?: boolean;
|
|
274
476
|
selected?: boolean;
|
|
477
|
+
/** Actions revealed by swiping right (towards the trailing edge). */
|
|
478
|
+
swipeActions?: ListSwipeAction[];
|
|
479
|
+
/** Actions revealed by swiping left. */
|
|
480
|
+
leadingSwipeActions?: ListSwipeAction[];
|
|
481
|
+
/** Width allotted to each revealed action button. */
|
|
482
|
+
swipeActionWidth?: number;
|
|
483
|
+
/** Turns the swipe gesture off, leaving the row's `onPress` only. */
|
|
484
|
+
swipeable?: boolean;
|
|
485
|
+
/** Opt out of the selection tick when a swipe opens. */
|
|
486
|
+
haptics?: boolean;
|
|
275
487
|
style?: StyleProp<ViewStyle>;
|
|
276
488
|
isDark?: boolean;
|
|
277
489
|
testID?: string;
|
|
278
490
|
}
|
|
279
491
|
|
|
492
|
+
/**
|
|
493
|
+
* Tracks which row of a List is open, so opening one closes the rest.
|
|
494
|
+
*
|
|
495
|
+
* A list with two open rows looks broken; iOS Mail and every kit that copied
|
|
496
|
+
* it keep at most one. The List provides the registry and each swipeable row
|
|
497
|
+
* registers its own close function.
|
|
498
|
+
*/
|
|
499
|
+
const OpenRowContext = createContext<{
|
|
500
|
+
openId: string | null;
|
|
501
|
+
setOpenId: (id: string | null) => void;
|
|
502
|
+
} | null>(null);
|
|
503
|
+
|
|
280
504
|
/**
|
|
281
505
|
* One row of a List.
|
|
282
506
|
*
|
|
@@ -295,6 +519,11 @@ export const ListItem = forwardRef<any, ListItemProps>(function ListItem(
|
|
|
295
519
|
onPress,
|
|
296
520
|
disabled = false,
|
|
297
521
|
selected = false,
|
|
522
|
+
swipeActions,
|
|
523
|
+
leadingSwipeActions,
|
|
524
|
+
swipeActionWidth = 78,
|
|
525
|
+
swipeable = true,
|
|
526
|
+
haptics = true,
|
|
298
527
|
style,
|
|
299
528
|
isDark: isDarkProp,
|
|
300
529
|
testID,
|
|
@@ -304,11 +533,106 @@ export const ListItem = forwardRef<any, ListItemProps>(function ListItem(
|
|
|
304
533
|
) {
|
|
305
534
|
const isDark = useIsDark(isDarkProp);
|
|
306
535
|
const theme = isDark ? colors.dark : colors.light;
|
|
307
|
-
const { View, Text: RNText, Pressable } = primitives();
|
|
536
|
+
const { View, Text: RNText, Pressable, PanResponder } = primitives();
|
|
537
|
+
const rowGroup = useContext(OpenRowContext);
|
|
308
538
|
|
|
309
539
|
const interactive = Boolean(onPress) && !disabled;
|
|
310
540
|
const showChevron = interactive && chevron !== false && trailing === undefined;
|
|
311
541
|
|
|
542
|
+
const trailActions = swipeActions?.filter(Boolean) ?? [];
|
|
543
|
+
const leadActions = leadingSwipeActions?.filter(Boolean) ?? [];
|
|
544
|
+
const canSwipe = swipeable && !disabled && (trailActions.length > 0 || leadActions.length > 0);
|
|
545
|
+
|
|
546
|
+
// The row's own identity, so a List can close its siblings.
|
|
547
|
+
const rowId = useRef<string>(`row-${Math.random().toString(36).slice(2)}`);
|
|
548
|
+
|
|
549
|
+
// 0 is closed; a positive offset reveals trailing actions, negative leading.
|
|
550
|
+
const [offset, setOffset] = useState(0);
|
|
551
|
+
const offsetRef = useRef(0);
|
|
552
|
+
offsetRef.current = offset;
|
|
553
|
+
// A gesture that moved is a swipe, not a tap: the press that follows the
|
|
554
|
+
// release must not fire the row's onPress.
|
|
555
|
+
const swipedRef = useRef(false);
|
|
556
|
+
|
|
557
|
+
const trailingWidth = trailActions.length * swipeActionWidth;
|
|
558
|
+
const leadingWidth = leadActions.length * swipeActionWidth;
|
|
559
|
+
|
|
560
|
+
const close = () => setOffset(0);
|
|
561
|
+
|
|
562
|
+
// When another row opens, this one closes.
|
|
563
|
+
useEffect(() => {
|
|
564
|
+
if (rowGroup && rowGroup.openId !== rowId.current && offsetRef.current !== 0) {
|
|
565
|
+
setOffset(0);
|
|
566
|
+
}
|
|
567
|
+
}, [rowGroup?.openId]);
|
|
568
|
+
|
|
569
|
+
const settle = (next: number) => {
|
|
570
|
+
setOffset(next);
|
|
571
|
+
if (rowGroup) {
|
|
572
|
+
rowGroup.setOpenId(next !== 0 ? rowId.current : null);
|
|
573
|
+
}
|
|
574
|
+
if (next !== 0 && haptics && offsetRef.current === 0) hapticSelection();
|
|
575
|
+
};
|
|
576
|
+
|
|
577
|
+
const panResponder = useMemo(() => {
|
|
578
|
+
if (!canSwipe || !PanResponder?.create) return null;
|
|
579
|
+
return PanResponder.create({
|
|
580
|
+
// A horizontal drag claims the gesture; a vertical one stays with the
|
|
581
|
+
// surrounding scroll view.
|
|
582
|
+
onMoveShouldSetPanResponder: (_event: any, gesture: any) =>
|
|
583
|
+
Math.abs(gesture.dx) > Math.abs(gesture.dy) && Math.abs(gesture.dx) > 8,
|
|
584
|
+
onPanResponderGrant: () => {
|
|
585
|
+
swipedRef.current = false;
|
|
586
|
+
},
|
|
587
|
+
onPanResponderMove: (_event: any, gesture: any) => {
|
|
588
|
+
if (Math.abs(gesture.dx) > 4) swipedRef.current = true;
|
|
589
|
+
const from = offsetRef.current;
|
|
590
|
+
let next = from + gesture.dx;
|
|
591
|
+
// Do not drag past what the actions actually occupy; a small
|
|
592
|
+
// overshoot makes the edge feel elastic rather than hard.
|
|
593
|
+
next = Math.min(next, trailingWidth + 24);
|
|
594
|
+
next = Math.max(next, -(leadingWidth + 24));
|
|
595
|
+
setOffset(next);
|
|
596
|
+
},
|
|
597
|
+
onPanResponderRelease: (_event: any, gesture: any) => {
|
|
598
|
+
const released = offsetRef.current;
|
|
599
|
+
// Beyond half an action, or with a decisive flick, it stays open;
|
|
600
|
+
// otherwise it falls back closed.
|
|
601
|
+
if (gesture.dx > 0 && trailActions.length > 0) {
|
|
602
|
+
settle(released > trailingWidth / 2 || gesture.vx > 0.5 ? trailingWidth : 0);
|
|
603
|
+
} else if (gesture.dx < 0 && leadActions.length > 0) {
|
|
604
|
+
settle(released < -leadingWidth / 2 || gesture.vx < -0.5 ? -leadingWidth : 0);
|
|
605
|
+
} else {
|
|
606
|
+
settle(offsetRef.current > 0 ? Math.min(offsetRef.current, trailingWidth) : Math.max(offsetRef.current, -leadingWidth));
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
onPanResponderTerminate: () => settle(0),
|
|
610
|
+
onPanResponderTerminationRequest: () => false,
|
|
611
|
+
});
|
|
612
|
+
// The responder reads from refs, so it never acts on a stale offset.
|
|
613
|
+
}, [canSwipe, PanResponder, trailingWidth, leadingWidth, trailActions.length, leadActions.length]);
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Runs an action and closes the row.
|
|
617
|
+
*
|
|
618
|
+
* The action is dispatched first so its own feedback is not delayed by the
|
|
619
|
+
* close, then the row resets — the reveal should not outlive the press.
|
|
620
|
+
*/
|
|
621
|
+
const runAction = (action: ListSwipeAction) => {
|
|
622
|
+
action.onPress();
|
|
623
|
+
settle(0);
|
|
624
|
+
if (rowGroup) rowGroup.setOpenId(null);
|
|
625
|
+
};
|
|
626
|
+
|
|
627
|
+
const guardPress = (handler?: () => void) => () => {
|
|
628
|
+
// Swallow the press that ends a swipe.
|
|
629
|
+
if (swipedRef.current) {
|
|
630
|
+
swipedRef.current = false;
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
handler?.();
|
|
634
|
+
};
|
|
635
|
+
|
|
312
636
|
const content = (
|
|
313
637
|
<>
|
|
314
638
|
{leading ? <View style={{ marginRight: 12 }}>{leading}</View> : null}
|
|
@@ -345,28 +669,87 @@ export const ListItem = forwardRef<any, ListItemProps>(function ListItem(
|
|
|
345
669
|
...(style as ViewStyle),
|
|
346
670
|
};
|
|
347
671
|
|
|
348
|
-
|
|
672
|
+
const rowInner = !interactive ? (
|
|
673
|
+
<View accessibilityRole="text" accessibilityState={{ disabled }} style={rowStyle}>
|
|
674
|
+
{content}
|
|
675
|
+
</View>
|
|
676
|
+
) : (
|
|
677
|
+
<Pressable
|
|
678
|
+
accessibilityRole="button"
|
|
679
|
+
accessibilityLabel={description ? `${title}, ${description}` : title}
|
|
680
|
+
accessibilityState={{ selected, disabled }}
|
|
681
|
+
disabled={disabled}
|
|
682
|
+
onPress={guardPress(onPress)}
|
|
683
|
+
style={({ pressed }: { pressed: boolean }) => ({ ...rowStyle, opacity: pressed ? 0.7 : rowStyle.opacity })}
|
|
684
|
+
>
|
|
685
|
+
{content}
|
|
686
|
+
</Pressable>
|
|
687
|
+
);
|
|
688
|
+
|
|
689
|
+
if (!canSwipe) {
|
|
349
690
|
return (
|
|
350
|
-
<View ref={ref} testID={testID}
|
|
351
|
-
{
|
|
691
|
+
<View ref={ref} testID={testID} style={{ overflow: "hidden" }} {...props}>
|
|
692
|
+
{rowInner}
|
|
352
693
|
</View>
|
|
353
694
|
);
|
|
354
695
|
}
|
|
355
696
|
|
|
697
|
+
/** The tinted tray behind the row: glass-tinted actions, flat not glass. */
|
|
698
|
+
const tray = (actions: ListSwipeAction[], edge: "left" | "right") => (
|
|
699
|
+
<View
|
|
700
|
+
style={{
|
|
701
|
+
position: "absolute",
|
|
702
|
+
top: 0,
|
|
703
|
+
bottom: 0,
|
|
704
|
+
[edge]: 0,
|
|
705
|
+
flexDirection: "row",
|
|
706
|
+
}}
|
|
707
|
+
>
|
|
708
|
+
{actions.map((action, index) => (
|
|
709
|
+
<Pressable
|
|
710
|
+
key={`${action.label}-${index}`}
|
|
711
|
+
accessibilityRole="button"
|
|
712
|
+
accessibilityLabel={action.label}
|
|
713
|
+
onPress={() => runAction(action)}
|
|
714
|
+
style={{
|
|
715
|
+
width: swipeActionWidth,
|
|
716
|
+
alignItems: "center",
|
|
717
|
+
justifyContent: "center",
|
|
718
|
+
gap: 3,
|
|
719
|
+
backgroundColor: action.color ?? theme.glassActive,
|
|
720
|
+
}}
|
|
721
|
+
>
|
|
722
|
+
{action.icon}
|
|
723
|
+
<RNText style={{ fontSize: 12, color: theme.foreground }} numberOfLines={1}>
|
|
724
|
+
{action.label}
|
|
725
|
+
</RNText>
|
|
726
|
+
</Pressable>
|
|
727
|
+
))}
|
|
728
|
+
</View>
|
|
729
|
+
);
|
|
730
|
+
|
|
356
731
|
return (
|
|
357
|
-
<
|
|
732
|
+
<View
|
|
358
733
|
ref={ref}
|
|
359
734
|
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 })}
|
|
735
|
+
accessibilityRole="none"
|
|
736
|
+
style={{ overflow: "hidden" }}
|
|
366
737
|
{...props}
|
|
367
738
|
>
|
|
368
|
-
{
|
|
369
|
-
|
|
739
|
+
{leadActions.length > 0 ? tray(leadActions, "right") : null}
|
|
740
|
+
{trailActions.length > 0 ? tray(trailActions, "left") : null}
|
|
741
|
+
<View
|
|
742
|
+
style={{
|
|
743
|
+
transform: [{ translateX: offset }],
|
|
744
|
+
// The row rides over its tray while it is open, so the actions are
|
|
745
|
+
// uncovered rather than shown alongside.
|
|
746
|
+
backgroundColor: "transparent",
|
|
747
|
+
}}
|
|
748
|
+
{...(panResponder ? panResponder.panHandlers : {})}
|
|
749
|
+
>
|
|
750
|
+
{rowInner}
|
|
751
|
+
</View>
|
|
752
|
+
</View>
|
|
370
753
|
);
|
|
371
754
|
});
|
|
372
755
|
|
|
@@ -395,15 +778,22 @@ export const List = forwardRef<any, ListProps>(function List(
|
|
|
395
778
|
|
|
396
779
|
const rows = Array.isArray(children) ? children.filter(Boolean) : children == null ? [] : [children];
|
|
397
780
|
|
|
781
|
+
// At most one swipeable row is open at a time, so a list never shows two
|
|
782
|
+
// trays at once.
|
|
783
|
+
const [openId, setOpenId] = useState<string | null>(null);
|
|
784
|
+
const group = useMemo(() => ({ openId, setOpenId }), [openId]);
|
|
785
|
+
|
|
398
786
|
const body = (
|
|
399
|
-
<
|
|
400
|
-
{
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
787
|
+
<OpenRowContext.Provider value={group}>
|
|
788
|
+
<View style={{ gap: 2 }}>
|
|
789
|
+
{rows.map((row, index) => (
|
|
790
|
+
<View key={index}>
|
|
791
|
+
{index > 0 ? <Separator isDark={isDark} inset={inset ? 14 : 0} /> : null}
|
|
792
|
+
{row}
|
|
793
|
+
</View>
|
|
794
|
+
))}
|
|
795
|
+
</View>
|
|
796
|
+
</OpenRowContext.Provider>
|
|
407
797
|
);
|
|
408
798
|
|
|
409
799
|
if (!inset) {
|