import React, {memo} from 'react';
import {BackHandler, Platform, StyleSheet, View} from 'react-native';
import rpx from '@/utils/rpx';
import {DrawerContentScrollView} from '@react-navigation/drawer';
import ListItem from '@/components/base/listItem';
import {ROUTE_PATH, useNavigate} from '@/core/router';
import ThemeText from '@/components/base/themeText';
import PageBackground from '@/components/base/pageBackground';
import DeviceInfo from 'react-native-device-info';
import deviceInfoModule from 'react-native-device-info';
import NativeUtils from '@/native/utils';
import {useTimingClose} from '@/utils/timingClose';
import timeformat from '@/utils/timeformat';
import {showPanel} from '@/components/panels/usePanel';
import Divider from '@/components/base/divider';
import TrackPlayer from '@/core/trackPlayer';
import {checkUpdateAndShowResult} from '@/hooks/useCheckUpdate.ts';
import {IIconName} from '@/components/base/icon.tsx';
const ITEM_HEIGHT = rpx(108);
interface ISettingOptions {
icon: IIconName;
title: string;
onPress?: () => void;
}
function HomeDrawer(props: any) {
const navigate = useNavigate();
function navigateToSetting(settingType: string) {
navigate(ROUTE_PATH.SETTING, {
type: settingType,
});
}
const basicSetting: ISettingOptions[] = [
{
icon: 'cog-8-tooth',
title: '基本设置',
onPress: () => {
navigateToSetting('basic');
},
},
{
icon: 'javascript',
title: '插件管理',
onPress: () => {
navigateToSetting('plugin');
},
},
{
icon: 't-shirt-outline',
title: '主题设置',
onPress: () => {
navigateToSetting('theme');
},
},
];
const otherSetting: ISettingOptions[] = [
{
icon: 'circle-stack',
title: '备份与恢复',
onPress: () => {
navigateToSetting('backup');
},
},
];
if (Platform.OS === 'android') {
otherSetting.push({
icon: 'shield-keyhole-outline',
title: '权限管理',
onPress: () => {
navigate(ROUTE_PATH.PERMISSIONS);
},
});
}
return (
<>
{DeviceInfo.getApplicationName()}
{/* */}
设置
{basicSetting.map(item => (
))}
其他
{otherSetting.map(item => (
))}
软件
{
checkUpdateAndShowResult(true);
}}>
{`当前版本: ${deviceInfoModule.getVersion()}`}
{
navigateToSetting('about');
}}>
{
// 仅安卓生效
BackHandler.exitApp();
}}>
{
await TrackPlayer.reset();
NativeUtils.exitApp();
}}>
>
);
}
export default memo(HomeDrawer, () => true);
const style = StyleSheet.create({
wrapper: {
flex: 1,
backgroundColor: '#999999',
},
scrollWrapper: {
paddingTop: rpx(12),
},
header: {
height: rpx(120),
width: '100%',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
marginLeft: rpx(24),
},
card: {
marginBottom: rpx(24),
},
cardContent: {
paddingHorizontal: 0,
},
/** 倒计时 */
countDownText: {
height: ITEM_HEIGHT,
textAlignVertical: 'center',
},
});
function _CountDownItem() {
const countDown = useTimingClose();
return (
{
showPanel('TimingClose');
}}>
{countDown ? timeformat(countDown) : ''}
);
}
const CountDownItem = memo(_CountDownItem, () => true);