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

App.tsx

103 lines3.8 KB

1import * as Linking from "expo-linking";
2import * as SplashScreen from "expo-splash-screen";
3import { useEffect } from "react";
4import { StatusBar, View } from "react-native";
5import { GestureHandlerRootView } from "react-native-gesture-handler";
6import { KeyboardProvider } from "react-native-keyboard-controller";
7import { SafeAreaProvider } from "react-native-safe-area-context";
8import { createStaticNavigation } from "@react-navigation/native";
9​
10import { RegistryContext } from "@effect/atom-react";
11import { ThreadArrangementHost } from "./features/threads/ThreadArrangementSheet";
12import { ConfirmDialogHost } from "./components/ConfirmDialogHost";
13import { CloudAuthProvider } from "./features/cloud/CloudAuthProvider";
14import { prepareNativeShowcaseCapture } from "./features/showcase/nativeShowcaseScene";
15import { IncomingShareProvider } from "./features/sharing/IncomingShareProvider";
16import {
17 AppearancePreferencesProvider,
18 useAppearancePreferences,
19} from "./features/settings/appearance/AppearancePreferencesProvider";
20import { RootStack } from "./Stack";
21import { appAtomRegistry } from "./state/atom-registry";
22import { OverlayPortalHost } from "./components/OverlayPortal";
23import { shouldHandleAppLink } from "./lib/appLinking";
24import { useMobileNavigationTheme } from "./lib/useMobileNavigationTheme";
25import { SubscriptionUsageCoordinator } from "./widgets/SubscriptionUsageCoordinator";
26​
27import "../global.css";
28​
29if (process.env.EXPO_PUBLIC_SHOWCASE === "1") {
30 prepareNativeShowcaseCapture();
32​
33void SplashScreen.preventAutoHideAsync().catch(() => {
34 // The native module can be unavailable in non-native test environments.
35});
36​
37const appLinking = {
38 prefixes: [Linking.createURL("/"), "t3code://", "t3code-dev://", "t3code-preview://"],
39 // Keep the compact thread list available beneath a directly opened thread.
40 config: { initialRouteName: "Home" },
41 filter: shouldHandleAppLink,
42};
43​
44const Navigation = createStaticNavigation(RootStack);
45​
46function SplashScreenCoordinator() {
47 const { isReady } = useAppearancePreferences();
48​
49 useEffect(() => {
50 if (isReady) void SplashScreen.hide();
51 }, [isReady]);
52​
53 return null;
55​
56export default function App() {
57 return (
58 <RegistryContext.Provider value={appAtomRegistry}>
59 <CloudAuthProvider>
60 <AppearancePreferencesProvider>
61 <AppContent />
62 </AppearancePreferencesProvider>
63 </CloudAuthProvider>
64 </RegistryContext.Provider>
65 );
67​
68function AppContent() {
69 const { themeAppearance } = useAppearancePreferences();
70 const navigationTheme = useMobileNavigationTheme();
71​
72 return (
73 <>
74 <SplashScreenCoordinator />
75 <SubscriptionUsageCoordinator />
76 <GestureHandlerRootView className="flex-1">
77 <KeyboardProvider statusBarTranslucent>
78 <SafeAreaProvider>
79 <StatusBar
80 barStyle={themeAppearance === "dark" ? "light-content" : "dark-content"}
81 translucent
82 />
83 {/* The navigation theme drives the NATIVE header appearance: native-stack
84 forwards `dark` as the nav bar's overrideUserInterfaceStyle. Without
85 this, React Navigation defaults to its light theme and every native
86 header (glass buttons, title, materials) is forced light even when
87 the system is in dark mode. */}
88 <View style={{ flex: 1 }}>
89 <IncomingShareProvider>
90 <Navigation linking={appLinking} theme={navigationTheme} />
91 </IncomingShareProvider>
92 <ConfirmDialogHost />
93 <ThreadArrangementHost />
94 </View>
95 {/* Anchored-menu overlays render here — in-window, so the
96 keyboard stays up while a dropdown is open. */}
97 <OverlayPortalHost />
98 </SafeAreaProvider>
99 </KeyboardProvider>
100 </GestureHandlerRootView>
101 </>
102 );