@marktiderman/genesis-ui-native 3.5.0 → 3.6.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/README.md +71 -7
- package/dist/{chunk-LBVD7XXL.js → chunk-2Z72MYHB.js} +627 -20
- package/dist/chunk-2Z72MYHB.js.map +1 -0
- package/dist/chunk-4OQOJ2OC.js +80 -0
- package/dist/chunk-4OQOJ2OC.js.map +1 -0
- package/dist/{chunk-6KWEAGRD.js → chunk-6PGLX6ET.js} +101 -6
- package/dist/chunk-6PGLX6ET.js.map +1 -0
- package/dist/{chunk-ONH2PCGH.js → chunk-AGTBABAH.js} +9 -15
- package/dist/chunk-AGTBABAH.js.map +1 -0
- package/dist/{chunk-ABVSSJNT.js → chunk-FUMSL7VZ.js} +198 -168
- package/dist/chunk-FUMSL7VZ.js.map +1 -0
- package/dist/{chunk-GHYUNNNU.js → chunk-NDXNSSM6.js} +175 -93
- package/dist/chunk-NDXNSSM6.js.map +1 -0
- package/dist/chunk-SEJ6RBP7.js +361 -0
- package/dist/chunk-SEJ6RBP7.js.map +1 -0
- package/dist/{chunk-D5RKSPMH.js → chunk-ZRQAFFTN.js} +4 -3
- package/dist/chunk-ZRQAFFTN.js.map +1 -0
- package/dist/components/index.d.ts +331 -4
- package/dist/components/index.js +5 -5
- package/dist/data/index.d.ts +68 -4
- package/dist/data/index.js +235 -31
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.d.ts +60 -1
- package/dist/hooks/index.js +2 -3
- package/dist/icons/lucide.d.ts +1 -1
- package/dist/icons/lucide.js +7 -1
- package/dist/icons/lucide.js.map +1 -1
- package/dist/{inbox-page-BEarNEIP.d.ts → inbox-page-B7_Oi2fS.d.ts} +2 -44
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -8
- package/dist/layouts/index.d.ts +40 -51
- package/dist/layouts/index.js +5 -4
- package/dist/{native-modules-PwnGltOU.d.ts → native-modules-Cl3zw3kh.d.ts} +27 -1
- package/package.json +78 -4
- package/src/__tests__/doctor-rules.test.ts +60 -0
- package/src/__tests__/native-modules-lists.test.tsx +1 -0
- package/src/components/__tests__/composer-bar.test.tsx +55 -0
- package/src/components/__tests__/gallery-card.test.tsx +59 -0
- package/src/components/__tests__/gallery-grid.test.tsx +160 -0
- package/src/components/__tests__/lightbox-resnap.test.tsx +50 -0
- package/src/components/__tests__/lightbox-zoom.test.ts +33 -0
- package/src/components/__tests__/lightbox.test.tsx +141 -0
- package/src/components/__tests__/live-indicator.test.tsx +72 -0
- package/src/components/__tests__/rating.test.tsx +82 -0
- package/src/components/__tests__/thread-list.test.tsx +156 -0
- package/src/components/composer-bar.tsx +198 -0
- package/src/components/drawer.tsx +15 -9
- package/src/components/gallery-card.tsx +109 -0
- package/src/components/gallery-grid.tsx +285 -0
- package/src/components/gallery-layout.ts +2 -0
- package/src/components/gallery-types.ts +2 -0
- package/src/components/index.ts +44 -0
- package/src/components/lightbox-zoom.tsx +282 -0
- package/src/components/lightbox.tsx +342 -0
- package/src/components/live-indicator.tsx +139 -0
- package/src/components/rating.tsx +128 -0
- package/src/components/skeleton.tsx +9 -4
- package/src/components/thread-list.tsx +427 -0
- package/src/components/toast.tsx +7 -4
- package/src/data/NativeConflictSheet.tsx +181 -0
- package/src/data/NativeResourceForm.tsx +15 -1
- package/src/data/index.ts +2 -0
- package/src/data/resource-view/NativeLinkPicker.tsx +1 -1
- package/src/data/resource-view/NativeRecordView.tsx +85 -8
- package/src/data/resource-view/NativeResourceView.tsx +79 -32
- package/src/data/resource-view/__tests__/native-link-picker.test.tsx +16 -0
- package/src/data/resource-view/__tests__/native-record-view.test.tsx +95 -1
- package/src/data/resource-view/__tests__/native-resource-gallery.test.tsx +125 -0
- package/src/data/resource-view/mapping.ts +3 -0
- package/src/hooks/__tests__/use-motion.test.tsx +106 -0
- package/src/hooks/__tests__/use-thread-jump.test.tsx +88 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/use-motion.ts +128 -0
- package/src/hooks/use-thread-jump.ts +110 -0
- package/src/icon-names.ts +6 -0
- package/src/icons/lucide.ts +12 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +6 -0
- package/src/layouts/__tests__/thread-page.test.tsx +114 -14
- package/src/layouts/inbox-page.tsx +6 -55
- package/src/layouts/index.ts +2 -0
- package/src/layouts/thread-page.tsx +326 -262
- package/src/native-modules.tsx +16 -2
- package/dist/chunk-6KWEAGRD.js.map +0 -1
- package/dist/chunk-7PCWEY6R.js +0 -27
- package/dist/chunk-7PCWEY6R.js.map +0 -1
- package/dist/chunk-ABVSSJNT.js.map +0 -1
- package/dist/chunk-D5RKSPMH.js.map +0 -1
- package/dist/chunk-GHYUNNNU.js.map +0 -1
- package/dist/chunk-LBVD7XXL.js.map +0 -1
- package/dist/chunk-ONH2PCGH.js.map +0 -1
- package/dist/chunk-Z3AQYVUA.js +0 -36
- package/dist/chunk-Z3AQYVUA.js.map +0 -1
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
} from "react-native";
|
|
27
27
|
import { SafeAreaInsetsContext } from "react-native-safe-area-context";
|
|
28
28
|
import { cn } from "../utils";
|
|
29
|
-
import {
|
|
29
|
+
import { useMotion } from "../hooks/use-motion";
|
|
30
30
|
import { useGenesisModules, type GenesisReanimatedModule } from "../native-modules";
|
|
31
31
|
|
|
32
32
|
export interface NativeDrawerProps {
|
|
@@ -41,8 +41,6 @@ export interface NativeDrawerProps {
|
|
|
41
41
|
testID?: string;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const OPEN_MS = 220;
|
|
45
|
-
const SETTLE_MS = 180;
|
|
46
44
|
|
|
47
45
|
export function NativeDrawer(props: NativeDrawerProps) {
|
|
48
46
|
const { reanimated } = useGenesisModules();
|
|
@@ -86,14 +84,18 @@ function useSwipe(
|
|
|
86
84
|
function ReanimatedDrawer({ reanimated: R, ...props }: NativeDrawerProps & { reanimated: GenesisReanimatedModule }) {
|
|
87
85
|
const { open, side = "left", width } = props;
|
|
88
86
|
const drawerWidth = width ?? Math.min(Dimensions.get("window").width * 0.8, 360);
|
|
89
|
-
|
|
87
|
+
// The shared motion tokens: a panel opens at `base`, a released drag settles at `fast`; Reduce Motion snaps.
|
|
88
|
+
const motion = useMotion();
|
|
89
|
+
const reducedMotion = motion.reduced;
|
|
90
|
+
const OPEN_MS = motion.duration.base;
|
|
91
|
+
const SETTLE_MS = motion.duration.fast;
|
|
90
92
|
const translate = R.useSharedValue(closedOffset(side, drawerWidth));
|
|
91
93
|
|
|
92
94
|
useEffect(() => {
|
|
93
95
|
const to = open ? 0 : closedOffset(side, drawerWidth);
|
|
94
96
|
translate.value = reducedMotion ? to : R.withTiming(to, { duration: OPEN_MS });
|
|
95
97
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
-
}, [drawerWidth, open, reducedMotion, side]);
|
|
98
|
+
}, [drawerWidth, open, reducedMotion, side, OPEN_MS]);
|
|
97
99
|
|
|
98
100
|
// `translate` and `R` are stable for the component's life.
|
|
99
101
|
const follow = useCallback((dx: number) => {
|
|
@@ -103,7 +105,7 @@ function ReanimatedDrawer({ reanimated: R, ...props }: NativeDrawerProps & { rea
|
|
|
103
105
|
const settle = useCallback(() => {
|
|
104
106
|
translate.value = reducedMotion ? 0 : R.withTiming(0, { duration: SETTLE_MS });
|
|
105
107
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
106
|
-
}, [reducedMotion]);
|
|
108
|
+
}, [reducedMotion, SETTLE_MS]);
|
|
107
109
|
const panResponder = useSwipe(side, drawerWidth, props.onOpenChange, follow, settle);
|
|
108
110
|
const animatedStyle = R.useAnimatedStyle(() => {
|
|
109
111
|
"worklet";
|
|
@@ -116,7 +118,11 @@ function ReanimatedDrawer({ reanimated: R, ...props }: NativeDrawerProps & { rea
|
|
|
116
118
|
function AnimatedDrawer(props: NativeDrawerProps) {
|
|
117
119
|
const { open, side = "left", width } = props;
|
|
118
120
|
const drawerWidth = width ?? Math.min(Dimensions.get("window").width * 0.8, 360);
|
|
119
|
-
|
|
121
|
+
// The shared motion tokens: a panel opens at `base`, a released drag settles at `fast`; Reduce Motion snaps.
|
|
122
|
+
const motion = useMotion();
|
|
123
|
+
const reducedMotion = motion.reduced;
|
|
124
|
+
const OPEN_MS = motion.duration.base;
|
|
125
|
+
const SETTLE_MS = motion.duration.fast;
|
|
120
126
|
const translate = useRef(new Animated.Value(closedOffset(side, drawerWidth))).current;
|
|
121
127
|
|
|
122
128
|
useEffect(() => {
|
|
@@ -125,7 +131,7 @@ function AnimatedDrawer(props: NativeDrawerProps) {
|
|
|
125
131
|
duration: reducedMotion ? 0 : OPEN_MS,
|
|
126
132
|
useNativeDriver: true,
|
|
127
133
|
}).start();
|
|
128
|
-
}, [drawerWidth, open, reducedMotion, side, translate]);
|
|
134
|
+
}, [drawerWidth, open, reducedMotion, side, translate, OPEN_MS]);
|
|
129
135
|
|
|
130
136
|
const follow = useCallback((dx: number) => translate.setValue(dx), [translate]);
|
|
131
137
|
const settle = useCallback(
|
|
@@ -135,7 +141,7 @@ function AnimatedDrawer(props: NativeDrawerProps) {
|
|
|
135
141
|
duration: reducedMotion ? 0 : SETTLE_MS,
|
|
136
142
|
useNativeDriver: true,
|
|
137
143
|
}).start(),
|
|
138
|
-
[reducedMotion, translate]
|
|
144
|
+
[reducedMotion, translate, SETTLE_MS]
|
|
139
145
|
);
|
|
140
146
|
const panResponder = useSwipe(side, drawerWidth, props.onOpenChange, follow, settle);
|
|
141
147
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeGalleryCard — a photo or video cover with an optional title line
|
|
3
|
+
* under it, and slots over the picture for badges (top-left) and actions
|
|
4
|
+
* (top-right). An album, a session recording, a product shot.
|
|
5
|
+
*
|
|
6
|
+
* The cover is `NativeImage` at `ratio` (4:3 by default); without `src`, or
|
|
7
|
+
* while `loading`, it is a muted box with a `NativeSkeleton`. The whole card
|
|
8
|
+
* is a button when `onPress` is given. Same props as the web `GalleryCard`.
|
|
9
|
+
*
|
|
10
|
+
* @stability Beta
|
|
11
|
+
*/
|
|
12
|
+
import type { ReactNode } from "react";
|
|
13
|
+
import { Pressable, Text, View } from "react-native";
|
|
14
|
+
import { cn } from "../utils";
|
|
15
|
+
import { NativeImage } from "./image";
|
|
16
|
+
import { NativeSkeleton } from "./skeleton";
|
|
17
|
+
|
|
18
|
+
export interface NativeGalleryCardProps {
|
|
19
|
+
/** The cover picture. Without it the cover is a placeholder. */
|
|
20
|
+
src?: string;
|
|
21
|
+
alt?: string;
|
|
22
|
+
title?: string;
|
|
23
|
+
subtitle?: string;
|
|
24
|
+
/** Over the cover, top-left (a `NativeBadge`, a `NativeLiveIndicator`). */
|
|
25
|
+
badges?: ReactNode;
|
|
26
|
+
/** Over the cover, top-right (an icon button, a menu). */
|
|
27
|
+
actions?: ReactNode;
|
|
28
|
+
/** Cover width ÷ height. Default 4/3. */
|
|
29
|
+
ratio?: number;
|
|
30
|
+
/** Draws the cover as a skeleton. */
|
|
31
|
+
loading?: boolean;
|
|
32
|
+
onPress?: () => void;
|
|
33
|
+
className?: string;
|
|
34
|
+
testID?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function NativeGalleryCard({
|
|
38
|
+
src,
|
|
39
|
+
alt,
|
|
40
|
+
title,
|
|
41
|
+
subtitle,
|
|
42
|
+
badges,
|
|
43
|
+
actions,
|
|
44
|
+
ratio = 4 / 3,
|
|
45
|
+
loading = false,
|
|
46
|
+
onPress,
|
|
47
|
+
className,
|
|
48
|
+
testID = "native-gallery-card",
|
|
49
|
+
}: NativeGalleryCardProps) {
|
|
50
|
+
const aspectRatio = Number.isFinite(ratio) && ratio > 0 ? ratio : 4 / 3;
|
|
51
|
+
const placeholder = loading || !src;
|
|
52
|
+
const body = (
|
|
53
|
+
<>
|
|
54
|
+
<View testID={`${testID}-cover`} className="relative w-full overflow-hidden bg-muted" style={{ aspectRatio }}>
|
|
55
|
+
{placeholder ? (
|
|
56
|
+
<NativeSkeleton testID={`${testID}-skeleton`} className="absolute inset-0 h-full w-full rounded-none" />
|
|
57
|
+
) : (
|
|
58
|
+
<NativeImage src={src} alt={alt} className="h-full w-full" />
|
|
59
|
+
)}
|
|
60
|
+
{badges ? (
|
|
61
|
+
<View testID={`${testID}-badges`} className="absolute left-2 top-2 flex-row items-center gap-1">
|
|
62
|
+
{badges}
|
|
63
|
+
</View>
|
|
64
|
+
) : null}
|
|
65
|
+
{actions ? (
|
|
66
|
+
<View testID={`${testID}-actions`} className="absolute right-2 top-2 flex-row items-center gap-1">
|
|
67
|
+
{actions}
|
|
68
|
+
</View>
|
|
69
|
+
) : null}
|
|
70
|
+
</View>
|
|
71
|
+
{title || subtitle ? (
|
|
72
|
+
<View testID={`${testID}-footer`} className="gap-0.5 px-3 py-2">
|
|
73
|
+
{title ? (
|
|
74
|
+
<Text testID={`${testID}-title`} numberOfLines={1} className="text-sm font-semibold text-foreground">
|
|
75
|
+
{title}
|
|
76
|
+
</Text>
|
|
77
|
+
) : null}
|
|
78
|
+
{subtitle ? (
|
|
79
|
+
<Text testID={`${testID}-subtitle`} numberOfLines={1} className="text-xs text-muted-foreground">
|
|
80
|
+
{subtitle}
|
|
81
|
+
</Text>
|
|
82
|
+
) : null}
|
|
83
|
+
</View>
|
|
84
|
+
) : null}
|
|
85
|
+
</>
|
|
86
|
+
);
|
|
87
|
+
const classes = cn("overflow-hidden rounded-lg border border-border bg-card", className);
|
|
88
|
+
|
|
89
|
+
if (onPress) {
|
|
90
|
+
return (
|
|
91
|
+
<Pressable
|
|
92
|
+
testID={testID}
|
|
93
|
+
accessibilityRole="button"
|
|
94
|
+
accessibilityLabel={title ?? alt}
|
|
95
|
+
accessibilityHint={subtitle}
|
|
96
|
+
accessibilityState={loading ? { busy: true } : undefined}
|
|
97
|
+
onPress={onPress}
|
|
98
|
+
className={classes}
|
|
99
|
+
>
|
|
100
|
+
{body}
|
|
101
|
+
</Pressable>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
return (
|
|
105
|
+
<View testID={testID} accessibilityState={loading ? { busy: true } : undefined} className={classes}>
|
|
106
|
+
{body}
|
|
107
|
+
</View>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeGalleryGrid — photos in rows: justified (each row scaled to fill the
|
|
3
|
+
* width, as in a photo library) or a fixed-column grid (square tiles by
|
|
4
|
+
* default, or each item's own shape with `aspectRatio="item"`).
|
|
5
|
+
*
|
|
6
|
+
* Rows come from the pure `justifyRows`, so the same items pack the same way
|
|
7
|
+
* as the web `GalleryGrid`, with the same defaults (`GALLERY_DEFAULTS`) and
|
|
8
|
+
* the same props, `onItemPress` in place of the web's `onItemClick` (as
|
|
9
|
+
* `NativeResourcePage` pairs with `ResourcePage`). The container width comes
|
|
10
|
+
* from `onLayout`; until it is measured nothing is drawn. The rows are a
|
|
11
|
+
* virtualized `FlatList` (the grid scrolls itself; `header` and `footer` go
|
|
12
|
+
* above and below), so a long gallery mounts only what's near the screen and
|
|
13
|
+
* `loadMore` fires when scrolling nears the end, for "load more". Don't put
|
|
14
|
+
* it inside a ScrollView: it fills its parent (`flex-1`), and nested it would
|
|
15
|
+
* draw every row and fire `loadMore` at once. Put what goes above or below
|
|
16
|
+
* it in `header` and `footer`. Tiles are
|
|
17
|
+
* `NativeImage` over a `bg-muted` placeholder sized from the item's ratio (so
|
|
18
|
+
* rows don't reflow while the picture loads), tappable when `onItemPress` is
|
|
19
|
+
* given (or when selecting); `renderItem` replaces the tile's content and
|
|
20
|
+
* `renderBadges` overlays its top-left.
|
|
21
|
+
*
|
|
22
|
+
* Selection (`selected` + `onSelectionChange`) toggles an id per press, in
|
|
23
|
+
* place of `onItemPress` (as on web), and rings the chosen tiles. `groupBy`
|
|
24
|
+
* lays each group out separately under a header.
|
|
25
|
+
*
|
|
26
|
+
* @stability Beta
|
|
27
|
+
*/
|
|
28
|
+
import { useMemo, useState, type ReactNode } from "react";
|
|
29
|
+
import { FlatList, Pressable, Text, View, type LayoutChangeEvent } from "react-native";
|
|
30
|
+
import { cn } from "../utils";
|
|
31
|
+
import { galleryItemRatio, justifyRows } from "./gallery-layout";
|
|
32
|
+
import { GALLERY_DEFAULTS, type GalleryItem, type GalleryTileAspect } from "./gallery-types";
|
|
33
|
+
import { NativeImage } from "./image";
|
|
34
|
+
|
|
35
|
+
export type NativeGalleryLayout = "justified" | "grid";
|
|
36
|
+
|
|
37
|
+
export interface NativeGalleryGridProps {
|
|
38
|
+
items: GalleryItem[];
|
|
39
|
+
/** Default "justified". */
|
|
40
|
+
layout?: NativeGalleryLayout;
|
|
41
|
+
/** Grid layout only: tiles per row. Default 3. */
|
|
42
|
+
columns?: number;
|
|
43
|
+
/** Grid layout only: each tile's shape, a ratio or `"item"` for the item's own. Default 1 (square), as on web. */
|
|
44
|
+
aspectRatio?: GalleryTileAspect;
|
|
45
|
+
/** Justified layout only: target row height in points. Default 180. */
|
|
46
|
+
rowHeight?: number;
|
|
47
|
+
/** Points between tiles. Default 4. */
|
|
48
|
+
gap?: number;
|
|
49
|
+
/** Called on a press. Not called when `onSelectionChange` is set: a press then only toggles the selection. */
|
|
50
|
+
onItemPress?: (item: GalleryItem, index: number) => void;
|
|
51
|
+
/** Replaces the tile's content (the image by default). */
|
|
52
|
+
renderItem?: (item: GalleryItem, index: number) => ReactNode;
|
|
53
|
+
/** Overlaid top-left of the default tile. */
|
|
54
|
+
renderBadges?: (item: GalleryItem, index: number) => ReactNode;
|
|
55
|
+
/** Ids of the selected items. With `onSelectionChange`, a press toggles the tile. */
|
|
56
|
+
selected?: string[];
|
|
57
|
+
onSelectionChange?: (ids: string[], detail: { item: GalleryItem; index: number }) => void;
|
|
58
|
+
/** Called when scrolling nears the last rows (FlatList's `onEndReached`): the hook for "load more" (NativeResourceView's name). */
|
|
59
|
+
loadMore?: () => void;
|
|
60
|
+
/** @deprecated Use `loadMore`. */
|
|
61
|
+
onNearEnd?: () => void;
|
|
62
|
+
/** Above the first row, scrolling with it. */
|
|
63
|
+
header?: ReactNode;
|
|
64
|
+
/** Below the last row (a "Loading more" spinner). */
|
|
65
|
+
footer?: ReactNode;
|
|
66
|
+
/** Groups items (in order of first appearance), each under a header reading the key (a view's `groupBy`, for an array). */
|
|
67
|
+
groupBy?: (item: GalleryItem) => string;
|
|
68
|
+
/** @deprecated Use `groupBy`. */
|
|
69
|
+
getGroup?: (item: GalleryItem) => string;
|
|
70
|
+
className?: string;
|
|
71
|
+
testID?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface Group {
|
|
75
|
+
key: string | null;
|
|
76
|
+
entries: { item: GalleryItem; index: number }[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function groupItems(items: GalleryItem[], groupBy?: (item: GalleryItem) => string): Group[] {
|
|
80
|
+
if (!groupBy) return [{ key: null, entries: items.map((item, index) => ({ item, index })) }];
|
|
81
|
+
const groups: Group[] = [];
|
|
82
|
+
const byKey = new Map<string, Group>();
|
|
83
|
+
items.forEach((item, index) => {
|
|
84
|
+
const key = groupBy(item);
|
|
85
|
+
let group = byKey.get(key);
|
|
86
|
+
if (!group) {
|
|
87
|
+
group = { key, entries: [] };
|
|
88
|
+
byKey.set(key, group);
|
|
89
|
+
groups.push(group);
|
|
90
|
+
}
|
|
91
|
+
group.entries.push({ item, index });
|
|
92
|
+
});
|
|
93
|
+
return groups;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** One line of the list: a group's header, or a row of tiles with their sizes. */
|
|
97
|
+
type Line =
|
|
98
|
+
| { kind: "header"; key: string; group: string }
|
|
99
|
+
| { kind: "row"; key: string; group: string | null; first: boolean; tiles: { item: GalleryItem; index: number; width: number; height: number }[] };
|
|
100
|
+
|
|
101
|
+
export function NativeGalleryGrid({
|
|
102
|
+
items,
|
|
103
|
+
layout = "justified",
|
|
104
|
+
columns = GALLERY_DEFAULTS.columns,
|
|
105
|
+
aspectRatio = 1,
|
|
106
|
+
rowHeight = GALLERY_DEFAULTS.rowHeight,
|
|
107
|
+
gap = GALLERY_DEFAULTS.gap,
|
|
108
|
+
onItemPress,
|
|
109
|
+
renderItem,
|
|
110
|
+
renderBadges,
|
|
111
|
+
selected,
|
|
112
|
+
onSelectionChange,
|
|
113
|
+
loadMore: loadMoreProp,
|
|
114
|
+
onNearEnd,
|
|
115
|
+
header,
|
|
116
|
+
footer,
|
|
117
|
+
groupBy: groupByProp,
|
|
118
|
+
getGroup,
|
|
119
|
+
className,
|
|
120
|
+
testID = "native-gallery-grid",
|
|
121
|
+
}: NativeGalleryGridProps) {
|
|
122
|
+
const loadMore = loadMoreProp ?? onNearEnd;
|
|
123
|
+
const groupBy = groupByProp ?? getGroup;
|
|
124
|
+
const [width, setWidth] = useState(0);
|
|
125
|
+
const onLayout = (e: LayoutChangeEvent) => {
|
|
126
|
+
const next = e.nativeEvent.layout.width;
|
|
127
|
+
if (next !== width) setWidth(next);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const selecting = Boolean(onSelectionChange);
|
|
131
|
+
const selectedIds = selected ?? [];
|
|
132
|
+
const isSelected = (item: GalleryItem) => selectedIds.includes(item.id);
|
|
133
|
+
|
|
134
|
+
const lines = useMemo<Line[]>(() => {
|
|
135
|
+
if (width <= 0) return [];
|
|
136
|
+
const out: Line[] = [];
|
|
137
|
+
groupItems(items, groupBy).forEach((group) => {
|
|
138
|
+
if (group.key !== null) out.push({ kind: "header", key: `h:${group.key}`, group: group.key });
|
|
139
|
+
const rows: Line[] = [];
|
|
140
|
+
if (layout === "grid") {
|
|
141
|
+
const cols = Math.max(1, Math.floor(columns));
|
|
142
|
+
const side = (width - gap * (cols - 1)) / cols;
|
|
143
|
+
for (let i = 0; i < group.entries.length; i += cols) {
|
|
144
|
+
const slice = group.entries.slice(i, i + cols);
|
|
145
|
+
// A row is as tall as its tallest tile ("item" shapes differ); squares by default.
|
|
146
|
+
const heights = slice.map(({ item }) => side / (aspectRatio === "item" ? galleryItemRatio(item) : aspectRatio));
|
|
147
|
+
rows.push({
|
|
148
|
+
kind: "row",
|
|
149
|
+
key: `r:${group.key ?? ""}:${i}`,
|
|
150
|
+
group: group.key,
|
|
151
|
+
first: i === 0,
|
|
152
|
+
tiles: slice.map(({ item, index }, n) => ({ item, index, width: side, height: heights[n]! })),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
} else {
|
|
156
|
+
justifyRows(group.entries.map((e) => e.item), width, rowHeight, gap).forEach((row, r) => {
|
|
157
|
+
rows.push({
|
|
158
|
+
kind: "row",
|
|
159
|
+
key: `r:${group.key ?? ""}:${r}`,
|
|
160
|
+
group: group.key,
|
|
161
|
+
first: r === 0,
|
|
162
|
+
tiles: row.tiles.map((t) => ({ item: t.item, index: group.entries[t.index]!.index, width: t.width, height: t.height })),
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
out.push(...rows);
|
|
167
|
+
});
|
|
168
|
+
return out;
|
|
169
|
+
}, [width, items, groupBy, layout, columns, aspectRatio, rowHeight, gap]);
|
|
170
|
+
|
|
171
|
+
const press = (item: GalleryItem, index: number) => {
|
|
172
|
+
if (onSelectionChange) {
|
|
173
|
+
const next = isSelected(item) ? selectedIds.filter((id) => id !== item.id) : [...selectedIds, item.id];
|
|
174
|
+
onSelectionChange(next, { item, index });
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
onItemPress?.(item, index);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const tile = (item: GalleryItem, index: number, size: { width: number; height: number }) => {
|
|
181
|
+
const chosen = isSelected(item);
|
|
182
|
+
const content = renderItem ? (
|
|
183
|
+
renderItem(item, index)
|
|
184
|
+
) : (
|
|
185
|
+
<>
|
|
186
|
+
<View className="absolute inset-0 bg-muted" />
|
|
187
|
+
{item.src ? (
|
|
188
|
+
<NativeImage src={item.src} alt={item.alt} className="h-full w-full" />
|
|
189
|
+
) : (
|
|
190
|
+
// No image: a neutral tile with its words, so the count matches what's drawn. The tile's
|
|
191
|
+
// own label (alt, then caption) names a pressable tile, so the words are hidden from
|
|
192
|
+
// readers then; a plain tile isn't pressable, so the placeholder is the named image.
|
|
193
|
+
<View
|
|
194
|
+
testID={`${testID}-placeholder-${item.id}`}
|
|
195
|
+
{...(onItemPress || selecting
|
|
196
|
+
? { importantForAccessibility: "no-hide-descendants" as const, accessibilityElementsHidden: true }
|
|
197
|
+
: {
|
|
198
|
+
accessible: true,
|
|
199
|
+
accessibilityRole: "image" as const,
|
|
200
|
+
accessibilityLabel: item.alt ?? item.caption ?? `Photo ${index + 1} of ${items.length}`,
|
|
201
|
+
})}
|
|
202
|
+
className="h-full w-full items-center justify-center gap-0.5 p-2"
|
|
203
|
+
>
|
|
204
|
+
{item.alt ? (
|
|
205
|
+
<Text numberOfLines={2} className="text-center text-sm font-medium text-foreground">
|
|
206
|
+
{item.alt}
|
|
207
|
+
</Text>
|
|
208
|
+
) : null}
|
|
209
|
+
{item.caption ? (
|
|
210
|
+
<Text numberOfLines={2} className="text-center text-xs text-muted-foreground">
|
|
211
|
+
{item.caption}
|
|
212
|
+
</Text>
|
|
213
|
+
) : null}
|
|
214
|
+
</View>
|
|
215
|
+
)}
|
|
216
|
+
{renderBadges ? (
|
|
217
|
+
<View testID={`${testID}-badges-${item.id}`} pointerEvents="box-none" className="absolute left-1 top-1 flex-row items-center gap-1">
|
|
218
|
+
{renderBadges(item, index)}
|
|
219
|
+
</View>
|
|
220
|
+
) : null}
|
|
221
|
+
</>
|
|
222
|
+
);
|
|
223
|
+
const tileID = `${testID}-item-${item.id}`;
|
|
224
|
+
const tileClass = cn("overflow-hidden rounded-md bg-muted", chosen && "border-2 border-ring");
|
|
225
|
+
if (onItemPress || selecting) {
|
|
226
|
+
return (
|
|
227
|
+
<Pressable
|
|
228
|
+
key={item.id}
|
|
229
|
+
testID={tileID}
|
|
230
|
+
accessibilityRole="button"
|
|
231
|
+
accessibilityLabel={item.alt ?? item.caption ?? `Photo ${index + 1} of ${items.length}`}
|
|
232
|
+
accessibilityState={selecting ? { selected: chosen } : undefined}
|
|
233
|
+
onPress={() => press(item, index)}
|
|
234
|
+
className={tileClass}
|
|
235
|
+
style={size}
|
|
236
|
+
>
|
|
237
|
+
{content}
|
|
238
|
+
</Pressable>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
return (
|
|
242
|
+
<View key={item.id} testID={tileID} className={tileClass} style={size}>
|
|
243
|
+
{content}
|
|
244
|
+
</View>
|
|
245
|
+
);
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const renderLine = ({ item: line, index: n }: { item: Line; index: number }) => {
|
|
249
|
+
if (line.kind === "header") {
|
|
250
|
+
return (
|
|
251
|
+
<Text accessibilityRole="header" testID={`${testID}-group-${line.group}`} className="mb-2 text-sm font-medium text-muted-foreground" style={{ marginTop: n === 0 ? 0 : gap * 3 }}>
|
|
252
|
+
{line.group}
|
|
253
|
+
</Text>
|
|
254
|
+
);
|
|
255
|
+
}
|
|
256
|
+
return (
|
|
257
|
+
<View
|
|
258
|
+
className="flex-row"
|
|
259
|
+
testID={line.group === null ? undefined : `${testID}-row-${line.group}`}
|
|
260
|
+
style={{ gap, marginTop: line.first ? 0 : gap }}
|
|
261
|
+
>
|
|
262
|
+
{line.tiles.map((t) => tile(t.item, t.index, { width: t.width, height: t.height }))}
|
|
263
|
+
</View>
|
|
264
|
+
);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
return (
|
|
268
|
+
<View testID={testID} onLayout={onLayout} className={cn("w-full flex-1", className)}>
|
|
269
|
+
{width > 0 ? (
|
|
270
|
+
<FlatList
|
|
271
|
+
testID={`${testID}-list`}
|
|
272
|
+
data={lines}
|
|
273
|
+
keyExtractor={(line) => line.key}
|
|
274
|
+
renderItem={renderLine}
|
|
275
|
+
ListHeaderComponent={header ? <>{header}</> : undefined}
|
|
276
|
+
ListFooterComponent={footer ? <>{footer}</> : undefined}
|
|
277
|
+
onEndReached={loadMore ? () => loadMore() : undefined}
|
|
278
|
+
onEndReachedThreshold={0.5}
|
|
279
|
+
initialNumToRender={8}
|
|
280
|
+
windowSize={7}
|
|
281
|
+
/>
|
|
282
|
+
) : null}
|
|
283
|
+
</View>
|
|
284
|
+
);
|
|
285
|
+
}
|
package/src/components/index.ts
CHANGED
|
@@ -284,6 +284,7 @@ export type {
|
|
|
284
284
|
GenesisDatePickerProps,
|
|
285
285
|
GenesisNavigationModule,
|
|
286
286
|
GenesisNavigationTheme,
|
|
287
|
+
KeyboardAvoidingLike,
|
|
287
288
|
} from "../native-modules";
|
|
288
289
|
|
|
289
290
|
export { NativeIcon } from "./icon";
|
|
@@ -296,3 +297,46 @@ export type { NativeImageProps } from "./image";
|
|
|
296
297
|
|
|
297
298
|
export { NativeGlassSurface, useLiquidGlass, useReduceTransparency } from "./glass-surface";
|
|
298
299
|
export type { NativeGlassSurfaceProps } from "./glass-surface";
|
|
300
|
+
|
|
301
|
+
export {
|
|
302
|
+
NativeThreadList,
|
|
303
|
+
threadListMode,
|
|
304
|
+
threadNearBottom,
|
|
305
|
+
THREAD_AT_BOTTOM_POINTS,
|
|
306
|
+
} from "./thread-list";
|
|
307
|
+
export type { NativeThreadListProps, NativeThreadListHandle, ThreadRowInfo } from "./thread-list";
|
|
308
|
+
export { NativeComposerBar } from "./composer-bar";
|
|
309
|
+
export type { NativeComposerBarProps, ComposerMode, ComposerTone } from "./composer-bar";
|
|
310
|
+
|
|
311
|
+
// --- Gallery and media primitives ---
|
|
312
|
+
|
|
313
|
+
export { GALLERY_DEFAULTS, type GalleryItem, type GalleryTileAspect } from "./gallery-types";
|
|
314
|
+
export { justifyRows, galleryItemRatio, DEFAULT_GALLERY_RATIO } from "./gallery-layout";
|
|
315
|
+
export type { JustifiedRow, JustifiedTile } from "./gallery-layout";
|
|
316
|
+
|
|
317
|
+
export { NativeRating, nextRating } from "./rating";
|
|
318
|
+
export type { NativeRatingProps, NativeRatingSize } from "./rating";
|
|
319
|
+
|
|
320
|
+
export { NativeGalleryGrid } from "./gallery-grid";
|
|
321
|
+
export type { NativeGalleryGridProps, NativeGalleryLayout } from "./gallery-grid";
|
|
322
|
+
|
|
323
|
+
export { NativeLightbox, defaultNativeLightboxLabels } from "./lightbox";
|
|
324
|
+
export type { NativeLightboxProps, NativeLightboxLabels } from "./lightbox";
|
|
325
|
+
export {
|
|
326
|
+
NativeZoomablePhoto,
|
|
327
|
+
lightboxShouldDismiss,
|
|
328
|
+
lightboxPinchScale,
|
|
329
|
+
lightboxTouchDistance,
|
|
330
|
+
lightboxPanLimit,
|
|
331
|
+
LIGHTBOX_DISMISS_DISTANCE,
|
|
332
|
+
LIGHTBOX_DISMISS_VELOCITY,
|
|
333
|
+
LIGHTBOX_MAX_ZOOM,
|
|
334
|
+
LIGHTBOX_DOUBLE_TAP_MS,
|
|
335
|
+
} from "./lightbox-zoom";
|
|
336
|
+
export type { NativeZoomablePhotoProps } from "./lightbox-zoom";
|
|
337
|
+
|
|
338
|
+
export { NativeGalleryCard } from "./gallery-card";
|
|
339
|
+
export type { NativeGalleryCardProps } from "./gallery-card";
|
|
340
|
+
|
|
341
|
+
export { NativeLiveIndicator } from "./live-indicator";
|
|
342
|
+
export type { NativeLiveIndicatorProps, NativeLiveIndicatorState, NativeLiveIndicatorVariant } from "./live-indicator";
|