Skip to content

Commit cf6c8dc

Browse files
authored
Clear image cache button (#8190)
1 parent 719d7b7 commit cf6c8dc

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {createSinglePathSVG} from './TEMPLATE'
2+
3+
export const BroomSparkle_Stroke2_Corner2_Rounded = createSinglePathSVG({
4+
path: 'M20.494 2.13a1 1 0 0 1 .375 1.364l-4.658 8.2.263.095c1.52.554 2.737 2.062 2.484 3.864-.336 2.393-1.358 4.12-3.245 6.047a1 1 0 0 1-1.102.222l-9.5-4a1 1 0 0 1-.166-1.754c1.458-.971 2.623-1.923 3.498-3.3 1.057-1.662 3.154-2.854 5.281-2.08l.58.212 4.827-8.494a1 1 0 0 1 1.363-.375ZM13.04 12.669c-.983-.358-2.19.142-2.91 1.273-.737 1.16-1.628 2.054-2.601 2.828l1.708.72a.2.2 0 0 0 .177-.011l2.13-1.218a.2.2 0 0 1 .29.237l-.551 1.653a.2.2 0 0 0 .112.247l3.353 1.413c1.359-1.494 1.994-2.76 2.23-4.435.094-.675-.359-1.405-1.188-1.707l-2.75-1ZM4.407 7.184a.5.5 0 0 1-.224.224l-1.29.645a.5.5 0 0 0 0 .894l1.29.645a.5.5 0 0 1 .224.224l.645 1.29a.5.5 0 0 0 .894 0l.645-1.29a.5.5 0 0 1 .224-.224l1.29-.645a.5.5 0 0 0 0-.894l-1.29-.645a.5.5 0 0 1-.224-.224l-.645-1.29a.5.5 0 0 0-.894 0l-.645 1.29ZM9.559 3.72a.36.36 0 0 0 .16-.16l.46-.921a.357.357 0 0 1 .64 0l.46.921q.054.106.16.16l.921.46a.357.357 0 0 1 0 .64l-.921.46a.36.36 0 0 0-.16.16l-.46.921a.357.357 0 0 1-.64 0l-.46-.921a.36.36 0 0 0-.16-.16l-.921-.46a.357.357 0 0 1 0-.64l.921-.46Z',
5+
})

src/screens/Settings/AboutSettings.tsx

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,68 @@
11
import {useMemo} from 'react'
22
import {Platform} from 'react-native'
33
import {setStringAsync} from 'expo-clipboard'
4+
import * as FileSystem from 'expo-file-system'
5+
import {Image} from 'expo-image'
46
import {msg, Trans} from '@lingui/macro'
57
import {useLingui} from '@lingui/react'
6-
import {NativeStackScreenProps} from '@react-navigation/native-stack'
8+
import {type NativeStackScreenProps} from '@react-navigation/native-stack'
9+
import {useMutation} from '@tanstack/react-query'
710
import {Statsig} from 'statsig-react-native-expo'
811

912
import {appVersion, BUNDLE_DATE, bundleInfo} from '#/lib/app-info'
1013
import {STATUS_PAGE_URL} from '#/lib/constants'
11-
import {CommonNavigatorParams} from '#/lib/routes/types'
14+
import {type CommonNavigatorParams} from '#/lib/routes/types'
15+
import {isAndroid, isNative} from '#/platform/detection'
1216
import {useDevModeEnabled} from '#/state/preferences/dev-mode'
1317
import * as Toast from '#/view/com/util/Toast'
1418
import * as SettingsList from '#/screens/Settings/components/SettingsList'
19+
import {BroomSparkle_Stroke2_Corner2_Rounded as BroomSparkleIcon} from '#/components/icons/BroomSparkle'
1520
import {CodeLines_Stroke2_Corner2_Rounded as CodeLinesIcon} from '#/components/icons/CodeLines'
1621
import {Globe_Stroke2_Corner0_Rounded as GlobeIcon} from '#/components/icons/Globe'
1722
import {Newspaper_Stroke2_Corner2_Rounded as NewspaperIcon} from '#/components/icons/Newspaper'
1823
import {Wrench_Stroke2_Corner2_Rounded as WrenchIcon} from '#/components/icons/Wrench'
1924
import * as Layout from '#/components/Layout'
25+
import {Loader} from '#/components/Loader'
2026
import {OTAInfo} from './components/OTAInfo'
2127

2228
type Props = NativeStackScreenProps<CommonNavigatorParams, 'AboutSettings'>
2329
export function AboutSettingsScreen({}: Props) {
24-
const {_} = useLingui()
30+
const {_, i18n} = useLingui()
2531
const [devModeEnabled, setDevModeEnabled] = useDevModeEnabled()
2632
const stableID = useMemo(() => Statsig.getStableID(), [])
2733

34+
const {mutate: onClearImageCache, isPending: isClearingImageCache} =
35+
useMutation({
36+
mutationFn: async () => {
37+
const freeSpaceBefore = await FileSystem.getFreeDiskStorageAsync()
38+
await Image.clearDiskCache()
39+
const freeSpaceAfter = await FileSystem.getFreeDiskStorageAsync()
40+
const spaceDiff = freeSpaceBefore - freeSpaceAfter
41+
return spaceDiff * -1
42+
},
43+
onSuccess: sizeDiffBytes => {
44+
if (isAndroid) {
45+
Toast.show(
46+
_(
47+
msg({
48+
message: `Image cache cleared, freed ${i18n.number(
49+
Math.abs(sizeDiffBytes / 1024 / 1024),
50+
{
51+
notation: 'compact',
52+
style: 'unit',
53+
unit: 'megabyte',
54+
},
55+
)}`,
56+
comment: `Android-only toast message which includes amount of space freed using localized number formatting`,
57+
}),
58+
),
59+
)
60+
} else {
61+
Toast.show(_(msg`Image cache cleared`))
62+
}
63+
},
64+
})
65+
2866
return (
2967
<Layout.Screen>
3068
<Layout.Header.Outer>
@@ -69,6 +107,18 @@ export function AboutSettingsScreen({}: Props) {
69107
<Trans>System log</Trans>
70108
</SettingsList.ItemText>
71109
</SettingsList.LinkItem>
110+
{isNative && (
111+
<SettingsList.PressableItem
112+
onPress={() => onClearImageCache()}
113+
label={_(msg`Clear image cache`)}
114+
disabled={isClearingImageCache}>
115+
<SettingsList.ItemIcon icon={BroomSparkleIcon} />
116+
<SettingsList.ItemText>
117+
<Trans>Clear image cache</Trans>
118+
</SettingsList.ItemText>
119+
{isClearingImageCache && <SettingsList.ItemIcon icon={Loader} />}
120+
</SettingsList.PressableItem>
121+
)}
72122
<SettingsList.PressableItem
73123
label={_(msg`Version ${appVersion}`)}
74124
accessibilityHint={_(msg`Copies build version to clipboard`)}

0 commit comments

Comments
 (0)