@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
|
@@ -11,8 +11,11 @@
|
|
|
11
11
|
*
|
|
12
12
|
* @stability Beta
|
|
13
13
|
*/
|
|
14
|
-
import { Pressable, Text, View } from "react-native";
|
|
14
|
+
import { Platform, Pressable, Text, View } from "react-native";
|
|
15
15
|
import { cn } from "../utils";
|
|
16
|
+
import { useThemeRoles } from "../hooks/use-theme-roles";
|
|
17
|
+
import { useGenesisModules } from "../native-modules";
|
|
18
|
+
import { NativeIcon } from "./icon";
|
|
16
19
|
|
|
17
20
|
export interface NativeListItemProps {
|
|
18
21
|
title: string;
|
|
@@ -58,14 +61,7 @@ export function NativeListItem({
|
|
|
58
61
|
) : null}
|
|
59
62
|
</View>
|
|
60
63
|
{trailing ? <View className="ml-3">{trailing}</View> : null}
|
|
61
|
-
{showChevron ?
|
|
62
|
-
<Text
|
|
63
|
-
accessibilityElementsHidden
|
|
64
|
-
className="ml-2 text-base text-muted-foreground"
|
|
65
|
-
>
|
|
66
|
-
›
|
|
67
|
-
</Text>
|
|
68
|
-
) : null}
|
|
64
|
+
{showChevron ? <Chevron /> : null}
|
|
69
65
|
</>
|
|
70
66
|
);
|
|
71
67
|
|
|
@@ -103,6 +99,30 @@ export function NativeListItem({
|
|
|
103
99
|
);
|
|
104
100
|
}
|
|
105
101
|
|
|
102
|
+
/**
|
|
103
|
+
* The drill-in chevron: an SF Symbol on iOS or the app's icon set
|
|
104
|
+
* (`modules.symbol` / `modules.icons`) when given, else a text "›".
|
|
105
|
+
*/
|
|
106
|
+
function Chevron() {
|
|
107
|
+
const { symbol, icons } = useGenesisModules();
|
|
108
|
+
const roles = useThemeRoles();
|
|
109
|
+
if ((Platform.OS === "ios" && symbol) || icons?.["chevron-right"]) {
|
|
110
|
+
return (
|
|
111
|
+
<View className="ml-2">
|
|
112
|
+
<NativeIcon name="chevron-right" size={14} weight="semibold" color={roles.tertiaryLabel} testID="native-list-item-chevron" />
|
|
113
|
+
</View>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
return (
|
|
117
|
+
<Text
|
|
118
|
+
accessibilityElementsHidden
|
|
119
|
+
className="ml-2 text-base text-muted-foreground"
|
|
120
|
+
>
|
|
121
|
+
›
|
|
122
|
+
</Text>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
106
126
|
export function NativeListItemDivider({ className }: { className?: string }) {
|
|
107
127
|
return <View className={cn("h-px bg-border", className)} />;
|
|
108
128
|
}
|
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
} from "react";
|
|
21
21
|
import { Modal, Pressable, View } from "react-native";
|
|
22
22
|
import { cn } from "../utils";
|
|
23
|
+
import { NativeGlassSurface } from "./glass-surface";
|
|
23
24
|
|
|
24
25
|
// React Native's View instance type — uses .measureInWindow().
|
|
25
26
|
type ViewHandle = {
|
|
@@ -180,15 +181,17 @@ export function NativePopoverContent({
|
|
|
180
181
|
}}
|
|
181
182
|
>
|
|
182
183
|
<Pressable onPress={() => {}}>
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
184
|
+
{/* Liquid Glass on iOS 26 with `modules.glass`; the popover surface otherwise. */}
|
|
185
|
+
{/* Every class stays on one view, as before: without glass it is
|
|
186
|
+
exactly the old popover, and `className` still sets its width. */}
|
|
187
|
+
<View testID={testID ?? "native-popover-content"} accessibilityViewIsModal>
|
|
188
|
+
<NativeGlassSurface
|
|
189
|
+
radius={14}
|
|
190
|
+
fallbackClassName="rounded-md border border-border bg-popover shadow-md"
|
|
191
|
+
className={cn("max-w-[280px] p-3", className)}
|
|
192
|
+
>
|
|
193
|
+
{children}
|
|
194
|
+
</NativeGlassSurface>
|
|
192
195
|
</View>
|
|
193
196
|
</Pressable>
|
|
194
197
|
</View>
|
|
@@ -26,6 +26,9 @@ export interface NativeSegmentedControlProps<T = string> {
|
|
|
26
26
|
testID?: string;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
const SELECTED_LIFT = { shadowColor: "black", shadowOpacity: 0.08, shadowRadius: 2, shadowOffset: { width: 0, height: 1 }, elevation: 1 } as const;
|
|
30
|
+
const UNSELECTED_LIFT = { shadowColor: "black", shadowOpacity: 0, shadowRadius: 0, shadowOffset: { width: 0, height: 0 }, elevation: 0 } as const;
|
|
31
|
+
|
|
29
32
|
export function NativeSegmentedControl<T = string>({
|
|
30
33
|
options,
|
|
31
34
|
value,
|
|
@@ -60,8 +63,11 @@ export function NativeSegmentedControl<T = string>({
|
|
|
60
63
|
onPress={() => onChange(opt.value)}
|
|
61
64
|
className={cn(
|
|
62
65
|
"min-h-[36px] flex-1 items-center justify-center rounded px-3 py-1",
|
|
63
|
-
selected && "bg-background
|
|
66
|
+
selected && "bg-background"
|
|
64
67
|
)}
|
|
68
|
+
// The lift as a style, not a `shadow-sm` class toggled on select: NativeWind treats a
|
|
69
|
+
// shadow class that appears later as an upgrade and, in development, crashes printing it.
|
|
70
|
+
style={selected ? SELECTED_LIFT : UNSELECTED_LIFT}
|
|
65
71
|
>
|
|
66
72
|
<Text
|
|
67
73
|
className={cn(
|
package/src/components/sheet.tsx
CHANGED
|
@@ -5,188 +5,331 @@
|
|
|
5
5
|
* from preserving screen context. For blocking confirmations, use
|
|
6
6
|
* <NativeDialog>. For full-screen flows, use a navigation route.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
* By default this is React Native's own `Modal`, which needs nothing mounted
|
|
9
|
+
* above it: the system page sheet on iOS (swipe down to close) and a bottom
|
|
10
|
+
* panel over a scrim on Android (back button or a tap on the scrim closes
|
|
11
|
+
* it). Content gets its own safe area (`useSafeAreaInsets` inside the sheet
|
|
12
|
+
* is the sheet's), and the bottom inset is padded. Put scrolling content in
|
|
13
|
+
* `NativeSheetScrollView`. The sheet doesn't move above the keyboard.
|
|
14
|
+
*
|
|
15
|
+
* `@gorhom/bottom-sheet` (snap points, drag between heights) is used only
|
|
16
|
+
* when the app opts in by mounting `<NativeSheetProvider bottomSheet={…}>`
|
|
17
|
+
* (or passing `bottomSheet` to `GenesisNativeApp`), never because the
|
|
18
|
+
* library happens to be installed: it throws on open unless its
|
|
19
|
+
* `BottomSheetModalProvider` is mounted, and it needs gesture-handler's
|
|
20
|
+
* `GestureHandlerRootView` at the root and Reanimated set up.
|
|
21
|
+
* `snapPoints` and `initialSnapIndex` apply only to that path.
|
|
22
|
+
*
|
|
23
|
+
* A sheet that is a screen of its own (a link can open it) belongs in the
|
|
24
|
+
* router instead: an expo-router screen with `presentation: "formSheet"` and
|
|
25
|
+
* `sheetAllowedDetents` (e.g. `[0.5, 1]`) is the system sheet with detents.
|
|
15
26
|
*
|
|
16
27
|
* @stability Beta
|
|
17
28
|
*/
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
29
|
+
import {
|
|
30
|
+
createContext,
|
|
31
|
+
useCallback,
|
|
32
|
+
useContext,
|
|
33
|
+
useEffect,
|
|
34
|
+
useRef,
|
|
35
|
+
useState,
|
|
36
|
+
type ComponentType,
|
|
37
|
+
type ReactNode,
|
|
38
|
+
} from "react";
|
|
39
|
+
import { AccessibilityInfo, Modal, Platform, Pressable, ScrollView, View, type ScrollViewProps, type ViewStyle } from "react-native";
|
|
40
|
+
import { SafeAreaProvider, useSafeAreaInsets } from "react-native-safe-area-context";
|
|
41
|
+
import { useThemeRoles } from "../hooks/use-theme-roles";
|
|
21
42
|
|
|
22
43
|
export interface NativeSheetProps {
|
|
23
44
|
/** Controlled visibility. */
|
|
24
45
|
open: boolean;
|
|
25
|
-
/** Fired when the user dismisses the sheet (backdrop,
|
|
46
|
+
/** Fired when the user dismisses the sheet (backdrop, swipe down, Android back). Set `open` false in it. */
|
|
26
47
|
onOpenChange: (open: boolean) => void;
|
|
27
|
-
/** Snap points
|
|
48
|
+
/** Snap points, with `@gorhom/bottom-sheet` only (see `NativeSheetProvider`). e.g. ["25%", "50%", "90%"]. */
|
|
28
49
|
snapPoints?: (string | number)[];
|
|
29
|
-
/** Index of initial snap point. Default 0. */
|
|
50
|
+
/** Index of initial snap point, with `@gorhom/bottom-sheet` only. Default 0. */
|
|
30
51
|
initialSnapIndex?: number;
|
|
31
|
-
/**
|
|
52
|
+
/** Keep the sheet open when the user taps the backdrop, swipes it down or presses Android back. Default false. */
|
|
32
53
|
disableBackdropDismiss?: boolean;
|
|
33
|
-
children:
|
|
54
|
+
children: ReactNode;
|
|
34
55
|
testID?: string;
|
|
35
56
|
}
|
|
36
57
|
|
|
37
|
-
|
|
38
|
-
// can still build / typecheck, and consumers that do install it don't pay
|
|
39
|
-
// the require() cost on every render.
|
|
40
|
-
type GorhomModule = {
|
|
41
|
-
BottomSheetModal: React.ComponentType<Record<string, unknown>>;
|
|
42
|
-
BottomSheetView: React.ComponentType<Record<string, unknown>>;
|
|
43
|
-
BottomSheetBackdrop: React.ComponentType<Record<string, unknown>>;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const GORHOM: GorhomModule | null = (() => {
|
|
47
|
-
try {
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
49
|
-
const mod = require("@gorhom/bottom-sheet");
|
|
50
|
-
return {
|
|
51
|
-
BottomSheetModal: mod.BottomSheetModal,
|
|
52
|
-
BottomSheetView: mod.BottomSheetView,
|
|
53
|
-
BottomSheetBackdrop: mod.BottomSheetBackdrop,
|
|
54
|
-
};
|
|
55
|
-
} catch {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
})();
|
|
58
|
+
type AnyComponent = ComponentType<Record<string, unknown>>;
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
/**
|
|
61
|
+
* The parts of `@gorhom/bottom-sheet` (v5) the sheet uses. Pass the whole
|
|
62
|
+
* module: `import * as BottomSheet from "@gorhom/bottom-sheet"`.
|
|
63
|
+
*/
|
|
64
|
+
export interface NativeSheetLibrary {
|
|
65
|
+
BottomSheetModal: unknown;
|
|
66
|
+
BottomSheetView: unknown;
|
|
67
|
+
BottomSheetBackdrop: unknown;
|
|
68
|
+
BottomSheetModalProvider: unknown;
|
|
69
|
+
/** Used by `NativeSheetScrollView` when present. */
|
|
70
|
+
BottomSheetScrollView?: unknown;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const REQUIRED_EXPORTS = ["BottomSheetModal", "BottomSheetView", "BottomSheetBackdrop", "BottomSheetModalProvider"] as const;
|
|
74
|
+
|
|
75
|
+
const SheetLibraryContext = createContext<NativeSheetLibrary | null>(null);
|
|
76
|
+
|
|
77
|
+
export interface NativeSheetProviderProps {
|
|
78
|
+
/**
|
|
79
|
+
* `@gorhom/bottom-sheet` v5 (`import * as BottomSheet from "@gorhom/bottom-sheet"`).
|
|
80
|
+
* Read once. The app must also wrap its root in gesture-handler's
|
|
81
|
+
* `GestureHandlerRootView` and set Reanimated up, as the library requires.
|
|
82
|
+
* Sheet content renders in the library's portal, inside this provider:
|
|
83
|
+
* mount it below the providers sheets read (data, session, navigation).
|
|
84
|
+
*/
|
|
85
|
+
bottomSheet: NativeSheetLibrary;
|
|
86
|
+
children: ReactNode;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Opts every `NativeSheet` below it into `@gorhom/bottom-sheet` and mounts
|
|
91
|
+
* the library's `BottomSheetModalProvider`. A module missing any export the
|
|
92
|
+
* sheet needs is reported with `console.error` and ignored, so sheets fall
|
|
93
|
+
* back to the native modal instead of crashing on open.
|
|
94
|
+
*
|
|
95
|
+
* @stability Beta
|
|
96
|
+
*/
|
|
97
|
+
export function NativeSheetProvider({ bottomSheet, children }: NativeSheetProviderProps) {
|
|
98
|
+
// Frozen: a different module later would remount everything below the provider.
|
|
99
|
+
const [library] = useState(() => (isSheetLibrary(bottomSheet) ? bottomSheet : null));
|
|
100
|
+
const [problem] = useState(() => (library ? null : invalidLibraryMessage(bottomSheet)));
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
if (problem) console.error(problem);
|
|
103
|
+
}, [problem]);
|
|
104
|
+
if (!library) return <>{children}</>;
|
|
105
|
+
const Provider = library.BottomSheetModalProvider as ComponentType<{ children: ReactNode }>;
|
|
84
106
|
return (
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
107
|
+
<SheetLibraryContext.Provider value={library}>
|
|
108
|
+
<Provider>{children}</Provider>
|
|
109
|
+
</SheetLibraryContext.Provider>
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function isSheetLibrary(value: unknown): value is NativeSheetLibrary {
|
|
114
|
+
if (!value || typeof value !== "object") return false;
|
|
115
|
+
const mod = value as Record<string, unknown>;
|
|
116
|
+
return REQUIRED_EXPORTS.every((name) => mod[name] != null);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function invalidLibraryMessage(value: unknown): string {
|
|
120
|
+
const mod = (value && typeof value === "object" ? value : {}) as Record<string, unknown>;
|
|
121
|
+
const missing = REQUIRED_EXPORTS.filter((name) => mod[name] == null);
|
|
122
|
+
return (
|
|
123
|
+
`NativeSheetProvider: \`bottomSheet\` is missing ${missing.join(", ")}, so sheets use the native modal. ` +
|
|
124
|
+
'Pass the whole module: `import * as BottomSheet from "@gorhom/bottom-sheet"`.'
|
|
93
125
|
);
|
|
94
126
|
}
|
|
95
127
|
|
|
96
|
-
|
|
97
|
-
|
|
128
|
+
/** @stability Beta */
|
|
129
|
+
export function NativeSheet(props: NativeSheetProps) {
|
|
130
|
+
const library = useContext(SheetLibraryContext);
|
|
131
|
+
if (library) return <LibrarySheet library={library} {...props} />;
|
|
132
|
+
return <ModalSheet {...props} />;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A `ScrollView` for sheet content: the library's `BottomSheetScrollView`
|
|
137
|
+
* under `NativeSheetProvider` (so scrolling and dragging the sheet don't
|
|
138
|
+
* fight), React Native's otherwise. Sized to its content until it reaches
|
|
139
|
+
* the sheet's height.
|
|
140
|
+
*
|
|
141
|
+
* @stability Beta
|
|
142
|
+
*/
|
|
143
|
+
export function NativeSheetScrollView({ style, ...props }: ScrollViewProps) {
|
|
144
|
+
const library = useContext(SheetLibraryContext);
|
|
145
|
+
const Scroll = (library?.BottomSheetScrollView as ComponentType<ScrollViewProps> | undefined) ?? ScrollView;
|
|
146
|
+
const own: ViewStyle = { flexGrow: 0 };
|
|
147
|
+
return <Scroll style={[own, ...(Array.isArray(style) ? style : style ? [style] : [])]} {...props} />;
|
|
98
148
|
}
|
|
99
149
|
|
|
100
|
-
type
|
|
150
|
+
type SheetHandle = { present: () => void; dismiss: () => void };
|
|
101
151
|
|
|
102
|
-
function
|
|
103
|
-
|
|
152
|
+
function LibrarySheet({
|
|
153
|
+
library,
|
|
104
154
|
open,
|
|
105
155
|
onOpenChange,
|
|
106
|
-
snapPoints,
|
|
107
|
-
initialSnapIndex,
|
|
108
|
-
disableBackdropDismiss,
|
|
156
|
+
snapPoints = ["50%", "90%"],
|
|
157
|
+
initialSnapIndex = 0,
|
|
158
|
+
disableBackdropDismiss = false,
|
|
109
159
|
testID,
|
|
110
160
|
children,
|
|
111
|
-
}:
|
|
112
|
-
const
|
|
161
|
+
}: NativeSheetProps & { library: NativeSheetLibrary }) {
|
|
162
|
+
const sheet = useRef<SheetHandle | null>(null);
|
|
163
|
+
// What the app asked for last, read when the library reports a dismiss: a dismiss
|
|
164
|
+
// that finishes after the app reopened the sheet is not the user closing it.
|
|
165
|
+
const wanted = useRef(open);
|
|
166
|
+
const onOpenChangeRef = useRef(onOpenChange);
|
|
167
|
+
onOpenChangeRef.current = onOpenChange;
|
|
113
168
|
|
|
169
|
+
// Child refs are attached before this runs, so the first render presents too.
|
|
114
170
|
useEffect(() => {
|
|
115
|
-
|
|
116
|
-
|
|
171
|
+
wanted.current = open;
|
|
172
|
+
if (open) sheet.current?.present();
|
|
173
|
+
else sheet.current?.dismiss();
|
|
117
174
|
}, [open]);
|
|
118
175
|
|
|
119
|
-
const
|
|
176
|
+
const BottomSheetModal = library.BottomSheetModal as AnyComponent;
|
|
177
|
+
const BottomSheetView = library.BottomSheetView as AnyComponent;
|
|
178
|
+
const BottomSheetBackdrop = library.BottomSheetBackdrop as AnyComponent;
|
|
179
|
+
|
|
180
|
+
const onDismiss = useCallback(() => {
|
|
181
|
+
if (wanted.current) {
|
|
182
|
+
wanted.current = false;
|
|
183
|
+
onOpenChangeRef.current(false);
|
|
184
|
+
}
|
|
185
|
+
}, []);
|
|
186
|
+
const backdrop = useCallback(
|
|
187
|
+
(p: Record<string, unknown>) => (
|
|
188
|
+
<BottomSheetBackdrop
|
|
189
|
+
{...p}
|
|
190
|
+
appearsOnIndex={0}
|
|
191
|
+
disappearsOnIndex={-1}
|
|
192
|
+
pressBehavior={disableBackdropDismiss ? "none" : "close"}
|
|
193
|
+
/>
|
|
194
|
+
),
|
|
195
|
+
[BottomSheetBackdrop, disableBackdropDismiss],
|
|
196
|
+
);
|
|
120
197
|
|
|
121
198
|
return (
|
|
122
199
|
<BottomSheetModal
|
|
123
|
-
ref={
|
|
200
|
+
ref={sheet}
|
|
124
201
|
snapPoints={snapPoints}
|
|
125
202
|
index={initialSnapIndex}
|
|
126
|
-
|
|
203
|
+
// v5 sizes to the content by default and adds that as a snap point, which would shift the indexes.
|
|
204
|
+
enableDynamicSizing={false}
|
|
205
|
+
onDismiss={onDismiss}
|
|
127
206
|
enablePanDownToClose={!disableBackdropDismiss}
|
|
128
|
-
backdropComponent={
|
|
129
|
-
<BottomSheetBackdrop
|
|
130
|
-
{...p}
|
|
131
|
-
appearsOnIndex={0}
|
|
132
|
-
disappearsOnIndex={-1}
|
|
133
|
-
pressBehavior={disableBackdropDismiss ? "none" : "close"}
|
|
134
|
-
/>
|
|
135
|
-
)}
|
|
207
|
+
backdropComponent={backdrop}
|
|
136
208
|
>
|
|
137
|
-
<BottomSheetView testID={testID ?? "native-sheet"}>
|
|
138
|
-
{children}
|
|
139
|
-
</BottomSheetView>
|
|
209
|
+
<BottomSheetView testID={testID ?? "native-sheet"}>{children}</BottomSheetView>
|
|
140
210
|
</BottomSheetModal>
|
|
141
211
|
);
|
|
142
212
|
}
|
|
143
213
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
function FallbackSheet({
|
|
153
|
-
open,
|
|
154
|
-
onOpenChange,
|
|
155
|
-
disableBackdropDismiss,
|
|
156
|
-
testID,
|
|
157
|
-
children,
|
|
158
|
-
}: FallbackSheetProps) {
|
|
159
|
-
const [reducedMotion, setReducedMotion] = useState(false);
|
|
214
|
+
/**
|
|
215
|
+
* Whether Reduce Motion is on, or `null` until the system has answered: a
|
|
216
|
+
* sheet mounted open waits for it, since the presentation animation is
|
|
217
|
+
* chosen when the sheet is presented.
|
|
218
|
+
*/
|
|
219
|
+
function useReduceMotionAnswer(): boolean | null {
|
|
220
|
+
const [reduced, setReduced] = useState<boolean | null>(null);
|
|
160
221
|
useEffect(() => {
|
|
161
|
-
|
|
222
|
+
let mounted = true;
|
|
223
|
+
AccessibilityInfo.isReduceMotionEnabled().then(
|
|
224
|
+
(value) => mounted && setReduced(value),
|
|
225
|
+
() => mounted && setReduced(false),
|
|
226
|
+
);
|
|
227
|
+
const sub = AccessibilityInfo.addEventListener("reduceMotionChanged", (value: boolean) => setReduced(value));
|
|
228
|
+
return () => {
|
|
229
|
+
mounted = false;
|
|
230
|
+
sub?.remove?.();
|
|
231
|
+
};
|
|
162
232
|
}, []);
|
|
233
|
+
return reduced;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* React Native's `Modal`, which needs no provider. iOS: the system page
|
|
238
|
+
* sheet (`presentationStyle="pageSheet"`), following the finger when swiped
|
|
239
|
+
* down (`allowSwipeDismissal`); with `disableBackdropDismiss` a swipe only
|
|
240
|
+
* asks and the sheet springs back. Android: a transparent modal with a scrim
|
|
241
|
+
* and a panel at the bottom, drawn under the system bars.
|
|
242
|
+
*/
|
|
243
|
+
function ModalSheet({ open, onOpenChange, disableBackdropDismiss = false, testID, children }: NativeSheetProps) {
|
|
244
|
+
const reducedMotion = useReduceMotionAnswer();
|
|
245
|
+
const roles = useThemeRoles();
|
|
246
|
+
const requestClose = () => {
|
|
247
|
+
if (!disableBackdropDismiss) onOpenChange(false);
|
|
248
|
+
};
|
|
249
|
+
const visible = open && reducedMotion !== null;
|
|
250
|
+
const animationType = reducedMotion ? "none" : "slide";
|
|
251
|
+
const id = testID ?? "native-sheet";
|
|
252
|
+
|
|
253
|
+
if (Platform.OS === "ios") {
|
|
254
|
+
return (
|
|
255
|
+
<Modal
|
|
256
|
+
visible={visible}
|
|
257
|
+
animationType={animationType}
|
|
258
|
+
presentationStyle="pageSheet"
|
|
259
|
+
allowSwipeDismissal={!disableBackdropDismiss}
|
|
260
|
+
backdropColor={roles.background}
|
|
261
|
+
onRequestClose={requestClose}
|
|
262
|
+
>
|
|
263
|
+
<SafeAreaProvider>
|
|
264
|
+
<SheetBody
|
|
265
|
+
testID={id}
|
|
266
|
+
onAccessibilityEscape={disableBackdropDismiss ? undefined : requestClose}
|
|
267
|
+
style={{ flex: 1, backgroundColor: roles.background }}
|
|
268
|
+
>
|
|
269
|
+
{children}
|
|
270
|
+
</SheetBody>
|
|
271
|
+
</SafeAreaProvider>
|
|
272
|
+
</Modal>
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
|
|
163
276
|
return (
|
|
164
277
|
<Modal
|
|
165
|
-
visible={
|
|
278
|
+
visible={visible}
|
|
166
279
|
transparent
|
|
167
|
-
animationType={
|
|
168
|
-
|
|
280
|
+
animationType={animationType}
|
|
281
|
+
statusBarTranslucent
|
|
282
|
+
navigationBarTranslucent
|
|
283
|
+
onRequestClose={requestClose}
|
|
169
284
|
>
|
|
170
|
-
<
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
285
|
+
<SafeAreaProvider>
|
|
286
|
+
<View style={{ flex: 1, justifyContent: "flex-end" }}>
|
|
287
|
+
<Pressable
|
|
288
|
+
testID={`${id}-backdrop`}
|
|
289
|
+
accessibilityRole="button"
|
|
290
|
+
accessibilityLabel="Close"
|
|
291
|
+
disabled={disableBackdropDismiss}
|
|
292
|
+
importantForAccessibility={disableBackdropDismiss ? "no-hide-descendants" : "auto"}
|
|
293
|
+
onPress={requestClose}
|
|
294
|
+
style={{ position: "absolute", top: 0, right: 0, bottom: 0, left: 0, backgroundColor: "rgba(0,0,0,0.4)" }}
|
|
295
|
+
/>
|
|
296
|
+
<SheetBody
|
|
297
|
+
testID={id}
|
|
298
|
+
style={{
|
|
299
|
+
maxHeight: "90%",
|
|
300
|
+
borderTopLeftRadius: 28,
|
|
301
|
+
borderTopRightRadius: 28,
|
|
302
|
+
backgroundColor: roles.surface,
|
|
303
|
+
paddingTop: 12,
|
|
304
|
+
}}
|
|
184
305
|
>
|
|
185
|
-
<View
|
|
306
|
+
<View
|
|
307
|
+
style={{ alignSelf: "center", width: 32, height: 4, borderRadius: 2, marginBottom: 8, backgroundColor: roles.tertiaryLabel }}
|
|
308
|
+
/>
|
|
186
309
|
{children}
|
|
187
|
-
</
|
|
188
|
-
</
|
|
189
|
-
</
|
|
310
|
+
</SheetBody>
|
|
311
|
+
</View>
|
|
312
|
+
</SafeAreaProvider>
|
|
190
313
|
</Modal>
|
|
191
314
|
);
|
|
192
315
|
}
|
|
316
|
+
|
|
317
|
+
/** The sheet's root, padded by the sheet's own bottom inset (the home indicator, the navigation bar). */
|
|
318
|
+
function SheetBody({
|
|
319
|
+
testID,
|
|
320
|
+
style,
|
|
321
|
+
onAccessibilityEscape,
|
|
322
|
+
children,
|
|
323
|
+
}: {
|
|
324
|
+
testID: string;
|
|
325
|
+
style: ViewStyle;
|
|
326
|
+
onAccessibilityEscape?: () => void;
|
|
327
|
+
children: ReactNode;
|
|
328
|
+
}) {
|
|
329
|
+
const insets = useSafeAreaInsets();
|
|
330
|
+
return (
|
|
331
|
+
<View testID={testID} accessibilityViewIsModal onAccessibilityEscape={onAccessibilityEscape} style={{ ...style, paddingBottom: insets.bottom }}>
|
|
332
|
+
{children}
|
|
333
|
+
</View>
|
|
334
|
+
);
|
|
335
|
+
}
|