71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
import { useConvexAuth } from "@convex-dev/auth/react"
|
|
import { DarkTheme, Stack, ThemeProvider } from "expo-router"
|
|
import { StatusBar } from "expo-status-bar"
|
|
import { useIsDark } from "@/lib/theme"
|
|
import { GestureHandlerRootView } from "react-native-gesture-handler"
|
|
import { SafeAreaProvider } from "react-native-safe-area-context"
|
|
|
|
import { Toaster } from "@/components/ui/toaster"
|
|
import { ConvexAppProvider } from "@/contexts/convex-app"
|
|
import { ServerConfigProvider, useServerConfig } from "@/contexts/server-config"
|
|
|
|
import { HandoffBridge } from "@/components/handoff-bridge"
|
|
|
|
const navigationTheme = {
|
|
...DarkTheme,
|
|
colors: { ...DarkTheme.colors, background: "#000", card: "#000" },
|
|
}
|
|
|
|
function RootNavigator() {
|
|
const { config, isLoading } = useServerConfig()
|
|
const auth = useConvexAuth()
|
|
|
|
if (isLoading || (config && (!auth || auth.isLoading))) {
|
|
return null
|
|
}
|
|
|
|
const isAuthenticated = Boolean(config && auth?.isAuthenticated)
|
|
|
|
return (
|
|
<Stack
|
|
screenOptions={{
|
|
headerShown: false,
|
|
animation: "none",
|
|
contentStyle: { backgroundColor: "#000" },
|
|
}}
|
|
>
|
|
<Stack.Screen name="index" />
|
|
<Stack.Protected guard={isAuthenticated}>
|
|
<Stack.Screen name="(app)" />
|
|
</Stack.Protected>
|
|
<Stack.Protected guard={Boolean(config) && !isAuthenticated}>
|
|
<Stack.Screen name="(auth)" />
|
|
</Stack.Protected>
|
|
<Stack.Protected guard={!config}>
|
|
<Stack.Screen name="server" />
|
|
</Stack.Protected>
|
|
</Stack>
|
|
)
|
|
}
|
|
|
|
export default function RootLayout() {
|
|
const isDark = useIsDark()
|
|
|
|
return (
|
|
<GestureHandlerRootView style={{ flex: 1, backgroundColor: "#000" }}>
|
|
<SafeAreaProvider>
|
|
<ServerConfigProvider>
|
|
<ConvexAppProvider>
|
|
<StatusBar style={isDark ? "light" : "dark"} />
|
|
<ThemeProvider value={navigationTheme}>
|
|
<HandoffBridge />
|
|
<RootNavigator />
|
|
</ThemeProvider>
|
|
<Toaster />
|
|
</ConvexAppProvider>
|
|
</ServerConfigProvider>
|
|
</SafeAreaProvider>
|
|
</GestureHandlerRootView>
|
|
)
|
|
}
|