@vvedantb/native-ui 0.34.0 → 0.36.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 +17 -2
- package/dist/Button.jsx +9 -3
- package/dist/ExpoWebRoot.jsx +42 -21
- package/dist/Field.jsx +309 -0
- package/dist/FloatingTabBar.jsx +98 -94
- package/dist/ai/conversation.jsx +1 -1
- package/dist/blur.js +6 -0
- package/dist/controlStyles.js +24 -2
- package/dist/entries/layout.js +1 -0
- package/dist/entries/primitives.js +1 -0
- package/dist/examples/ParityGallery.jsx +488 -475
- package/dist/glassBlur.jsx +1 -1
- package/dist/index.js +2 -0
- package/dist/primitives/window-layer.jsx +35 -28
- package/dist/settings/ThemeModePicker.jsx +135 -0
- package/package.json +27 -3
- package/src/Button.tsx +10 -4
- package/src/DropdownMenu.tsx +11 -2
- package/src/ExpoWebRoot.tsx +18 -3
- package/src/Field.tsx +105 -0
- package/src/FloatingTabBar.tsx +17 -12
- package/src/Spinner.tsx +2 -2
- package/src/ai/conversation.tsx +1 -1
- package/src/ai/message.tsx +2 -2
- package/src/auth/AccountScreens.tsx +4 -4
- package/src/auth/SignInScreen.tsx +4 -4
- package/src/blur.ts +8 -0
- package/src/controlStyles.ts +29 -2
- package/src/entries/layout.ts +2 -0
- package/src/entries/primitives.ts +2 -0
- package/src/examples/ParityGallery.tsx +22 -1
- package/src/glassBlur.tsx +5 -7
- package/src/index.ts +4 -0
- package/src/primitives/sheet-gesture.tsx +1 -2
- package/src/primitives/web-click-guard.ts +3 -3
- package/src/primitives/window-layer.tsx +8 -6
- package/src/settings/ThemeModePicker.tsx +132 -0
- package/src/tabBarRoutes.ts +4 -3
- package/src/webview/HtmlView.tsx +5 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRef, useState, type ReactNode } from "react";
|
|
2
|
-
import
|
|
1
|
+
import { useRef, useState, type ComponentRef, type ReactNode } from "react";
|
|
2
|
+
import { TextInput } from "react-native";
|
|
3
3
|
import { useUser } from "@clerk/expo";
|
|
4
4
|
import { useRouter, type Href } from "expo-router";
|
|
5
5
|
import { Button } from "../Button";
|
|
@@ -86,8 +86,8 @@ export function ChangePasswordScreen({
|
|
|
86
86
|
const [confirm, setConfirm] = useState("");
|
|
87
87
|
const [error, setError] = useState("");
|
|
88
88
|
const [submitting, setSubmitting] = useState(false);
|
|
89
|
-
const nextField = useRef<TextInput
|
|
90
|
-
const confirmField = useRef<TextInput
|
|
89
|
+
const nextField = useRef<ComponentRef<typeof TextInput>>(null);
|
|
90
|
+
const confirmField = useRef<ComponentRef<typeof TextInput>>(null);
|
|
91
91
|
const id = (name: string) => `${testIDPrefix}-${name}`;
|
|
92
92
|
// Until the user loads, show the current-password field: most accounts have one.
|
|
93
93
|
const hasPassword = user ? user.passwordEnabled : true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRef, useState, type ReactNode } from "react";
|
|
2
|
-
import { Text,
|
|
1
|
+
import { useRef, useState, type ComponentRef, type ReactNode } from "react";
|
|
2
|
+
import { Text, TextInput, View } from "react-native";
|
|
3
3
|
import { useSignIn, useSignUp } from "@clerk/expo";
|
|
4
4
|
import { useRouter, type Href } from "expo-router";
|
|
5
5
|
import { Button } from "../Button";
|
|
@@ -237,8 +237,8 @@ export function SignInScreen({
|
|
|
237
237
|
const [error, setError] = useState("");
|
|
238
238
|
const [submitting, setSubmitting] = useState(false);
|
|
239
239
|
// The field each "next" key moves to.
|
|
240
|
-
const passwordField = useRef<TextInput
|
|
241
|
-
const confirmField = useRef<TextInput
|
|
240
|
+
const passwordField = useRef<ComponentRef<typeof TextInput>>(null);
|
|
241
|
+
const confirmField = useRef<ComponentRef<typeof TextInput>>(null);
|
|
242
242
|
const signUp = mode === "sign-up";
|
|
243
243
|
const reset = mode === "reset-password";
|
|
244
244
|
const id = (name: string) => `${testIDPrefix ?? mode}-${name}`;
|
package/src/blur.ts
CHANGED
|
@@ -2,6 +2,14 @@ import type * as ExpoBlur from "expo-blur";
|
|
|
2
2
|
|
|
3
3
|
export type ExpoBlurModule = typeof ExpoBlur;
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The ref an expo-blur `BlurView` blurs (its `blurTarget` prop, and the ref a
|
|
7
|
+
* `BlurTargetView` takes). Derived from expo-blur's own type so the two match
|
|
8
|
+
* under any React Native version.
|
|
9
|
+
*/
|
|
10
|
+
export type BlurTargetRef = NonNullable<ExpoBlur.BlurViewProps["blurTarget"]>;
|
|
11
|
+
export type BlurTargetElement = NonNullable<BlurTargetRef["current"]>;
|
|
12
|
+
|
|
5
13
|
let expoBlur: ExpoBlurModule | null | undefined;
|
|
6
14
|
|
|
7
15
|
/**
|
package/src/controlStyles.ts
CHANGED
|
@@ -14,17 +14,29 @@ type Scheme = "light" | "dark";
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* `primary` and `default` are the same (`default` is the web name). `outline`
|
|
17
|
-
* is the web bordered neutral button. `
|
|
18
|
-
*
|
|
17
|
+
* is the web bordered neutral button. `tertiary` is the web name for `ghost`
|
|
18
|
+
* and `danger` for `destructive`. `success`, `warning` and `flat` match the web
|
|
19
|
+
* variants. `tinted` is a legacy alias: the pink tint that `outline` drew
|
|
20
|
+
* before 0.3.0 (it keeps its NativeWind classes).
|
|
21
|
+
*
|
|
22
|
+
* Hierarchy: `primary`/`default` is the one main action, `secondary` an
|
|
23
|
+
* alternative, `tertiary`/`ghost` a dismissive action, `destructive`/`danger`
|
|
24
|
+
* a destructive action, `success` and `warning` show status, and `outline`,
|
|
25
|
+
* `link` and `flat` are visual.
|
|
19
26
|
*/
|
|
20
27
|
export type ButtonVariant =
|
|
21
28
|
| "primary"
|
|
22
29
|
| "default"
|
|
23
30
|
| "secondary"
|
|
31
|
+
| "tertiary"
|
|
24
32
|
| "outline"
|
|
25
33
|
| "destructive"
|
|
34
|
+
| "danger"
|
|
26
35
|
| "ghost"
|
|
27
36
|
| "link"
|
|
37
|
+
| "success"
|
|
38
|
+
| "warning"
|
|
39
|
+
| "flat"
|
|
28
40
|
| "tinted";
|
|
29
41
|
|
|
30
42
|
export type ButtonColors = {
|
|
@@ -54,9 +66,24 @@ export function buttonColors(variant: ButtonVariant, scheme: Scheme): ButtonColo
|
|
|
54
66
|
color: tokens.color.foreground[scheme],
|
|
55
67
|
};
|
|
56
68
|
case "destructive":
|
|
69
|
+
case "danger":
|
|
57
70
|
return { backgroundColor: palette.destructive, borderColor: none, color: tokens.color.white };
|
|
58
71
|
case "ghost":
|
|
72
|
+
case "tertiary":
|
|
73
|
+
case "flat":
|
|
59
74
|
return { backgroundColor: none, borderColor: none, color: tokens.color.muted[scheme] };
|
|
75
|
+
case "success":
|
|
76
|
+
return {
|
|
77
|
+
backgroundColor: palette.success[scheme],
|
|
78
|
+
borderColor: none,
|
|
79
|
+
color: palette.successForeground[scheme],
|
|
80
|
+
};
|
|
81
|
+
case "warning":
|
|
82
|
+
return {
|
|
83
|
+
backgroundColor: palette.warning[scheme],
|
|
84
|
+
borderColor: none,
|
|
85
|
+
color: palette.warningForeground[scheme],
|
|
86
|
+
};
|
|
60
87
|
case "link":
|
|
61
88
|
return { backgroundColor: none, borderColor: none, color: palette.primary[scheme] };
|
|
62
89
|
case "tinted":
|
package/src/entries/layout.ts
CHANGED
|
@@ -15,6 +15,8 @@ export { SettingsToggleRow } from "../settings/SettingsToggleRow";
|
|
|
15
15
|
export { SettingsStack } from "../settings/SettingsStack";
|
|
16
16
|
export { SettingsEmptyState } from "../settings/SettingsEmptyState";
|
|
17
17
|
export type { SettingsEmptyStateProps } from "../settings/SettingsEmptyState";
|
|
18
|
+
export { ThemeModePicker, THEME_MODES } from "../settings/ThemeModePicker";
|
|
19
|
+
export type { ThemeMode, ThemeModePickerProps } from "../settings/ThemeModePicker";
|
|
18
20
|
export { PinnedBotTile, BotPinGrid } from "../PinnedBotTile";
|
|
19
21
|
export type { PinnedBotTileProps, BotPinGridProps } from "../PinnedBotTile";
|
|
20
22
|
export { ArtifactList } from "../ArtifactList";
|
|
@@ -15,6 +15,8 @@ export { Textarea } from "../Textarea";
|
|
|
15
15
|
export type { TextareaProps } from "../Textarea";
|
|
16
16
|
export { Label } from "../Label";
|
|
17
17
|
export type { LabelProps } from "../Label";
|
|
18
|
+
export { Field, FieldControl, FieldDescription, FieldError, FieldLabel } from "../Field";
|
|
19
|
+
export type { FieldProps } from "../Field";
|
|
18
20
|
export { Select } from "../Select";
|
|
19
21
|
export type { SelectOption, SelectProps } from "../Select";
|
|
20
22
|
export { Switch } from "../Switch";
|
|
@@ -68,6 +68,11 @@ import {
|
|
|
68
68
|
GoogleMark,
|
|
69
69
|
IconButton,
|
|
70
70
|
Input,
|
|
71
|
+
Field,
|
|
72
|
+
FieldControl,
|
|
73
|
+
FieldDescription,
|
|
74
|
+
FieldError,
|
|
75
|
+
FieldLabel,
|
|
71
76
|
Label,
|
|
72
77
|
LabeledSwitchRow,
|
|
73
78
|
ListRow,
|
|
@@ -131,12 +136,19 @@ import {
|
|
|
131
136
|
} from "../ai";
|
|
132
137
|
import { AiChatSamples } from "./AiChatGallery";
|
|
133
138
|
|
|
139
|
+
// Every shared variant; the aliases (`primary`, `tertiary`, `danger`) draw as the name they alias.
|
|
134
140
|
const BUTTON_VARIANTS: ButtonVariant[] = [
|
|
135
141
|
"default",
|
|
142
|
+
"primary",
|
|
136
143
|
"secondary",
|
|
137
144
|
"outline",
|
|
138
145
|
"destructive",
|
|
146
|
+
"danger",
|
|
139
147
|
"ghost",
|
|
148
|
+
"tertiary",
|
|
149
|
+
"flat",
|
|
150
|
+
"success",
|
|
151
|
+
"warning",
|
|
140
152
|
"link",
|
|
141
153
|
];
|
|
142
154
|
|
|
@@ -289,7 +301,7 @@ function GalleryScreen() {
|
|
|
289
301
|
{/* The web gallery: a full-width column of variants, then the sm row. */}
|
|
290
302
|
<View className="gap-2">
|
|
291
303
|
{BUTTON_VARIANTS.map((variant) => (
|
|
292
|
-
<Button key={variant} variant={variant} onPress={() => toast(variant)}>
|
|
304
|
+
<Button key={variant} testID={`button-variant-${variant}`} variant={variant} onPress={() => toast(variant)}>
|
|
293
305
|
{variant}
|
|
294
306
|
</Button>
|
|
295
307
|
))}
|
|
@@ -307,6 +319,9 @@ function GalleryScreen() {
|
|
|
307
319
|
Small
|
|
308
320
|
</Button>
|
|
309
321
|
<Button fullWidth={false}>Default</Button>
|
|
322
|
+
<Button size="md" fullWidth={false}>
|
|
323
|
+
Medium
|
|
324
|
+
</Button>
|
|
310
325
|
<Button size="lg" fullWidth={false}>
|
|
311
326
|
Large
|
|
312
327
|
</Button>
|
|
@@ -357,6 +372,12 @@ function GalleryScreen() {
|
|
|
357
372
|
<Label nativeID="gallery-name">Name</Label>
|
|
358
373
|
<Input placeholder="Your name" accessibilityLabel="Name" />
|
|
359
374
|
</View>
|
|
375
|
+
<Field testID="field-parity">
|
|
376
|
+
<FieldLabel testID="field-parity-label">Email</FieldLabel>
|
|
377
|
+
<FieldControl testID="field-parity-input" placeholder="you@example.com" />
|
|
378
|
+
<FieldDescription testID="field-parity-description">We never share it.</FieldDescription>
|
|
379
|
+
<FieldError testID="field-parity-error">Enter a valid email.</FieldError>
|
|
380
|
+
</Field>
|
|
360
381
|
{/* Empty (`sm`: icon and placeholder) and filled (`md`: the clear button). */}
|
|
361
382
|
<SearchInput value={emptySearch} onChange={setEmptySearch} />
|
|
362
383
|
<SearchInput value={search} onChange={setSearch} size="md" label="Search colours" />
|
package/src/glassBlur.tsx
CHANGED
|
@@ -5,14 +5,10 @@ import {
|
|
|
5
5
|
useRef,
|
|
6
6
|
useState,
|
|
7
7
|
useSyncExternalStore,
|
|
8
|
-
type ComponentRef,
|
|
9
8
|
type ReactNode,
|
|
10
|
-
type RefObject,
|
|
11
9
|
} from "react";
|
|
12
10
|
import { StyleSheet, View, type ViewProps } from "react-native";
|
|
13
|
-
import { loadBlur } from "./blur";
|
|
14
|
-
|
|
15
|
-
type BlurTargetRef = RefObject<ComponentRef<typeof View> | null>;
|
|
11
|
+
import { loadBlur, type BlurTargetElement, type BlurTargetRef } from "./blur";
|
|
16
12
|
|
|
17
13
|
/**
|
|
18
14
|
* The current blur target, outside React state. A target change (each tab
|
|
@@ -84,7 +80,7 @@ export function GlassBlurTarget({
|
|
|
84
80
|
...props
|
|
85
81
|
}: GlassBlurTargetProps) {
|
|
86
82
|
const store = useContext(BlurTargetStoreContext);
|
|
87
|
-
const ref = useRef<
|
|
83
|
+
const ref = useRef<BlurTargetElement>(null);
|
|
88
84
|
const BlurTargetView = loadBlur()?.BlurTargetView;
|
|
89
85
|
|
|
90
86
|
// Publish the ref only once it is attached: expo-blur compares
|
|
@@ -102,12 +98,14 @@ export function GlassBlurTarget({
|
|
|
102
98
|
// Surfaces in here get no target: a blur view must not sit inside its own.
|
|
103
99
|
const content = <BlurTargetStoreContext.Provider value={null}>{children}</BlurTargetStoreContext.Provider>;
|
|
104
100
|
|
|
101
|
+
// The plain `View` is the fallback when expo-blur is absent: no `BlurView`
|
|
102
|
+
// then reads the store, so this branch needs no target ref.
|
|
105
103
|
return BlurTargetView ? (
|
|
106
104
|
<BlurTargetView ref={ref} style={[styles.fill, style]} {...props}>
|
|
107
105
|
{content}
|
|
108
106
|
</BlurTargetView>
|
|
109
107
|
) : (
|
|
110
|
-
<View
|
|
108
|
+
<View style={[styles.fill, style]} {...props}>
|
|
111
109
|
{content}
|
|
112
110
|
</View>
|
|
113
111
|
);
|
package/src/index.ts
CHANGED
|
@@ -52,6 +52,8 @@ export { Textarea } from "./Textarea";
|
|
|
52
52
|
export type { TextareaProps } from "./Textarea";
|
|
53
53
|
export { Label } from "./Label";
|
|
54
54
|
export type { LabelProps } from "./Label";
|
|
55
|
+
export { Field, FieldControl, FieldDescription, FieldError, FieldLabel } from "./Field";
|
|
56
|
+
export type { FieldProps } from "./Field";
|
|
55
57
|
export { Select } from "./Select";
|
|
56
58
|
export type { SelectOption, SelectProps } from "./Select";
|
|
57
59
|
export { Switch } from "./Switch";
|
|
@@ -225,6 +227,8 @@ export { SettingsToggleRow } from "./settings/SettingsToggleRow";
|
|
|
225
227
|
export { SettingsStack } from "./settings/SettingsStack";
|
|
226
228
|
export { SettingsEmptyState } from "./settings/SettingsEmptyState";
|
|
227
229
|
export type { SettingsEmptyStateProps } from "./settings/SettingsEmptyState";
|
|
230
|
+
export { ThemeModePicker, THEME_MODES } from "./settings/ThemeModePicker";
|
|
231
|
+
export type { ThemeMode, ThemeModePickerProps } from "./settings/ThemeModePicker";
|
|
228
232
|
export { PinnedBotTile, BotPinGrid } from "./PinnedBotTile";
|
|
229
233
|
export type { PinnedBotTileProps, BotPinGridProps } from "./PinnedBotTile";
|
|
230
234
|
export { ArtifactList } from "./ArtifactList";
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
Gesture,
|
|
5
5
|
GestureDetector,
|
|
6
6
|
GestureHandlerRootView,
|
|
7
|
-
type NativeGesture,
|
|
8
7
|
} from "react-native-gesture-handler";
|
|
9
8
|
import Animated, {
|
|
10
9
|
cancelAnimation,
|
|
@@ -46,7 +45,7 @@ import { GestureToastDrag } from "./toast-drag-gesture";
|
|
|
46
45
|
/** What a body inside the sheet needs from the drag around it. */
|
|
47
46
|
type SheetScrollLink = {
|
|
48
47
|
/** The body's native scroll, run together with the sheet's pan. */
|
|
49
|
-
native:
|
|
48
|
+
native: ReturnType<typeof Gesture.Native>;
|
|
50
49
|
/** While the sheet follows the finger: the scroll offset the body holds; else `null`. */
|
|
51
50
|
heldTop: SharedValue<number | null>;
|
|
52
51
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useRef } from "react";
|
|
2
|
-
import { Platform,
|
|
1
|
+
import { useRef, type ComponentRef } from "react";
|
|
2
|
+
import { Platform, View } from "react-native";
|
|
3
3
|
|
|
4
4
|
/** The part of a DOM element the web click guard uses: on the web a `View` is a DOM element. */
|
|
5
5
|
type DomNode = {
|
|
@@ -27,7 +27,7 @@ export function useWebClickGuard(swallowOnDown: () => boolean = () => false) {
|
|
|
27
27
|
swallowNext: () => {
|
|
28
28
|
swallow.current = true;
|
|
29
29
|
},
|
|
30
|
-
ref: (node: View | null) => {
|
|
30
|
+
ref: (node: ComponentRef<typeof View> | null) => {
|
|
31
31
|
if (Platform.OS !== "web" || !node || !isDomNode(node)) return;
|
|
32
32
|
const onClick = (event: DomEvent) => {
|
|
33
33
|
if (!swallow.current) return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useId, useLayoutEffect, useSyncExternalStore, type ReactNode } from "react";
|
|
1
|
+
import { useId, useLayoutEffect, useSyncExternalStore, type ComponentRef, type ReactNode } from "react";
|
|
2
2
|
import { BackHandler, Modal, StyleSheet, View } from "react-native";
|
|
3
|
-
import Animated, { FadeIn, FadeOut
|
|
3
|
+
import Animated, { FadeIn, FadeOut } from "react-native-reanimated";
|
|
4
4
|
import { useReduceMotion } from "../useReduceMotion";
|
|
5
5
|
|
|
6
6
|
// Overlays drawn in the app's own window. A React Native `Modal` is a window
|
|
@@ -59,7 +59,7 @@ const onBack = () => {
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
/** Mounted: the host is there, and it answers Android back for its layers. */
|
|
62
|
-
const hostRef = (view: View | null) => {
|
|
62
|
+
const hostRef = (view: ComponentRef<typeof View> | null) => {
|
|
63
63
|
if (view === null) return undefined;
|
|
64
64
|
hosts += 1;
|
|
65
65
|
const back = BackHandler.addEventListener("hardwareBackPress", onBack);
|
|
@@ -79,9 +79,11 @@ const hostRef = (view: View | null) => {
|
|
|
79
79
|
export function WindowLayerHost({ children }: { children: ReactNode }) {
|
|
80
80
|
const shown = useSyncExternalStore(subscribe, () => layers, () => EMPTY);
|
|
81
81
|
// The layers fade in and out as a Modal's `fade`, unless they move on their
|
|
82
|
-
// own (`fade={false}`)
|
|
83
|
-
|
|
84
|
-
const
|
|
82
|
+
// own (`fade={false}`). With Reduce Motion they get no layout animation at
|
|
83
|
+
// all, as the fallback Modal gets `animationType="none"`.
|
|
84
|
+
const reduceMotion = useReduceMotion();
|
|
85
|
+
const enter = reduceMotion ? undefined : FadeIn.duration(200);
|
|
86
|
+
const exit = reduceMotion ? undefined : FadeOut.duration(150);
|
|
85
87
|
return (
|
|
86
88
|
<View ref={hostRef} style={styles.fill}>
|
|
87
89
|
<View
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { IconCheck, IconCircleHalf, IconDeviceDesktop, IconMoon, IconSun } from "@tabler/icons-react-native";
|
|
2
|
+
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
3
|
+
import Svg, { Defs, LinearGradient, Rect, Stop } from "react-native-svg";
|
|
4
|
+
import { cn } from "../cn";
|
|
5
|
+
import { sizeStyle, typeStyle } from "../controlStyles";
|
|
6
|
+
import { palette, withAlpha } from "../palette";
|
|
7
|
+
import { useLargerText } from "../theme";
|
|
8
|
+
import { tokens } from "../tokens";
|
|
9
|
+
import { useScheme } from "../useScheme";
|
|
10
|
+
|
|
11
|
+
/** A theme the picker can show, as the web `ThemeModePicker`. Neutral is the dark scheme with a grey palette. */
|
|
12
|
+
export type ThemeMode = "light" | "neutral" | "dark" | "system";
|
|
13
|
+
|
|
14
|
+
/** Default order: light to dark, then system. */
|
|
15
|
+
export const THEME_MODES = ["light", "neutral", "dark", "system"] as const satisfies readonly ThemeMode[];
|
|
16
|
+
|
|
17
|
+
const LABELS: Record<ThemeMode, string> = { light: "Light", neutral: "Neutral", dark: "Dark", system: "System" };
|
|
18
|
+
const ICONS = { light: IconSun, neutral: IconCircleHalf, dark: IconMoon, system: IconDeviceDesktop };
|
|
19
|
+
/** Web `bg-zinc-900`. */
|
|
20
|
+
const ZINC_900 = "#18181b";
|
|
21
|
+
// Swatches and icons show the theme itself, so they use the web's fixed colours, not tokens.
|
|
22
|
+
// System has no swatch colour (it is a gradient) and a muted icon.
|
|
23
|
+
const SWATCHES: Record<ThemeMode, string | null> = {
|
|
24
|
+
light: "#ffffff",
|
|
25
|
+
neutral: "#3f3f46",
|
|
26
|
+
dark: ZINC_900,
|
|
27
|
+
system: null,
|
|
28
|
+
};
|
|
29
|
+
const ICON_COLOURS: Record<ThemeMode, string | null> = {
|
|
30
|
+
light: "#f59e0b",
|
|
31
|
+
neutral: "#d4d4d8",
|
|
32
|
+
dark: "#93c5fd",
|
|
33
|
+
system: null,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type ThemeModePickerProps = {
|
|
37
|
+
/** The stored choice, not the resolved scheme. */
|
|
38
|
+
value: string | undefined;
|
|
39
|
+
onChange: (mode: ThemeMode) => void;
|
|
40
|
+
/** Themes to show, in order. Default `THEME_MODES`. */
|
|
41
|
+
modes?: readonly ThemeMode[];
|
|
42
|
+
className?: string;
|
|
43
|
+
/** Each tile gets `${testID}-${mode}`. */
|
|
44
|
+
testID?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** The web System swatch, `bg-linear-to-br from-white to-zinc-900`. */
|
|
48
|
+
function GradientSwatch() {
|
|
49
|
+
return (
|
|
50
|
+
// Sized by props: an unsized Svg is 300 wide and widens the tile.
|
|
51
|
+
<Svg width="100%" height="100%" style={StyleSheet.absoluteFill}>
|
|
52
|
+
<Defs>
|
|
53
|
+
<LinearGradient id="theme-mode-system" x1="0" y1="0" x2="1" y2="1">
|
|
54
|
+
<Stop offset="0" stopColor="#ffffff" />
|
|
55
|
+
<Stop offset="1" stopColor={ZINC_900} />
|
|
56
|
+
</LinearGradient>
|
|
57
|
+
</Defs>
|
|
58
|
+
<Rect width="100%" height="100%" fill="url(#theme-mode-system)" />
|
|
59
|
+
</Svg>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Theme tiles for an Appearance settings section, as the web
|
|
65
|
+
* `ThemeModePicker`: a swatch with the theme icon over the label, in one row
|
|
66
|
+
* that the tiles share evenly. The selected tile gets the border, a primary
|
|
67
|
+
* wash and a check badge. The app owns the stored mode and how Neutral paints.
|
|
68
|
+
*/
|
|
69
|
+
export function ThemeModePicker({ value, onChange, modes = THEME_MODES, className, testID }: ThemeModePickerProps) {
|
|
70
|
+
const scheme = useScheme();
|
|
71
|
+
const largerText = useLargerText();
|
|
72
|
+
const labelSize = largerText ? "text-base" : "text-sm";
|
|
73
|
+
return (
|
|
74
|
+
<View accessibilityRole="radiogroup" accessibilityLabel="Theme" className={cn("flex-row gap-2", className)}>
|
|
75
|
+
{modes.map((mode) => {
|
|
76
|
+
const active = value === mode;
|
|
77
|
+
const Icon = ICONS[mode];
|
|
78
|
+
const swatch = SWATCHES[mode];
|
|
79
|
+
return (
|
|
80
|
+
<Pressable
|
|
81
|
+
key={mode}
|
|
82
|
+
testID={testID ? `${testID}-${mode}` : undefined}
|
|
83
|
+
accessibilityRole="radio"
|
|
84
|
+
accessibilityLabel={LABELS[mode]}
|
|
85
|
+
accessibilityState={{ checked: active }}
|
|
86
|
+
onPress={() => onChange(mode)}
|
|
87
|
+
className="flex-1 items-center gap-2 rounded-2xl border px-1 py-3 active:opacity-80"
|
|
88
|
+
style={{
|
|
89
|
+
borderColor: active ? tokens.color.border[scheme] : "transparent",
|
|
90
|
+
backgroundColor: active
|
|
91
|
+
? withAlpha(palette.primary[scheme], 0.08)
|
|
92
|
+
: withAlpha(tokens.color.surfaceSecondary[scheme], 0.4),
|
|
93
|
+
}}
|
|
94
|
+
>
|
|
95
|
+
<View
|
|
96
|
+
className="mx-2 h-12 items-center justify-center self-stretch overflow-hidden rounded-2xl"
|
|
97
|
+
style={swatch ? { backgroundColor: swatch } : undefined}
|
|
98
|
+
>
|
|
99
|
+
{swatch ? null : <GradientSwatch />}
|
|
100
|
+
{/* Positioned, so the web build paints it over the positioned gradient. */}
|
|
101
|
+
<View className="absolute inset-0 items-center justify-center">
|
|
102
|
+
<Icon size={22} color={ICON_COLOURS[mode] ?? tokens.color.muted[scheme]} />
|
|
103
|
+
</View>
|
|
104
|
+
</View>
|
|
105
|
+
{/* After the swatch, so it draws over the swatch corner. */}
|
|
106
|
+
{active ? (
|
|
107
|
+
<View
|
|
108
|
+
className="absolute right-2 top-2 h-4 w-4 items-center justify-center rounded-full"
|
|
109
|
+
style={{ backgroundColor: palette.primary[scheme] }}
|
|
110
|
+
>
|
|
111
|
+
<IconCheck size={10} strokeWidth={3} color={palette.primaryForeground[scheme]} />
|
|
112
|
+
</View>
|
|
113
|
+
) : null}
|
|
114
|
+
{/* On a narrow phone at a large font scale, "Neutral" shrinks to fit, not wraps. */}
|
|
115
|
+
<Text
|
|
116
|
+
numberOfLines={1}
|
|
117
|
+
adjustsFontSizeToFit
|
|
118
|
+
className={cn("font-instrument-sans-medium", labelSize)}
|
|
119
|
+
style={[
|
|
120
|
+
sizeStyle(labelSize),
|
|
121
|
+
typeStyle("medium"),
|
|
122
|
+
{ color: active ? palette.primary[scheme] : tokens.color.muted[scheme] },
|
|
123
|
+
]}
|
|
124
|
+
>
|
|
125
|
+
{LABELS[mode]}
|
|
126
|
+
</Text>
|
|
127
|
+
</Pressable>
|
|
128
|
+
);
|
|
129
|
+
})}
|
|
130
|
+
</View>
|
|
131
|
+
);
|
|
132
|
+
}
|
package/src/tabBarRoutes.ts
CHANGED
|
@@ -27,10 +27,11 @@ export type FloatingTabOptions = {
|
|
|
27
27
|
* Only `display: "none"` is read: on the focused route it hides the whole
|
|
28
28
|
* bar, as in React Navigation's own bar (for example while a screen is in
|
|
29
29
|
* select mode and shows its `BulkActionBar` in the bar's place). Typed
|
|
30
|
-
* loosely:
|
|
31
|
-
* which is an object or a
|
|
30
|
+
* loosely: Expo Router's own type is an animated style, each member of
|
|
31
|
+
* which is an object, a falsy value or `void` (a mapped animated field).
|
|
32
|
+
* `displayOf` reads only `display`.
|
|
32
33
|
*/
|
|
33
|
-
tabBarStyle?: object | false | "" | null;
|
|
34
|
+
tabBarStyle?: object | false | "" | null | void;
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
/** The `display` a style resolves to: in an array the last one set wins, as in `StyleSheet.flatten`. */
|
package/src/webview/HtmlView.tsx
CHANGED
|
@@ -60,7 +60,10 @@ export function HtmlView({
|
|
|
60
60
|
ref: handle,
|
|
61
61
|
testID,
|
|
62
62
|
}: HtmlViewProps) {
|
|
63
|
-
|
|
63
|
+
// `WebView<object>`: react-native-webview 14 types the class as
|
|
64
|
+
// `WebView<P = undefined>`, and its props as `WebViewProps & P`, which is
|
|
65
|
+
// `never` without a type argument.
|
|
66
|
+
const ref = useRef<WebView<object>>(null);
|
|
64
67
|
useImperativeHandle(handle, () => ({
|
|
65
68
|
postMessage: (message: string) => ref.current?.injectJavaScript(htmlViewPostScript(message)),
|
|
66
69
|
}));
|
|
@@ -77,7 +80,7 @@ export function HtmlView({
|
|
|
77
80
|
|
|
78
81
|
return (
|
|
79
82
|
<View testID={testID} style={{ height }}>
|
|
80
|
-
<WebView
|
|
83
|
+
<WebView<object>
|
|
81
84
|
ref={ref}
|
|
82
85
|
source={{ html }}
|
|
83
86
|
accessibilityLabel={title}
|