android - React-Native 在 Android 上禁用图像缓存

标签 android react-native caching expo

我正在尝试为我正在创建的演示应用程序使用随机图像生成器。

我已经尝试过端点:

  1. http://thecatapi.com/api/images/get?format=src&type=gif&size=small
  2. 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/

相关文章:

javascript - 使用 Redux-Saga 的 Firebase 身份验证不起作用

objective-c - ReactiveCocoa 中的缓存失效

使用给定单词列表的 Android 语音识别(在搜索小部件中)

ios - React Native Webview NSURLErrorDomain 1022

reactjs - 导航到不同屏幕时如何断开套接字

javascript - 使用 Javascript 加载和缓存图像并了解 HTTP 状态代码

c# - 在不同 session 之间共享一级缓存?

Android线程和数据库锁定

android - 如何在gridview中实现图片延迟加载

java - LinearLayout onShow 它将 ScrollView 向下移动