【问题标题】:React Native Image https url not show image in lower api 23React Native Image https url不在较低的api 23中显示图像
【发布时间】:2020-11-07 07:15:20
【问题描述】:

我正在使用 react native 0.61.0 版本。反应 16.9.0 版本。我们的服务器启用 TLS 1.2 和 1.3。 api 请求在 api 23 以下工作正常,但只有图像不显示在图像组件中。

这是我的示例图像代码

//_renderImage = (image: any, index: number) => {
_renderImage = (image, index) => {
const { width } = Dimensions.get('window');
const { onPress, customSlide } = this.props;
const offset = { marginLeft: index === -1 ? -width : 0 };
const imageStyle = [styles.image, { width }, offset];

if (customSlide) {
  return customSlide({ item: image, style: imageStyle, index, width });
}

const imageObject = typeof image === 'string' ? { uri: image } : image;
const imageComponent = (
 <Image key={index} source={imageObject} style={[imageStyle]} resizeMethod="resize" resizeMode="cover" />
);

if (onPress) {
  return (
    <TouchableOpacity
      key={index}
      style={[imageStyle, offset]}
      onPress={() => onPress && onPress({ image, index })}
      delayPressIn={200}
    >
      {imageComponent}
    </TouchableOpacity>
  );
}

return imageComponent;

};

 <ImageSliders
          loop
          autoPlayWithInterval={3000}
          images={images} // here i pass image url array
        />

在 android api 23 以上运行正常,但 api 23 及以下无法运行,任何人都知道为什么会发生这种情况。

【问题讨论】:

  • 可能是 typeof image === 'string' 条件为假或 onPress 道具条件为假。你能检查并分享图像 uri 的价值吗? _renderImage 在哪里调用?再分享一段代码
  • 这是 imageObject 的输出。 11-07 16:12:50.423 9723-9771/com.runitpass I/ReactNativeJS: 图像 {"uri":"runitpassapi.com/images/1603627007994.png"} 11-07 16:12:50.435 9723-9771/com.runitpass I/ReactNativeJS:输出图片 {"uri":"images.pexels.com/photos/164595/pexels-photo-164595.jpeg"}
  • 图像 uri 看起来不错。从图像中删除样式仅用于检查或仅使用 style={{wdith:xx, height: xx}}
  • 按照命令执行,仍然遇到同样的问题。

标签: android react-native


【解决方案1】:

尝试这样做

Change style={[imageStyle]} to style={imageStyle}

另一个变化可能是这样的

return onPress ? (
    <TouchableOpacity> 
      ......
      {imageComponent}
    </TouchableOpacity>
  ) : null;
}

【讨论】:

  • 这个也试试,结果一样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-23
  • 1970-01-01
  • 2019-05-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多