|
1 | 1 | import {useMemo} from 'react'
|
2 | 2 | import {Platform} from 'react-native'
|
3 | 3 | import {setStringAsync} from 'expo-clipboard'
|
| 4 | +import * as FileSystem from 'expo-file-system' |
| 5 | +import {Image} from 'expo-image' |
4 | 6 | import {msg, Trans} from '@lingui/macro'
|
5 | 7 | 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' |
7 | 10 | import {Statsig} from 'statsig-react-native-expo'
|
8 | 11 |
|
9 | 12 | import {appVersion, BUNDLE_DATE, bundleInfo} from '#/lib/app-info'
|
10 | 13 | 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' |
12 | 16 | import {useDevModeEnabled} from '#/state/preferences/dev-mode'
|
13 | 17 | import * as Toast from '#/view/com/util/Toast'
|
14 | 18 | import * as SettingsList from '#/screens/Settings/components/SettingsList'
|
| 19 | +import {BroomSparkle_Stroke2_Corner2_Rounded as BroomSparkleIcon} from '#/components/icons/BroomSparkle' |
15 | 20 | import {CodeLines_Stroke2_Corner2_Rounded as CodeLinesIcon} from '#/components/icons/CodeLines'
|
16 | 21 | import {Globe_Stroke2_Corner0_Rounded as GlobeIcon} from '#/components/icons/Globe'
|
17 | 22 | import {Newspaper_Stroke2_Corner2_Rounded as NewspaperIcon} from '#/components/icons/Newspaper'
|
18 | 23 | import {Wrench_Stroke2_Corner2_Rounded as WrenchIcon} from '#/components/icons/Wrench'
|
19 | 24 | import * as Layout from '#/components/Layout'
|
| 25 | +import {Loader} from '#/components/Loader' |
20 | 26 | import {OTAInfo} from './components/OTAInfo'
|
21 | 27 |
|
22 | 28 | type Props = NativeStackScreenProps<CommonNavigatorParams, 'AboutSettings'>
|
23 | 29 | export function AboutSettingsScreen({}: Props) {
|
24 |
| - const {_} = useLingui() |
| 30 | + const {_, i18n} = useLingui() |
25 | 31 | const [devModeEnabled, setDevModeEnabled] = useDevModeEnabled()
|
26 | 32 | const stableID = useMemo(() => Statsig.getStableID(), [])
|
27 | 33 |
|
| 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 | + |
28 | 66 | return (
|
29 | 67 | <Layout.Screen>
|
30 | 68 | <Layout.Header.Outer>
|
@@ -69,6 +107,18 @@ export function AboutSettingsScreen({}: Props) {
|
69 | 107 | <Trans>System log</Trans>
|
70 | 108 | </SettingsList.ItemText>
|
71 | 109 | </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 | + )} |
72 | 122 | <SettingsList.PressableItem
|
73 | 123 | label={_(msg`Version ${appVersion}`)}
|
74 | 124 | accessibilityHint={_(msg`Copies build version to clipboard`)}
|
|
0 commit comments