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