我想使用 image library 解决问题在 React Native 中:
当获取数据时,我得到一个带有图像 url 的 Json,它们显示在屏幕(图像)中,如果我在新的 Json 中更改图像的 url,则获取新的 Json已下载,但图像未在 View 中更新(好像有 android 的内部缓存)。
是否可以在没有任何外部库的情况下只删除图像缓存? 或者您建议在这种情况下使用哪个库?
非常感谢,希望得到解答。
最佳答案
据我所知,react-native 不支持开箱即用的清除缓存。您可以做的是快速破解。您可以将一个随机数(例如以毫秒为单位的当前日期)附加到要强制重新加载的图像 uri。因为 uri 改变了缓存的图像将不会被使用。
示例
export default class App extends Component {
render() {
const uri = 'https://picsum.photos/200/300?date=' + (new Date()).getTime();
return (
<View style={styles.container}>
<Image source={{uri}} style={{ width: 200, height: 300}} />
<Text style={styles.paragraph}>
Change code in the editor and watch it change on your phone!
Save to get a shareable url.
</Text>
</View>
);
}
}
关于android - 在 React Native 中重置内部 android 图像缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49603434/