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