【发布时间】:2019-04-17 07:24:03
【问题描述】:
我有一个应用程序,它显示了我从 API 加载的多个图像。现在的问题是某些图像已过期,这导致 Android 出现问题,在 Android 中,一旦过期图像加载到屏幕上,屏幕就会开始滞后。
我试过用onError={() => this.imgRefs[img_unique_id].setNativeProps({src: [{uri: this.state.workingUri}]})}这个方法替换图像源,但它不起作用。
我不能使用本地状态,因为它没有将输出保存在本地状态。
我试过下面的代码
<Image
source={image.url}
progressiveRenderingEnabled={true}
ref={item.id}
onError={(e) => this.refs[item.id].setNativeProps({source: [{uri: "working image URL"}]})}
resizeMethod={"scale"}>
</Image>
上面的代码给了我一个未定义的 setNativeProps 错误,如果我不在 android 上使用 onError,它会显示内存泄漏错误。
【问题讨论】:
-
这种情况下为什么不能使用本地状态?
-
只需使用
native-base而不是原始的 react-native 构造,native-baseImage通过为您提供支持fallbackSource甚至fallbackComponent来支持失败的图像
标签: react-native react-native-android react-native-image