@vvedantb/native-ui 0.37.2 → 0.38.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 +8 -7
- package/dist/app-root/AuthGroupGate.jsx +65 -0
- package/dist/app-root/SsoCallbackScreen.jsx +97 -0
- package/dist/app-root/fonts.js +88 -0
- package/dist/app-root/index.js +3 -0
- package/dist/auth/AuthScreen.jsx +252 -74
- package/dist/auth/SecondFactorScreen.jsx +18 -12
- package/dist/auth/SignInScreen.jsx +40 -17
- package/dist/crash/LastCrashDialog.jsx +56 -0
- package/dist/crash/lastCrash.js +213 -0
- package/dist/entries/app-root.js +6 -0
- package/dist/entries/crash.js +5 -0
- package/dist/entries/theme.js +3 -0
- package/dist/index.js +3 -0
- package/dist/neutralTheme.js +163 -0
- package/dist/primitives/icon.jsx +0 -4
- package/dist/primitives/select.jsx +0 -2
- package/dist/settings/ThemeModePicker.jsx +2 -5
- package/dist/themeModeStore.js +67 -0
- package/dist/themeModes.js +9 -0
- package/package.json +47 -19
- package/src/app-root/AuthGroupGate.tsx +46 -0
- package/src/app-root/SsoCallbackScreen.tsx +62 -0
- package/src/app-root/fonts.ts +55 -0
- package/src/app-root/index.ts +6 -0
- package/src/auth/AuthScreen.tsx +102 -1
- package/src/auth/SecondFactorScreen.tsx +20 -2
- package/src/auth/SignInScreen.tsx +119 -53
- package/src/crash/LastCrashDialog.tsx +42 -0
- package/src/crash/lastCrash.ts +239 -0
- package/src/entries/app-root.ts +6 -0
- package/src/entries/crash.ts +16 -0
- package/src/entries/theme.ts +6 -0
- package/src/highlight.ts +1 -1
- package/src/index.ts +5 -0
- package/src/neutralTheme.ts +130 -0
- package/src/primitives/icon.tsx +0 -2
- package/src/primitives/select.tsx +0 -2
- package/src/settings/ThemeModePicker.tsx +2 -5
- package/src/themeModeStore.ts +94 -0
- package/src/themeModes.ts +10 -0
- package/types/prism-react-renderer.d.ts +22 -0
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/native-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.0",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar, AI chat parts, the family app marks, a NativeWind preset, the Expo web root and Clerk + Convex auth screens.",
|
|
5
|
+
"description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar, AI chat parts, the family app marks, a NativeWind preset, the Expo web root, the app root shell helpers and Clerk + Convex auth screens.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"publishConfig": {
|
|
8
|
-
"access": "public"
|
|
9
|
-
"provenance": true
|
|
8
|
+
"access": "public"
|
|
10
9
|
},
|
|
11
10
|
"repository": {
|
|
12
11
|
"type": "git",
|
|
13
|
-
"url": "git+https://github.com/vvedantb/
|
|
12
|
+
"url": "git+https://github.com/vvedantb/v.git",
|
|
14
13
|
"directory": "packages/native-ui"
|
|
15
14
|
},
|
|
16
15
|
"exports": {
|
|
@@ -124,6 +123,11 @@
|
|
|
124
123
|
"source": "./src/entries/date-time.ts",
|
|
125
124
|
"default": "./dist/entries/date-time.js"
|
|
126
125
|
},
|
|
126
|
+
"./crash": {
|
|
127
|
+
"types": "./src/entries/crash.ts",
|
|
128
|
+
"source": "./src/entries/crash.ts",
|
|
129
|
+
"default": "./dist/entries/crash.js"
|
|
130
|
+
},
|
|
127
131
|
"./ai": {
|
|
128
132
|
"types": "./src/entries/ai.ts",
|
|
129
133
|
"source": "./src/entries/ai.ts",
|
|
@@ -174,6 +178,11 @@
|
|
|
174
178
|
"source": "./src/entries/expo-web-root.ts",
|
|
175
179
|
"default": "./dist/entries/expo-web-root.js"
|
|
176
180
|
},
|
|
181
|
+
"./app-root": {
|
|
182
|
+
"types": "./src/entries/app-root.ts",
|
|
183
|
+
"source": "./src/entries/app-root.ts",
|
|
184
|
+
"default": "./dist/entries/app-root.js"
|
|
185
|
+
},
|
|
177
186
|
"./tailwind-preset": {
|
|
178
187
|
"types": "./src/tailwind-preset.d.cts",
|
|
179
188
|
"require": "./src/tailwind-preset.cjs",
|
|
@@ -185,12 +194,14 @@
|
|
|
185
194
|
"files": [
|
|
186
195
|
"dist",
|
|
187
196
|
"src",
|
|
197
|
+
"types/prism-react-renderer.d.ts",
|
|
188
198
|
"LICENSE"
|
|
189
199
|
],
|
|
190
200
|
"sideEffects": false,
|
|
191
201
|
"peerDependencies": {
|
|
192
202
|
"expo-paste-input": ">=0.2.0",
|
|
193
203
|
"@clerk/expo": ">=4.16.0",
|
|
204
|
+
"@expo-google-fonts/instrument-sans": "*",
|
|
194
205
|
"@expo/vector-icons": "*",
|
|
195
206
|
"@json-render/core": ">=0.21.0",
|
|
196
207
|
"@json-render/react-native": ">=0.21.0",
|
|
@@ -199,8 +210,8 @@
|
|
|
199
210
|
"@rn-primitives/slot": "*",
|
|
200
211
|
"@rn-primitives/switch": "*",
|
|
201
212
|
"@swmansion/react-native-bottom-sheet": ">=1.1.0",
|
|
202
|
-
"@tabler/icons-react-native": "
|
|
203
|
-
"@vvedantb/server": ">=0.
|
|
213
|
+
"@tabler/icons-react-native": "^3.52.0",
|
|
214
|
+
"@vvedantb/server": ">=0.18.0",
|
|
204
215
|
"class-variance-authority": ">=0.7.0",
|
|
205
216
|
"clsx": ">=2.0.0",
|
|
206
217
|
"convex": "*",
|
|
@@ -209,13 +220,15 @@
|
|
|
209
220
|
"expo-blur": "*",
|
|
210
221
|
"expo-constants": "*",
|
|
211
222
|
"expo-device": "*",
|
|
223
|
+
"expo-font": "*",
|
|
212
224
|
"expo-haptics": "*",
|
|
213
225
|
"expo-linear-gradient": "*",
|
|
214
226
|
"expo-notifications": "*",
|
|
215
227
|
"expo-router": "*",
|
|
228
|
+
"expo-secure-store": "*",
|
|
229
|
+
"expo-splash-screen": "*",
|
|
216
230
|
"expo-video": "*",
|
|
217
231
|
"expo-web-browser": "*",
|
|
218
|
-
"lucide-react-native": "*",
|
|
219
232
|
"nativewind": ">=4.0.0",
|
|
220
233
|
"prism-react-renderer": ">=2.0.0",
|
|
221
234
|
"react": ">=19.0.0",
|
|
@@ -228,9 +241,18 @@
|
|
|
228
241
|
"react-native-screens": "*",
|
|
229
242
|
"react-native-svg": "*",
|
|
230
243
|
"react-native-webview": "*",
|
|
231
|
-
"tailwind-merge": ">=
|
|
244
|
+
"tailwind-merge": ">=3.0.0"
|
|
232
245
|
},
|
|
233
246
|
"peerDependenciesMeta": {
|
|
247
|
+
"@expo-google-fonts/instrument-sans": {
|
|
248
|
+
"optional": true
|
|
249
|
+
},
|
|
250
|
+
"expo-font": {
|
|
251
|
+
"optional": true
|
|
252
|
+
},
|
|
253
|
+
"expo-splash-screen": {
|
|
254
|
+
"optional": true
|
|
255
|
+
},
|
|
234
256
|
"expo-paste-input": {
|
|
235
257
|
"optional": true
|
|
236
258
|
},
|
|
@@ -282,6 +304,9 @@
|
|
|
282
304
|
"expo-router": {
|
|
283
305
|
"optional": true
|
|
284
306
|
},
|
|
307
|
+
"expo-secure-store": {
|
|
308
|
+
"optional": true
|
|
309
|
+
},
|
|
285
310
|
"expo-video": {
|
|
286
311
|
"optional": true
|
|
287
312
|
},
|
|
@@ -308,35 +333,38 @@
|
|
|
308
333
|
}
|
|
309
334
|
},
|
|
310
335
|
"devDependencies": {
|
|
311
|
-
"@babel/core": "
|
|
312
|
-
"@clerk/expo": "4.17.
|
|
336
|
+
"@babel/core": "7.29.13",
|
|
337
|
+
"@clerk/expo": "4.17.4",
|
|
338
|
+
"@expo-google-fonts/instrument-sans": "^0.4.2",
|
|
313
339
|
"@react-native-community/datetimepicker": "9.2.1",
|
|
314
|
-
"@types/react": "
|
|
340
|
+
"@types/react": "19.3.0",
|
|
315
341
|
"expo": "~58.0.26",
|
|
316
342
|
"expo-auth-session": "~58.0.19",
|
|
317
343
|
"expo-blur": "~58.0.6",
|
|
318
344
|
"expo-constants": "~58.0.16",
|
|
319
345
|
"expo-device": "~58.0.5",
|
|
346
|
+
"expo-font": "~58.0.12",
|
|
320
347
|
"expo-haptics": "~58.0.8",
|
|
321
348
|
"expo-linear-gradient": "~58.0.4",
|
|
322
349
|
"expo-notifications": "~58.1.9",
|
|
323
350
|
"expo-router": "~58.0.32",
|
|
351
|
+
"expo-splash-screen": "~58.0.14",
|
|
324
352
|
"expo-video": "~58.0.14",
|
|
325
353
|
"expo-web-browser": "~58.1.0",
|
|
326
|
-
"happy-dom": "
|
|
327
|
-
"react": "
|
|
354
|
+
"happy-dom": "21.0.4",
|
|
355
|
+
"react": "19.3.0",
|
|
328
356
|
"react-native": "0.88.1",
|
|
329
|
-
"react-native-gesture-handler": "
|
|
357
|
+
"react-native-gesture-handler": "3.3.0",
|
|
330
358
|
"react-native-keyboard-controller": "1.22.7",
|
|
331
359
|
"react-native-reanimated": "4.8.0",
|
|
332
|
-
"react-native-safe-area-context": "
|
|
333
|
-
"react-native-screens": "
|
|
360
|
+
"react-native-safe-area-context": "5.11.1",
|
|
361
|
+
"react-native-screens": "4.30.1",
|
|
334
362
|
"react-native-svg": "15.16.0",
|
|
335
363
|
"react-native-webview": "14.0.1",
|
|
336
364
|
"react-native-worklets": "0.14.0",
|
|
337
365
|
"typescript": "7.0.2",
|
|
338
|
-
"vitest": "
|
|
339
|
-
"@vvedantb/server": "0.
|
|
366
|
+
"vitest": "5.1.1",
|
|
367
|
+
"@vvedantb/server": "0.18.0"
|
|
340
368
|
},
|
|
341
369
|
"scripts": {
|
|
342
370
|
"build": "node scripts/build-dist.mjs && node scripts/check-exports.mjs",
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useAuth } from "@clerk/expo";
|
|
2
|
+
import { Redirect, type Href } from "expo-router";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
export type AuthGroupGateProps = {
|
|
6
|
+
/** The auth stack, shown when nothing redirects. */
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
/** Wait for Clerk to load before anything else. Default `true`. */
|
|
9
|
+
waitForLoaded?: boolean;
|
|
10
|
+
/** Shown while waiting. Default: nothing. */
|
|
11
|
+
loading?: ReactNode;
|
|
12
|
+
/** Passed to `useAuth`. Unset keeps Clerk's own default. */
|
|
13
|
+
treatPendingAsSignedOut?: boolean;
|
|
14
|
+
/** Where a signed-in user goes. Default `/`. */
|
|
15
|
+
signedInHref?: Href;
|
|
16
|
+
/** `Redirect` `withAnchor`, for apps that open a tab group under the target. */
|
|
17
|
+
withAnchor?: boolean;
|
|
18
|
+
/** Leave signed-in users on the auth screens, for UI preview builds. */
|
|
19
|
+
skipSignedInRedirect?: boolean;
|
|
20
|
+
/** Where a signed-out user goes instead of the auth screens, for UI preview builds. */
|
|
21
|
+
previewHref?: Href;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The layout of an `(auth)` route group: waits for Clerk when asked, sends signed-in
|
|
26
|
+
* users on, and renders the auth stack otherwise. The app passes its own loading UI.
|
|
27
|
+
*/
|
|
28
|
+
export function AuthGroupGate({
|
|
29
|
+
children,
|
|
30
|
+
waitForLoaded = true,
|
|
31
|
+
loading = null,
|
|
32
|
+
treatPendingAsSignedOut,
|
|
33
|
+
signedInHref = "/",
|
|
34
|
+
withAnchor,
|
|
35
|
+
skipSignedInRedirect = false,
|
|
36
|
+
previewHref,
|
|
37
|
+
}: AuthGroupGateProps) {
|
|
38
|
+
const { isSignedIn, isLoaded } = useAuth(
|
|
39
|
+
treatPendingAsSignedOut === undefined ? undefined : { treatPendingAsSignedOut },
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (waitForLoaded && !isLoaded) return loading;
|
|
43
|
+
if (isSignedIn && !skipSignedInRedirect) return <Redirect href={signedInHref} withAnchor={withAnchor} />;
|
|
44
|
+
if (previewHref) return <Redirect href={previewHref} />;
|
|
45
|
+
return children;
|
|
46
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useAuth } from "@clerk/expo";
|
|
2
|
+
import { Redirect, useRouter, type Href } from "expo-router";
|
|
3
|
+
import type { ReactNode } from "react";
|
|
4
|
+
import { View } from "react-native";
|
|
5
|
+
import { Button } from "../Button";
|
|
6
|
+
import { CenteredSpinner } from "../Spinner";
|
|
7
|
+
|
|
8
|
+
export type SsoCallbackScreenProps = {
|
|
9
|
+
/** Where a signed-in user goes. Default `/`. */
|
|
10
|
+
signedInHref?: Href;
|
|
11
|
+
/** Where a signed-out user goes, or where the back button goes. Default `/sign-in`. */
|
|
12
|
+
signedOutHref?: Href;
|
|
13
|
+
/** `Redirect` `withAnchor` for the signed-in redirect. */
|
|
14
|
+
withAnchor?: boolean;
|
|
15
|
+
/** Passed to `useAuth`. Unset keeps Clerk's own default. */
|
|
16
|
+
treatPendingAsSignedOut?: boolean;
|
|
17
|
+
/** The waiting UI. Default: a centred spinner labelled "Signing in". */
|
|
18
|
+
loading?: ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* Label of a ghost back button. When set, the screen stays on the waiting UI for a
|
|
21
|
+
* signed-out user and the button goes to `signedOutHref`. Unset: it redirects there.
|
|
22
|
+
*/
|
|
23
|
+
backLabel?: string;
|
|
24
|
+
/** Class of the view around `loading` and the back button. */
|
|
25
|
+
className?: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const DEFAULT_LOADING = <CenteredSpinner label="Signing in" />;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The `sso-callback` route of the Google sign-in redirect. `useSSO` completes the
|
|
32
|
+
* session; this screen only waits for it, then opens the app.
|
|
33
|
+
*/
|
|
34
|
+
export function SsoCallbackScreen({
|
|
35
|
+
signedInHref = "/",
|
|
36
|
+
signedOutHref = "/sign-in",
|
|
37
|
+
withAnchor,
|
|
38
|
+
treatPendingAsSignedOut,
|
|
39
|
+
loading = DEFAULT_LOADING,
|
|
40
|
+
backLabel,
|
|
41
|
+
className = "flex-1 items-center justify-center gap-6 px-6",
|
|
42
|
+
}: SsoCallbackScreenProps) {
|
|
43
|
+
const { isLoaded, isSignedIn } = useAuth(
|
|
44
|
+
treatPendingAsSignedOut === undefined ? undefined : { treatPendingAsSignedOut },
|
|
45
|
+
);
|
|
46
|
+
const router = useRouter();
|
|
47
|
+
|
|
48
|
+
if (isLoaded && isSignedIn) return <Redirect href={signedInHref} withAnchor={withAnchor} />;
|
|
49
|
+
|
|
50
|
+
if (backLabel === undefined) {
|
|
51
|
+
return isLoaded ? <Redirect href={signedOutHref} /> : loading;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<View className={className}>
|
|
56
|
+
{loading}
|
|
57
|
+
<Button variant="ghost" fullWidth={false} onPress={() => router.replace(signedOutHref)}>
|
|
58
|
+
{backLabel}
|
|
59
|
+
</Button>
|
|
60
|
+
</View>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { InstrumentSans_400Regular } from "@expo-google-fonts/instrument-sans/400Regular";
|
|
2
|
+
import { InstrumentSans_500Medium } from "@expo-google-fonts/instrument-sans/500Medium";
|
|
3
|
+
import { InstrumentSans_600SemiBold } from "@expo-google-fonts/instrument-sans/600SemiBold";
|
|
4
|
+
import { InstrumentSans_700Bold } from "@expo-google-fonts/instrument-sans/700Bold";
|
|
5
|
+
import { InstrumentSans_400Regular_Italic } from "@expo-google-fonts/instrument-sans/400Regular_Italic";
|
|
6
|
+
import { InstrumentSans_500Medium_Italic } from "@expo-google-fonts/instrument-sans/500Medium_Italic";
|
|
7
|
+
import { InstrumentSans_600SemiBold_Italic } from "@expo-google-fonts/instrument-sans/600SemiBold_Italic";
|
|
8
|
+
import { InstrumentSans_700Bold_Italic } from "@expo-google-fonts/instrument-sans/700Bold_Italic";
|
|
9
|
+
import { useFonts } from "expo-font";
|
|
10
|
+
import * as SplashScreen from "expo-splash-screen";
|
|
11
|
+
import { useEffect } from "react";
|
|
12
|
+
|
|
13
|
+
/** The font sources `useFonts` takes: family name to module. */
|
|
14
|
+
export type FontMap = Record<string, number>;
|
|
15
|
+
|
|
16
|
+
export type InstrumentSansOptions = {
|
|
17
|
+
/** Also load the four italic weights. Default `false` (upright only). */
|
|
18
|
+
italics?: boolean;
|
|
19
|
+
/** More fonts to load with it, for example Michroma. */
|
|
20
|
+
extra?: FontMap;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const UPRIGHT: FontMap = {
|
|
24
|
+
InstrumentSans_400Regular,
|
|
25
|
+
InstrumentSans_500Medium,
|
|
26
|
+
InstrumentSans_600SemiBold,
|
|
27
|
+
InstrumentSans_700Bold,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const ITALIC: FontMap = {
|
|
31
|
+
InstrumentSans_400Regular_Italic,
|
|
32
|
+
InstrumentSans_500Medium_Italic,
|
|
33
|
+
InstrumentSans_600SemiBold_Italic,
|
|
34
|
+
InstrumentSans_700Bold_Italic,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** The Instrument Sans fonts the `font-instrument-sans*` classes use, plus any `extra`. */
|
|
38
|
+
export function instrumentSansFontMap({ italics = false, extra }: InstrumentSansOptions = {}): FontMap {
|
|
39
|
+
return { ...extra, ...UPRIGHT, ...(italics ? ITALIC : undefined) };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** `[loaded, error]` as `useFonts` returns them, for the Instrument Sans map. */
|
|
43
|
+
export function useInstrumentSansFonts(options: InstrumentSansOptions = {}) {
|
|
44
|
+
return useFonts(instrumentSansFontMap(options));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Hides the native splash once `ready` is true. Call `SplashScreen.preventAutoHideAsync()`
|
|
49
|
+
* at module load in the app, so the call site keeps the timing. A failed hide is ignored.
|
|
50
|
+
*/
|
|
51
|
+
export function useHideSplashWhenReady(ready: boolean) {
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (ready) void SplashScreen.hideAsync().catch(() => {});
|
|
54
|
+
}, [ready]);
|
|
55
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { instrumentSansFontMap, useInstrumentSansFonts, useHideSplashWhenReady } from "./fonts";
|
|
2
|
+
export type { FontMap, InstrumentSansOptions } from "./fonts";
|
|
3
|
+
export { AuthGroupGate } from "./AuthGroupGate";
|
|
4
|
+
export type { AuthGroupGateProps } from "./AuthGroupGate";
|
|
5
|
+
export { SsoCallbackScreen } from "./SsoCallbackScreen";
|
|
6
|
+
export type { SsoCallbackScreenProps } from "./SsoCallbackScreen";
|
package/src/auth/AuthScreen.tsx
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useEffect, useState, type ReactNode } from "react";
|
|
2
2
|
import { Keyboard, KeyboardAvoidingView, ScrollView, StyleSheet, Text, View } from "react-native";
|
|
3
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
3
4
|
import { cn } from "../cn";
|
|
4
5
|
import { textStyle, typeStyle } from "../controlStyles";
|
|
6
|
+
import { floatingShadow } from "../floating";
|
|
5
7
|
import { palette } from "../palette";
|
|
6
8
|
import { tokens } from "../tokens";
|
|
7
9
|
import { useScheme } from "../useScheme";
|
|
@@ -16,8 +18,20 @@ export type AuthScreenProps = {
|
|
|
16
18
|
footer?: ReactNode;
|
|
17
19
|
testID?: string;
|
|
18
20
|
className?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Default `"default"`: the centred column. `"hero"`: a coloured band with the
|
|
23
|
+
* header, title and subtitle, over a rounded sheet that holds the form.
|
|
24
|
+
*/
|
|
25
|
+
variant?: "default" | "hero";
|
|
26
|
+
/** The hero band and screen colour. Only used with `variant="hero"`. Default `"#db2777"`. */
|
|
27
|
+
heroColor?: string;
|
|
28
|
+
/** The hero title and subtitle colour. Only used with `variant="hero"`. Default `"#ffffff"`. */
|
|
29
|
+
heroForeground?: string;
|
|
19
30
|
};
|
|
20
31
|
|
|
32
|
+
const DEFAULT_HERO_COLOR = "#db2777";
|
|
33
|
+
const DEFAULT_HERO_FOREGROUND = "#ffffff";
|
|
34
|
+
|
|
21
35
|
/** Space under the form while the keyboard is open, on top of its height. */
|
|
22
36
|
const KEYBOARD_EXTRA = 24;
|
|
23
37
|
|
|
@@ -45,10 +59,37 @@ function useKeyboardHeight(): number {
|
|
|
45
59
|
* the scroll content gains the keyboard height as bottom space, so the focused
|
|
46
60
|
* field and the submit button scroll above the keyboard.
|
|
47
61
|
*/
|
|
48
|
-
export function AuthScreen({
|
|
62
|
+
export function AuthScreen({
|
|
63
|
+
title,
|
|
64
|
+
subtitle,
|
|
65
|
+
children,
|
|
66
|
+
header,
|
|
67
|
+
footer,
|
|
68
|
+
testID,
|
|
69
|
+
className,
|
|
70
|
+
variant = "default",
|
|
71
|
+
heroColor,
|
|
72
|
+
heroForeground,
|
|
73
|
+
}: AuthScreenProps) {
|
|
49
74
|
const scheme = useScheme();
|
|
50
75
|
const keyboardHeight = useKeyboardHeight();
|
|
51
76
|
const keyboardOpen = keyboardHeight > 0;
|
|
77
|
+
if (variant === "hero") {
|
|
78
|
+
return (
|
|
79
|
+
<HeroAuthScreen
|
|
80
|
+
title={title}
|
|
81
|
+
subtitle={subtitle}
|
|
82
|
+
header={header}
|
|
83
|
+
footer={footer}
|
|
84
|
+
testID={testID}
|
|
85
|
+
className={className}
|
|
86
|
+
heroColor={heroColor ?? DEFAULT_HERO_COLOR}
|
|
87
|
+
heroForeground={heroForeground ?? DEFAULT_HERO_FOREGROUND}
|
|
88
|
+
>
|
|
89
|
+
{children}
|
|
90
|
+
</HeroAuthScreen>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
52
93
|
return (
|
|
53
94
|
<KeyboardAvoidingView
|
|
54
95
|
// Padding on both platforms, as OverlayModal and PromptInput: Android `height` does nothing edge-to-edge.
|
|
@@ -88,6 +129,66 @@ export function AuthScreen({ title, subtitle, children, header, footer, testID,
|
|
|
88
129
|
);
|
|
89
130
|
}
|
|
90
131
|
|
|
132
|
+
type HeroAuthScreenProps = Omit<AuthScreenProps, "variant" | "heroColor" | "heroForeground"> & {
|
|
133
|
+
heroColor: string;
|
|
134
|
+
heroForeground: string;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/** The `variant="hero"` frame. Separate so only the hero reads the safe-area insets. */
|
|
138
|
+
function HeroAuthScreen({
|
|
139
|
+
title,
|
|
140
|
+
subtitle,
|
|
141
|
+
children,
|
|
142
|
+
header,
|
|
143
|
+
footer,
|
|
144
|
+
testID,
|
|
145
|
+
className,
|
|
146
|
+
heroColor,
|
|
147
|
+
heroForeground,
|
|
148
|
+
}: HeroAuthScreenProps) {
|
|
149
|
+
const scheme = useScheme();
|
|
150
|
+
const insets = useSafeAreaInsets();
|
|
151
|
+
return (
|
|
152
|
+
<KeyboardAvoidingView behavior="padding" className="flex-1" style={{ backgroundColor: heroColor }}>
|
|
153
|
+
<ScrollView
|
|
154
|
+
testID={testID}
|
|
155
|
+
className="flex-1"
|
|
156
|
+
contentContainerClassName="grow"
|
|
157
|
+
keyboardShouldPersistTaps="handled"
|
|
158
|
+
keyboardDismissMode="on-drag"
|
|
159
|
+
>
|
|
160
|
+
<View className="px-6 pb-6" style={{ paddingTop: insets.top + 24 }}>
|
|
161
|
+
{header}
|
|
162
|
+
<Text
|
|
163
|
+
accessibilityRole="header"
|
|
164
|
+
className="mt-10 mb-1 text-4xl font-instrument-sans-medium"
|
|
165
|
+
style={{ color: heroForeground }}
|
|
166
|
+
>
|
|
167
|
+
{title}
|
|
168
|
+
</Text>
|
|
169
|
+
{subtitle ? (
|
|
170
|
+
<Text className="text-lg font-instrument-sans-medium" style={{ color: heroForeground }}>
|
|
171
|
+
{subtitle}
|
|
172
|
+
</Text>
|
|
173
|
+
) : null}
|
|
174
|
+
</View>
|
|
175
|
+
<View
|
|
176
|
+
className={cn("grow rounded-t-[32px] px-6 pt-8", className)}
|
|
177
|
+
style={[
|
|
178
|
+
{ backgroundColor: tokens.color.surface[scheme], paddingBottom: insets.bottom + 24 },
|
|
179
|
+
floatingShadow,
|
|
180
|
+
]}
|
|
181
|
+
>
|
|
182
|
+
<View className="gap-4">{children}</View>
|
|
183
|
+
{footer ? (
|
|
184
|
+
<View className="mt-6 flex-row flex-wrap items-center justify-center gap-1">{footer}</View>
|
|
185
|
+
) : null}
|
|
186
|
+
</View>
|
|
187
|
+
</ScrollView>
|
|
188
|
+
</KeyboardAvoidingView>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
91
192
|
/** A separator, "or", a separator: between Google and the email fields. */
|
|
92
193
|
export function OrDivider({ label = "or" }: { label?: string }) {
|
|
93
194
|
const scheme = useScheme();
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { useState, type ReactNode } from "react";
|
|
4
4
|
import { Button } from "../Button";
|
|
5
5
|
import { Input } from "../Input";
|
|
6
|
-
import { AuthScreen, FieldError } from "./AuthScreen";
|
|
6
|
+
import { AuthScreen, FieldError, type AuthScreenProps } from "./AuthScreen";
|
|
7
7
|
|
|
8
8
|
export type SecondFactorScreenProps = {
|
|
9
9
|
title: string;
|
|
@@ -30,6 +30,12 @@ export type SecondFactorScreenProps = {
|
|
|
30
30
|
digitsOnly?: boolean;
|
|
31
31
|
/** Placeholder when `digitsOnly` is `false`. Default "Code". */
|
|
32
32
|
placeholder?: string;
|
|
33
|
+
/** Passed to `AuthScreen`. Default `"default"`. */
|
|
34
|
+
variant?: AuthScreenProps["variant"];
|
|
35
|
+
/** Passed to `AuthScreen`. Used with `variant="hero"`. */
|
|
36
|
+
heroColor?: string;
|
|
37
|
+
/** Passed to `AuthScreen`. Used with `variant="hero"`. */
|
|
38
|
+
heroForeground?: string;
|
|
33
39
|
};
|
|
34
40
|
|
|
35
41
|
/** A one-time code step: digits only, a Verify button, an inline error and a back link. */
|
|
@@ -47,6 +53,9 @@ export function SecondFactorScreen({
|
|
|
47
53
|
footer,
|
|
48
54
|
digitsOnly = true,
|
|
49
55
|
placeholder,
|
|
56
|
+
variant,
|
|
57
|
+
heroColor,
|
|
58
|
+
heroForeground,
|
|
50
59
|
}: SecondFactorScreenProps) {
|
|
51
60
|
const [code, setCode] = useState("");
|
|
52
61
|
const ready = code.length === codeLength && !loading;
|
|
@@ -56,7 +65,16 @@ export function SecondFactorScreen({
|
|
|
56
65
|
};
|
|
57
66
|
|
|
58
67
|
return (
|
|
59
|
-
<AuthScreen
|
|
68
|
+
<AuthScreen
|
|
69
|
+
testID={`${testIDPrefix}-screen`}
|
|
70
|
+
title={title}
|
|
71
|
+
subtitle={description}
|
|
72
|
+
header={header}
|
|
73
|
+
footer={footer}
|
|
74
|
+
variant={variant}
|
|
75
|
+
heroColor={heroColor}
|
|
76
|
+
heroForeground={heroForeground}
|
|
77
|
+
>
|
|
60
78
|
<Input
|
|
61
79
|
testID={`${testIDPrefix}-code`}
|
|
62
80
|
accessibilityLabel="Verification code"
|