xref: /MusicFree/src/entry/index.tsx (revision c7676810b7e3ee33e19fb268dd964ad9af487cc7)
1import React, {useEffect} from 'react';
2import {Image, StyleSheet} from 'react-native';
3
4import {NavigationContainer} from '@react-navigation/native';
5import {createNativeStackNavigator} from '@react-navigation/native-stack';
6import bootstrap from './bootstrap';
7import {routes} from './router';
8import {Provider as PaperProvider} from 'react-native-paper';
9import {GestureHandlerRootView} from 'react-native-gesture-handler';
10import Dialogs from '@/components/dialogs';
11import Toast from 'react-native-toast-message';
12import Panels from '@/components/panels';
13import {CustomTheme, DarkTheme, DefaultTheme} from './theme';
14import {useConfig} from '@/common/localConfigManager';
15import Share from '@/components/share';
16import RNBootSplash from 'react-native-bootsplash';
17import logManager from '@/common/logManager';
18import PageBackground from '@/components/pageBackground';
19import {SafeAreaProvider} from 'react-native-safe-area-context';
20
21/**
22 * 字体颜色
23 */
24
25bootstrap();
26const Stack = createNativeStackNavigator();
27
28export default function Pages() {
29  const themeName = useConfig('setting.theme.mode') ?? 'dark';
30  const themeColors = useConfig('setting.theme.colors') ?? {};
31  const theme = themeName.includes('dark') ? CustomTheme : DefaultTheme;
32  const isCustom = themeName.includes('custom') ? true : false;
33  const mergedTheme = isCustom
34    ? {
35        ...theme,
36        colors: {
37          ...theme.colors,
38          ...themeColors,
39        },
40      }
41    : theme;
42  useEffect(() => {
43    if (__DEV__) {
44      RNBootSplash.hide({fade: true});
45      logManager.error('TEST');
46    }
47  }, []);
48
49  return (
50    <GestureHandlerRootView style={{flex: 1}}>
51      <PaperProvider theme={mergedTheme}>
52        <SafeAreaProvider>
53          <NavigationContainer theme={mergedTheme}>
54            <PageBackground></PageBackground>
55            <Stack.Navigator
56              initialRouteName={routes[0].path}
57              screenOptions={{
58                statusBarColor: 'transparent',
59                statusBarTranslucent: true,
60                headerShown: false,
61                animation: 'slide_from_right',
62                animationDuration: 200,
63              }}>
64              {routes.map(route => (
65                <Stack.Screen
66                  key={route.path}
67                  name={route.path}
68                  component={route.component}></Stack.Screen>
69              ))}
70            </Stack.Navigator>
71
72            <Panels></Panels>
73            <Dialogs></Dialogs>
74            <Share></Share>
75            <Toast></Toast>
76          </NavigationContainer>
77        </SafeAreaProvider>
78      </PaperProvider>
79    </GestureHandlerRootView>
80  );
81}
82
83const style = StyleSheet.create({
84  blur: {
85    width: '100%',
86    height: '100%',
87    position: 'absolute',
88    top: 0,
89    left: 0,
90    right: 0,
91    bottom: 0,
92  },
93});
94