create-astratra-app 1.3.0 → 1.4.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.
Files changed (49) hide show
  1. package/README.md +21 -0
  2. package/package.json +3 -2
  3. package/src/bricks.js +4 -4
  4. package/src/createProject.js +66 -11
  5. package/templates/mobile/README.md +70 -0
  6. package/templates/mobile/app/_layout.tsx +58 -0
  7. package/templates/mobile/app/dashboard.tsx +73 -0
  8. package/templates/mobile/app/forgot-password.tsx +64 -0
  9. package/templates/mobile/app/home.tsx +32 -0
  10. package/templates/mobile/app/index.tsx +27 -0
  11. package/templates/mobile/app/login.tsx +118 -0
  12. package/templates/mobile/app/notifications.tsx +67 -0
  13. package/templates/mobile/app/onboarding/_layout.tsx +5 -0
  14. package/templates/mobile/app/onboarding/done.tsx +45 -0
  15. package/templates/mobile/app/onboarding/index.tsx +52 -0
  16. package/templates/mobile/app/settings.tsx +95 -0
  17. package/templates/mobile/app.config.js +37 -0
  18. package/templates/mobile/babel.config.js +17 -0
  19. package/templates/mobile/components/AnimatedPressable.tsx +34 -0
  20. package/templates/mobile/components/BrandBackground.tsx +33 -0
  21. package/templates/mobile/components/ErrorBoundary.tsx +28 -0
  22. package/templates/mobile/components/GlassPanel.tsx +67 -0
  23. package/templates/mobile/components/GridBackground.tsx +35 -0
  24. package/templates/mobile/components/KeyboardScreen.tsx +81 -0
  25. package/templates/mobile/components/PasswordEyeIcon.tsx +41 -0
  26. package/templates/mobile/components/SessionGuard.tsx +29 -0
  27. package/templates/mobile/components/dashboard/DashboardHeader.tsx +71 -0
  28. package/templates/mobile/components/dashboard/DashboardReveal.tsx +46 -0
  29. package/templates/mobile/components/dashboard/KpiBubble.tsx +169 -0
  30. package/templates/mobile/components/dashboard/MoreButton.tsx +65 -0
  31. package/templates/mobile/components/dashboard/NotificationBell.tsx +80 -0
  32. package/templates/mobile/components/dashboard/StaffTabBar.tsx +70 -0
  33. package/templates/mobile/components/dashboard/ToolCard.tsx +136 -0
  34. package/templates/mobile/components/glass/LiquidGlassSurface.tsx +266 -0
  35. package/templates/mobile/components/onboarding/StepScreen.tsx +185 -0
  36. package/templates/mobile/constants/dashboard.ts +50 -0
  37. package/templates/mobile/constants/theme.ts +104 -0
  38. package/templates/mobile/context/AuthContext.tsx +106 -0
  39. package/templates/mobile/eas.json +9 -0
  40. package/templates/mobile/env.example +2 -0
  41. package/templates/mobile/features/routes.ts +23 -0
  42. package/templates/mobile/gitignore +7 -0
  43. package/templates/mobile/i18n/config.ts +24 -0
  44. package/templates/mobile/i18n/locales/en.json +62 -0
  45. package/templates/mobile/i18n/locales/fr.json +62 -0
  46. package/templates/mobile/package.json +48 -0
  47. package/templates/mobile/services/push.ts +67 -0
  48. package/templates/mobile/services/session.ts +77 -0
  49. package/templates/mobile/tsconfig.json +8 -0
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The notification list, and the foreground watch that keeps it live.
3
+ *
4
+ * The first sweep raises no banner: on launch every unread item looks new, and
5
+ * twenty banners at once is how notifications get switched off for good.
6
+ */
7
+ import { useEffect, useRef, useState } from 'react';
8
+ import { AppState, FlatList, Text, View } from 'react-native';
9
+ import { useTranslation } from 'react-i18next';
10
+ import { FOREGROUND_POLL_MS, freshItems, nextStamp, shouldPoll } from '@astratra/native';
11
+ import { api } from '../services/session';
12
+ import { useAuth } from '../context/AuthContext';
13
+ import { GlassPanel } from '../components/GlassPanel';
14
+ import { colors, fontWeights, spacing } from '../constants/theme';
15
+ import GridBackground from '../components/GridBackground';
16
+
17
+ type Item = { id: string; title?: string; message?: string; createdAt?: string; read?: boolean };
18
+
19
+ export default function Notifications() {
20
+ const { t } = useTranslation();
21
+ const { user } = useAuth();
22
+ const [items, setItems] = useState<Item[]>([]);
23
+ const lastSeen = useRef<string | null>(null);
24
+
25
+ useEffect(() => {
26
+ let alive = true;
27
+
28
+ const sweep = async () => {
29
+ if (!shouldPoll(AppState.currentState, Boolean(user))) return;
30
+ try {
31
+ const list = await api.request<Item[]>('/notifications');
32
+ if (!alive) return;
33
+ setItems(list);
34
+ /* Banner only what arrived since the last sweep, then move the mark —
35
+ forward only, or the same item banners again next time. */
36
+ void freshItems(list, lastSeen.current);
37
+ lastSeen.current = nextStamp(list, lastSeen.current);
38
+ } catch {
39
+ /* a failed sweep is not worth a message: the next one is 30s away */
40
+ }
41
+ };
42
+
43
+ void sweep();
44
+ const timer = setInterval(sweep, FOREGROUND_POLL_MS);
45
+ return () => { alive = false; clearInterval(timer); };
46
+ }, [user]);
47
+
48
+ return (
49
+ <View style={{ flex: 1, backgroundColor: colors.background }}>
50
+ <GridBackground />
51
+ <View style={{ flex: 1, padding: spacing.lg, paddingTop: spacing.xl * 2 }}>
52
+ <Text style={{ color: colors.text, fontSize: 28, fontWeight: fontWeights.bold }}>{t('notifications.title')}</Text>
53
+ <FlatList
54
+ data={items}
55
+ keyExtractor={(item) => item.id}
56
+ ListEmptyComponent={<Text style={{ color: colors.muted, marginTop: spacing.lg }}>{t('notifications.empty')}</Text>}
57
+ renderItem={({ item }) => (
58
+ <GlassPanel style={{ marginTop: spacing.sm }}>
59
+ <Text style={{ color: colors.text, fontWeight: fontWeights.semibold }}>{item.title}</Text>
60
+ <Text style={{ color: colors.muted, marginTop: spacing.xs }}>{item.message}</Text>
61
+ </GlassPanel>
62
+ )}
63
+ />
64
+ </View>
65
+ </View>
66
+ );
67
+ }
@@ -0,0 +1,5 @@
1
+ import { Stack } from 'expo-router';
2
+
3
+ export default function OnboardingLayout() {
4
+ return <Stack screenOptions={{ headerShown: false, animation: 'slide_from_right' }} />;
5
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The closing screen of the flow — the one showcase screen in the template.
3
+ *
4
+ * `BrandBackground` is for exactly this: a full-bleed gradient with almost
5
+ * nothing on it. It is NOT for screens carrying content, where coloured ink on
6
+ * a saturated gradient stops being readable.
7
+ */
8
+ import { Text, View } from 'react-native';
9
+ import { useRouter } from 'expo-router';
10
+ import { useTranslation } from 'react-i18next';
11
+ import BrandBackground from '../../components/BrandBackground';
12
+ import { AnimatedPressable } from '../../components/AnimatedPressable';
13
+ import { colors, fontWeights, spacing } from '../../constants/theme';
14
+
15
+ export default function OnboardingDone() {
16
+ const { t } = useTranslation();
17
+ const router = useRouter();
18
+
19
+ return (
20
+ <BrandBackground>
21
+ <View style={{ flex: 1, justifyContent: 'center', padding: spacing.xl }}>
22
+ <Text style={{ color: colors.onAccent, fontSize: 32, fontWeight: fontWeights.bold }}>
23
+ {t('onboarding.done_title')}
24
+ </Text>
25
+ <Text style={{ color: 'rgba(255,255,255,0.82)', marginTop: spacing.sm, fontSize: 16 }}>
26
+ {t('onboarding.done_help')}
27
+ </Text>
28
+
29
+ <AnimatedPressable
30
+ onPress={() => router.replace('/login')}
31
+ style={{
32
+ marginTop: spacing.xl,
33
+ backgroundColor: colors.onAccent,
34
+ borderRadius: 14,
35
+ padding: spacing.md
36
+ }}
37
+ >
38
+ <Text style={{ color: colors.accent, textAlign: 'center', fontWeight: fontWeights.semibold }}>
39
+ {t('auth.sign_in')}
40
+ </Text>
41
+ </AnimatedPressable>
42
+ </View>
43
+ </BrandBackground>
44
+ );
45
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * The first step of a sign-up, and the shape every other step copies.
3
+ *
4
+ * A flow like this is a chain of `StepScreen`s: each one owns its fields and
5
+ * says where "next" goes. The shell — progress, title, keyboard handling, the
6
+ * back affordance — is not each screen's business.
7
+ */
8
+ import { useState } from 'react';
9
+ import { Text, TextInput } from 'react-native';
10
+ import { useRouter } from 'expo-router';
11
+ import { useTranslation } from 'react-i18next';
12
+ import StepScreen from '../../components/onboarding/StepScreen';
13
+ import { colors, fontWeights, spacing } from '../../constants/theme';
14
+
15
+ const TOTAL_STEPS = 2;
16
+
17
+ export default function OnboardingAccount() {
18
+ const { t } = useTranslation();
19
+ const router = useRouter();
20
+ const [email, setEmail] = useState('');
21
+
22
+ return (
23
+ <StepScreen
24
+ step={1}
25
+ totalSteps={TOTAL_STEPS}
26
+ eyebrow={t('onboarding.eyebrow')}
27
+ title={t('onboarding.account_title')}
28
+ onNext={() => router.push('/onboarding/done')}
29
+ nextDisabled={!email.includes('@')}
30
+ onSkip={() => router.replace('/login')}
31
+ >
32
+ <Text style={{ color: colors.muted, marginBottom: spacing.md }}>{t('onboarding.account_help')}</Text>
33
+ <TextInput
34
+ style={{
35
+ color: colors.text,
36
+ backgroundColor: colors.surface,
37
+ borderColor: colors.border,
38
+ borderWidth: 1,
39
+ borderRadius: 14,
40
+ padding: spacing.md,
41
+ fontWeight: fontWeights.medium
42
+ }}
43
+ placeholder={t('auth.email')}
44
+ placeholderTextColor={colors.muted}
45
+ autoCapitalize="none"
46
+ keyboardType="email-address"
47
+ value={email}
48
+ onChangeText={setEmail}
49
+ />
50
+ </StepScreen>
51
+ );
52
+ }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Settings: two switches that both talk to the device, not just to the app.
3
+ *
4
+ * The push switch is driven by the controller from @astratra/native — the one
5
+ * that re-reads the real state after every action instead of assuming its own
6
+ * success, and that publishes nothing once the screen is gone.
7
+ */
8
+ import { useEffect, useState } from 'react';
9
+ import { Switch, Text, View } from 'react-native';
10
+ import * as LocalAuthentication from 'expo-local-authentication';
11
+ import * as SecureStore from 'expo-secure-store';
12
+ import { Linking } from 'react-native';
13
+ import { useTranslation } from 'react-i18next';
14
+ import { createBiometricGate, createPushSettingsController, isPushEnabled } from '@astratra/native';
15
+ import { useAuth } from '../context/AuthContext';
16
+ import { push } from '../services/push';
17
+ import { NAMESPACE } from '../services/session';
18
+ import { AnimatedPressable } from '../components/AnimatedPressable';
19
+ import { GlassPanel } from '../components/GlassPanel';
20
+ import { colors, fontWeights, spacing } from '../constants/theme';
21
+ import GridBackground from '../components/GridBackground';
22
+
23
+ const gate = createBiometricGate({
24
+ keystore: SecureStore,
25
+ authenticator: LocalAuthentication,
26
+ namespace: NAMESPACE
27
+ });
28
+
29
+ export default function Settings() {
30
+ const { t } = useTranslation();
31
+ const { signOut } = useAuth();
32
+ const [biometric, setBiometric] = useState({ enabled: false, supported: false });
33
+ const [pushState, setPushState] = useState({ state: 'loading' as string, busy: false });
34
+ const [togglePush, setTogglePush] = useState<() => void>(() => () => {});
35
+
36
+ useEffect(() => {
37
+ void gate.read().then(setBiometric);
38
+ }, []);
39
+
40
+ useEffect(() => {
41
+ const controller = createPushSettingsController(
42
+ {
43
+ getState: () => push.getState(),
44
+ enable: () => push.enable(),
45
+ disable: () => push.disable(),
46
+ openSettings: () => Linking.openSettings()
47
+ },
48
+ setPushState
49
+ );
50
+ const screen = controller.activate();
51
+ setTogglePush(() => () => void controller.act());
52
+ return () => screen.dispose();
53
+ }, []);
54
+
55
+ const toggleBiometric = async () => {
56
+ const next = biometric.enabled ? await gate.disable() : await gate.enable({ promptMessage: t('app.name') });
57
+ setBiometric(await gate.read());
58
+ void next;
59
+ };
60
+
61
+ const row = { flexDirection: 'row' as const, alignItems: 'center' as const, justifyContent: 'space-between' as const };
62
+
63
+ return (
64
+ <View style={{ flex: 1, backgroundColor: colors.background }}>
65
+ <GridBackground />
66
+ <View style={{ flex: 1, padding: spacing.lg, paddingTop: spacing.xl * 2 }}>
67
+ <Text style={{ color: colors.text, fontSize: 28, fontWeight: fontWeights.bold }}>{t('settings.title')}</Text>
68
+
69
+ {biometric.supported && (
70
+ <GlassPanel style={{ marginTop: spacing.lg }}>
71
+ <View style={row}>
72
+ <Text style={{ color: colors.text }}>{t('settings.biometric')}</Text>
73
+ <Switch value={biometric.enabled} onValueChange={toggleBiometric} />
74
+ </View>
75
+ </GlassPanel>
76
+ )}
77
+
78
+ <GlassPanel style={{ marginTop: spacing.md }}>
79
+ <View style={row}>
80
+ <Text style={{ color: colors.text }}>{t('settings.notifications')}</Text>
81
+ <Switch value={isPushEnabled(pushState.state)} disabled={pushState.busy} onValueChange={togglePush} />
82
+ </View>
83
+ </GlassPanel>
84
+
85
+ <AnimatedPressable onPress={signOut} style={{ marginTop: spacing.xl }}>
86
+ <GlassPanel>
87
+ <Text style={{ color: colors.danger, textAlign: 'center', fontWeight: fontWeights.semibold }}>
88
+ {t('settings.sign_out')}
89
+ </Text>
90
+ </GlassPanel>
91
+ </AnimatedPressable>
92
+ </View>
93
+ </View>
94
+ );
95
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The app's identity, read at build time.
3
+ *
4
+ * The API URL is NOT baked in here as a literal: staging and production build
5
+ * from the same source. It arrives through the environment, and the code has a
6
+ * development default so a fresh clone runs without any setup.
7
+ *
8
+ * A KEY WITH NO VALUE IS OMITTED, NEVER SET TO null. Expo serialises `null` in
9
+ * `extra` as `{}` — an empty object, which is truthy. A `projectId: null`
10
+ * therefore reaches the CLI as `projectId: {}`, and manifest signing crashes
11
+ * with "path must be of type string" before the app ever loads.
12
+ */
13
+ const extra = {};
14
+
15
+ if (process.env.EXPO_PUBLIC_API_BASE_URL) {
16
+ extra.apiBaseUrl = process.env.EXPO_PUBLIC_API_BASE_URL;
17
+ }
18
+
19
+ if (process.env.EAS_PROJECT_ID) {
20
+ extra.eas = { projectId: process.env.EAS_PROJECT_ID };
21
+ }
22
+
23
+ module.exports = {
24
+ expo: {
25
+ name: 'Astratra App',
26
+ slug: 'astratra-app',
27
+ scheme: 'astratraapp',
28
+ version: '1.0.0',
29
+ orientation: 'portrait',
30
+ userInterfaceStyle: 'automatic',
31
+ newArchEnabled: true,
32
+ ios: { supportsTablet: true, bundleIdentifier: 'com.example.astratraapp' },
33
+ android: { package: 'com.example.astratraapp', edgeToEdgeEnabled: true },
34
+ plugins: ['expo-router', 'expo-secure-store', 'expo-notifications', 'expo-local-authentication'],
35
+ extra
36
+ }
37
+ };
@@ -0,0 +1,17 @@
1
+ /**
2
+ * `react-native-worklets/plugin` is not optional.
3
+ *
4
+ * Reanimated 4 compiles its worklets through this Babel plugin, and Skia's
5
+ * animation layer pulls Reanimated in. Without it the bundle builds fine and
6
+ * then throws at runtime — the failure looks like a missing package, not like
7
+ * a missing Babel plugin.
8
+ *
9
+ * It must stay LAST in the list.
10
+ */
11
+ module.exports = function babelConfig(api) {
12
+ api.cache(true);
13
+ return {
14
+ presets: ['babel-preset-expo'],
15
+ plugins: ['react-native-worklets/plugin']
16
+ };
17
+ };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * A press that answers immediately.
3
+ *
4
+ * Native apps confirm a touch before the network does anything. Without it a
5
+ * tap feels lost, and people tap again — which is how a payment gets sent
6
+ * twice.
7
+ */
8
+ import { useRef } from 'react';
9
+ import { Animated, Pressable, type PressableProps, type ViewStyle } from 'react-native';
10
+
11
+ export function AnimatedPressable({ children, style, ...props }: PressableProps & { style?: ViewStyle }) {
12
+ const scale = useRef(new Animated.Value(1)).current;
13
+
14
+ const to = (value: number) => Animated.spring(scale, {
15
+ toValue: value,
16
+ useNativeDriver: true,
17
+ speed: 40,
18
+ bounciness: 4
19
+ }).start();
20
+
21
+ return (
22
+ <Pressable
23
+ onPressIn={() => to(0.97)}
24
+ onPressOut={() => to(1)}
25
+ {...props}
26
+ >
27
+ <Animated.View style={[style, { transform: [{ scale }] }]}>{children}</Animated.View>
28
+ </Pressable>
29
+ );
30
+ }
31
+
32
+ /* Both shapes exported: the screens here import it by name, the ported
33
+ components by default. Neither should have to change to match the other. */
34
+ export default AnimatedPressable;
@@ -0,0 +1,33 @@
1
+ import { ReactNode } from "react";
2
+ import { StyleSheet, ViewStyle } from "react-native";
3
+ import { LinearGradient } from "expo-linear-gradient";
4
+
5
+ /* Two steps of the accent. Change these and every showcase screen follows. */
6
+ const GRADIENT = ["#4a7af4", "#1a45d4"] as const;
7
+
8
+ interface BrandBackgroundProps {
9
+ children: ReactNode;
10
+ style?: ViewStyle;
11
+ }
12
+
13
+ /**
14
+ * A full-bleed brand gradient, for showcase screens — a splash, a public
15
+ * landing. Not for screens holding content: coloured ink on a saturated
16
+ * gradient is unreadable.
17
+ */
18
+ export default function BrandBackground({ children, style }: BrandBackgroundProps) {
19
+ return (
20
+ <LinearGradient
21
+ colors={GRADIENT}
22
+ start={{ x: 0, y: 0 }}
23
+ end={{ x: 1, y: 1 }}
24
+ style={[styles.fill, style]}
25
+ >
26
+ {children}
27
+ </LinearGradient>
28
+ );
29
+ }
30
+
31
+ const styles = StyleSheet.create({
32
+ fill: { flex: 1 },
33
+ });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * One broken screen must not take the app with it.
3
+ *
4
+ * Without a boundary, a render error on a detail screen unmounts everything
5
+ * and leaves a white rectangle — indistinguishable, to the person holding the
6
+ * phone, from a crash.
7
+ */
8
+ import { Component, type ReactNode } from 'react';
9
+ import { Text, View } from 'react-native';
10
+
11
+ type State = { failed: boolean };
12
+
13
+ export class ErrorBoundary extends Component<{ children: ReactNode; fallback?: ReactNode }, State> {
14
+ state: State = { failed: false };
15
+
16
+ static getDerivedStateFromError(): State {
17
+ return { failed: true };
18
+ }
19
+
20
+ render() {
21
+ if (!this.state.failed) return this.props.children;
22
+ return this.props.fallback ?? (
23
+ <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', padding: 24 }}>
24
+ <Text>Something went wrong on this screen.</Text>
25
+ </View>
26
+ );
27
+ }
28
+ }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * The translucent surface — a real one, on both platforms.
3
+ *
4
+ * The first version blurred on iOS and painted a flat plate everywhere else.
5
+ * That was wrong: Android renders a genuine backdrop blur, it just has to be
6
+ * asked for by name (`experimentalBlurMethod`, handled by `blurPropsFor`).
7
+ * Asked properly, both platforms get the same material.
8
+ *
9
+ * THE BLUR IS A LAYER, NOT THE CONTAINER. It fills the panel behind the
10
+ * content, and the border and radius live on the wrapper. Putting content
11
+ * inside a BlurView makes the content itself blurry on some Android versions.
12
+ *
13
+ * NO `elevation` HERE. Android draws elevation against an opaque background:
14
+ * given a translucent one it paints a solid rectangle behind the whole view —
15
+ * a white block inside the card, which is exactly how it looked. The blur and
16
+ * the border do the separating instead.
17
+ */
18
+ import { Platform, StyleSheet, View, type ViewProps } from 'react-native';
19
+ import { BlurView } from 'expo-blur';
20
+ import { blurPropsFor, resolveGlassMode } from '@astratra/native';
21
+ import { colors } from '../constants/theme';
22
+
23
+ const mode = resolveGlassMode({
24
+ platform: Platform.OS,
25
+ apiAvailable: true,
26
+ effectAvailable: Platform.OS === 'ios' && Number.parseInt(String(Platform.Version), 10) >= 26,
27
+ /* expo-blur covers iOS and Android; only the web build has no real blur. */
28
+ blurAvailable: Platform.OS !== 'web'
29
+ });
30
+
31
+ const blurred = mode !== 'fallback';
32
+
33
+ export function GlassPanel({ style, children, ...props }: ViewProps) {
34
+ return (
35
+ <View
36
+ style={[
37
+ {
38
+ borderRadius: 20,
39
+ borderWidth: 1,
40
+ borderColor: colors.border,
41
+ padding: 18,
42
+ overflow: 'hidden',
43
+ /* A blurred panel needs only a veil of colour; a flat one has to
44
+ carry the whole surface itself. */
45
+ backgroundColor: blurred ? colors.veil : colors.surfaceOpaque
46
+ },
47
+ Platform.OS === 'ios' ? styles.lift : null,
48
+ style
49
+ ]}
50
+ {...props}
51
+ >
52
+ {blurred && <BlurView {...blurPropsFor(Platform.OS)} style={StyleSheet.absoluteFill} />}
53
+ {children}
54
+ </View>
55
+ );
56
+ }
57
+
58
+ const styles = StyleSheet.create({
59
+ /* iOS renders this softly; Android ignores shadow* entirely, and its
60
+ `elevation` equivalent is incompatible with a translucent background. */
61
+ lift: {
62
+ shadowColor: '#18234f',
63
+ shadowOpacity: 0.1,
64
+ shadowRadius: 18,
65
+ shadowOffset: { width: 0, height: 10 }
66
+ }
67
+ });
@@ -0,0 +1,35 @@
1
+ import { StyleSheet } from "react-native";
2
+ import Svg, { Defs, Pattern, Path, RadialGradient, Stop, Mask, Rect } from "react-native-svg";
3
+
4
+ const CELL = 40;
5
+ /* Faint on purpose: the grid gives the glass something to refract, it is not
6
+ meant to be read as a grid. */
7
+ const LINE_COLOR = "rgba(61,90,254,0.08)";
8
+
9
+ /**
10
+ * The paper behind the glass.
11
+ *
12
+ * A translucent card over a flat, near-white background is invisible — there is
13
+ * nothing for it to sit on, so the panel reads as no panel at all. This is a
14
+ * 40px rule, faded radially towards the edges: enough texture for the surface
15
+ * to separate, not enough to notice.
16
+ */
17
+ export default function GridBackground() {
18
+ return (
19
+ <Svg style={StyleSheet.absoluteFill} width="100%" height="100%">
20
+ <Defs>
21
+ <Pattern id="grid" width={CELL} height={CELL} patternUnits="userSpaceOnUse">
22
+ <Path d={`M ${CELL} 0 L 0 0 0 ${CELL}`} fill="none" stroke={LINE_COLOR} strokeWidth={1} />
23
+ </Pattern>
24
+ <RadialGradient id="fade" cx="50%" cy="45%" rx="75%" ry="60%">
25
+ <Stop offset="30%" stopColor="#fff" stopOpacity={1} />
26
+ <Stop offset="100%" stopColor="#fff" stopOpacity={0} />
27
+ </RadialGradient>
28
+ <Mask id="fadeMask">
29
+ <Rect width="100%" height="100%" fill="url(#fade)" />
30
+ </Mask>
31
+ </Defs>
32
+ <Rect width="100%" height="100%" fill="url(#grid)" mask="url(#fadeMask)" />
33
+ </Svg>
34
+ );
35
+ }
@@ -0,0 +1,81 @@
1
+ /**
2
+ * A screen that holds a form, and the keyboard that covers it.
3
+ *
4
+ * This was the same twenty lines pasted onto every screen with a text field —
5
+ * and pasted with DRIFT, which is the part that hurts: three screens, three
6
+ * different `behavior` values, so the keyboard pushed the layout differently
7
+ * depending on where you were.
8
+ *
9
+ * ANDROID TAKES NO `behavior`, AND THAT IS DELIBERATE. Expo sets
10
+ * `softwareKeyboardLayoutMode: 'resize'` by default, so the OS already shrinks
11
+ * the window when the keyboard opens. Adding `behavior="height"` on top makes
12
+ * the app correct for the same thing twice — the layout jumps, and inputs end
13
+ * up under the keyboard anyway. iOS does not resize, so it needs `padding`.
14
+ *
15
+ * SCROLLING IS ON BY DEFAULT. A form that fits today stops fitting on a small
16
+ * phone, in a larger font, or in a language with longer words. `flexGrow: 1`
17
+ * keeps a short form vertically centred while letting a long one scroll.
18
+ *
19
+ * A DRAG DISMISSES THE KEYBOARD, A TAP DOES NOT. `keyboardShouldPersistTaps`
20
+ * is what lets someone tap "Sign in" while the keyboard is still up: without
21
+ * it the first tap only closes the keyboard and the button appears dead.
22
+ */
23
+ import type { ReactNode } from 'react';
24
+ import {
25
+ Keyboard,
26
+ KeyboardAvoidingView,
27
+ Platform,
28
+ ScrollView,
29
+ View,
30
+ type StyleProp,
31
+ type ViewStyle
32
+ } from 'react-native';
33
+ import { SafeAreaView } from 'react-native-safe-area-context';
34
+ import { colors } from '../constants/theme';
35
+
36
+ export function KeyboardScreen({
37
+ children,
38
+ scroll = true,
39
+ offset = 0,
40
+ style,
41
+ contentStyle,
42
+ background
43
+ }: {
44
+ children: ReactNode;
45
+ /** Turn off for a screen that manages its own scrolling — a chat, a long list. */
46
+ scroll?: boolean;
47
+ /** Height of anything fixed above the form (a header), in points. */
48
+ offset?: number;
49
+ style?: StyleProp<ViewStyle>;
50
+ contentStyle?: StyleProp<ViewStyle>;
51
+ /** Rendered behind everything: a gradient, a grid, an image. */
52
+ background?: ReactNode;
53
+ }) {
54
+ const body = scroll ? (
55
+ <ScrollView
56
+ keyboardShouldPersistTaps="handled"
57
+ onScrollBeginDrag={Keyboard.dismiss}
58
+ contentContainerStyle={[{ flexGrow: 1 }, contentStyle]}
59
+ showsVerticalScrollIndicator={false}
60
+ >
61
+ {children}
62
+ </ScrollView>
63
+ ) : (
64
+ <View style={[{ flex: 1 }, contentStyle]}>{children}</View>
65
+ );
66
+
67
+ return (
68
+ <View style={[{ flex: 1, backgroundColor: colors.background }, style]}>
69
+ {background}
70
+ <SafeAreaView style={{ flex: 1 }}>
71
+ <KeyboardAvoidingView
72
+ style={{ flex: 1 }}
73
+ behavior={Platform.OS === 'ios' ? 'padding' : undefined}
74
+ keyboardVerticalOffset={offset}
75
+ >
76
+ {body}
77
+ </KeyboardAvoidingView>
78
+ </SafeAreaView>
79
+ </View>
80
+ );
81
+ }
@@ -0,0 +1,41 @@
1
+ import Svg, { Path, Circle, Line } from "react-native-svg";
2
+ import { MUTED } from "../constants/theme";
3
+
4
+ /**
5
+ * Show or hide the password.
6
+ *
7
+ * `visible` describes what the FIELD is doing, not what the icon draws: when
8
+ * the password is visible the icon is the struck-through eye, because that is
9
+ * the action offered — hide it. Getting this backwards is the classic bug.
10
+ */
11
+ interface PasswordEyeIconProps {
12
+ visible: boolean;
13
+ size?: number;
14
+ color?: string;
15
+ }
16
+
17
+ export default function PasswordEyeIcon({ visible, size = 18, color = MUTED }: PasswordEyeIconProps) {
18
+ if (visible) {
19
+ return (
20
+ <Svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth={2}>
21
+ <Path
22
+ d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"
23
+ strokeLinecap="round"
24
+ strokeLinejoin="round"
25
+ />
26
+ <Line x1="1" y1="1" x2="23" y2="23" strokeLinecap="round" />
27
+ </Svg>
28
+ );
29
+ }
30
+
31
+ return (
32
+ <Svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth={2}>
33
+ <Path
34
+ d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"
35
+ strokeLinecap="round"
36
+ strokeLinejoin="round"
37
+ />
38
+ <Circle cx="12" cy="12" r="3" />
39
+ </Svg>
40
+ );
41
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The screens behind the session, kept behind it.
3
+ *
4
+ * Signing out used to replace the top screen with the sign-in page and leave
5
+ * the whole stack behind it: a few taps on Back returned to the dashboard —
6
+ * signed out, with the previous person's data still on screen. `replace`, not
7
+ * `push`, and the decision waits for the session to finish restoring.
8
+ */
9
+ import { useEffect } from 'react';
10
+ import { useRouter, useSegments } from 'expo-router';
11
+ import { guard } from '../features/routes';
12
+ import { useAuth } from '../context/AuthContext';
13
+
14
+ export function SessionGuard({ children }: { children: React.ReactNode }) {
15
+ const { user, loading } = useAuth();
16
+ const segments = useSegments();
17
+ const router = useRouter();
18
+
19
+ useEffect(() => {
20
+ const redirect = guard.shouldRedirectToLogin({
21
+ isLoading: loading,
22
+ isAuthenticated: Boolean(user),
23
+ route: segments as readonly string[]
24
+ });
25
+ if (redirect) router.replace(guard.loginRoute as never);
26
+ }, [user, loading, segments, router]);
27
+
28
+ return <>{children}</>;
29
+ }