Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to display image with React Native with uri

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?

'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>
    );
  }
});
like image 374
csakon Avatar asked May 07 '15 03:05

csakon


4 Answers

Try giving the image component a height and width value.

<Image style= {{ height:50, width: 50 }} >
like image 132
boredgames Avatar answered Sep 21 '22 23:09

boredgames


flex: 1,
width: null,
height: null,
resizeMode: 'cover',

This style will make image flexible and cover the whole container

like image 35
ArtixZ Avatar answered Sep 22 '22 23:09

ArtixZ


In iOS you are unable to receive http requests, only https. Try adding this to your info.plist file in xcode (make sure it is in this order exactly):

<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>
like image 33
Kristina Darroch Avatar answered Sep 23 '22 23:09

Kristina Darroch


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

like image 27
Dulanga Heshan Avatar answered Sep 21 '22 23:09

Dulanga Heshan