Start using `react-native-expo-image-cache`

This commit is contained in:
Zhiyuan Zheng 2020-12-24 11:12:40 +01:00
parent 97442b31db
commit dca138eb5c
No known key found for this signature in database
GPG Key ID: 078A93AB607D85E0
6 changed files with 50 additions and 7 deletions

View File

@ -32,10 +32,12 @@
"expo-web-browser": "~8.6.0", "expo-web-browser": "~8.6.0",
"i18next": "^19.8.4", "i18next": "^19.8.4",
"lodash": "^4.17.20", "lodash": "^4.17.20",
"pretty-bytes": "^5.5.0",
"react": "16.13.1", "react": "16.13.1",
"react-dom": "16.13.1", "react-dom": "16.13.1",
"react-i18next": "^11.8.4", "react-i18next": "^11.8.4",
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.0.tar.gz", "react-native": "https://github.com/expo/react-native/archive/sdk-40.0.0.tar.gz",
"react-native-expo-image-cache": "^4.1.0",
"react-native-gesture-handler": "~1.8.0", "react-native-gesture-handler": "~1.8.0",
"react-native-htmlview": "^0.16.0", "react-native-htmlview": "^0.16.0",
"react-native-image-zoom-viewer": "^3.0.1", "react-native-image-zoom-viewer": "^3.0.1",

View File

