Open History to see the last commit
1import { PermissionUpdateNotice } from "./features/connection/PermissionUpdateNotice";
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, getStateFromPath } from "@react-navigation/native";
10
11import { RegistryContext } from "@effect/atom-react";
12import { ThreadArrangementHost } from "./features/threads/ThreadArrangementSheet";
13import * as Dialog from "./components/ui/Dialog";
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 { subscribeComposerDraftModelReconciliation } from "./state/use-composer-drafts";
24import { environmentThreadShells } from "./state/threads";
25import { environmentShell } from "./state/shell";
26import { OverlayPortalHost } from "./components/ui/OverlayPortal";
27import { shouldHandleAppLink, restoreDraftLinkState } from "./lib/appLinking";
28import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme";
29import { useUiRuntimeMemoryWarningGc } from "./lib/useUiRuntimeMemoryWarningGc";
30import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator";
31import { VoiceInputProvider } from "./features/voice-input/VoiceInputProvider";
32import { GlobalVoiceInputControl } from "./features/voice-input/GlobalVoiceInputControl";
33import { NativeLayoutMetricsProvider } from "./native/native-layout-metrics";
34
35import "../global.css";
36
37if (process.env.EXPO_PUBLIC_SHOWCASE === "1") {
38 prepareNativeShowcaseCapture();
39}
40
41void SplashScreen.preventAutoHideAsync().catch(() => {});
42
43const appLinking = {
44 prefixes: [Linking.createURL("/"), "t3code://", "t3code-dev://", "t3code-preview://"],
45 config: { initialRouteName: "Home" },
46 filter: shouldHandleAppLink,
47 getStateFromPath: (path: string, options: Parameters<typeof getStateFromPath>[1]) =>
48 restoreDraftLinkState(getStateFromPath(path, options), path),
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;
61}
62
63export default function App() {
64 useUiRuntimeMemoryWarningGc();
65 useEffect(
66 () =>
67 subscribeComposerDraftModelReconciliation({
68 registry: appAtomRegistry,
69 threadShellAtom: environmentThreadShells.threadShellAtom,
70 threadRefsAtom: environmentThreadShells.threadRefsAtom,
71 shellStateAtom: environmentShell.stateAtom,
72 }),
73 [],
74 );
75
76 return (
77 <RegistryContext.Provider value={appAtomRegistry}>
78 <CloudAuthProvider>
79 <AppearancePreferencesProvider>
80 <AppContent />
81 </AppearancePreferencesProvider>
82 </CloudAuthProvider>
83 </RegistryContext.Provider>
84 );
85}
86
87function AppContent() {
88 const { themeAppearance } = useAppearancePreferences();
89 const navigationTheme = useMobileNavigationTheme();
90
91 return (
92 <>
93 <SplashScreenCoordinator />
94 <SubscriptionUsageCoordinator />
95 <PermissionUpdateNotice />
96 <GestureHandlerRootView className="flex-1">
97 <KeyboardProvider statusBarTranslucent>
98 <SafeAreaProvider>
99 <VoiceInputProvider>
100 <StatusBar barStyle={themeAppearance === "dark" ? "light-content" : "dark-content"} />
101 {/* The navigation theme drives the NATIVE header appearance: native-stack
102 forwards `dark` as the nav bar's overrideUserInterfaceStyle. Without
103 this, React Navigation defaults to its light theme and every native
104 header (glass buttons, title, materials) is forced light even when
105 the system is in dark mode. */}
106 <GlobalVoiceInputControl>
107 <NativeLayoutMetricsProvider>
108 <IncomingShareProvider>
109 <Navigation linking={appLinking} theme={navigationTheme} />
110 </IncomingShareProvider>
111 <Dialog.Host />
112 <ThreadArrangementHost />
113 </NativeLayoutMetricsProvider>
114 </GlobalVoiceInputControl>
115 {/* Anchored-menu overlays render here — in-window, so the
116 keyboard stays up while a dropdown is open. */}
117 <OverlayPortalHost />
118 </VoiceInputProvider>
119 </SafeAreaProvider>
120 </KeyboardProvider>
121 </GestureHandlerRootView>
122 </>
123 );
124}