@marktiderman/genesis-ui-native 2.1.0 → 2.3.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 +134 -0
- package/dist/chunk-7PCWEY6R.js +27 -0
- package/dist/chunk-7PCWEY6R.js.map +1 -0
- package/dist/chunk-D5RKSPMH.js +24 -0
- package/dist/chunk-D5RKSPMH.js.map +1 -0
- package/dist/{chunk-5HRGIA6F.js → chunk-EFXCJ5AN.js} +76 -3
- package/dist/chunk-EFXCJ5AN.js.map +1 -0
- package/dist/{chunk-ULS7I6ZS.js → chunk-ERHGCWTY.js} +81 -12
- package/dist/chunk-ERHGCWTY.js.map +1 -0
- package/dist/{chunk-3LK5ZJ4M.js → chunk-FIITITXO.js} +67 -108
- package/dist/chunk-FIITITXO.js.map +1 -0
- package/dist/chunk-FZY2IXOX.js +1559 -0
- package/dist/chunk-FZY2IXOX.js.map +1 -0
- package/dist/{chunk-TXJT55JC.js → chunk-W7BK3ARU.js} +715 -293
- package/dist/chunk-W7BK3ARU.js.map +1 -0
- package/dist/components/index.d.ts +143 -17
- package/dist/components/index.js +6 -4
- package/dist/data/index.d.ts +7 -1
- package/dist/data/index.js +31 -6
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.js +2 -1
- package/dist/icons/lucide.d.ts +7 -0
- package/dist/icons/lucide.js +47 -0
- package/dist/icons/lucide.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +7 -6
- package/dist/layouts/index.d.ts +399 -7
- package/dist/layouts/index.js +3 -3
- package/dist/native-modules-BSVaEb3D.d.ts +206 -0
- package/package.json +34 -5
- package/src/__tests__/fake-modules.tsx +134 -0
- package/src/__tests__/native-modules-lists.test.tsx +70 -0
- package/src/__tests__/native-modules.test.tsx +631 -0
- package/src/components/__tests__/sheet.test.tsx +193 -0
- package/src/components/__tests__/toast.test.tsx +15 -0
- package/src/components/avatar.tsx +69 -16
- package/src/components/date-time-picker.tsx +128 -10
- package/src/components/drawer.tsx +158 -68
- package/src/components/dropdown-menu.tsx +7 -6
- package/src/components/glass-surface.tsx +150 -0
- package/src/components/icon.tsx +66 -0
- package/src/components/image.tsx +89 -0
- package/src/components/index.ts +33 -2
- package/src/components/list-item.tsx +29 -9
- package/src/components/popover.tsx +12 -9
- package/src/components/segmented-control.tsx +7 -1
- package/src/components/sheet.tsx +276 -133
- package/src/components/skeleton.tsx +75 -53
- package/src/components/textarea.tsx +1 -0
- package/src/components/toast.tsx +185 -87
- package/src/data/NativeResourcePage.tsx +48 -3
- package/src/data/__tests__/resource-page-offline.test.tsx +47 -0
- package/src/hooks/use-reduced-motion.ts +24 -10
- package/src/icon-names.ts +49 -0
- package/src/icons/lucide.ts +88 -0
- package/src/layouts/__tests__/apple-sign-in.test.tsx +97 -0
- package/src/layouts/__tests__/google-sign-in.test.tsx +26 -0
- package/src/layouts/__tests__/inbox-page.test.tsx +155 -0
- package/src/layouts/__tests__/keyboard-scroll.test.tsx +42 -1
- package/src/layouts/__tests__/settings-page-native-look.test.tsx +142 -0
- package/src/layouts/__tests__/thread-page.test.tsx +128 -0
- package/src/layouts/apple-sign-in.tsx +136 -0
- package/src/layouts/auth-screen.tsx +17 -8
- package/src/layouts/auth.tsx +29 -19
- package/src/layouts/google-sign-in.tsx +42 -0
- package/src/layouts/inbox-page.tsx +408 -0
- package/src/layouts/index.ts +45 -2
- package/src/layouts/keyboard.tsx +61 -9
- package/src/layouts/notifications-page.tsx +133 -16
- package/src/layouts/screen-container.tsx +6 -2
- package/src/layouts/settings-page.tsx +117 -14
- package/src/layouts/settings-sub-page.tsx +9 -3
- package/src/layouts/thread-page.tsx +444 -0
- package/src/native-modules.tsx +186 -0
- package/dist/chunk-3LK5ZJ4M.js.map +0 -1
- package/dist/chunk-5HRGIA6F.js.map +0 -1
- package/dist/chunk-F2TGDKOO.js +0 -43
- package/dist/chunk-F2TGDKOO.js.map +0 -1
- package/dist/chunk-TXJT55JC.js.map +0 -1
- package/dist/chunk-U2SPACTV.js +0 -876
- package/dist/chunk-U2SPACTV.js.map +0 -1
- package/dist/chunk-ULS7I6ZS.js.map +0 -1
|
@@ -0,0 +1,408 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* InboxPage — a list of conversations or tickets: unread state, a time, a
|
|
3
|
+
* preview line, swipe actions, pull to refresh, paging and an empty state.
|
|
4
|
+
*
|
|
5
|
+
* Generic: the rows are whatever the app has (support reports, direct
|
|
6
|
+
* messages, an idea board). Data and actions come in as props; the layout
|
|
7
|
+
* draws them the platform's way. On iOS it is the Settings app's inset
|
|
8
|
+
* grouped style, like `SettingsPage`: the page is `groupedBackground`, the
|
|
9
|
+
* rows one rounded group on `surface` with hairline separators that start at
|
|
10
|
+
* the text. On Android rows are full width.
|
|
11
|
+
*
|
|
12
|
+
* Swipe actions: each row's `swipeActions` are always reachable without a
|
|
13
|
+
* gesture library, as VoiceOver / TalkBack custom actions and on long press
|
|
14
|
+
* (a menu). For the swipe itself, fill the `swipeable` slot with your
|
|
15
|
+
* gesture-handler wrapper (`ReanimatedSwipeable` from
|
|
16
|
+
* react-native-gesture-handler, an optional peer); it receives the actions
|
|
17
|
+
* and the row.
|
|
18
|
+
*
|
|
19
|
+
* Slots: `row`, `swipeable`, `header` (above the group), `footer` (below it,
|
|
20
|
+
* the paging spinner by default) and `empty`. `slots` swaps a part for your
|
|
21
|
+
* component (same props), `slotProps` feeds the default more props, `null`
|
|
22
|
+
* drops it.
|
|
23
|
+
*
|
|
24
|
+
* Header: `getInboxPageStackOptions()` for `<Stack.Screen options>`.
|
|
25
|
+
*
|
|
26
|
+
* @stability Beta
|
|
27
|
+
*/
|
|
28
|
+
import { Fragment, useState, type ReactNode } from "react";
|
|
29
|
+
import { renderSlot, type SlotPropsFor, type Slots } from "@marktiderman/genesis-core/slots";
|
|
30
|
+
import { ActivityIndicator, Alert, FlatList, Platform, Pressable, RefreshControl, StyleSheet, View } from "react-native";
|
|
31
|
+
import { SafeAreaView } from "react-native-safe-area-context";
|
|
32
|
+
import { useThemeRoles } from "../hooks/use-theme-roles";
|
|
33
|
+
import { NativeEmptyState } from "../components/empty-state";
|
|
34
|
+
import { NativeText } from "../components/text";
|
|
35
|
+
import { NativeButton } from "../components/button";
|
|
36
|
+
import { NativeBadge } from "../components/badge";
|
|
37
|
+
import { composeHeaderOptions, type ScreenHeaderProps } from "./screen-container";
|
|
38
|
+
|
|
39
|
+
/** An action on a row: swipe, long press, or an accessibility action. */
|
|
40
|
+
export interface InboxSwipeAction {
|
|
41
|
+
id: string;
|
|
42
|
+
label: string;
|
|
43
|
+
onPress: () => void;
|
|
44
|
+
/** Destructive tone (delete, leave). */
|
|
45
|
+
destructive?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface InboxItem {
|
|
49
|
+
/** Stable id for keying. */
|
|
50
|
+
id: string;
|
|
51
|
+
title: string;
|
|
52
|
+
/** The latest message or a summary, at most two lines. */
|
|
53
|
+
preview?: string;
|
|
54
|
+
/** When it last changed. Shown as a short time or date. */
|
|
55
|
+
timestamp?: string | Date;
|
|
56
|
+
/** Something new the person hasn't read: a dot, and the title in bold. */
|
|
57
|
+
unread?: boolean;
|
|
58
|
+
/** How many unread messages; shown as a count instead of the dot when above 0. */
|
|
59
|
+
unreadCount?: number;
|
|
60
|
+
/** A short status shown under the preview ("In progress", "12 votes"). */
|
|
61
|
+
meta?: string;
|
|
62
|
+
/** Replaces the unread dot (an avatar, an icon). */
|
|
63
|
+
leading?: ReactNode;
|
|
64
|
+
/** Shown at the end of the row (a vote button, a badge). Replaces the chevron. */
|
|
65
|
+
trailing?: ReactNode;
|
|
66
|
+
/** Opens the conversation. Rows with `onPress` show a chevron unless `trailing` is set. */
|
|
67
|
+
onPress?: () => void;
|
|
68
|
+
swipeActions?: InboxSwipeAction[];
|
|
69
|
+
/** testID override. Default `<page testID>-row-<id>`. */
|
|
70
|
+
testID?: string;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** The parts `slots` and `slotProps` reach, with the props each receives. */
|
|
74
|
+
export type InboxPageSlotMap = {
|
|
75
|
+
row: InboxItem & { testID: string; isFirst: boolean; isLast: boolean; timeLabel: string | null };
|
|
76
|
+
swipeable: { actions: InboxSwipeAction[]; testID: string; children?: ReactNode };
|
|
77
|
+
header: { testID: string };
|
|
78
|
+
footer: { loadingMore: boolean; testID: string };
|
|
79
|
+
empty: { title: string; body: string; actionLabel?: string; onAction?: () => void; testID: string };
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export interface InboxPageProps extends ScreenHeaderProps {
|
|
83
|
+
/** Newest first, as they should show. Empty → the empty state. */
|
|
84
|
+
items: InboxItem[];
|
|
85
|
+
refreshing?: boolean;
|
|
86
|
+
onRefresh?: () => void | Promise<void>;
|
|
87
|
+
/** Called near the end of the list, to load the next page. */
|
|
88
|
+
onEndReached?: () => void;
|
|
89
|
+
/** A next page is loading: the default footer shows a spinner. */
|
|
90
|
+
loadingMore?: boolean;
|
|
91
|
+
/** Above the group (a filter, a call to action). Prefer `slots.header` for a component. */
|
|
92
|
+
header?: ReactNode;
|
|
93
|
+
/** An optional title over the group, in the Settings header style. */
|
|
94
|
+
sectionTitle?: string;
|
|
95
|
+
emptyTitle?: string;
|
|
96
|
+
emptyBody?: string;
|
|
97
|
+
/** The first page is loading: a spinner instead of the empty state. */
|
|
98
|
+
loading?: boolean;
|
|
99
|
+
/** The read failed: the empty slot shows `errorTitle` / `errorBody` instead (and pull to refresh retries). */
|
|
100
|
+
error?: boolean;
|
|
101
|
+
errorTitle?: string;
|
|
102
|
+
errorBody?: string;
|
|
103
|
+
/** A button in the empty state ("Send feedback"). */
|
|
104
|
+
emptyActionLabel?: string;
|
|
105
|
+
onEmptyAction?: () => void;
|
|
106
|
+
/** How a row's time reads. Default: the time today, "Yesterday", the weekday this week, else the date. */
|
|
107
|
+
formatTime?: (date: Date, now: Date) => string;
|
|
108
|
+
/** The clock, for tests. */
|
|
109
|
+
now?: () => Date;
|
|
110
|
+
slots?: Slots<InboxPageSlotMap>;
|
|
111
|
+
slotProps?: SlotPropsFor<InboxPageSlotMap>;
|
|
112
|
+
/** testID on the root. Default `"inbox-page"`. */
|
|
113
|
+
testID?: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** `<Stack.Screen options>` for an InboxPage: a large title that collapses on scroll. */
|
|
117
|
+
export function getInboxPageStackOptions(props: ScreenHeaderProps & { headerTitle?: string }): Record<string, unknown> {
|
|
118
|
+
return composeHeaderOptions({
|
|
119
|
+
headerTitle: props.headerTitle ?? "Inbox",
|
|
120
|
+
large: props.large ?? true,
|
|
121
|
+
scrollEdgeBehavior: props.scrollEdgeBehavior ?? "match",
|
|
122
|
+
headerLeft: props.headerLeft,
|
|
123
|
+
headerRight: props.headerRight,
|
|
124
|
+
headerOptions: props.headerOptions,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
129
|
+
|
|
130
|
+
/** The default row time: `9:41`, `Yesterday`, `Monday`, then a short date. */
|
|
131
|
+
export function formatInboxTime(date: Date, now: Date): string {
|
|
132
|
+
const start = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();
|
|
133
|
+
const days = Math.round((start(now) - start(date)) / DAY_MS);
|
|
134
|
+
if (days <= 0) return date.toLocaleTimeString(undefined, { hour: "numeric", minute: "2-digit" });
|
|
135
|
+
if (days === 1) return "Yesterday";
|
|
136
|
+
if (days < 7) return date.toLocaleDateString(undefined, { weekday: "long" });
|
|
137
|
+
return date.toLocaleDateString(undefined, { day: "numeric", month: "short", year: date.getFullYear() === now.getFullYear() ? undefined : "numeric" });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** UIKit's inset grouped margin on a phone, in points (as SettingsPage). */
|
|
141
|
+
const IOS_GROUP_MARGIN = 16;
|
|
142
|
+
|
|
143
|
+
function iosGroupRadius(): number {
|
|
144
|
+
return Number.parseFloat(String(Platform.Version)) >= 26 ? 26 : 10;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function InboxPage({
|
|
148
|
+
items,
|
|
149
|
+
refreshing,
|
|
150
|
+
onRefresh,
|
|
151
|
+
onEndReached,
|
|
152
|
+
loadingMore = false,
|
|
153
|
+
header,
|
|
154
|
+
sectionTitle,
|
|
155
|
+
emptyTitle,
|
|
156
|
+
emptyBody,
|
|
157
|
+
emptyActionLabel,
|
|
158
|
+
onEmptyAction,
|
|
159
|
+
loading = false,
|
|
160
|
+
error = false,
|
|
161
|
+
errorTitle,
|
|
162
|
+
errorBody,
|
|
163
|
+
formatTime = formatInboxTime,
|
|
164
|
+
now = () => new Date(),
|
|
165
|
+
slots = {},
|
|
166
|
+
slotProps = {},
|
|
167
|
+
testID = "inbox-page",
|
|
168
|
+
}: InboxPageProps) {
|
|
169
|
+
const colors = useThemeRoles();
|
|
170
|
+
const clock = now();
|
|
171
|
+
const rows: InboxPageSlotMap["row"][] = items.map((item, index) => ({
|
|
172
|
+
...item,
|
|
173
|
+
testID: item.testID ?? `${testID}-row-${item.id}`,
|
|
174
|
+
isFirst: index === 0,
|
|
175
|
+
isLast: index === items.length - 1,
|
|
176
|
+
timeLabel: item.timestamp ? formatTime(typeof item.timestamp === "string" ? new Date(item.timestamp) : item.timestamp, clock) : null,
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
const headerNode = (
|
|
180
|
+
<View>
|
|
181
|
+
{header ?? renderSlot(EmptyPart, slots.header, { testID: `${testID}-header` }, slotProps.header)}
|
|
182
|
+
{sectionTitle ? <SectionTitle title={sectionTitle} testID={`${testID}-section-title`} /> : null}
|
|
183
|
+
</View>
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
if (items.length === 0) {
|
|
187
|
+
return (
|
|
188
|
+
<SafeAreaView testID={testID} edges={["left", "right", "bottom"]} style={{ flex: 1, backgroundColor: colors.groupedBackground }}>
|
|
189
|
+
{headerNode}
|
|
190
|
+
{loading ? (
|
|
191
|
+
<View testID={`${testID}-loading`} style={{ paddingVertical: 32 }}>
|
|
192
|
+
<ActivityIndicator accessibilityLabel="Loading" />
|
|
193
|
+
</View>
|
|
194
|
+
) : (
|
|
195
|
+
renderSlot(
|
|
196
|
+
DefaultEmpty,
|
|
197
|
+
slots.empty,
|
|
198
|
+
error
|
|
199
|
+
? {
|
|
200
|
+
title: errorTitle ?? "Couldn't load this",
|
|
201
|
+
body: errorBody ?? "Check your connection, then pull to refresh.",
|
|
202
|
+
actionLabel: onRefresh ? "Try again" : undefined,
|
|
203
|
+
onAction: onRefresh ? () => void onRefresh() : undefined,
|
|
204
|
+
testID: `${testID}-error`,
|
|
205
|
+
}
|
|
206
|
+
: {
|
|
207
|
+
title: emptyTitle ?? "Nothing here yet",
|
|
208
|
+
body: emptyBody ?? "When there's something new, it shows up here.",
|
|
209
|
+
actionLabel: emptyActionLabel,
|
|
210
|
+
onAction: onEmptyAction,
|
|
211
|
+
testID: `${testID}-empty`,
|
|
212
|
+
},
|
|
213
|
+
slotProps.empty,
|
|
214
|
+
)
|
|
215
|
+
)}
|
|
216
|
+
</SafeAreaView>
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return (
|
|
221
|
+
<SafeAreaView testID={testID} edges={["left", "right", "bottom"]} style={{ flex: 1, backgroundColor: colors.groupedBackground }}>
|
|
222
|
+
<FlatList
|
|
223
|
+
testID={`${testID}-list`}
|
|
224
|
+
data={rows}
|
|
225
|
+
keyExtractor={(row) => row.id}
|
|
226
|
+
contentInsetAdjustmentBehavior="automatic"
|
|
227
|
+
// The header can hold a text field (the idea board's "Suggest"): its button's first tap
|
|
228
|
+
// must press it, not only close the keyboard.
|
|
229
|
+
keyboardShouldPersistTaps="handled"
|
|
230
|
+
ListHeaderComponent={headerNode}
|
|
231
|
+
ListFooterComponent={renderSlot(DefaultFooter, slots.footer, { loadingMore, testID: `${testID}-footer` }, slotProps.footer)}
|
|
232
|
+
contentContainerStyle={{ paddingTop: 8, paddingBottom: 32 }}
|
|
233
|
+
onEndReached={onEndReached}
|
|
234
|
+
onEndReachedThreshold={0.5}
|
|
235
|
+
refreshControl={onRefresh ? <RefreshControl testID={`${testID}-refresh`} refreshing={!!refreshing} onRefresh={onRefresh} /> : undefined}
|
|
236
|
+
renderItem={({ item: row }) => {
|
|
237
|
+
const content = renderSlot(DefaultRow, slots.row, row, slotProps.row);
|
|
238
|
+
const actions = row.swipeActions ?? [];
|
|
239
|
+
return (
|
|
240
|
+
<Fragment>
|
|
241
|
+
{actions.length && slots.swipeable !== null
|
|
242
|
+
? renderSlot(PassThroughSwipeable, slots.swipeable, { actions, testID: `${row.testID}-swipe`, children: content }, slotProps.swipeable)
|
|
243
|
+
: content}
|
|
244
|
+
</Fragment>
|
|
245
|
+
);
|
|
246
|
+
}}
|
|
247
|
+
/>
|
|
248
|
+
</SafeAreaView>
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function EmptyPart(_props: InboxPageSlotMap["header"]) {
|
|
253
|
+
return null;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** The default `swipeable`: no gesture, just the row (its actions are on long press and in the accessibility actions). */
|
|
257
|
+
function PassThroughSwipeable({ children }: InboxPageSlotMap["swipeable"]) {
|
|
258
|
+
return <>{children}</>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function SectionTitle({ title, testID }: { title: string; testID: string }) {
|
|
262
|
+
const colors = useThemeRoles();
|
|
263
|
+
const ios = Platform.OS === "ios";
|
|
264
|
+
return (
|
|
265
|
+
<NativeText
|
|
266
|
+
testID={testID}
|
|
267
|
+
accessibilityRole="header"
|
|
268
|
+
className={ios ? "px-4 pb-1.5 pt-2" : "px-4 pb-2 pt-4 text-primary"}
|
|
269
|
+
style={
|
|
270
|
+
ios
|
|
271
|
+
? { marginHorizontal: IOS_GROUP_MARGIN, color: colors.secondaryLabel, fontSize: 13, lineHeight: 18, textTransform: "uppercase" }
|
|
272
|
+
: { fontSize: 14, lineHeight: 20, fontWeight: "500" }
|
|
273
|
+
}
|
|
274
|
+
>
|
|
275
|
+
{title}
|
|
276
|
+
</NativeText>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** Opens a row's actions as a menu (long press). */
|
|
281
|
+
export function showInboxActions(title: string, actions: InboxSwipeAction[], cancelLabel = "Cancel"): void {
|
|
282
|
+
Alert.alert(title, undefined, [
|
|
283
|
+
...actions.map((a) => ({ text: a.label, style: a.destructive ? ("destructive" as const) : ("default" as const), onPress: a.onPress })),
|
|
284
|
+
{ text: cancelLabel, style: "cancel" as const },
|
|
285
|
+
]);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function DefaultRow(row: InboxPageSlotMap["row"]) {
|
|
289
|
+
const colors = useThemeRoles();
|
|
290
|
+
const ios = Platform.OS === "ios";
|
|
291
|
+
const [pressed, setPressed] = useState(false);
|
|
292
|
+
const actions = row.swipeActions ?? [];
|
|
293
|
+
const radius = iosGroupRadius();
|
|
294
|
+
const unreadLabel = row.unreadCount && row.unreadCount > 0 ? `${row.unreadCount} unread` : row.unread ? "Unread" : null;
|
|
295
|
+
const label = [unreadLabel, row.title, row.timeLabel, row.preview, row.meta].filter(Boolean).join(", ");
|
|
296
|
+
return (
|
|
297
|
+
<View
|
|
298
|
+
testID={`${row.testID}-cell`}
|
|
299
|
+
style={[
|
|
300
|
+
{ backgroundColor: colors.surface },
|
|
301
|
+
ios
|
|
302
|
+
? {
|
|
303
|
+
marginHorizontal: IOS_GROUP_MARGIN,
|
|
304
|
+
borderTopLeftRadius: row.isFirst ? radius : 0,
|
|
305
|
+
borderTopRightRadius: row.isFirst ? radius : 0,
|
|
306
|
+
borderBottomLeftRadius: row.isLast ? radius : 0,
|
|
307
|
+
borderBottomRightRadius: row.isLast ? radius : 0,
|
|
308
|
+
overflow: "hidden",
|
|
309
|
+
}
|
|
310
|
+
: null,
|
|
311
|
+
]}
|
|
312
|
+
>
|
|
313
|
+
<Pressable
|
|
314
|
+
testID={row.testID}
|
|
315
|
+
accessibilityRole={row.onPress ? "button" : undefined}
|
|
316
|
+
accessibilityLabel={label}
|
|
317
|
+
accessibilityActions={actions.map((a) => ({ name: a.id, label: a.label }))}
|
|
318
|
+
onAccessibilityAction={(event) => actions.find((a) => a.id === event.nativeEvent.actionName)?.onPress()}
|
|
319
|
+
onPress={row.onPress}
|
|
320
|
+
onLongPress={actions.length ? () => showInboxActions(row.title, actions) : undefined}
|
|
321
|
+
onPressIn={() => setPressed(true)}
|
|
322
|
+
onPressOut={() => setPressed(false)}
|
|
323
|
+
style={{ flexDirection: "row", alignItems: "center", paddingHorizontal: 16, paddingVertical: 11, minHeight: 60, backgroundColor: pressed && row.onPress ? colors.fill : undefined }}
|
|
324
|
+
>
|
|
325
|
+
<View style={{ width: 18, alignItems: "flex-start" }}>
|
|
326
|
+
{row.leading ?? (row.unreadCount && row.unreadCount > 0 ? null : <UnreadDot unread={!!row.unread} testID={`${row.testID}-unread`} color={colors.tint} />)}
|
|
327
|
+
</View>
|
|
328
|
+
<View style={{ flex: 1, minWidth: 0 }}>
|
|
329
|
+
<View style={{ flexDirection: "row", alignItems: "baseline" }}>
|
|
330
|
+
<NativeText
|
|
331
|
+
numberOfLines={1}
|
|
332
|
+
style={{ flex: 1, color: colors.label, fontSize: 17, lineHeight: 22, fontWeight: row.unread || (row.unreadCount ?? 0) > 0 ? "600" : "400" }}
|
|
333
|
+
>
|
|
334
|
+
{row.title}
|
|
335
|
+
</NativeText>
|
|
336
|
+
{row.timeLabel ? (
|
|
337
|
+
<NativeText testID={`${row.testID}-time`} style={{ marginLeft: 8, color: colors.secondaryLabel, fontSize: 15, lineHeight: 20 }}>
|
|
338
|
+
{row.timeLabel}
|
|
339
|
+
</NativeText>
|
|
340
|
+
) : null}
|
|
341
|
+
</View>
|
|
342
|
+
{row.preview ? (
|
|
343
|
+
<NativeText numberOfLines={2} style={{ marginTop: 2, color: colors.secondaryLabel, fontSize: 15, lineHeight: 20 }}>
|
|
344
|
+
{row.preview}
|
|
345
|
+
</NativeText>
|
|
346
|
+
) : null}
|
|
347
|
+
{row.meta ? (
|
|
348
|
+
<NativeText testID={`${row.testID}-meta`} style={{ marginTop: 4, color: colors.tertiaryLabel, fontSize: 13, lineHeight: 18 }}>
|
|
349
|
+
{row.meta}
|
|
350
|
+
</NativeText>
|
|
351
|
+
) : null}
|
|
352
|
+
</View>
|
|
353
|
+
{row.unreadCount && row.unreadCount > 0 ? (
|
|
354
|
+
<View style={{ marginLeft: 8 }}>
|
|
355
|
+
<NativeBadge testID={`${row.testID}-count`}>{String(row.unreadCount)}</NativeBadge>
|
|
356
|
+
</View>
|
|
357
|
+
) : null}
|
|
358
|
+
{row.trailing ? <View style={{ marginLeft: 8 }}>{row.trailing}</View> : row.onPress ? <Chevron color={colors.tertiaryLabel} /> : null}
|
|
359
|
+
</Pressable>
|
|
360
|
+
{row.isLast ? null : (
|
|
361
|
+
<View accessibilityElementsHidden importantForAccessibility="no-hide-descendants" style={{ flexDirection: "row", height: StyleSheet.hairlineWidth }}>
|
|
362
|
+
<View style={{ width: 34 }} />
|
|
363
|
+
<View testID={`${row.testID}-separator-line`} style={{ flex: 1, backgroundColor: colors.separator }} />
|
|
364
|
+
</View>
|
|
365
|
+
)}
|
|
366
|
+
</View>
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function Chevron({ color }: { color: unknown }) {
|
|
371
|
+
return (
|
|
372
|
+
<NativeText accessibilityElementsHidden importantForAccessibility="no" style={{ marginLeft: 8, color: color as string, fontSize: 20, lineHeight: 22 }}>
|
|
373
|
+
›
|
|
374
|
+
</NativeText>
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
function UnreadDot({ unread, testID, color }: { unread: boolean; testID: string; color: unknown }) {
|
|
379
|
+
if (!unread) return <View testID={testID} style={{ width: 10, height: 10 }} />;
|
|
380
|
+
return <View testID={testID} style={{ width: 10, height: 10, borderRadius: 5, backgroundColor: color as string }} />;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function DefaultFooter({ loadingMore, testID }: InboxPageSlotMap["footer"]) {
|
|
384
|
+
if (!loadingMore) return null;
|
|
385
|
+
return (
|
|
386
|
+
<View testID={testID} style={{ paddingVertical: 16 }}>
|
|
387
|
+
<ActivityIndicator accessibilityLabel="Loading more" />
|
|
388
|
+
</View>
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function DefaultEmpty({ title, body, actionLabel, onAction, testID }: InboxPageSlotMap["empty"]) {
|
|
393
|
+
return (
|
|
394
|
+
<NativeEmptyState
|
|
395
|
+
variant="first-run"
|
|
396
|
+
title={title}
|
|
397
|
+
body={body}
|
|
398
|
+
testID={testID}
|
|
399
|
+
primaryAction={
|
|
400
|
+
actionLabel && onAction ? (
|
|
401
|
+
<NativeButton onPress={onAction} testID={`${testID}-action`}>
|
|
402
|
+
{actionLabel}
|
|
403
|
+
</NativeButton>
|
|
404
|
+
) : undefined
|
|
405
|
+
}
|
|
406
|
+
/>
|
|
407
|
+
);
|
|
408
|
+
}
|
package/src/layouts/index.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Layer-2 primitive: ScreenContainer (composable chrome).
|
|
5
5
|
* Layer-3/4 layouts: SettingsPage, SettingsSubPage, NotificationsPage,
|
|
6
|
-
* AuthScreen (assembled from AuthForm +
|
|
6
|
+
* InboxPage, ThreadPage, AuthScreen (assembled from AuthForm +
|
|
7
|
+
* SocialAuthRow + AuthBranding).
|
|
7
8
|
*
|
|
8
9
|
* See standards/usage-doctrine.md for the Layer 1-4 progression.
|
|
9
10
|
*/
|
|
@@ -46,11 +47,36 @@ export {
|
|
|
46
47
|
export {
|
|
47
48
|
NotificationsPage,
|
|
48
49
|
getNotificationsPageStackOptions,
|
|
50
|
+
defaultStickyHeaderOffset,
|
|
51
|
+
iosCompactNavigationBarHeight,
|
|
49
52
|
type NotificationsPageProps,
|
|
50
53
|
type NotificationsPageSlotMap,
|
|
51
54
|
type NotificationItem,
|
|
52
55
|
} from "./notifications-page";
|
|
53
56
|
|
|
57
|
+
export {
|
|
58
|
+
InboxPage,
|
|
59
|
+
formatInboxTime,
|
|
60
|
+
getInboxPageStackOptions,
|
|
61
|
+
showInboxActions,
|
|
62
|
+
type InboxItem,
|
|
63
|
+
type InboxPageProps,
|
|
64
|
+
type InboxPageSlotMap,
|
|
65
|
+
type InboxSwipeAction,
|
|
66
|
+
} from "./inbox-page";
|
|
67
|
+
|
|
68
|
+
export {
|
|
69
|
+
ThreadPage,
|
|
70
|
+
getThreadPageStackOptions,
|
|
71
|
+
readReceiptFor,
|
|
72
|
+
type ThreadAttachment,
|
|
73
|
+
type ThreadComposer,
|
|
74
|
+
type ThreadLabels,
|
|
75
|
+
type ThreadMessage,
|
|
76
|
+
type ThreadPageProps,
|
|
77
|
+
type ThreadPageSlotMap,
|
|
78
|
+
} from "./thread-page";
|
|
79
|
+
|
|
54
80
|
export {
|
|
55
81
|
AuthForm,
|
|
56
82
|
SocialAuthRow,
|
|
@@ -64,4 +90,21 @@ export {
|
|
|
64
90
|
} from "./auth";
|
|
65
91
|
|
|
66
92
|
export { AuthScreen, type AuthScreenProps, type AuthScreenSlotMap } from "./auth-screen";
|
|
67
|
-
export {
|
|
93
|
+
export {
|
|
94
|
+
KEYBOARD_TOOLBAR_HEIGHT,
|
|
95
|
+
KeyboardScrollProvider,
|
|
96
|
+
useKeyboardScroll,
|
|
97
|
+
useKeyboardToolbar,
|
|
98
|
+
type KeyboardScrollProps,
|
|
99
|
+
type KeyboardToolbarProps,
|
|
100
|
+
} from "./keyboard";
|
|
101
|
+
|
|
102
|
+
export {
|
|
103
|
+
AppleSignInButton,
|
|
104
|
+
appleProvider,
|
|
105
|
+
type AppleButtonModuleLike,
|
|
106
|
+
type AppleProviderOptions,
|
|
107
|
+
type AppleSignInButtonProps,
|
|
108
|
+
} from "./apple-sign-in";
|
|
109
|
+
|
|
110
|
+
export { googleProvider, type GoogleProviderOptions } from "./google-sign-in";
|
package/src/layouts/keyboard.tsx
CHANGED
|
@@ -4,15 +4,24 @@
|
|
|
4
4
|
* `KeyboardAvoidingView` for real apps; it is an optional peer here, so an app
|
|
5
5
|
* that has it passes it once:
|
|
6
6
|
*
|
|
7
|
-
* import { KeyboardAwareScrollView } from "react-native-keyboard-controller";
|
|
8
|
-
* <
|
|
7
|
+
* import { KeyboardAwareScrollView, KeyboardProvider, KeyboardToolbar } from "react-native-keyboard-controller";
|
|
8
|
+
* <KeyboardProvider>
|
|
9
|
+
* <KeyboardScrollProvider component={KeyboardAwareScrollView} toolbar={KeyboardToolbar}>…</KeyboardScrollProvider>
|
|
10
|
+
* </KeyboardProvider>
|
|
9
11
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
+
* `KeyboardAwareScrollView` does nothing without react-native-keyboard-controller's
|
|
13
|
+
* `KeyboardProvider` above it, mounted once at the root. (The native app
|
|
14
|
+
* shell does both, with `keyboardProvider` and `keyboardScroll`.) Without a
|
|
15
|
+
* scroll view here, form screens fall back to `KeyboardAvoidingView`.
|
|
16
|
+
*
|
|
17
|
+
* `toolbar` (optional, `KeyboardToolbar`) adds the previous / next / done bar
|
|
18
|
+
* above the keyboard on Genesis's multi-field form layouts (`AuthScreen`,
|
|
19
|
+
* `SettingsSubPage`). It needs `component` too: the bar sits beside the
|
|
20
|
+
* keyboard-aware scroll view. Without it, nothing changes.
|
|
12
21
|
*
|
|
13
22
|
* @stability Beta
|
|
14
23
|
*/
|
|
15
|
-
import { createContext, createElement, useContext, type ComponentType, type ReactNode } from "react";
|
|
24
|
+
import { createContext, createElement, useContext, useMemo, type ComponentType, type ReactNode } from "react";
|
|
16
25
|
import type { ViewStyle } from "react-native";
|
|
17
26
|
|
|
18
27
|
/** The props Genesis passes to a keyboard-aware scroll view. */
|
|
@@ -27,13 +36,56 @@ export interface KeyboardScrollProps {
|
|
|
27
36
|
bottomOffset?: number;
|
|
28
37
|
}
|
|
29
38
|
|
|
30
|
-
|
|
39
|
+
/**
|
|
40
|
+
* The props Genesis may pass to a keyboard toolbar, all optional and all
|
|
41
|
+
* `KeyboardToolbar`'s own: a settings form passes none (previous / next /
|
|
42
|
+
* done), a one-question form (forms-native's `FormFocus`) hides the arrows
|
|
43
|
+
* and makes Done its Next or Send. To theme it, pass a wrapper defined at
|
|
44
|
+
* module scope that renders it with your props and forwards these.
|
|
45
|
+
*/
|
|
46
|
+
export interface KeyboardToolbarProps {
|
|
47
|
+
/** Show the previous / next arrows. `KeyboardToolbar`'s default is true. */
|
|
48
|
+
showArrows?: boolean;
|
|
49
|
+
/** The done button's label. */
|
|
50
|
+
doneText?: ReactNode;
|
|
51
|
+
/** Called when done is pressed. The keyboard closes too, unless the callback calls `event.preventDefault()`. */
|
|
52
|
+
onDoneCallback?: (event: { preventDefault(): void }) => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Height of react-native-keyboard-controller's `KeyboardToolbar`, kept clear
|
|
57
|
+
* above the focused input. Mirrors `KEYBOARD_TOOLBAR_HEIGHT` in the library's
|
|
58
|
+
* `src/components/KeyboardToolbar/constants.ts` (1.22): move them together.
|
|
59
|
+
*/
|
|
60
|
+
export const KEYBOARD_TOOLBAR_HEIGHT = 42;
|
|
61
|
+
|
|
62
|
+
interface KeyboardScrollValue {
|
|
63
|
+
component: ComponentType<KeyboardScrollProps>;
|
|
64
|
+
toolbar: ComponentType<KeyboardToolbarProps> | null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const KeyboardScrollContext = createContext<KeyboardScrollValue | null>(null);
|
|
31
68
|
|
|
32
|
-
export function KeyboardScrollProvider({
|
|
33
|
-
|
|
69
|
+
export function KeyboardScrollProvider({
|
|
70
|
+
component,
|
|
71
|
+
toolbar,
|
|
72
|
+
children,
|
|
73
|
+
}: {
|
|
74
|
+
component: ComponentType<KeyboardScrollProps>;
|
|
75
|
+
/** `KeyboardToolbar` from react-native-keyboard-controller: previous / next / done above the keyboard. */
|
|
76
|
+
toolbar?: ComponentType<KeyboardToolbarProps>;
|
|
77
|
+
children: ReactNode;
|
|
78
|
+
}) {
|
|
79
|
+
const value = useMemo(() => ({ component, toolbar: toolbar ?? null }), [component, toolbar]);
|
|
80
|
+
return createElement(KeyboardScrollContext.Provider, { value }, children);
|
|
34
81
|
}
|
|
35
82
|
|
|
36
83
|
/** The app's keyboard-aware scroll view, or null when none was provided. */
|
|
37
84
|
export function useKeyboardScroll(): ComponentType<KeyboardScrollProps> | null {
|
|
38
|
-
return useContext(KeyboardScrollContext);
|
|
85
|
+
return useContext(KeyboardScrollContext)?.component ?? null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** The app's keyboard toolbar, or null when none was provided (or no scroll view to go with it). */
|
|
89
|
+
export function useKeyboardToolbar(): ComponentType<KeyboardToolbarProps> | null {
|
|
90
|
+
return useContext(KeyboardScrollContext)?.toolbar ?? null;
|
|
39
91
|
}
|