frontend client for gemstone. decentralised workplace app
1import { isDevMode } from "@/lib/utils/env";
2import { RootProviders } from "@/providers";
3import { useCurrentPalette } from "@/providers/ThemeProvider";
4import {
5 Lexend_100Thin,
6 Lexend_200ExtraLight,
7 Lexend_300Light,
8 Lexend_400Regular,
9 Lexend_500Medium,
10 Lexend_600SemiBold,
11 Lexend_700Bold,
12 Lexend_800ExtraBold,
13 Lexend_900Black,
14 useFonts,
15} from "@expo-google-fonts/lexend";
16import { Slot, SplashScreen } from "expo-router";
17import { useEffect } from "react";
18import { Platform, View } from "react-native";
19
20const RootLayoutInner = () => {
21 const [loaded, error] = useFonts({
22 Lexend_100Thin,
23 Lexend_200ExtraLight,
24 Lexend_300Light,
25 Lexend_400Regular,
26 Lexend_500Medium,
27 Lexend_600SemiBold,
28 Lexend_700Bold,
29 Lexend_800ExtraBold,
30 Lexend_900Black,
31 });
32
33 const { semantic } = useCurrentPalette();
34
35 useEffect(() => {
36 if (!isDevMode) return;
37 if (Platform.OS === "web" && typeof window !== "undefined") {
38 const hostname = window.location.hostname;
39 if (hostname === "127.0.0.1") return;
40 if (hostname === "localhost") {
41 const newUrl = window.location.href.replace(
42 "localhost",
43 "127.0.0.1",
44 );
45 window.location.replace(newUrl);
46 return;
47 }
48
49 throw new Error(
50 "don't use localhost, use 127.0.0.1. this shouldn't error unless you've done something very wrong.",
51 );
52 }
53 });
54
55 useEffect(() => {
56 if (loaded || error) {
57 void SplashScreen.hideAsync();
58 }
59 }, [loaded, error]);
60
61 if (!loaded && !error) {
62 return null;
63 }
64
65 return (
66 <View style={{ backgroundColor: semantic.background, flex: 1 }}>
67 <Slot />
68 </View>
69 );
70};
71
72const RootLayout = () => {
73 return (
74 <RootProviders>
75 <RootLayoutInner />
76 </RootProviders>
77 );
78};
79
80export default RootLayout;