mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
124 lines
3.7 KiB
Handlebars
124 lines
3.7 KiB
Handlebars
{{#if (eq backend "convex")}}
|
|
import { ConvexProvider, ConvexReactClient } from "convex/react";
|
|
{{else}}
|
|
{{#unless (eq api "none")}}
|
|
import { QueryClientProvider } from "@tanstack/react-query";
|
|
{{/unless}}
|
|
{{/if}}
|
|
import { Stack } from "expo-router";
|
|
import {
|
|
DarkTheme,
|
|
DefaultTheme,
|
|
type Theme,
|
|
ThemeProvider,
|
|
} from "@react-navigation/native";
|
|
import { StatusBar } from "expo-status-bar";
|
|
import { GestureHandlerRootView } from "react-native-gesture-handler";
|
|
import "../global.css";
|
|
{{#if (eq api "trpc")}}
|
|
import { queryClient } from "@/utils/trpc";
|
|
{{/if}}
|
|
{{#if (eq api "orpc")}}
|
|
import { queryClient } from "@/utils/orpc";
|
|
{{/if}}
|
|
import { NAV_THEME } from "@/lib/constants";
|
|
import React, { useRef } from "react";
|
|
import { useColorScheme } from "@/lib/use-color-scheme";
|
|
import { Platform } from "react-native";
|
|
import { setAndroidNavigationBar } from "@/lib/android-navigation-bar";
|
|
|
|
const LIGHT_THEME: Theme = {
|
|
...DefaultTheme,
|
|
colors: NAV_THEME.light,
|
|
};
|
|
const DARK_THEME: Theme = {
|
|
...DarkTheme,
|
|
colors: NAV_THEME.dark,
|
|
};
|
|
|
|
export const unstable_settings = {
|
|
initialRouteName: "(drawer)",
|
|
};
|
|
|
|
{{#if (eq backend "convex")}}
|
|
const convex = new ConvexReactClient(process.env.EXPO_PUBLIC_CONVEX_URL!, {
|
|
unsavedChangesWarning: false,
|
|
});
|
|
{{/if}}
|
|
|
|
export default function RootLayout() {
|
|
const hasMounted = useRef(false);
|
|
const { colorScheme, isDarkColorScheme } = useColorScheme();
|
|
const [isColorSchemeLoaded, setIsColorSchemeLoaded] = React.useState(false);
|
|
|
|
useIsomorphicLayoutEffect(() => {
|
|
if (hasMounted.current) {
|
|
return;
|
|
}
|
|
|
|
if (Platform.OS === "web") {
|
|
document.documentElement.classList.add("bg-background");
|
|
}
|
|
setAndroidNavigationBar(colorScheme);
|
|
setIsColorSchemeLoaded(true);
|
|
hasMounted.current = true;
|
|
}, []);
|
|
|
|
if (!isColorSchemeLoaded) {
|
|
return null;
|
|
}
|
|
return (
|
|
{{#if (eq backend "convex")}}
|
|
<ConvexProvider client={convex}>
|
|
<ThemeProvider value={isDarkColorScheme ? DARK_THEME : LIGHT_THEME}>
|
|
<StatusBar style={isDarkColorScheme ? "light" : "dark"} />
|
|
<GestureHandlerRootView style=\{{ flex: 1 }}>
|
|
<Stack>
|
|
<Stack.Screen name="(drawer)" options=\{{ headerShown: false }} />
|
|
<Stack.Screen
|
|
name="modal"
|
|
options=\{{ title: "Modal", presentation: "modal" }}
|
|
/>
|
|
</Stack>
|
|
</GestureHandlerRootView>
|
|
</ThemeProvider>
|
|
</ConvexProvider>
|
|
{{else}}
|
|
{{#unless (eq api "none")}}
|
|
<QueryClientProvider client={queryClient}>
|
|
<ThemeProvider value={isDarkColorScheme ? DARK_THEME : LIGHT_THEME}>
|
|
<StatusBar style={isDarkColorScheme ? "light" : "dark"} />
|
|
<GestureHandlerRootView style=\{{ flex: 1 }}>
|
|
<Stack>
|
|
<Stack.Screen name="(drawer)" options=\{{ headerShown: false }} />
|
|
<Stack.Screen
|
|
name="modal"
|
|
options=\{{ title: "Modal", presentation: "modal" }}
|
|
/>
|
|
</Stack>
|
|
</GestureHandlerRootView>
|
|
</ThemeProvider>
|
|
</QueryClientProvider>
|
|
{{else}}
|
|
<ThemeProvider value={isDarkColorScheme ? DARK_THEME : LIGHT_THEME}>
|
|
<StatusBar style={isDarkColorScheme ? "light" : "dark"} />
|
|
<GestureHandlerRootView style=\{{ flex: 1 }}>
|
|
<Stack>
|
|
<Stack.Screen name="(drawer)" options=\{{ headerShown: false }} />
|
|
<Stack.Screen
|
|
name="modal"
|
|
options=\{{ title: "Modal", presentation: "modal" }}
|
|
/>
|
|
</Stack>
|
|
</GestureHandlerRootView>
|
|
</ThemeProvider>
|
|
{{/unless}}
|
|
{{/if}}
|
|
);
|
|
}
|
|
|
|
const useIsomorphicLayoutEffect =
|
|
Platform.OS === "web" && typeof window === "undefined"
|
|
? React.useEffect
|
|
: React.useLayoutEffect;
|