我正在尝试为我正在创建的演示应用程序使用随机图像生成器。
我已经尝试过端点:
- http://thecatapi.com/api/images/get?format=src&type=gif&size=small
- http://junglebiscuit.com/images/random/rand_image.pl
但是当我将图像列表添加到我的页面时:
<View>
<Image
source={{ uri: 'http://thecatapi.com/api/images/get?format=src&type=gif&size=small' }}
style={{ width: 100, height: 100 }}
/>
<Image
source={{ uri: 'http://thecatapi.com/api/images/get?format=src&type=gif&size=small' }}
style={{ width: 100, height: 100 }}
/>
<Image
source={{ uri: 'http://thecatapi.com/api/images/get?format=src&type=gif&size=small' }}
style={{ width: 100, height: 100 }}
/>
</View>
期望对于每个Image
组件,将显示不同的图像。奇怪的是,这在 Android 上不起作用。图像或 url 似乎被缓存在某处,因此当使用相同的 URI 再次渲染图像时,会显示相同的图像。
我在 IOS 上尝试了相同的应用程序(该应用程序是使用 React Native expo.io 创建的)。图像与 IOS 上的预期不同,这似乎是 Android 特有的问题。
有没有办法阻止 android 缓存图像并在每次渲染 Image
组件时显示不同的图像?
最佳答案
到 2020 年,这仍然是 React Native 的一个问题(正如 Dishant Walia 提到的)。现在github上最好的解决方案是:
在url后添加查询字符串,适用于两个平台
<Image
style={styles.drawerAccountImg}
source={uri: this.state.photoURL + '?' + new Date()}
/>
关于android - React-Native 在 Android 上禁用图像缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52357246/