@marktiderman/genesis-ui-native 2.0.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/dist/chunk-BAU4YQZV.js +760 -0
- package/dist/chunk-BAU4YQZV.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +10 -0
- package/dist/chunk-DGUM43GV.js.map +1 -0
- package/dist/chunk-HNIEFTEL.js +43 -0
- package/dist/chunk-HNIEFTEL.js.map +1 -0
- package/dist/chunk-N4WHTQIO.js +20 -0
- package/dist/chunk-N4WHTQIO.js.map +1 -0
- package/dist/chunk-OHZD7KRO.js +11 -0
- package/dist/chunk-OHZD7KRO.js.map +1 -0
- package/dist/chunk-PTJ2KCLM.js +160 -0
- package/dist/chunk-PTJ2KCLM.js.map +1 -0
- package/dist/chunk-TXJT55JC.js +2213 -0
- package/dist/chunk-TXJT55JC.js.map +1 -0
- package/dist/chunk-ULS7I6ZS.js +183 -0
- package/dist/chunk-ULS7I6ZS.js.map +1 -0
- package/dist/chunk-ZVF6PONU.js +522 -0
- package/dist/chunk-ZVF6PONU.js.map +1 -0
- package/dist/components/index.d.ts +908 -0
- package/dist/components/index.js +8 -0
- package/dist/components/index.js.map +1 -0
- package/dist/data/index.d.ts +117 -0
- package/dist/data/index.js +770 -0
- package/dist/data/index.js.map +1 -0
- package/dist/hooks/index.d.ts +31 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/layouts/index.d.ts +364 -0
- package/dist/layouts/index.js +8 -0
- package/dist/layouts/index.js.map +1 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +4 -0
- package/dist/utils.js.map +1 -0
- package/package.json +127 -0
- package/src/components/__tests__/accordion.test.tsx +122 -0
- package/src/components/__tests__/chip-group.test.tsx +45 -0
- package/src/components/__tests__/combobox.test.tsx +97 -0
- package/src/components/__tests__/drawer.test.tsx +98 -0
- package/src/components/__tests__/empty-state.test.tsx +66 -0
- package/src/components/__tests__/header-card.test.tsx +31 -0
- package/src/components/__tests__/layout.test.tsx +109 -0
- package/src/components/__tests__/list-item.test.tsx +31 -0
- package/src/components/__tests__/number-input.test.tsx +46 -0
- package/src/components/__tests__/pagination.test.tsx +43 -0
- package/src/components/__tests__/search-bar.test.tsx +41 -0
- package/src/components/__tests__/segmented-empty-alert.test.tsx +79 -0
- package/src/components/__tests__/slider.test.tsx +134 -0
- package/src/components/__tests__/stepper.test.tsx +25 -0
- package/src/components/__tests__/toast.test.tsx +63 -0
- package/src/components/accordion.tsx +223 -0
- package/src/components/alert.tsx +131 -0
- package/src/components/avatar.tsx +68 -0
- package/src/components/badge.tsx +80 -0
- package/src/components/button.tsx +118 -0
- package/src/components/card.tsx +120 -0
- package/src/components/checkbox.tsx +60 -0
- package/src/components/chip-group.tsx +127 -0
- package/src/components/combobox.tsx +137 -0
- package/src/components/date-time-picker.tsx +127 -0
- package/src/components/dialog.tsx +131 -0
- package/src/components/drawer.tsx +131 -0
- package/src/components/dropdown-menu.tsx +133 -0
- package/src/components/empty-state.tsx +161 -0
- package/src/components/header-card.tsx +116 -0
- package/src/components/index.ts +259 -0
- package/src/components/inline-alert.tsx +150 -0
- package/src/components/input.tsx +51 -0
- package/src/components/label.tsx +35 -0
- package/src/components/layout/box.tsx +115 -0
- package/src/components/layout/flex.ts +24 -0
- package/src/components/layout/grid.tsx +73 -0
- package/src/components/layout/index.ts +27 -0
- package/src/components/layout/inline.tsx +63 -0
- package/src/components/layout/spacing.ts +116 -0
- package/src/components/layout/stack.tsx +58 -0
- package/src/components/list-item.tsx +108 -0
- package/src/components/number-input.tsx +119 -0
- package/src/components/pagination.tsx +132 -0
- package/src/components/popover.tsx +198 -0
- package/src/components/progress.tsx +50 -0
- package/src/components/radio-group.tsx +92 -0
- package/src/components/refresh-control.tsx +73 -0
- package/src/components/search-bar.tsx +128 -0
- package/src/components/section-list.tsx +54 -0
- package/src/components/segmented-control.tsx +79 -0
- package/src/components/select.tsx +178 -0
- package/src/components/separator.tsx +31 -0
- package/src/components/sheet.tsx +192 -0
- package/src/components/skeleton.tsx +104 -0
- package/src/components/slider.tsx +223 -0
- package/src/components/stepper.tsx +96 -0
- package/src/components/switch.tsx +35 -0
- package/src/components/tabs.tsx +147 -0
- package/src/components/text.tsx +62 -0
- package/src/components/textarea.tsx +52 -0
- package/src/components/toast.tsx +228 -0
- package/src/components/toggle.tsx +85 -0
- package/src/components/tooltip.tsx +104 -0
- package/src/data/NativeDataFilters.tsx +100 -0
- package/src/data/NativeDataPageShell.tsx +111 -0
- package/src/data/NativeDetailPanel.tsx +130 -0
- package/src/data/NativeEmptyState.tsx +46 -0
- package/src/data/NativeResourceForm.tsx +157 -0
- package/src/data/NativeResourceFormField.tsx +280 -0
- package/src/data/NativeResourcePage.tsx +505 -0
- package/src/data/index.ts +9 -0
- package/src/hooks/index.ts +16 -0
- package/src/hooks/use-genesis-extension.ts +81 -0
- package/src/hooks/use-reduced-motion.ts +32 -0
- package/src/hooks/use-theme-mode.ts +31 -0
- package/src/index.ts +5 -0
- package/src/layouts/__tests__/auth.test.tsx +150 -0
- package/src/layouts/__tests__/nav-bar.test.tsx +86 -0
- package/src/layouts/__tests__/notifications-page.test.tsx +94 -0
- package/src/layouts/__tests__/screen-container.test.tsx +79 -0
- package/src/layouts/__tests__/settings-page.test.tsx +107 -0
- package/src/layouts/__tests__/settings-sub-page.test.tsx +53 -0
- package/src/layouts/auth.tsx +352 -0
- package/src/layouts/index.ts +61 -0
- package/src/layouts/nav-bar.tsx +200 -0
- package/src/layouts/notifications-page.tsx +274 -0
- package/src/layouts/screen-container.tsx +213 -0
- package/src/layouts/settings-page.tsx +195 -0
- package/src/layouts/settings-sub-page.tsx +183 -0
- package/src/nativewind.d.ts +40 -0
- package/src/utils.ts +6 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Select — single-selection dropdown trigger + content.
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { createContext, useContext, useState } from "react";
|
|
7
|
+
import { Modal, Pressable, Text, View } from "react-native";
|
|
8
|
+
import { cn } from "../utils";
|
|
9
|
+
|
|
10
|
+
interface SelectContextValue {
|
|
11
|
+
value: string;
|
|
12
|
+
onValueChange: (value: string) => void;
|
|
13
|
+
open: boolean;
|
|
14
|
+
setOpen: (open: boolean) => void;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const SelectContext = createContext<SelectContextValue | null>(null);
|
|
18
|
+
|
|
19
|
+
function useSelect() {
|
|
20
|
+
const context = useContext(SelectContext);
|
|
21
|
+
if (!context)
|
|
22
|
+
throw new Error("Select components must be used within <NativeSelect>");
|
|
23
|
+
return context;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface NativeSelectProps {
|
|
27
|
+
value?: string;
|
|
28
|
+
defaultValue?: string;
|
|
29
|
+
onValueChange?: (value: string) => void;
|
|
30
|
+
children: React.ReactNode;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function NativeSelect({
|
|
34
|
+
value: controlledValue,
|
|
35
|
+
defaultValue = "",
|
|
36
|
+
onValueChange: controlledOnValueChange,
|
|
37
|
+
children,
|
|
38
|
+
}: NativeSelectProps) {
|
|
39
|
+
const [uncontrolledValue, setUncontrolledValue] = useState(defaultValue);
|
|
40
|
+
const [open, setOpen] = useState(false);
|
|
41
|
+
const value = controlledValue ?? uncontrolledValue;
|
|
42
|
+
const onValueChange = controlledOnValueChange ?? setUncontrolledValue;
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<SelectContext.Provider value={{ value, onValueChange, open, setOpen }}>
|
|
46
|
+
{children}
|
|
47
|
+
</SelectContext.Provider>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface NativeSelectTriggerProps {
|
|
52
|
+
className?: string;
|
|
53
|
+
children?: React.ReactNode;
|
|
54
|
+
placeholder?: string;
|
|
55
|
+
disabled?: boolean;
|
|
56
|
+
testID?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function NativeSelectTrigger({
|
|
60
|
+
className,
|
|
61
|
+
children,
|
|
62
|
+
placeholder,
|
|
63
|
+
disabled,
|
|
64
|
+
...props
|
|
65
|
+
}: NativeSelectTriggerProps) {
|
|
66
|
+
const { value, open, setOpen } = useSelect();
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<Pressable
|
|
70
|
+
className={cn(
|
|
71
|
+
"h-10 flex-row items-center justify-between rounded-md border border-input bg-background px-3",
|
|
72
|
+
disabled && "opacity-50",
|
|
73
|
+
className
|
|
74
|
+
)}
|
|
75
|
+
onPress={() => setOpen(true)}
|
|
76
|
+
disabled={disabled}
|
|
77
|
+
accessibilityRole="button"
|
|
78
|
+
accessibilityState={{ expanded: open, disabled }}
|
|
79
|
+
{...props}
|
|
80
|
+
>
|
|
81
|
+
{children ?? (
|
|
82
|
+
<Text
|
|
83
|
+
className={cn(
|
|
84
|
+
"text-sm",
|
|
85
|
+
value ? "text-foreground" : "text-muted-foreground"
|
|
86
|
+
)}
|
|
87
|
+
>
|
|
88
|
+
{value || placeholder || "Select..."}
|
|
89
|
+
</Text>
|
|
90
|
+
)}
|
|
91
|
+
<Text className="text-sm text-muted-foreground">{"\u25BE"}</Text>
|
|
92
|
+
</Pressable>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface NativeSelectContentProps {
|
|
97
|
+
className?: string;
|
|
98
|
+
children: React.ReactNode;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function NativeSelectContent({
|
|
102
|
+
className,
|
|
103
|
+
children,
|
|
104
|
+
}: NativeSelectContentProps) {
|
|
105
|
+
const { open, setOpen } = useSelect();
|
|
106
|
+
|
|
107
|
+
if (!open) return null;
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<Modal transparent animationType="fade" onRequestClose={() => setOpen(false)}>
|
|
111
|
+
<Pressable className="flex-1 items-center justify-center bg-black/50" onPress={() => setOpen(false)}>
|
|
112
|
+
{/* Intentional no-op: prevents overlay press from closing the modal when touching content area */}
|
|
113
|
+
<Pressable onPress={() => {}}>
|
|
114
|
+
<View
|
|
115
|
+
className={cn(
|
|
116
|
+
"min-w-[10rem] rounded-md border border-border bg-popover p-1 shadow-md",
|
|
117
|
+
className
|
|
118
|
+
)}
|
|
119
|
+
>
|
|
120
|
+
{children}
|
|
121
|
+
</View>
|
|
122
|
+
</Pressable>
|
|
123
|
+
</Pressable>
|
|
124
|
+
</Modal>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface NativeSelectItemProps {
|
|
129
|
+
className?: string;
|
|
130
|
+
value: string;
|
|
131
|
+
children: React.ReactNode;
|
|
132
|
+
testID?: string;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function NativeSelectItem({
|
|
136
|
+
className,
|
|
137
|
+
value,
|
|
138
|
+
children,
|
|
139
|
+
...props
|
|
140
|
+
}: NativeSelectItemProps) {
|
|
141
|
+
const { value: selectedValue, onValueChange, setOpen } = useSelect();
|
|
142
|
+
const isSelected = selectedValue === value;
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<Pressable
|
|
146
|
+
className={cn(
|
|
147
|
+
"flex-row items-center rounded-sm px-2 py-1.5",
|
|
148
|
+
isSelected && "bg-accent",
|
|
149
|
+
className
|
|
150
|
+
)}
|
|
151
|
+
onPress={() => {
|
|
152
|
+
onValueChange(value);
|
|
153
|
+
setOpen(false);
|
|
154
|
+
}}
|
|
155
|
+
{...props}
|
|
156
|
+
>
|
|
157
|
+
{typeof children === "string" ? (
|
|
158
|
+
<Text
|
|
159
|
+
className={cn(
|
|
160
|
+
"text-sm",
|
|
161
|
+
isSelected ? "text-accent-foreground" : "text-popover-foreground"
|
|
162
|
+
)}
|
|
163
|
+
>
|
|
164
|
+
{children}
|
|
165
|
+
</Text>
|
|
166
|
+
) : (
|
|
167
|
+
children
|
|
168
|
+
)}
|
|
169
|
+
</Pressable>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export {
|
|
174
|
+
NativeSelect,
|
|
175
|
+
NativeSelectTrigger,
|
|
176
|
+
NativeSelectContent,
|
|
177
|
+
NativeSelectItem,
|
|
178
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Separator — visual divider line (horizontal or vertical).
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { View, type ViewProps } from "react-native";
|
|
7
|
+
import { cn } from "../utils";
|
|
8
|
+
|
|
9
|
+
export interface NativeSeparatorProps extends ViewProps {
|
|
10
|
+
orientation?: "horizontal" | "vertical";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function NativeSeparator({
|
|
14
|
+
className,
|
|
15
|
+
orientation = "horizontal",
|
|
16
|
+
...props
|
|
17
|
+
}: NativeSeparatorProps) {
|
|
18
|
+
return (
|
|
19
|
+
<View
|
|
20
|
+
className={cn(
|
|
21
|
+
"bg-border",
|
|
22
|
+
orientation === "horizontal" ? "h-px w-full" : "h-full w-px",
|
|
23
|
+
className
|
|
24
|
+
)}
|
|
25
|
+
accessibilityRole="none"
|
|
26
|
+
{...props}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { NativeSeparator };
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sheet / BottomSheet — modal that slides up from the bottom.
|
|
3
|
+
*
|
|
4
|
+
* Use for non-blocking selections, filters, and short flows that benefit
|
|
5
|
+
* from preserving screen context. For blocking confirmations, use
|
|
6
|
+
* <NativeDialog>. For full-screen flows, use a navigation route.
|
|
7
|
+
*
|
|
8
|
+
* Implementation prefers @gorhom/bottom-sheet (gesture-driven, snap
|
|
9
|
+
* points, native feel). Consumers must install @gorhom/bottom-sheet,
|
|
10
|
+
* react-native-gesture-handler, and react-native-reanimated as peer
|
|
11
|
+
* deps; wrap the app root in <GestureHandlerRootView> +
|
|
12
|
+
* <BottomSheetModalProvider>. If the peer is not installed, this
|
|
13
|
+
* primitive falls back to a simple RN Modal with a slide animation —
|
|
14
|
+
* acceptable for samples but not production.
|
|
15
|
+
*
|
|
16
|
+
* @stability Beta
|
|
17
|
+
*/
|
|
18
|
+
import { useEffect, useRef, useState } from "react";
|
|
19
|
+
import { AccessibilityInfo, Modal, Pressable, View } from "react-native";
|
|
20
|
+
import { cn } from "../utils";
|
|
21
|
+
|
|
22
|
+
export interface NativeSheetProps {
|
|
23
|
+
/** Controlled visibility. */
|
|
24
|
+
open: boolean;
|
|
25
|
+
/** Fired when the user dismisses the sheet (backdrop, gesture, swipe). */
|
|
26
|
+
onOpenChange: (open: boolean) => void;
|
|
27
|
+
/** Snap points (gorhom-style). e.g. ["25%", "50%", "90%"]. */
|
|
28
|
+
snapPoints?: (string | number)[];
|
|
29
|
+
/** Index of initial snap point. Default 0. */
|
|
30
|
+
initialSnapIndex?: number;
|
|
31
|
+
/** Disable dismissing by tapping the backdrop. Default false. */
|
|
32
|
+
disableBackdropDismiss?: boolean;
|
|
33
|
+
children: React.ReactNode;
|
|
34
|
+
testID?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Lazy-load gorhom once at module scope so consumers that don't install it
|
|
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
|
+
})();
|
|
59
|
+
|
|
60
|
+
export function NativeSheet({
|
|
61
|
+
open,
|
|
62
|
+
onOpenChange,
|
|
63
|
+
snapPoints = ["50%", "90%"],
|
|
64
|
+
initialSnapIndex = 0,
|
|
65
|
+
disableBackdropDismiss = false,
|
|
66
|
+
children,
|
|
67
|
+
testID,
|
|
68
|
+
}: NativeSheetProps) {
|
|
69
|
+
if (GORHOM) {
|
|
70
|
+
return (
|
|
71
|
+
<GorhomSheet
|
|
72
|
+
gorhom={GORHOM}
|
|
73
|
+
open={open}
|
|
74
|
+
onOpenChange={onOpenChange}
|
|
75
|
+
snapPoints={snapPoints}
|
|
76
|
+
initialSnapIndex={initialSnapIndex}
|
|
77
|
+
disableBackdropDismiss={disableBackdropDismiss}
|
|
78
|
+
testID={testID}
|
|
79
|
+
>
|
|
80
|
+
{children}
|
|
81
|
+
</GorhomSheet>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return (
|
|
85
|
+
<FallbackSheet
|
|
86
|
+
open={open}
|
|
87
|
+
onOpenChange={onOpenChange}
|
|
88
|
+
disableBackdropDismiss={disableBackdropDismiss}
|
|
89
|
+
testID={testID}
|
|
90
|
+
>
|
|
91
|
+
{children}
|
|
92
|
+
</FallbackSheet>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
interface GorhomSheetProps extends NativeSheetProps {
|
|
97
|
+
gorhom: GorhomModule;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
type GorhomSheetHandle = { present: () => void; dismiss: () => void };
|
|
101
|
+
|
|
102
|
+
function GorhomSheet({
|
|
103
|
+
gorhom,
|
|
104
|
+
open,
|
|
105
|
+
onOpenChange,
|
|
106
|
+
snapPoints,
|
|
107
|
+
initialSnapIndex,
|
|
108
|
+
disableBackdropDismiss,
|
|
109
|
+
testID,
|
|
110
|
+
children,
|
|
111
|
+
}: GorhomSheetProps) {
|
|
112
|
+
const ref = useRef<GorhomSheetHandle | null>(null);
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
if (open) ref.current?.present();
|
|
116
|
+
else ref.current?.dismiss();
|
|
117
|
+
}, [open]);
|
|
118
|
+
|
|
119
|
+
const { BottomSheetModal, BottomSheetView, BottomSheetBackdrop } = gorhom;
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<BottomSheetModal
|
|
123
|
+
ref={ref}
|
|
124
|
+
snapPoints={snapPoints}
|
|
125
|
+
index={initialSnapIndex}
|
|
126
|
+
onDismiss={() => onOpenChange(false)}
|
|
127
|
+
enablePanDownToClose={!disableBackdropDismiss}
|
|
128
|
+
backdropComponent={(p: Record<string, unknown>) => (
|
|
129
|
+
<BottomSheetBackdrop
|
|
130
|
+
{...p}
|
|
131
|
+
appearsOnIndex={0}
|
|
132
|
+
disappearsOnIndex={-1}
|
|
133
|
+
pressBehavior={disableBackdropDismiss ? "none" : "close"}
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
136
|
+
>
|
|
137
|
+
<BottomSheetView testID={testID ?? "native-sheet"}>
|
|
138
|
+
{children}
|
|
139
|
+
</BottomSheetView>
|
|
140
|
+
</BottomSheetModal>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
interface FallbackSheetProps {
|
|
145
|
+
open: boolean;
|
|
146
|
+
onOpenChange: (open: boolean) => void;
|
|
147
|
+
disableBackdropDismiss?: boolean;
|
|
148
|
+
testID?: string;
|
|
149
|
+
children: React.ReactNode;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function FallbackSheet({
|
|
153
|
+
open,
|
|
154
|
+
onOpenChange,
|
|
155
|
+
disableBackdropDismiss,
|
|
156
|
+
testID,
|
|
157
|
+
children,
|
|
158
|
+
}: FallbackSheetProps) {
|
|
159
|
+
const [reducedMotion, setReducedMotion] = useState(false);
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
AccessibilityInfo.isReduceMotionEnabled().then(setReducedMotion);
|
|
162
|
+
}, []);
|
|
163
|
+
return (
|
|
164
|
+
<Modal
|
|
165
|
+
visible={open}
|
|
166
|
+
transparent
|
|
167
|
+
animationType={reducedMotion ? "none" : "slide"}
|
|
168
|
+
onRequestClose={() => onOpenChange(false)}
|
|
169
|
+
>
|
|
170
|
+
<Pressable
|
|
171
|
+
className="flex-1 justify-end bg-black/50"
|
|
172
|
+
onPress={() => {
|
|
173
|
+
if (!disableBackdropDismiss) onOpenChange(false);
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
<Pressable onPress={() => {}}>
|
|
177
|
+
<View
|
|
178
|
+
testID={testID ?? "native-sheet"}
|
|
179
|
+
accessibilityViewIsModal
|
|
180
|
+
accessibilityRole="alert"
|
|
181
|
+
className={cn(
|
|
182
|
+
"min-h-[200px] rounded-t-2xl border-t border-border bg-background p-4 shadow-lg"
|
|
183
|
+
)}
|
|
184
|
+
>
|
|
185
|
+
<View className="mb-3 self-center h-1 w-12 rounded-full bg-muted" />
|
|
186
|
+
{children}
|
|
187
|
+
</View>
|
|
188
|
+
</Pressable>
|
|
189
|
+
</Pressable>
|
|
190
|
+
</Modal>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skeleton — loading placeholder block.
|
|
3
|
+
*
|
|
4
|
+
* @stability Stable
|
|
5
|
+
*/
|
|
6
|
+
import { useEffect, useRef, useState } from "react";
|
|
7
|
+
import { AccessibilityInfo, Animated, Easing } from "react-native";
|
|
8
|
+
import { cn } from "../utils";
|
|
9
|
+
|
|
10
|
+
export interface NativeSkeletonProps {
|
|
11
|
+
className?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Width of the skeleton. Use className for NativeWind sizing instead
|
|
14
|
+
* when possible (e.g. className="w-24 h-4").
|
|
15
|
+
*/
|
|
16
|
+
width?: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
/** Shorthand that sets both width and height (useful for circle skeletons). */
|
|
19
|
+
size?: number;
|
|
20
|
+
circle?: boolean;
|
|
21
|
+
testID?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function NativeSkeleton({
|
|
25
|
+
className,
|
|
26
|
+
width,
|
|
27
|
+
height,
|
|
28
|
+
size,
|
|
29
|
+
circle,
|
|
30
|
+
...props
|
|
31
|
+
}: NativeSkeletonProps) {
|
|
32
|
+
const opacity = useRef(new Animated.Value(0.3)).current;
|
|
33
|
+
const [reduceMotion, setReduceMotion] = useState(false);
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
let cancelled = false;
|
|
37
|
+
AccessibilityInfo.isReduceMotionEnabled()
|
|
38
|
+
.then((enabled) => {
|
|
39
|
+
if (!cancelled) setReduceMotion(enabled);
|
|
40
|
+
})
|
|
41
|
+
.catch(() => {
|
|
42
|
+
// Defensive: some RN runtimes (web, older Android) reject when
|
|
43
|
+
// the AccessibilityManager isn't wired up. Fall back to "no
|
|
44
|
+
// reduce-motion" so the skeleton still animates rather than
|
|
45
|
+
// crashing the host screen with an unhandled rejection.
|
|
46
|
+
if (!cancelled) setReduceMotion(false);
|
|
47
|
+
});
|
|
48
|
+
const sub = AccessibilityInfo.addEventListener(
|
|
49
|
+
"reduceMotionChanged",
|
|
50
|
+
(enabled) => setReduceMotion(enabled),
|
|
51
|
+
);
|
|
52
|
+
return () => {
|
|
53
|
+
cancelled = true;
|
|
54
|
+
sub.remove();
|
|
55
|
+
};
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (reduceMotion) {
|
|
60
|
+
// Hold the skeleton at a static, legible opacity instead of
|
|
61
|
+
// pulsing — required by visual-regression flow `screenshot-
|
|
62
|
+
// reduced-motion.yaml` and by users with vestibular-motion
|
|
63
|
+
// sensitivity (Apple HIG / WCAG 2.3.3).
|
|
64
|
+
opacity.setValue(0.6);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const animation = Animated.loop(
|
|
68
|
+
Animated.sequence([
|
|
69
|
+
Animated.timing(opacity, {
|
|
70
|
+
toValue: 1,
|
|
71
|
+
duration: 1000,
|
|
72
|
+
easing: Easing.inOut(Easing.ease),
|
|
73
|
+
useNativeDriver: true,
|
|
74
|
+
}),
|
|
75
|
+
Animated.timing(opacity, {
|
|
76
|
+
toValue: 0.3,
|
|
77
|
+
duration: 1000,
|
|
78
|
+
easing: Easing.inOut(Easing.ease),
|
|
79
|
+
useNativeDriver: true,
|
|
80
|
+
}),
|
|
81
|
+
])
|
|
82
|
+
);
|
|
83
|
+
animation.start();
|
|
84
|
+
return () => animation.stop();
|
|
85
|
+
}, [opacity, reduceMotion]);
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<Animated.View
|
|
89
|
+
className={cn(
|
|
90
|
+
"rounded-md bg-muted",
|
|
91
|
+
circle && "rounded-full",
|
|
92
|
+
className
|
|
93
|
+
)}
|
|
94
|
+
style={[
|
|
95
|
+
{ opacity },
|
|
96
|
+
(width ?? size) !== undefined ? { width: width ?? size } : undefined,
|
|
97
|
+
(height ?? size) !== undefined ? { height: height ?? size } : undefined,
|
|
98
|
+
].filter(Boolean) as any[]}
|
|
99
|
+
{...props}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { NativeSkeleton };
|