javascript 无法使用带有 uri 的 React Native 显示图像
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30091398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to display image with React Native with uri
提问by csakon
I'm tinkering with React Native and am trying to simply display an image with the image library from a URL. When I run this, all that is shown is the 'React Native' text, but no image. What am I doing wrong?
我正在修改 React Native 并尝试简单地从 URL 显示带有图像库的图像。当我运行它时,显示的只是“React Native”文本,但没有图像。我究竟做错了什么?
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Image,
Text,
View,
} = React;
var AwesomeProject = React.createClass({
render: function() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
React Native
</Text>
<Image
source={{uri: 'http://facebook.github.io/react/img/logo_og.png'}}
/>
</View>
);
}
});
回答by boredgames
Try giving the image component a height and width value.
尝试给图像组件一个高度和宽度值。
<Image style= {{ height:50, width: 50 }} >
回答by ArtixZ
flex: 1,
width: null,
height: null,
resizeMode: 'cover',
This style will make image flexible and cover the whole container
这种风格将使图像灵活并覆盖整个容器
回答by Kristina Darroch
In iOS you are unable to receive http requests, only https. Try adding this to your info.plistfile in xcode (make sure it is in this order exactly):
在 iOS 中,您无法接收 http 请求,只能接收 https。尝试将其添加到xcode 中的info.plist文件中(确保它完全按照此顺序):
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>example.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
回答by Dulanga Heshan
when we use an image in react-native the image will not expand to fill the space available to it by default instead we have to add style rule that how big the image should be.if your not add style for image with height and width you cant appear the image
当我们在 react-native 中使用图像时,默认情况下图像不会扩展以填充它可用的空间,而是我们必须添加图像应该有多大的样式规则。如果您没有为具有高度和宽度的图像添加样式无法显示图像