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

App.tsx

122 lines4.8 KB

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 } 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 } 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();
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};
48​
49const Navigation = createStaticNavigation(RootStack);
50​
51function SplashScreenCoordinator() {
52 const { isReady } = useAppearancePreferences();
53​
54 useEffect(() => {
55 if (isReady) void SplashScreen.hide();
56 }, [isReady]);
57​
58 return null;
60​
61export default function App() {
62 useUiRuntimeMemoryWarningGc();
63 useEffect(
64 () =>
65 subscribeComposerDraftModelReconciliation({
66 registry: appAtomRegistry,
67 threadShellAtom: environmentThreadShells.threadShellAtom,
68 threadRefsAtom: environmentThreadShells.threadRefsAtom,
69 shellStateAtom: environmentShell.stateAtom,
70 }),
71 [],
72 );
73​
74 return (
75 <RegistryContext.Provider value={appAtomRegistry}>
76 <CloudAuthProvider>
77 <AppearancePreferencesProvider>
78 <AppContent />
79 </AppearancePreferencesProvider>
80 </CloudAuthProvider>
81 </RegistryContext.Provider>
82 );
84​
85function AppContent() {
86 const { themeAppearance } = useAppearancePreferences();
87 const navigationTheme = useMobileNavigationTheme();
88​
89 return (
90 <>
91 <SplashScreenCoordinator />
92 <SubscriptionUsageCoordinator />
93 <PermissionUpdateNotice />
94 <GestureHandlerRootView className="flex-1">
95 <KeyboardProvider statusBarTranslucent>
96 <SafeAreaProvider>
97 <VoiceInputProvider>
98 <StatusBar barStyle={themeAppearance === "dark" ? "light-content" : "dark-content"} />
99 {/* The navigation theme drives the NATIVE header appearance: native-stack
100 forwards `dark` as the nav bar's overrideUserInterfaceStyle. Without
101 this, React Navigation defaults to its light theme and every native
102 header (glass buttons, title, materials) is forced light even when
103 the system is in dark mode. */}
104 <GlobalVoiceInputControl>
105 <NativeLayoutMetricsProvider>
106 <IncomingShareProvider>
107 <Navigation linking={appLinking} theme={navigationTheme} />
108 </IncomingShareProvider>
109 <Dialog.Host />
110 <ThreadArrangementHost />
111 </NativeLayoutMetricsProvider>
112 </GlobalVoiceInputControl>
113 {/* Anchored-menu overlays render here — in-window, so the
114 keyboard stays up while a dropdown is open. */}
115 <OverlayPortalHost />
116 </VoiceInputProvider>
117 </SafeAreaProvider>
118 </KeyboardProvider>
119 </GestureHandlerRootView>
120 </>
121 );