xref: /MusicFree/src/entry/index.tsx (revision 734113be9d256a2b4d36bb272d6d3565beaeb236)
1import React from 'react';
2import {NavigationContainer} from '@react-navigation/native';
3import {createNativeStackNavigator} from '@react-navigation/native-stack';
4import bootstrap from './bootstrap';
5import {routes} from './router';
6import {Provider as PaperProvider} from 'react-native-paper';
7import {GestureHandlerRootView} from 'react-native-gesture-handler';
8import Dialogs from '@/components/dialogs';
9import Toast from 'react-native-toast-message';
10import Panels from '@/components/panels';
11import {CustomTheme, DefaultTheme} from './theme';
12import Config from '@/core/config';
13import PageBackground from '@/components/base/pageBackground';
14import {SafeAreaProvider} from 'react-native-safe-area-context';
15import toastConfig from '@/components/base/toast';
16import useBootstrap from './useBootstrap';
17import Debug from '@/components/debug';
18import useOrientation from '@/hooks/useOrientation';
19
20/**
21 * 字体颜色
22 */
23
24bootstrap();
25const Stack = createNativeStackNavigator<any>();
26
27export default function Pages() {
28    const themeName = Config.useConfig('setting.theme.mode') ?? 'dark';
29    const themeColors = Config.useConfig('setting.theme.colors') ?? {};
30    const theme = themeName.includes('dark') ? CustomTheme : DefaultTheme;
31    const isCustom = themeName.includes('custom') ? true : false;
32    const mergedTheme = isCustom
33        ? {
34              ...theme,
35              colors: {
36                  ...theme.colors,
37                  ...themeColors,
38              },
39          }
40        : theme;
41
42    useBootstrap();
43
44    const orientation = useOrientation();
45    console.log(orientation);
46
47    return (
48        <GestureHandlerRootView style={{flex: 1}}>
49            <PaperProvider theme={mergedTheme}>
50                <SafeAreaProvider>
51                    <NavigationContainer theme={mergedTheme}>
52                        <PageBackground />
53                        <Stack.Navigator
54                            initialRouteName={routes[0].path}
55                            screenOptions={{
56                                statusBarColor: 'transparent',
57                                statusBarTranslucent: true,
58                                headerShown: false,
59                                animation: 'slide_from_right',
60                                animationDuration: 200,
61                            }}>
62                            {routes.map(route => (
63                                <Stack.Screen
64                                    key={route.path}
65                                    name={route.path}
66                                    component={route.component}
67                                />
68                            ))}
69                        </Stack.Navigator>
70
71                        <Panels />
72                        <Dialogs />
73                        <Toast config={toastConfig} />
74                        <Debug />
75                    </NavigationContainer>
76                </SafeAreaProvider>
77            </PaperProvider>
78        </GestureHandlerRootView>
79    );
80}
81