aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/app/_layout.tsx
blob: 62c29c27727b20040bbe5c43983d8aee39e61682 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import "@/globals.css";
import "expo-dev-client";

import { useEffect } from "react";
import { View } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import { useRouter } from "expo-router";
import { Stack } from "expo-router/stack";
import { ShareIntentProvider, useShareIntent } from "expo-share-intent";
import { StatusBar } from "expo-status-bar";
import { StyledStack } from "@/components/navigation/stack";
import { Providers } from "@/lib/providers";
import useAppSettings from "@/lib/settings";
import { cn } from "@/lib/utils";
import { useColorScheme } from "nativewind";

export default function RootLayout() {
  const router = useRouter();
  const { hasShareIntent } = useShareIntent();
  const { colorScheme, setColorScheme } = useColorScheme();
  const { settings } = useAppSettings();

  useEffect(() => {
    if (hasShareIntent) {
      router.replace({
        pathname: "sharing",
      });
    }
  }, [hasShareIntent]);

  useEffect(() => {
    setColorScheme(settings.theme);
  }, [settings.theme]);

  return (
    <ShareIntentProvider>
      <Providers>
        <GestureHandlerRootView style={{ flex: 1 }}>
          <View
            className={cn(
              "w-full flex-1 bg-gray-100 text-foreground dark:bg-background",
              colorScheme == "dark" ? "dark" : "light",
            )}
          >
            <StyledStack
              contentClassName="bg-gray-100 dark:bg-background"
              screenOptions={{
                headerShown: false,
                headerTransparent: true,
              }}
            >
              <Stack.Screen name="index" />
              <Stack.Screen
                name="signin"
                options={{
                  headerShown: true,
                  headerBackVisible: true,
                  headerBackTitle: "Back",
                  title: "",
                }}
              />
              <Stack.Screen name="server-address" />
              <Stack.Screen
                name="sharing"
                options={{ presentation: "modal" }}
              />
              <Stack.Screen
                name="test-connection"
                options={{
                  title: "Test Connection",
                  headerShown: true,
                  presentation: "modal",
                }}
              />
            </StyledStack>
            <StatusBar style="auto" />
          </View>
        </GestureHandlerRootView>
      </Providers>
    </ShareIntentProvider>
  );
}