Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image not showing on device for React Native movies tutorial on existing application

I'm currently doing the react native movies tutorial (https://facebook.github.io/react-native/docs/tutorial.html), and I am using a device to display the results. I used an existing project, put a view using storyboard, and subclassed it correctly. For some reason, the image is not being displayed, and a red box is being shown instead. Am I doing something wrong? My React code:

'use strict';  
var React = require('react-native');

var {
  AppRegistry,
  Image,
  StyleSheet,
  Text,
  View,
} = React;

var MOCKED_MOVIES_DATA = [
  {title: 'Title', year: '2015', posters: {thumbnail: 'http://i.imgur.com/UePbdph.jpg'}},
];
var styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  thumbnail: {
    width: 53,
    height: 81,
  },
});

var Movies = React.createClass({
  render: function() {
  var movie = MOCKED_MOVIES_DATA[0];
  return (
    <View style={styles.container}>
      <Text>{movie.title}</Text>
      <Text>{movie.year}</Text>
      <Image
        source={{uri: movie.posters.thumbnail}}
        style={styles.thumbnail}
      />
    </View>
  );
}

});

React.AppRegistry.registerComponent('Movies', () => Movies);

This is a screenshot of what is being displayed on my phone: enter image description here

like image 688
Andy Hadjigeorgiou Avatar asked Jun 08 '15 03:06

Andy Hadjigeorgiou


People also ask

How do I display an image in Uri in react native?

To load images in react native from URL you must specify the image width, and height. React native cannot determine the width and height from downloaded images. After specifying width, and height we can specify the URL to the image source prop. Inside this prop we will specify a uri which holds our image URL.

How do you add an image to a path in react native?

Image In Class Component In React Native To browse the image from the local disk first create a folder and put the image in that folder. You can copy and paste from other folder. After that provide the path of that image inside the require which is a property of source of Image tag.

How do I fetch an image from API in react native?

To fetch image from API with React, we can use the fetch function. We call fetch with the imageUrl to make a GET request to it. Then we call res. blob to convert the response object to a blob.


1 Answers

Just write https instead of http and it will work. But it will only work if the server accepts https. Otherwise change the info.plist file.

like image 122
Robi Avatar answered Oct 30 '22 15:10

Robi