xref: /MusicFree/src/pages/home/components/drawer/index.tsx (revision f7a931fd16f3bdedf231501477b73b5b838f8b77)
1359f51feS猫头猫import React, {memo} from 'react';
2e2257bd6S猫头猫import {StyleSheet, View} from 'react-native';
3bf6e62f2S猫头猫import rpx from '@/utils/rpx';
4bf6e62f2S猫头猫import {DrawerContentScrollView} from '@react-navigation/drawer';
5b882a19dS猫头猫import {Button, Card} from 'react-native-paper';
619dc08ecS猫头猫import ListItem from '@/components/base/listItem';
7e7fa3837S猫头猫import {ROUTE_PATH, useNavigate} from '@/entry/router';
819dc08ecS猫头猫import ThemeText from '@/components/base/themeText';
919dc08ecS猫头猫import PageBackground from '@/components/base/pageBackground';
10c7676810S猫头猫import DeviceInfo from 'react-native-device-info';
119cd1998bS猫头猫import NativeUtils from '@/native/utils';
12e2257bd6S猫头猫import MusicQueue from '@/core/musicQueue';
13359f51feS猫头猫import {useTimingClose} from '@/utils/timingClose';
14359f51feS猫头猫import usePanel from '@/components/panels/usePanel';
15359f51feS猫头猫import timeformat from '@/utils/timeformat';
16bf6e62f2S猫头猫
17359f51feS猫头猫const ITEM_HEIGHT = rpx(108);
18*f7a931fdS猫头猫function HomeDrawer(props: any) {
19e7fa3837S猫头猫    const navigate = useNavigate();
20bf6e62f2S猫头猫    function navigateToSetting(settingType: string) {
21e7fa3837S猫头猫        navigate(ROUTE_PATH.SETTING, {
22bf6e62f2S猫头猫            type: settingType,
23bf6e62f2S猫头猫        });
24bf6e62f2S猫头猫    }
253ee62d1bS猫头猫
263ee62d1bS猫头猫    const basicSetting = [
273ee62d1bS猫头猫        {
283ee62d1bS猫头猫            icon: 'cog-outline',
293ee62d1bS猫头猫            title: '基本设置',
303ee62d1bS猫头猫            onPress: () => {
313ee62d1bS猫头猫                navigateToSetting('basic');
323ee62d1bS猫头猫            },
333ee62d1bS猫头猫        },
343ee62d1bS猫头猫        {
353ee62d1bS猫头猫            icon: 'language-javascript',
363ee62d1bS猫头猫            title: '插件设置',
373ee62d1bS猫头猫            onPress: () => {
383ee62d1bS猫头猫                navigateToSetting('plugin');
393ee62d1bS猫头猫            },
403ee62d1bS猫头猫        },
413ee62d1bS猫头猫        {
423ee62d1bS猫头猫            icon: 'tshirt-v-outline',
433ee62d1bS猫头猫            title: '主题设置',
443ee62d1bS猫头猫            onPress: () => {
453ee62d1bS猫头猫                navigateToSetting('theme');
463ee62d1bS猫头猫            },
473ee62d1bS猫头猫        },
48359f51feS猫头猫    ] as const;
49359f51feS猫头猫
50359f51feS猫头猫    const otherSetting = [
513ee62d1bS猫头猫        {
523ee62d1bS猫头猫            icon: 'backup-restore',
533ee62d1bS猫头猫            title: '备份与恢复',
54dec7a5f8S猫头猫            onPress: () => {
55dec7a5f8S猫头猫                navigateToSetting('backup');
56dec7a5f8S猫头猫            },
573ee62d1bS猫头猫        },
580cffb46aS猫头猫        {
590cffb46aS猫头猫            icon: 'information-outline',
600cffb46aS猫头猫            title: '关于',
610cffb46aS猫头猫            onPress: () => {
620cffb46aS猫头猫                navigateToSetting('about');
630cffb46aS猫头猫            },
640cffb46aS猫头猫        },
653ee62d1bS猫头猫    ] as const;
663ee62d1bS猫头猫
67bf6e62f2S猫头猫    return (
6865fc5a50S猫头猫        <>
694060c00aS猫头猫            <PageBackground />
704060c00aS猫头猫            <DrawerContentScrollView {...[props]} style={style.scrollWrapper}>
71bf6e62f2S猫头猫                <View style={style.header}>
72dec7a5f8S猫头猫                    <ThemeText fontSize="appbar" fontWeight="bold">
73dec7a5f8S猫头猫                        {DeviceInfo.getApplicationName()}
74dec7a5f8S猫头猫                    </ThemeText>
75b882a19dS猫头猫                    {/* <IconButton icon={'qrcode-scan'} size={rpx(36)} /> */}
76bf6e62f2S猫头猫                </View>
77bf6e62f2S猫头猫                <Card style={style.card}>
78bf6e62f2S猫头猫                    <Card.Title
798b51f01aS猫头猫                        title={
80dec7a5f8S猫头猫                            <ThemeText fontSize="description">设置</ThemeText>
814060c00aS猫头猫                        }
824060c00aS猫头猫                    />
83dec7a5f8S猫头猫                    <Card.Content style={style.cardContent}>
843ee62d1bS猫头猫                        {basicSetting.map(item => (
85bf6e62f2S猫头猫                            <ListItem
86359f51feS猫头猫                                itemHeight={ITEM_HEIGHT}
87359f51feS猫头猫                                key={item.title}
88359f51feS猫头猫                                left={{
89359f51feS猫头猫                                    icon: {
90359f51feS猫头猫                                        name: item.icon,
91359f51feS猫头猫                                        size: 'normal',
92359f51feS猫头猫                                        fontColor: 'normal',
93359f51feS猫头猫                                    },
94359f51feS猫头猫                                    width: rpx(48),
95359f51feS猫头猫                                }}
96359f51feS猫头猫                                title={item.title}
97359f51feS猫头猫                                onPress={item.onPress}
98359f51feS猫头猫                            />
99359f51feS猫头猫                        ))}
100359f51feS猫头猫                    </Card.Content>
101359f51feS猫头猫                </Card>
102359f51feS猫头猫                <Card style={style.card}>
103359f51feS猫头猫                    <Card.Title
104359f51feS猫头猫                        title={
105359f51feS猫头猫                            <ThemeText fontSize="description">其他</ThemeText>
106359f51feS猫头猫                        }
107359f51feS猫头猫                    />
108359f51feS猫头猫                    <Card.Content style={style.cardContent}>
109359f51feS猫头猫                        <CountDownItem />
110359f51feS猫头猫                        {otherSetting.map(item => (
111359f51feS猫头猫                            <ListItem
112359f51feS猫头猫                                itemHeight={ITEM_HEIGHT}
1133ee62d1bS猫头猫                                key={item.title}
1143ee62d1bS猫头猫                                left={{
1153ee62d1bS猫头猫                                    icon: {
1163ee62d1bS猫头猫                                        name: item.icon,
1173ee62d1bS猫头猫                                        size: 'normal',
1183ee62d1bS猫头猫                                        fontColor: 'normal',
1193ee62d1bS猫头猫                                    },
1203ee62d1bS猫头猫                                    width: rpx(48),
1213ee62d1bS猫头猫                                }}
1223ee62d1bS猫头猫                                title={item.title}
1234060c00aS猫头猫                                onPress={item.onPress}
1244060c00aS猫头猫                            />
1253ee62d1bS猫头猫                        ))}
126bf6e62f2S猫头猫                    </Card.Content>
127bf6e62f2S猫头猫                </Card>
128bf6e62f2S猫头猫                <View style={style.bottom}>
129bf6e62f2S猫头猫                    <Button
130e2257bd6S猫头猫                        onPress={async () => {
131e2257bd6S猫头猫                            await MusicQueue.reset();
132e2257bd6S猫头猫                            NativeUtils.exitApp();
133bf6e62f2S猫头猫                        }}>
134e2257bd6S猫头猫                        <ThemeText>退出</ThemeText>
135bf6e62f2S猫头猫                    </Button>
136bf6e62f2S猫头猫                </View>
137bf6e62f2S猫头猫            </DrawerContentScrollView>
13865fc5a50S猫头猫        </>
139bf6e62f2S猫头猫    );
140bf6e62f2S猫头猫}
141bf6e62f2S猫头猫
142*f7a931fdS猫头猫export default memo(HomeDrawer, () => true);
143*f7a931fdS猫头猫
144bf6e62f2S猫头猫const style = StyleSheet.create({
145bf6e62f2S猫头猫    wrapper: {
146bf6e62f2S猫头猫        flex: 1,
147bf6e62f2S猫头猫        backgroundColor: '#999999',
148bf6e62f2S猫头猫    },
149bf6e62f2S猫头猫    scrollWrapper: {
150bf6e62f2S猫头猫        paddingTop: rpx(12),
151bf6e62f2S猫头猫    },
152bf6e62f2S猫头猫
153bf6e62f2S猫头猫    header: {
15494b17902S猫头猫        height: rpx(120),
155bf6e62f2S猫头猫        width: '100%',
156bf6e62f2S猫头猫        flexDirection: 'row',
157bf6e62f2S猫头猫        justifyContent: 'space-between',
158bf6e62f2S猫头猫        alignItems: 'center',
15994b17902S猫头猫        marginLeft: rpx(24),
160bf6e62f2S猫头猫    },
161bf6e62f2S猫头猫    card: {
162bf6e62f2S猫头猫        backgroundColor: '#eeeeee22',
163359f51feS猫头猫        marginBottom: rpx(24),
164bf6e62f2S猫头猫    },
165dec7a5f8S猫头猫    cardContent: {
1664060c00aS猫头猫        paddingHorizontal: 0,
167dec7a5f8S猫头猫    },
168bf6e62f2S猫头猫    bottom: {
169bf6e62f2S猫头猫        height: rpx(100),
170bf6e62f2S猫头猫        flexDirection: 'row',
171bf6e62f2S猫头猫        alignItems: 'center',
172bf6e62f2S猫头猫        justifyContent: 'flex-end',
173bf6e62f2S猫头猫    },
174359f51feS猫头猫    /** 倒计时 */
175359f51feS猫头猫    countDownText: {
176359f51feS猫头猫        height: ITEM_HEIGHT,
177359f51feS猫头猫        textAlignVertical: 'center',
178359f51feS猫头猫    },
179bf6e62f2S猫头猫});
180359f51feS猫头猫
181359f51feS猫头猫function _CountDownItem() {
182359f51feS猫头猫    const countDown = useTimingClose();
183359f51feS猫头猫    const {showPanel} = usePanel();
184359f51feS猫头猫
185359f51feS猫头猫    return (
186359f51feS猫头猫        <ListItem
187359f51feS猫头猫            title="定时关闭"
188359f51feS猫头猫            onPress={() => {
189359f51feS猫头猫                showPanel('TimingClose');
190359f51feS猫头猫            }}
191359f51feS猫头猫            left={{
192359f51feS猫头猫                icon: {
193359f51feS猫头猫                    name: 'timer-outline',
194359f51feS猫头猫                    size: 'normal',
195359f51feS猫头猫                    fontColor: 'normal',
196359f51feS猫头猫                },
197359f51feS猫头猫                width: rpx(48),
198359f51feS猫头猫            }}
199359f51feS猫头猫            itemHeight={ITEM_HEIGHT}
200359f51feS猫头猫            right={() => (
201359f51feS猫头猫                <ThemeText style={style.countDownText} fontSize="subTitle">
202359f51feS猫头猫                    {countDown ? timeformat(countDown) : ''}
203359f51feS猫头猫                </ThemeText>
204359f51feS猫头猫            )}
205359f51feS猫头猫        />
206359f51feS猫头猫    );
207359f51feS猫头猫}
208359f51feS猫头猫
209359f51feS猫头猫const CountDownItem = memo(_CountDownItem, () => true);
210