简体   繁体   English

图像未显示在 React Native Image Tag 中

[英]Image is not displaying in React Native Image Tag

image not display in react native image tag with url: http://p16-sign-sg.tiktokcdn.com/v0201/242656049b324dff81b45d22479a1a61~tplv-noop.image?x-expires=1622659795&x-signature=CA4o%2BuzVVSTyUdH7T08a2%2FPgFpY%3D image not display in react native image tag with url: http://p16-sign-sg.tiktokcdn.com/v0201/242656049b324dff81b45d22479a1a61~tplv-noop.image?x-expires=1622659795&x-signature=CA4o%2BuzVVSTyUdH7T08a2%2FPgFpY%3D

const url='http://p16-sign-sg.tiktokcdn.com/v0201/242656049b324dff81b45d22479a1a61~tplv-noop.image?x-expires=1622659795&x-signature=CA4o%2BuzVVSTyUdH7T08a2%2FPgFpY%3D';
<Image
  style={styles.image}
  source={{ uri: url }}
  imageStyle={styles.imageRadius}
  defaultSource={require('assets/loadingImage.png')}
 />

This happened with me in older react native version, fixed after updating.这发生在我较旧的 react native 版本中,更新后修复。 Update react native version.更新反应原生版本。

This is maybe because You are using react native and iOS emulator version 14.这可能是因为您使用的是 react native 和 iOS 模拟器版本 14。

If you are using iOS emulator version 14 then follow these steps to fix your problem如果您使用的是 iOS 仿真器版本 14,请按照以下步骤解决您的问题

go to file ~> /node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m go 到文件 ~> /node_modules/react-native/Libraries/Image/RCTUIImageViewAnimated.m

go to lines 270-290 and you could see the code like this: go 到第 270-290 行,您可以看到如下代码:

- (void)displayLayer:(CALayer *)layer
{
  if (_currentFrame) {
    layer.contentsScale = self.animatedImageScale;
    layer.contents = (__bridge id)_currentFrame.CGImage;
  }
}

add an else statement to the if block and make it something like this:将 else 语句添加到 if 块并使其如下所示:

- (void)displayLayer:(CALayer *)layer
{
  if (_currentFrame) {
    layer.contentsScale = self.animatedImageScale;
    layer.contents = (__bridge id)_currentFrame.CGImage;
  }else {
    [super displayLayer:layer];
  }
}

Then close everything and run command.然后关闭一切并运行命令。 npm start -- --reset cache for clearing the cache and then launch the app using command npx react-native run-ios this should fix your problem. npm start -- --reset cache用于清除缓存,然后使用命令npx react-native run-ios启动应用程序,这应该可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM