import { View, Text, ScrollView, TouchableOpacity } from "react-native"; import React, { useState, useEffect, useContext } from "react"; import { useTailwind } from "tailwind-rn"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Icon, Button } from "@rneui/themed"; import * as FileSystem from "expo-file-system"; import { AuthContext } from "../../../App"; import MyDivider from "../../../components/MyDivider"; export default function SelectSettingItem({ navigation }) { const tailwind = useTailwind(); const insets = useSafeAreaInsets(); //点击退出登陆 const { signOut } = useContext(AuthContext); const [cacheSize, setCacheSize] = useState(); //查看所有缓存文件大小 useEffect(() => { async function getCacheDirectoryInfo() { const cacheInfo = await FileSystem.getInfoAsync( FileSystem.cacheDirectory ); setCacheSize(cacheInfo.size); } getCacheDirectoryInfo(); }, []); //清除所有图片缓存 async function clearCache() { const cacheDir = FileSystem.cacheDirectory; const contents = await FileSystem.readDirectoryAsync(cacheDir); for (let file of contents) { await FileSystem.deleteAsync(`${cacheDir}/${file}`); } const cacheInfo = await FileSystem.getInfoAsync(cacheDir); setCacheSize(cacheInfo.size); } //可进详情的选项组件 const SettingItem = ({ title, to }) => { return ( <> navigation.navigate(to)} style={tailwind("flex-row justify-between pt-4 pb-2")} > {title} ); }; return ( 清理缓存 {`${(cacheSize / 1024 / 1024).toFixed(2)}M`} ); }