我有一个头像组件,里面有以下 XML
<Image
source={avatars && avatars[deferredKey]
? { uri: avatars[deferredKey] } : defaultAvatar}
style={{
width: size, height: size, borderRadius: size / 2, ...containerStyle,
}}
onError={this.onError}
/>
当应用程序加载头像时为空,因此 defaultAvatar 加载,然后几秒钟后图像接收到新的道具,它应该切换到 uri 图像,但它无法做到这一点。
当我将代码更改为
<Image
source={{ uri: avatars[deferredKey] }}
style={{
width: size, height: size, borderRadius: size / 2, ...containerStyle,
}}
onError={this.onError}
/>
然后组件按预期工作,最初头像加载空白,几秒钟后它正确加载 uri 图像。
该问题似乎仅在头像必须从本地存储的资产切换到 uri 时才存在。