@ -45,14 +45,14 @@ const Core: React.FC<Props> = ({
</View> </View>
{(content || iconBack) && ( {(content || iconBack) && (
<View style={styles.back}> <View style={styles.back}>
{content && ( {content && content.length ? (
<Text <Text
style={[styles.content, { color: theme.secondary }]} style={[styles.content, { color: theme.secondary }]}
numberOfLines={1} numberOfLines={1}
> >
{content} {content}
</Text> </Text>
)} ) : null}
{iconBack && ( {iconBack && (
<Feather <Feather
name={iconBack} name={iconBack}

View File

@ -1,7 +1,9 @@
import React, { useCallback } from 'react' import React, { useCallback } from 'react'
import { Image, Pressable, StyleSheet } from 'react-native' import { Pressable, StyleSheet } from 'react-native'
import { Image } from 'react-native-expo-image-cache'
import { StyleConstants } from '@utils/styles/constants' import { StyleConstants } from '@utils/styles/constants'
import { useNavigation } from '@react-navigation/native' import { useNavigation } from '@react-navigation/native'
import { useTheme } from '@root/utils/styles/ThemeManager'
export interface Props { export interface Props {
queryKey?: QueryKey.Timeline queryKey?: QueryKey.Timeline
@ -9,6 +11,7 @@ export interface Props {
} }
const TimelineAvatar: React.FC<Props> = ({ queryKey, account }) => { const TimelineAvatar: React.FC<Props> = ({ queryKey, account }) => {
const { mode } = useTheme()
const navigation = useNavigation() const navigation = useNavigation()
// Need to fix go back root // Need to fix go back root
const onPress = useCallback(() => { const onPress = useCallback(() => {
@ -17,7 +20,7 @@ const TimelineAvatar: React.FC<Props> = ({ queryKey, account }) => {
return ( return (
<Pressable style={styles.avatar} onPress={onPress}> <Pressable style={styles.avatar} onPress={onPress}>
<Image source={{ uri: account.avatar_static }} style={styles.image} /> <Image uri={account.avatar_static} style={styles.image} />
</Pressable> </Pressable>
) )
} }

View File

@ -26,6 +26,9 @@ export default {
cancel: '$t(common:buttons.cancel)' cancel: '$t(common:buttons.cancel)'
} }
}, },
cache: {
heading: '清空缓存'
},
copyrights: { copyrights: {
heading: '版权信息' heading: '版权信息'
}, },

View File

@ -1,8 +1,9 @@
import React from 'react' import prettyBytes from 'pretty-bytes'
import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { ActionSheetIOS, StyleSheet, Text } from 'react-native' import { ActionSheetIOS, StyleSheet, Text } from 'react-native'
import { CacheManager } from 'react-native-expo-image-cache'
import { useDispatch, useSelector } from 'react-redux' import { useDispatch, useSelector } from 'react-redux'
import { MenuContainer, MenuRow } from '@components/Menu' import { MenuContainer, MenuRow } from '@components/Menu'
import { import {
changeBrowser, changeBrowser,
@ -23,6 +24,13 @@ const ScreenMeSettings: React.FC = () => {
const settingsBrowser = useSelector(getSettingsBrowser) const settingsBrowser = useSelector(getSettingsBrowser)
const dispatch = useDispatch() const dispatch = useDispatch()
const [cacheSize, setCacheSize] = useState<number>()
useEffect(() => {
const getCacheSize = async () =>
setCacheSize(await CacheManager.getCacheSize())
getCacheSize()
}, [])
return ( return (
<> <>
<MenuContainer> <MenuContainer>
@ -117,6 +125,15 @@ const ScreenMeSettings: React.FC = () => {
/> />
</MenuContainer> </MenuContainer>
<MenuContainer> <MenuContainer>
<MenuRow
title={t('content.cache.heading')}
content={cacheSize ? prettyBytes(cacheSize) : undefined}
iconBack='chevron-right'
onPress={async () => {
await CacheManager.clearCache()
setCacheSize(0)
}}
/>
<MenuRow <MenuRow
title={t('content.copyrights.heading')} title={t('content.copyrights.heading')}
iconBack='chevron-right' iconBack='chevron-right'

View File

@ -2390,6 +2390,11 @@ cross-spawn@^6.0.0, cross-spawn@^6.0.5:
shebang-command "^1.2.0" shebang-command "^1.2.0"
which "^1.2.9" which "^1.2.9"
crypto-js@^3.1.9-1:
version "3.3.0"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-3.3.0.tgz#846dd1cce2f68aacfa156c8578f926a609b7976b"
integrity sha512-DIT51nX0dCfKltpRiXV+/TVZq+Qq2NgF4644+K7Ttnla7zEzqc+kjJyiB96BHNyUTBxyjzRcZYpUdZa+QAqi6Q==
css-select@^2.1.0: css-select@^2.1.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/css-select/-/css-select-2.1.0.tgz#6a34653356635934a81baca68d0255432105dbef" resolved "https://registry.yarnpkg.com/css-select/-/css-select-2.1.0.tgz#6a34653356635934a81baca68d0255432105dbef"
@ -4101,7 +4106,7 @@ lodash.throttle@^4.1.1:
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4" resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
integrity sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ= integrity sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ=
lodash@^4, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.3.0, lodash@^4.5.0, lodash@^4.6.0: lodash@^4, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.4, lodash@^4.3.0, lodash@^4.5.0, lodash@^4.6.0:
version "4.17.20" version "4.17.20"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52"
integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==
@ -5075,6 +5080,11 @@ prettier-linter-helpers@^1.0.0:
dependencies: dependencies:
fast-diff "^1.1.2" fast-diff "^1.1.2"
pretty-bytes@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.5.0.tgz#0cecda50a74a941589498011cf23275aa82b339e"
integrity sha512-p+T744ZyjjiaFlMUZZv6YPC5JrkNj8maRmPaQCWFJFplUAzpIUTRaTcS+7wmZtUoFXHtESJb23ISliaWyz3SHA==
pretty-format@^24.7.0, pretty-format@^24.9.0: pretty-format@^24.7.0, pretty-format@^24.9.0:
version "24.9.0" version "24.9.0"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.9.0.tgz#12fac31b37019a4eea3c11aa9a959eb7628aa7c9" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-24.9.0.tgz#12fac31b37019a4eea3c11aa9a959eb7628aa7c9"
@ -5220,6 +5230,14 @@ react-is@^17.0.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.1.tgz#5b3531bd76a645a4c9fb6e693ed36419e3301339" resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.1.tgz#5b3531bd76a645a4c9fb6e693ed36419e3301339"
integrity sha512-NAnt2iGDXohE5LI7uBnLnqvLQMtzhkiAOLXTmv+qnF9Ky7xAPcX8Up/xWIhxvLVGJvuLiNc4xQLtuqDRzb4fSA== integrity sha512-NAnt2iGDXohE5LI7uBnLnqvLQMtzhkiAOLXTmv+qnF9Ky7xAPcX8Up/xWIhxvLVGJvuLiNc4xQLtuqDRzb4fSA==
react-native-expo-image-cache@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/react-native-expo-image-cache/-/react-native-expo-image-cache-4.1.0.tgz#649cbe9786249134d3eafed5baba50bbfa80c029"
integrity sha512-U6xHtuyalNZThhM11lu4+mRNSpJFkdh4dSLbWkKAj5QfY63cKlTnDVtv8c88njn71GHL4exEzf8hNKBMWhH37Q==
dependencies:
crypto-js "^3.1.9-1"
lodash "^4.17.4"
react-native-gesture-handler@~1.8.0: react-native-gesture-handler@~1.8.0:
version "1.8.0" version "1.8.0"
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-1.8.0.tgz#18f61f51da50320f938957b0ee79bc58f47449dc" resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-1.8.0.tgz#18f61f51da50320f938957b0ee79bc58f47449dc"