@marktiderman/genesis-ui-native 3.6.0 → 3.8.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 +48 -1
- package/dist/{chunk-NDXNSSM6.js → chunk-DHONOH6K.js} +24 -211
- package/dist/chunk-DHONOH6K.js.map +1 -0
- package/dist/{chunk-6PGLX6ET.js → chunk-FGIIBON3.js} +334 -24
- package/dist/chunk-FGIIBON3.js.map +1 -0
- package/dist/{chunk-ZRQAFFTN.js → chunk-FOJJB6AB.js} +2 -2
- package/dist/{chunk-ZRQAFFTN.js.map → chunk-FOJJB6AB.js.map} +1 -1
- package/dist/{chunk-SEJ6RBP7.js → chunk-JZ7RAGDQ.js} +117 -60
- package/dist/chunk-JZ7RAGDQ.js.map +1 -0
- package/dist/chunk-PWS2HLDE.js +137 -0
- package/dist/chunk-PWS2HLDE.js.map +1 -0
- package/dist/{chunk-AGTBABAH.js → chunk-PWYMRUAK.js} +43 -30
- package/dist/chunk-PWYMRUAK.js.map +1 -0
- package/dist/{chunk-FUMSL7VZ.js → chunk-T7FEVT62.js} +53 -12
- package/dist/chunk-T7FEVT62.js.map +1 -0
- package/dist/{chunk-2Z72MYHB.js → chunk-UZCJDMGE.js} +353 -19
- package/dist/chunk-UZCJDMGE.js.map +1 -0
- package/dist/components/index.d.ts +275 -24
- package/dist/components/index.js +5 -5
- package/dist/data/index.d.ts +2 -1
- package/dist/data/index.js +7 -12
- package/dist/data/index.js.map +1 -1
- package/dist/hooks/index.d.ts +36 -3
- package/dist/hooks/index.js +2 -2
- package/dist/icons/lucide.d.ts +1 -1
- package/dist/icons/lucide.js +13 -3
- package/dist/icons/lucide.js.map +1 -1
- package/dist/{inbox-page-B7_Oi2fS.d.ts → inbox-page-BGqR_cBs.d.ts} +4 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +8 -8
- package/dist/layouts/index.d.ts +12 -3
- package/dist/layouts/index.js +5 -5
- package/dist/{native-modules-Cl3zw3kh.d.ts → native-modules-CeAaO2Dh.d.ts} +55 -3
- package/package.json +73 -2
- package/src/__tests__/doctor-rules.test.ts +27 -0
- package/src/__tests__/native-modules-lists.test.tsx +1 -0
- package/src/components/__tests__/bulk-bar.test.tsx +36 -0
- package/src/components/__tests__/button-haptic.test.tsx +74 -0
- package/src/components/__tests__/composer-bar.test.tsx +140 -1
- package/src/components/__tests__/gallery-grid.test.tsx +2 -2
- package/src/components/__tests__/library-round-5.test.tsx +121 -0
- package/src/components/__tests__/share-sheet.test.tsx +47 -0
- package/src/components/__tests__/swipe-row-context-menu.test.tsx +215 -0
- package/src/components/__tests__/tab-bar.test.tsx +43 -0
- package/src/components/__tests__/thread-list.test.tsx +200 -0
- package/src/components/__tests__/tier-badge.test.tsx +57 -0
- package/src/components/__tests__/whats-new-sheet.test.tsx +29 -0
- package/src/components/bulk-bar.tsx +91 -0
- package/src/components/button.tsx +81 -25
- package/src/components/choice-card.tsx +104 -0
- package/src/components/composer-bar.tsx +104 -25
- package/src/components/context-menu.tsx +101 -0
- package/src/components/gallery-grid.tsx +10 -4
- package/src/components/index.ts +19 -2
- package/src/components/inline-alert.tsx +36 -1
- package/src/components/input.tsx +3 -0
- package/src/components/progress.tsx +24 -2
- package/src/components/rating.tsx +35 -16
- package/src/components/share-sheet.tsx +127 -0
- package/src/components/sheet.tsx +9 -1
- package/src/components/swipe-row.tsx +74 -0
- package/src/components/tab-bar.tsx +133 -0
- package/src/components/tabs.tsx +2 -0
- package/src/components/text.tsx +3 -0
- package/src/components/textarea.tsx +3 -0
- package/src/components/thread-list.tsx +78 -23
- package/src/components/tier-badge.tsx +74 -0
- package/src/components/whats-new-sheet.tsx +89 -0
- package/src/data/resource-view/NativeRecordView.tsx +3 -8
- package/src/data/resource-view/use-native-resource-view.ts +2 -2
- package/src/hooks/__tests__/use-haptics.test.tsx +146 -0
- package/src/hooks/index.ts +3 -1
- package/src/hooks/use-haptics.ts +64 -0
- package/src/hooks/use-press-feedback.ts +87 -0
- package/src/hooks/use-theme-roles.ts +3 -0
- package/src/icon-names.ts +12 -2
- package/src/icons/lucide.ts +27 -7
- package/src/layouts/__tests__/inbox-page.test.tsx +26 -7
- package/src/layouts/__tests__/thread-page.test.tsx +89 -2
- package/src/layouts/inbox-page.tsx +28 -12
- package/src/layouts/thread-page.tsx +69 -8
- package/src/native-modules.tsx +20 -0
- package/dist/chunk-2Z72MYHB.js.map +0 -1
- package/dist/chunk-4OQOJ2OC.js +0 -80
- package/dist/chunk-4OQOJ2OC.js.map +0 -1
- package/dist/chunk-6PGLX6ET.js.map +0 -1
- package/dist/chunk-AGTBABAH.js.map +0 -1
- package/dist/chunk-FUMSL7VZ.js.map +0 -1
- package/dist/chunk-NDXNSSM6.js.map +0 -1
- package/dist/chunk-SEJ6RBP7.js.map +0 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeChoiceCard — one selectable option drawn as a card: an indicator
|
|
3
|
+
* (a radio circle, or a checkbox square with `multiple`), an optional
|
|
4
|
+
* `media` slot (a thumbnail, an icon), a title and a description.
|
|
5
|
+
*
|
|
6
|
+
* The whole card is the press target (at least 44pt high) and reads as one
|
|
7
|
+
* radio or checkbox to VoiceOver and TalkBack, named "title, description".
|
|
8
|
+
* Selected, the border and indicator take the primary colour and the card a
|
|
9
|
+
* light primary wash; `invalid` draws the border in the destructive colour
|
|
10
|
+
* (and says "Needs an answer"). Controlled: the parent owns `selected`.
|
|
11
|
+
*
|
|
12
|
+
* Use a column of them for a question with pictures or explanations per
|
|
13
|
+
* option; for a plain list of words use NativeRadioGroup or NativeChipGroup.
|
|
14
|
+
*
|
|
15
|
+
* @stability Beta
|
|
16
|
+
*/
|
|
17
|
+
import { Pressable, Text, View } from "react-native";
|
|
18
|
+
import { cn } from "../utils";
|
|
19
|
+
|
|
20
|
+
export interface NativeChoiceCardProps {
|
|
21
|
+
title: string;
|
|
22
|
+
/** A second line under the title, muted. */
|
|
23
|
+
description?: string;
|
|
24
|
+
/** Slot left of the text: a thumbnail (NativeImage), an icon. */
|
|
25
|
+
media?: React.ReactNode;
|
|
26
|
+
selected: boolean;
|
|
27
|
+
onPress: () => void;
|
|
28
|
+
/** A checkbox (several can be chosen) rather than a radio. */
|
|
29
|
+
multiple?: boolean;
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
/** The question still needs an answer: a destructive border and hint. */
|
|
32
|
+
invalid?: boolean;
|
|
33
|
+
/** Extra accessibility hint, such as "Option 2 of 4". */
|
|
34
|
+
hint?: string;
|
|
35
|
+
className?: string;
|
|
36
|
+
testID?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function Indicator({ on, multiple, testID }: { on: boolean; multiple: boolean; testID?: string | undefined }) {
|
|
40
|
+
return (
|
|
41
|
+
<View
|
|
42
|
+
testID={testID}
|
|
43
|
+
className={cn(
|
|
44
|
+
"h-5 w-5 items-center justify-center border",
|
|
45
|
+
multiple ? "rounded" : "rounded-full",
|
|
46
|
+
on ? "border-primary" : "border-input",
|
|
47
|
+
on && multiple && "bg-primary",
|
|
48
|
+
)}
|
|
49
|
+
>
|
|
50
|
+
{on ? (
|
|
51
|
+
multiple ? (
|
|
52
|
+
<Text className="text-xs font-bold text-primary-foreground">✓</Text>
|
|
53
|
+
) : (
|
|
54
|
+
<View className="h-2.5 w-2.5 rounded-full bg-primary" />
|
|
55
|
+
)
|
|
56
|
+
) : null}
|
|
57
|
+
</View>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function NativeChoiceCard({
|
|
62
|
+
title,
|
|
63
|
+
description,
|
|
64
|
+
media,
|
|
65
|
+
selected,
|
|
66
|
+
onPress,
|
|
67
|
+
multiple = false,
|
|
68
|
+
disabled = false,
|
|
69
|
+
invalid = false,
|
|
70
|
+
hint,
|
|
71
|
+
className,
|
|
72
|
+
testID = "native-choice-card",
|
|
73
|
+
}: NativeChoiceCardProps) {
|
|
74
|
+
const name = description ? `${title}, ${description}` : title;
|
|
75
|
+
const accessibilityHint = [hint, invalid ? "Needs an answer" : ""].filter(Boolean).join(". ") || undefined;
|
|
76
|
+
return (
|
|
77
|
+
<Pressable
|
|
78
|
+
testID={testID}
|
|
79
|
+
onPress={onPress}
|
|
80
|
+
disabled={disabled}
|
|
81
|
+
accessibilityRole={multiple ? "checkbox" : "radio"}
|
|
82
|
+
accessibilityLabel={name}
|
|
83
|
+
accessibilityHint={accessibilityHint}
|
|
84
|
+
accessibilityState={{ checked: selected, selected, disabled }}
|
|
85
|
+
className={cn(
|
|
86
|
+
"min-h-[44px] flex-row items-center gap-3 rounded-lg border bg-card p-3",
|
|
87
|
+
selected ? "border-primary bg-primary/5" : invalid ? "border-destructive" : "border-border",
|
|
88
|
+
disabled && "opacity-50",
|
|
89
|
+
className,
|
|
90
|
+
)}
|
|
91
|
+
>
|
|
92
|
+
<Indicator on={selected} multiple={multiple} testID={`${testID}-indicator`} />
|
|
93
|
+
{media ? (
|
|
94
|
+
<View testID={`${testID}-media`} accessibilityElementsHidden importantForAccessibility="no-hide-descendants">
|
|
95
|
+
{media}
|
|
96
|
+
</View>
|
|
97
|
+
) : null}
|
|
98
|
+
<View className="flex-1">
|
|
99
|
+
<Text className="text-base text-foreground">{title}</Text>
|
|
100
|
+
{description ? <Text className="mt-0.5 text-sm text-muted-foreground">{description}</Text> : null}
|
|
101
|
+
</View>
|
|
102
|
+
</Pressable>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -9,8 +9,14 @@
|
|
|
9
9
|
* the input in the theme's `warning` role, so a staff-only note never
|
|
10
10
|
* reads like a reply (the send button keeps the tint: text on `warning`
|
|
11
11
|
* would fail contrast). The row it sends carries the same tone (ThreadPage).
|
|
12
|
-
* - **Slots:** `leading` (attach), `trailing` (beside send:
|
|
13
|
-
* (a reply preview, attachments waiting to send)
|
|
12
|
+
* - **Slots:** `leading` (attach), `trailing` (beside send: an emoji button),
|
|
13
|
+
* `above` (a reply preview, attachments waiting to send), `idleAction` (in
|
|
14
|
+
* Send's place while there's nothing to send: a hold-to-record mic) and
|
|
15
|
+
* `replaceInput` (instead of `leading` and the input: a recording's
|
|
16
|
+
* waveform). Attachments with no text: pass `hasContent`.
|
|
17
|
+
* - **More ways to send:** `sendActions` ("Schedule"). Touch and hold Send:
|
|
18
|
+
* one action runs, several open a menu. Each is also an accessibility
|
|
19
|
+
* action on Send.
|
|
14
20
|
* - **Keyboard:** the bar doesn't move itself. Put it under a keyboard-aware
|
|
15
21
|
* container (ThreadPage does, with `GenesisModules.keyboardAvoidingView`);
|
|
16
22
|
* the list above it dismisses the keyboard interactively on a drag.
|
|
@@ -21,11 +27,13 @@
|
|
|
21
27
|
*
|
|
22
28
|
* @stability Beta
|
|
23
29
|
*/
|
|
24
|
-
import { useEffect, type ReactNode } from "react";
|
|
25
|
-
import { AccessibilityInfo, ActivityIndicator, Dimensions, Platform, Pressable, TextInput, View } from "react-native";
|
|
30
|
+
import { useEffect, useState, type ReactNode } from "react";
|
|
31
|
+
import { AccessibilityInfo, ActivityIndicator, Animated, Dimensions, Platform, Pressable, TextInput, View } from "react-native";
|
|
26
32
|
import type { ComposerMode } from "@marktiderman/genesis-core/conversation";
|
|
27
33
|
import { useThemeRoles } from "../hooks/use-theme-roles";
|
|
28
34
|
import { useGenesisModules } from "../native-modules";
|
|
35
|
+
import { usePressFeedback } from "../hooks/use-press-feedback";
|
|
36
|
+
import { NativeContextMenu } from "./context-menu";
|
|
29
37
|
import { NativeIcon } from "./icon";
|
|
30
38
|
import { NativeText } from "./text";
|
|
31
39
|
|
|
@@ -48,15 +56,47 @@ export interface NativeComposerBarProps {
|
|
|
48
56
|
maxLines?: number;
|
|
49
57
|
/** Ways to send ("Reply", "Internal note"). Two or more show the picker. */
|
|
50
58
|
modes?: readonly ComposerMode[];
|
|
59
|
+
/** The picker's name, to VoiceOver. Default "Send as". */
|
|
60
|
+
modesLabel?: string;
|
|
51
61
|
/** The chosen mode's id. Default the first. */
|
|
52
62
|
mode?: string;
|
|
53
63
|
onModeChange?: (id: string) => void;
|
|
54
64
|
leading?: ReactNode;
|
|
55
65
|
trailing?: ReactNode;
|
|
56
66
|
above?: ReactNode;
|
|
67
|
+
/**
|
|
68
|
+
* Whether there's something to send. By default, a `value` that isn't blank; pass `true` when
|
|
69
|
+
* attachments are waiting and no text is needed, and `false` while `replaceInput` is showing.
|
|
70
|
+
*/
|
|
71
|
+
hasContent?: boolean;
|
|
72
|
+
/** Takes Send's place (the same 44pt spot) while there's nothing to send and nothing sending: a hold-to-record mic. */
|
|
73
|
+
idleAction?: ReactNode;
|
|
74
|
+
/** Shown instead of `leading` and the input (a recording in progress). Label it yourself: it's one region to VoiceOver. */
|
|
75
|
+
replaceInput?: ReactNode;
|
|
76
|
+
/** Touch and hold Send for these (one runs straight away; several open a menu). Each is also an accessibility action on Send. */
|
|
77
|
+
sendActions?: readonly ComposerSendAction[];
|
|
78
|
+
/** Title of the menu when there are several `sendActions`. */
|
|
79
|
+
sendActionsTitle?: string;
|
|
80
|
+
/** The hint on Send when it has `sendActions`. Default "Touch and hold for more options". */
|
|
81
|
+
sendActionsHint?: string;
|
|
82
|
+
/** Passed to the input (to insert at the cursor, say). */
|
|
83
|
+
onSelectionChange?: (e: { nativeEvent: { selection: { start: number; end: number } } }) => void;
|
|
84
|
+
/**
|
|
85
|
+
* The input takes text (default). When false, Send is off and the input reads as disabled.
|
|
86
|
+
* `idleAction` is the app's, so disable it too.
|
|
87
|
+
*/
|
|
88
|
+
editable?: boolean;
|
|
57
89
|
testID?: string;
|
|
58
90
|
}
|
|
59
91
|
|
|
92
|
+
/** Another way to send (touch and hold Send). */
|
|
93
|
+
export interface ComposerSendAction {
|
|
94
|
+
id: string;
|
|
95
|
+
label: string;
|
|
96
|
+
onPress: () => void;
|
|
97
|
+
destructive?: boolean;
|
|
98
|
+
}
|
|
99
|
+
|
|
60
100
|
const LINE = 22;
|
|
61
101
|
const PAD_Y = 8;
|
|
62
102
|
|
|
@@ -72,11 +112,20 @@ export function NativeComposerBar({
|
|
|
72
112
|
maxLength,
|
|
73
113
|
maxLines = 6,
|
|
74
114
|
modes,
|
|
115
|
+
modesLabel = "Send as",
|
|
75
116
|
mode,
|
|
76
117
|
onModeChange,
|
|
77
118
|
leading,
|
|
78
119
|
trailing,
|
|
79
120
|
above,
|
|
121
|
+
hasContent,
|
|
122
|
+
idleAction,
|
|
123
|
+
replaceInput,
|
|
124
|
+
sendActions,
|
|
125
|
+
sendActionsTitle,
|
|
126
|
+
sendActionsHint = "Touch and hold for more options",
|
|
127
|
+
onSelectionChange,
|
|
128
|
+
editable = true,
|
|
80
129
|
testID = "composer",
|
|
81
130
|
}: NativeComposerBarProps) {
|
|
82
131
|
const colors = useThemeRoles();
|
|
@@ -85,8 +134,12 @@ export function NativeComposerBar({
|
|
|
85
134
|
const hasIcon = Boolean(symbol || icons?.["arrow-up"]);
|
|
86
135
|
const current = modes?.find((m) => m.id === mode) ?? modes?.[0];
|
|
87
136
|
const internal = current?.tone === "internal";
|
|
88
|
-
const blank = !value.trim();
|
|
89
|
-
const canSend = !blank && !disabled && !sending;
|
|
137
|
+
const blank = !(hasContent ?? value.trim().length > 0);
|
|
138
|
+
const canSend = !blank && !disabled && !sending && editable;
|
|
139
|
+
const actions = sendActions?.length ? sendActions : null;
|
|
140
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
141
|
+
const idle = idleAction != null && blank && !sending;
|
|
142
|
+
const sendPress = usePressFeedback({ haptic: "light", scale: 0.9, disabled: !canSend });
|
|
90
143
|
// A multiline input grows with its text by itself; this caps it, after which it scrolls.
|
|
91
144
|
// Lines grow with the person's text size (Dynamic Type, Android font scale).
|
|
92
145
|
const fontScale = Dimensions.get("window").fontScale || 1;
|
|
@@ -110,7 +163,7 @@ export function NativeComposerBar({
|
|
|
110
163
|
}}
|
|
111
164
|
>
|
|
112
165
|
{modes && modes.length > 1 ? (
|
|
113
|
-
<View testID={`${testID}-modes`} accessibilityRole="tablist" style={{ flexDirection: "row", gap: 4 }}>
|
|
166
|
+
<View testID={`${testID}-modes`} accessibilityRole="tablist" accessibilityLabel={modesLabel} style={{ flexDirection: "row", gap: 4 }}>
|
|
114
167
|
{modes.map((m) => {
|
|
115
168
|
const on = m.id === current?.id;
|
|
116
169
|
return (
|
|
@@ -141,6 +194,10 @@ export function NativeComposerBar({
|
|
|
141
194
|
) : null}
|
|
142
195
|
{above}
|
|
143
196
|
<View style={{ flexDirection: "row", alignItems: "flex-end", gap: 8 }}>
|
|
197
|
+
{replaceInput != null ? (
|
|
198
|
+
<View style={{ flex: 1, minHeight: 44, justifyContent: "center" }}>{replaceInput}</View>
|
|
199
|
+
) : (
|
|
200
|
+
<>
|
|
144
201
|
{leading}
|
|
145
202
|
<TextInput
|
|
146
203
|
testID={`${testID}-input`}
|
|
@@ -149,6 +206,9 @@ export function NativeComposerBar({
|
|
|
149
206
|
placeholder={internal ? current!.label : placeholder}
|
|
150
207
|
placeholderTextColor={colors.tertiaryLabel as string}
|
|
151
208
|
accessibilityLabel={internal ? current!.label : placeholder}
|
|
209
|
+
accessibilityState={editable ? undefined : { disabled: true }}
|
|
210
|
+
editable={editable}
|
|
211
|
+
onSelectionChange={onSelectionChange}
|
|
152
212
|
multiline
|
|
153
213
|
maxLength={maxLength}
|
|
154
214
|
style={{
|
|
@@ -166,33 +226,52 @@ export function NativeComposerBar({
|
|
|
166
226
|
backgroundColor: colors.surface,
|
|
167
227
|
borderWidth: internal ? 1 : 0,
|
|
168
228
|
borderColor: colors.warning,
|
|
229
|
+
opacity: editable ? 1 : 0.6,
|
|
169
230
|
}}
|
|
170
231
|
/>
|
|
232
|
+
</>
|
|
233
|
+
)}
|
|
171
234
|
{trailing}
|
|
172
|
-
{
|
|
235
|
+
{idle ? (
|
|
236
|
+
<View testID={`${testID}-idle`} style={{ minWidth: 44, height: 44, alignItems: "center", justifyContent: "center" }}>
|
|
237
|
+
{idleAction}
|
|
238
|
+
</View>
|
|
239
|
+
) : sending ? (
|
|
173
240
|
<View testID={`${testID}-sending`} accessible accessibilityLabel={sendingLabel} accessibilityLiveRegion="polite" style={{ width: 44, height: 44, alignItems: "center", justifyContent: "center" }}>
|
|
174
241
|
<ActivityIndicator />
|
|
175
242
|
</View>
|
|
176
243
|
) : (
|
|
177
|
-
<
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
244
|
+
<Animated.View style={sendPress.style}>
|
|
245
|
+
<Pressable
|
|
246
|
+
testID={`${testID}-send`}
|
|
247
|
+
accessibilityRole="button"
|
|
248
|
+
accessibilityLabel={sendLabel}
|
|
249
|
+
accessibilityState={{ disabled: !canSend }}
|
|
250
|
+
accessibilityHint={actions ? sendActionsHint : undefined}
|
|
251
|
+
accessibilityActions={actions && canSend ? actions.map((a) => ({ name: a.id, label: a.label })) : undefined}
|
|
252
|
+
onAccessibilityAction={actions ? (e) => actions.find((a) => a.id === e.nativeEvent.actionName)?.onPress() : undefined}
|
|
253
|
+
onLongPress={actions ? () => (actions.length === 1 ? actions[0]!.onPress() : setMenuOpen(true)) : undefined}
|
|
254
|
+
disabled={!canSend}
|
|
255
|
+
onPressIn={sendPress.onPressIn}
|
|
256
|
+
onPressOut={sendPress.onPressOut}
|
|
257
|
+
onPress={() => {
|
|
258
|
+
sendPress.confirm();
|
|
259
|
+
onSend();
|
|
260
|
+
}}
|
|
261
|
+
style={{ minWidth: 44, height: 44, paddingHorizontal: hasIcon ? 0 : 14, borderRadius: 22, alignItems: "center", justifyContent: "center", backgroundColor: canSend ? colors.tint : colors.fill }}
|
|
262
|
+
>
|
|
263
|
+
{hasIcon ? (
|
|
264
|
+
<NativeIcon name="arrow-up" size={20} color={canSend ? colors.background : colors.tertiaryLabel} />
|
|
265
|
+
) : (
|
|
266
|
+
<NativeText preset="label" className={canSend ? "text-primary-foreground" : undefined} style={canSend ? undefined : { color: colors.tertiaryLabel }}>
|
|
267
|
+
{sendLabel}
|
|
268
|
+
</NativeText>
|
|
269
|
+
)}
|
|
270
|
+
</Pressable>
|
|
271
|
+
</Animated.View>
|
|
194
272
|
)}
|
|
195
273
|
</View>
|
|
274
|
+
{actions && actions.length > 1 ? <NativeContextMenu open={menuOpen} onOpenChange={setMenuOpen} actions={actions} {...(sendActionsTitle ? { title: sendActionsTitle } : {})} testID={`${testID}-send-menu`} /> : null}
|
|
196
275
|
</View>
|
|
197
276
|
);
|
|
198
277
|
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NativeContextMenu — what a long press opens: a short list of actions in a
|
|
3
|
+
* sheet that fits them, with Cancel, instead of the system `Alert`. It's the
|
|
4
|
+
* same on iOS and Android, a row of its own for each action (44pt, a destructive
|
|
5
|
+
* one in the theme's `destructive`), and opening it taps `medium`.
|
|
6
|
+
*
|
|
7
|
+
* Controlled, like `NativeSheet`: keep `open` in your screen and set it from
|
|
8
|
+
* `onLongPress`. Offer the same actions as accessibility actions on the
|
|
9
|
+
* pressable too (`accessibilityActions`), since VoiceOver doesn't long press.
|
|
10
|
+
*
|
|
11
|
+
* An action runs once, and once the sheet has gone: iOS won't present an alert
|
|
12
|
+
* or another modal over one that's still dismissing.
|
|
13
|
+
*
|
|
14
|
+
* @stability Beta
|
|
15
|
+
*/
|
|
16
|
+
import { useEffect, useRef } from "react";
|
|
17
|
+
import { Platform, Pressable, View } from "react-native";
|
|
18
|
+
import { useHaptics } from "../hooks/use-haptics";
|
|
19
|
+
import { useThemeRoles } from "../hooks/use-theme-roles";
|
|
20
|
+
import { NativeSheet } from "./sheet";
|
|
21
|
+
import { NativeText } from "./text";
|
|
22
|
+
|
|
23
|
+
export interface NativeContextMenuAction {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
onPress: () => void;
|
|
27
|
+
destructive?: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface NativeContextMenuProps {
|
|
31
|
+
open: boolean;
|
|
32
|
+
onOpenChange: (open: boolean) => void;
|
|
33
|
+
actions: readonly NativeContextMenuAction[];
|
|
34
|
+
/** Over the actions: what they act on. */
|
|
35
|
+
title?: string;
|
|
36
|
+
cancelLabel?: string;
|
|
37
|
+
testID?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** If iOS never says the sheet has gone (Modal's `onDismiss` can be skipped), run the action after this. */
|
|
41
|
+
const IOS_DISMISS_FALLBACK_MS = 600;
|
|
42
|
+
|
|
43
|
+
export function NativeContextMenu({ open, onOpenChange, actions, title, cancelLabel = "Cancel", testID = "context-menu" }: NativeContextMenuProps) {
|
|
44
|
+
const colors = useThemeRoles();
|
|
45
|
+
const play = useHaptics();
|
|
46
|
+
const opened = useRef(false);
|
|
47
|
+
// What was tapped, until the sheet has gone. Taken once: a second tap, or the fallback after onDismiss, finds nothing.
|
|
48
|
+
const tapped = useRef<(() => void) | null>(null);
|
|
49
|
+
const ran = useRef(false);
|
|
50
|
+
const fallback = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (open && !opened.current) {
|
|
53
|
+
play("medium");
|
|
54
|
+
ran.current = false;
|
|
55
|
+
}
|
|
56
|
+
opened.current = open;
|
|
57
|
+
}, [open, play]);
|
|
58
|
+
|
|
59
|
+
const runTapped = () => {
|
|
60
|
+
if (fallback.current) clearTimeout(fallback.current);
|
|
61
|
+
fallback.current = null;
|
|
62
|
+
const action = tapped.current;
|
|
63
|
+
tapped.current = null;
|
|
64
|
+
action?.();
|
|
65
|
+
};
|
|
66
|
+
const run = (action: NativeContextMenuAction) => {
|
|
67
|
+
if (ran.current) return;
|
|
68
|
+
ran.current = true;
|
|
69
|
+
tapped.current = action.onPress;
|
|
70
|
+
onOpenChange(false);
|
|
71
|
+
if (Platform.OS === "ios") fallback.current = setTimeout(runTapped, IOS_DISMISS_FALLBACK_MS);
|
|
72
|
+
else runTapped();
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<NativeSheet open={open} onOpenChange={onOpenChange} fitContent onDismissed={runTapped} testID={testID}>
|
|
77
|
+
<View style={{ paddingHorizontal: 16, paddingBottom: 8 }}>
|
|
78
|
+
{title ? (
|
|
79
|
+
<NativeText testID={`${testID}-title`} accessibilityRole="header" numberOfLines={2} style={{ paddingVertical: 8, color: colors.secondaryLabel, fontSize: 13, lineHeight: 18, textAlign: "center" }}>
|
|
80
|
+
{title}
|
|
81
|
+
</NativeText>
|
|
82
|
+
) : null}
|
|
83
|
+
{actions.map((action) => (
|
|
84
|
+
<Pressable
|
|
85
|
+
key={action.id}
|
|
86
|
+
testID={`${testID}-action-${action.id}`}
|
|
87
|
+
accessibilityRole="button"
|
|
88
|
+
accessibilityLabel={action.label}
|
|
89
|
+
onPress={() => run(action)}
|
|
90
|
+
style={{ minHeight: 48, alignItems: "center", justifyContent: "center" }}
|
|
91
|
+
>
|
|
92
|
+
<NativeText style={{ color: action.destructive ? colors.destructive : colors.tint, fontSize: 17, lineHeight: 22 }}>{action.label}</NativeText>
|
|
93
|
+
</Pressable>
|
|
94
|
+
))}
|
|
95
|
+
<Pressable testID={`${testID}-cancel`} accessibilityRole="button" accessibilityLabel={cancelLabel} onPress={() => onOpenChange(false)} style={{ minHeight: 48, alignItems: "center", justifyContent: "center" }}>
|
|
96
|
+
<NativeText style={{ color: colors.label, fontSize: 17, lineHeight: 22, fontWeight: "600" }}>{cancelLabel}</NativeText>
|
|
97
|
+
</Pressable>
|
|
98
|
+
</View>
|
|
99
|
+
</NativeSheet>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* Rows come from the pure `justifyRows`, so the same items pack the same way
|
|
7
7
|
* as the web `GalleryGrid`, with the same defaults (`GALLERY_DEFAULTS`) and
|
|
8
8
|
* the same props, `onItemPress` in place of the web's `onItemClick` (as
|
|
9
|
-
* `NativeResourcePage` pairs with `ResourcePage`). The
|
|
10
|
-
*
|
|
9
|
+
* `NativeResourcePage` pairs with `ResourcePage`). The first paint lays out
|
|
10
|
+
* at the window width, and `onLayout` corrects it to the container's. The rows are a
|
|
11
11
|
* virtualized `FlatList` (the grid scrolls itself; `header` and `footer` go
|
|
12
12
|
* above and below), so a long gallery mounts only what's near the screen and
|
|
13
13
|
* `loadMore` fires when scrolling nears the end, for "load more". Don't put
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* @stability Beta
|
|
27
27
|
*/
|
|
28
28
|
import { useMemo, useState, type ReactNode } from "react";
|
|
29
|
-
import { FlatList, Pressable, Text, View, type LayoutChangeEvent } from "react-native";
|
|
29
|
+
import { Dimensions, FlatList, Pressable, Text, View, type FlatListProps, type LayoutChangeEvent } from "react-native";
|
|
30
30
|
import { cn } from "../utils";
|
|
31
31
|
import { galleryItemRatio, justifyRows } from "./gallery-layout";
|
|
32
32
|
import { GALLERY_DEFAULTS, type GalleryItem, type GalleryTileAspect } from "./gallery-types";
|
|
@@ -67,6 +67,8 @@ export interface NativeGalleryGridProps {
|
|
|
67
67
|
groupBy?: (item: GalleryItem) => string;
|
|
68
68
|
/** @deprecated Use `groupBy`. */
|
|
69
69
|
getGroup?: (item: GalleryItem) => string;
|
|
70
|
+
/** iOS: how the list insets under a large-title or translucent header. Default `"automatic"`, so the first row starts below the header. */
|
|
71
|
+
contentInsetAdjustmentBehavior?: FlatListProps<unknown>["contentInsetAdjustmentBehavior"];
|
|
70
72
|
className?: string;
|
|
71
73
|
testID?: string;
|
|
72
74
|
}
|
|
@@ -116,12 +118,15 @@ export function NativeGalleryGrid({
|
|
|
116
118
|
footer,
|
|
117
119
|
groupBy: groupByProp,
|
|
118
120
|
getGroup,
|
|
121
|
+
contentInsetAdjustmentBehavior = "automatic",
|
|
119
122
|
className,
|
|
120
123
|
testID = "native-gallery-grid",
|
|
121
124
|
}: NativeGalleryGridProps) {
|
|
122
125
|
const loadMore = loadMoreProp ?? onNearEnd;
|
|
123
126
|
const groupBy = groupByProp ?? getGroup;
|
|
124
|
-
|
|
127
|
+
// Start from the window width so the list mounts on the first paint (iOS applies the
|
|
128
|
+
// large-title content inset only to a scroll view present at mount); onLayout corrects it.
|
|
129
|
+
const [width, setWidth] = useState(() => Dimensions.get("window").width);
|
|
125
130
|
const onLayout = (e: LayoutChangeEvent) => {
|
|
126
131
|
const next = e.nativeEvent.layout.width;
|
|
127
132
|
if (next !== width) setWidth(next);
|
|
@@ -269,6 +274,7 @@ export function NativeGalleryGrid({
|
|
|
269
274
|
{width > 0 ? (
|
|
270
275
|
<FlatList
|
|
271
276
|
testID={`${testID}-list`}
|
|
277
|
+
contentInsetAdjustmentBehavior={contentInsetAdjustmentBehavior}
|
|
272
278
|
data={lines}
|
|
273
279
|
keyExtractor={(line) => line.key}
|
|
274
280
|
renderItem={renderLine}
|
package/src/components/index.ts
CHANGED
|
@@ -128,6 +128,8 @@ export type { NativeRefreshControlProps } from "./refresh-control";
|
|
|
128
128
|
|
|
129
129
|
export { NativeBadge, badgeVariants, badgeTextVariants } from "./badge";
|
|
130
130
|
export type { NativeBadgeProps } from "./badge";
|
|
131
|
+
export { NativeTierBadge } from "./tier-badge";
|
|
132
|
+
export type { NativeTierBadgeProps } from "./tier-badge";
|
|
131
133
|
|
|
132
134
|
export { NativeInput } from "./input";
|
|
133
135
|
export type { NativeInputProps } from "./input";
|
|
@@ -197,6 +199,8 @@ export type {
|
|
|
197
199
|
export { NativeLabel } from "./label";
|
|
198
200
|
export type { NativeLabelProps } from "./label";
|
|
199
201
|
|
|
202
|
+
export { NativeChoiceCard } from "./choice-card";
|
|
203
|
+
export type { NativeChoiceCardProps } from "./choice-card";
|
|
200
204
|
export { NativeRadioGroup, NativeRadioGroupItem } from "./radio-group";
|
|
201
205
|
export type {
|
|
202
206
|
NativeRadioGroupProps,
|
|
@@ -306,7 +310,11 @@ export {
|
|
|
306
310
|
} from "./thread-list";
|
|
307
311
|
export type { NativeThreadListProps, NativeThreadListHandle, ThreadRowInfo } from "./thread-list";
|
|
308
312
|
export { NativeComposerBar } from "./composer-bar";
|
|
309
|
-
export type { NativeComposerBarProps, ComposerMode, ComposerTone } from "./composer-bar";
|
|
313
|
+
export type { NativeComposerBarProps, ComposerMode, ComposerTone, ComposerSendAction } from "./composer-bar";
|
|
314
|
+
export { NativeSwipeRow } from "./swipe-row";
|
|
315
|
+
export type { NativeSwipeRowProps } from "./swipe-row";
|
|
316
|
+
export { NativeContextMenu } from "./context-menu";
|
|
317
|
+
export type { NativeContextMenuProps, NativeContextMenuAction } from "./context-menu";
|
|
310
318
|
|
|
311
319
|
// --- Gallery and media primitives ---
|
|
312
320
|
|
|
@@ -315,7 +323,7 @@ export { justifyRows, galleryItemRatio, DEFAULT_GALLERY_RATIO } from "./gallery-
|
|
|
315
323
|
export type { JustifiedRow, JustifiedTile } from "./gallery-layout";
|
|
316
324
|
|
|
317
325
|
export { NativeRating, nextRating } from "./rating";
|
|
318
|
-
export type { NativeRatingProps, NativeRatingSize } from "./rating";
|
|
326
|
+
export type { NativeRatingProps, NativeRatingSize, NativeRatingTone } from "./rating";
|
|
319
327
|
|
|
320
328
|
export { NativeGalleryGrid } from "./gallery-grid";
|
|
321
329
|
export type { NativeGalleryGridProps, NativeGalleryLayout } from "./gallery-grid";
|
|
@@ -340,3 +348,12 @@ export type { NativeGalleryCardProps } from "./gallery-card";
|
|
|
340
348
|
|
|
341
349
|
export { NativeLiveIndicator } from "./live-indicator";
|
|
342
350
|
export type { NativeLiveIndicatorProps, NativeLiveIndicatorState, NativeLiveIndicatorVariant } from "./live-indicator";
|
|
351
|
+
|
|
352
|
+
export { NativeTabBar } from "./tab-bar";
|
|
353
|
+
export type { NativeTabBarItem, NativeTabBarProps } from "./tab-bar";
|
|
354
|
+
export { NativeBulkBar } from "./bulk-bar";
|
|
355
|
+
export type { NativeBulkAction, NativeBulkBarProps } from "./bulk-bar";
|
|
356
|
+
export { NativeShareSheet } from "./share-sheet";
|
|
357
|
+
export type { NativeShareSheetProps } from "./share-sheet";
|
|
358
|
+
export { NativeWhatsNewSheet } from "./whats-new-sheet";
|
|
359
|
+
export type { NativeWhatsNewNote, NativeWhatsNewSheetProps } from "./whats-new-sheet";
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
* sparingly — for transient confirmation use <NativeToast>; for
|
|
10
10
|
* blocking issues use <NativeDialog>.
|
|
11
11
|
*
|
|
12
|
-
* Both share variants: info / success / warning / destructive.
|
|
12
|
+
* Both share variants: info / success / warning / destructive. Under the
|
|
13
|
+
* description, `children` takes any content (an error summary's list of
|
|
14
|
+
* links, a status line) and `actions` a row of buttons ("Retry", "Review"),
|
|
15
|
+
* so neither has to be drawn by hand around the alert.
|
|
13
16
|
*
|
|
14
17
|
* @stability Beta
|
|
15
18
|
*/
|
|
@@ -30,6 +33,10 @@ interface BaseProps {
|
|
|
30
33
|
icon?: React.ReactNode;
|
|
31
34
|
/** When provided, renders an "✕" dismiss button with this label. */
|
|
32
35
|
onDismiss?: () => void;
|
|
36
|
+
/** Content under the description (a list of the fields to fix, a status line). */
|
|
37
|
+
children?: React.ReactNode;
|
|
38
|
+
/** A row of buttons under the content (NativeButton size="sm"). */
|
|
39
|
+
actions?: React.ReactNode;
|
|
33
40
|
className?: string;
|
|
34
41
|
testID?: string;
|
|
35
42
|
}
|
|
@@ -48,6 +55,24 @@ const titleClasses: Record<NativeInlineAlertVariant, string> = {
|
|
|
48
55
|
destructive: "text-destructive",
|
|
49
56
|
};
|
|
50
57
|
|
|
58
|
+
/** The alert's content and actions slots, under the description. */
|
|
59
|
+
function AlertExtras({ children, actions, testID }: { children?: React.ReactNode; actions?: React.ReactNode; testID?: string | undefined }) {
|
|
60
|
+
return (
|
|
61
|
+
<>
|
|
62
|
+
{children ? (
|
|
63
|
+
<View testID={testID ? `${testID}-content` : undefined} className="mt-2">
|
|
64
|
+
{children}
|
|
65
|
+
</View>
|
|
66
|
+
) : null}
|
|
67
|
+
{actions ? (
|
|
68
|
+
<View testID={testID ? `${testID}-actions` : undefined} className="mt-3 flex-row flex-wrap gap-2">
|
|
69
|
+
{actions}
|
|
70
|
+
</View>
|
|
71
|
+
) : null}
|
|
72
|
+
</>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
51
76
|
export interface NativeInlineAlertProps extends BaseProps {}
|
|
52
77
|
|
|
53
78
|
export function NativeInlineAlert({
|
|
@@ -56,6 +81,8 @@ export function NativeInlineAlert({
|
|
|
56
81
|
description,
|
|
57
82
|
icon,
|
|
58
83
|
onDismiss,
|
|
84
|
+
children,
|
|
85
|
+
actions,
|
|
59
86
|
className,
|
|
60
87
|
testID,
|
|
61
88
|
}: NativeInlineAlertProps) {
|
|
@@ -81,6 +108,9 @@ export function NativeInlineAlert({
|
|
|
81
108
|
{description}
|
|
82
109
|
</Text>
|
|
83
110
|
) : null}
|
|
111
|
+
<AlertExtras testID={testID} actions={actions}>
|
|
112
|
+
{children}
|
|
113
|
+
</AlertExtras>
|
|
84
114
|
</View>
|
|
85
115
|
{onDismiss ? (
|
|
86
116
|
<Pressable
|
|
@@ -106,6 +136,8 @@ export function NativeBanner({
|
|
|
106
136
|
description,
|
|
107
137
|
icon,
|
|
108
138
|
onDismiss,
|
|
139
|
+
children,
|
|
140
|
+
actions,
|
|
109
141
|
className,
|
|
110
142
|
testID,
|
|
111
143
|
}: NativeBannerProps) {
|
|
@@ -132,6 +164,9 @@ export function NativeBanner({
|
|
|
132
164
|
{description}
|
|
133
165
|
</Text>
|
|
134
166
|
) : null}
|
|
167
|
+
<AlertExtras testID={testID} actions={actions}>
|
|
168
|
+
{children}
|
|
169
|
+
</AlertExtras>
|
|
135
170
|
</View>
|
|
136
171
|
{onDismiss ? (
|
|
137
172
|
<Pressable
|
package/src/components/input.tsx
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @stability Stable
|
|
5
5
|
*/
|
|
6
|
+
import type { ComponentRef, Ref } from "react";
|
|
6
7
|
import { Text, TextInput, type TextInputProps, View } from "react-native";
|
|
7
8
|
import { nativeColors } from "@marktiderman/genesis-design-system/tokens/native";
|
|
8
9
|
import { cn } from "../utils";
|
|
@@ -12,6 +13,8 @@ export interface NativeInputProps extends TextInputProps {
|
|
|
12
13
|
inputClassName?: string;
|
|
13
14
|
label?: string;
|
|
14
15
|
error?: string;
|
|
16
|
+
/** The underlying TextInput (React 19 passes `ref` as a prop). */
|
|
17
|
+
ref?: Ref<ComponentRef<typeof TextInput>> | undefined;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
function NativeInput({
|