1.安装依赖
npm install rn-fetch-blob --save
npm install react-native-rn-cacheimage --save
2.导入
import {CacheHelper, AnimatedCacheImage} from 'react-native-rn-cacheimage';
3.使用
<AnimatedCacheImage
source={{
uri: 'picUrl',
}}
defaultSource={默认图片url}
style={{width: 500, height: 700}}
/>
4.获取缓存大小
_getSize = async () => {
try {
const value = await CacheHelper.getCacheSizeFormat();
} catch (error) {
// Error retrieving data
}
};
5.清除缓存
CacheHelper.clearCache();