Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

App.tsx

111 lines4.4 KB

1import { BlurTargetView } from "expo-blur";
2import * as Linking from "expo-linking";
3import * as SplashScreen from "expo-splash-screen";
4import { useEffect } from "react";
5import { StatusBar } from "react-native";
6import { GestureHandlerRootView } from "react-native-gesture-handler";
7import { KeyboardProvider } from "react-native-keyboard-controller";
8import { SafeAreaProvider } from "react-native-safe-area-context";
9import { createStaticNavigation } from "@react-navigation/native";
10​
11import { RegistryContext } from "@effect/atom-react";
12import { ThreadArrangementHost } from "./features/threads/ThreadArrangementSheet";
13import { ConfirmDialogHost } from "./components/ConfirmDialogHost";
14import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider";
15import { prepareNativeShowcaseCapture } from "./features/showcase/nativeShowcaseScene";
16import { IncomingShareProvider } from "./features/sharing/IncomingShareProvider";
17import {
18 AppearancePreferencesProvider,
19 useAppearancePreferences,
20} from "./features/settings/appearance/AppearancePreferencesProvider";
21import { RootStack } from "./Stack";
22import { appAtomRegistry } from "./state/atom-registry";
23import { OverlayPortalHost } from "./components/OverlayPortal";
24import { appBlurTargetRef } from "./lib/appBlurTarget";
25import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme";
26​
27import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator";
28​
29import "../global.css";
30​
31if (process.env.EXPO_PUBLIC_SHOWCASE === "1") {
32 prepareNativeShowcaseCapture();
34​
35void SplashScreen.preventAutoHideAsync().catch(() => {
36 // The native module can be unavailable in non-native test environments.
37});
38​
39const appLinking = {
40 prefixes: [Linking.createURL("/"), "t3code://", "t3code-dev://", "t3code-preview://"],
41 // The Expo dev client launches the app via
42 // <scheme>://expo-development-client/?url=<packager> — that URL addresses
43 // the launcher, not app navigation. Without this filter it falls through
44 // to the NotFound wildcard route on every dev launch.
45 // expo-sharing uses a private lifecycle URL only to wake the app. The
46 // persisted share inbox below owns navigation once the payload is durable.
47 filter: (url: string) =>
48 !url.includes("expo-development-client") && !url.includes("://expo-sharing"),
49};
50​
51const Navigation = createStaticNavigation(RootStack);
52​
53function SplashScreenCoordinator() {
54 const { isReady } = useAppearancePreferences();
55​
56 useEffect(() => {
57 if (isReady) void SplashScreen.hide();
58 }, [isReady]);
59​
60 return null;
62​
63export default function App() {
64 return (
65 <RegistryContext.Provider value={appAtomRegistry}>
66 <CloudAuthProvider>
67 <AppearancePreferencesProvider>
68 <AppContent />
69 </AppearancePreferencesProvider>
70 </CloudAuthProvider>
71 </RegistryContext.Provider>
72 );
74​
75function AppContent() {
76 const { themeAppearance } = useAppearancePreferences();
77 const navigationTheme = useMobileNavigationTheme();
78​
79 return (
80 <>
81 <SplashScreenCoordinator />
82 <SubscriptionUsageCoordinator />
83 <GestureHandlerRootView className="flex-1">
84 <KeyboardProvider statusBarTranslucent>
85 <SafeAreaProvider>
86 <StatusBar
87 barStyle={themeAppearance === "dark" ? "light-content" : "dark-content"}
88 translucent
89 />
90 {/* The navigation theme drives the NATIVE header appearance: native-stack
91 forwards `dark` as the nav bar's overrideUserInterfaceStyle. Without
92 this, React Navigation defaults to its light theme and every native
93 header (glass buttons, title, materials) is forced light even when
94 the system is in dark mode. */}
95 {/* Blur target for Android dropdown backdrops — see appBlurTarget.ts. */}
96 <BlurTargetView ref={appBlurTargetRef} style={{ flex: 1 }}>
97 <IncomingShareProvider>
98 <Navigation linking={appLinking} theme={navigationTheme} />
99 </IncomingShareProvider>
100 <ConfirmDialogHost />
101 <ThreadArrangementHost />
102 </BlurTargetView>
103 {/* Anchored-menu overlays render here — in-window, so the
104 keyboard stays up while a dropdown is open. */}
105 <OverlayPortalHost />
106 </SafeAreaProvider>
107 </KeyboardProvider>
108 </GestureHandlerRootView>
109 </>
110 );