Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

javascript - Can't show Image in React Native

I'm using react-native 0.28.0

I'm trying to show an image on iPhone simulator according to this tutorial: Introduction to React Native: Building iOS Apps with JavaScript | Appcoda

var styles = StyleSheet.create({
image: {
    width: 107,
    height: 165,
    padding: 10
  }
}

var imageURI = 'http://books.google.com/books/content?id=PCDengEACAAJ&printsec=frontcover&img=1&zoom=1&source=gbs_api'

Then in the render() function, I add this:

<Image style={styles.image} source={{uri:imageURI}} />

The space allocated for the image is there, but the image is not shown.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Hope the following solutions can help you - all can be used for Image

1. HTTPS-Solution:

  1. Your picture is provided by an URI - source={{uri:imageURI}}
  2. Example: source={{uri: 'https://i.vimeocdn.com/portrait/58832_300x300.jpg'}}
  3. Important: Dont forget to set the clip twice: {{}}

2. HTTP-Solution:

  1. If you want http look the following solution - HTTP Github issue
  2. The solution: - HTTP-Solution

3. Local-Picture

  1. Save: Create a new folder for your images and save them locally there (folder: images)
  2. Require: Require the picture you saved locally by using the among syntax

var yourPicture = require ('./images/picture.jpg');

  • Notation for the same folder ('./')
  • Notation for the above folder ('../')
  • Notation for more folder above ('../../../')
  1. Use: Use your image in the render function
render(){
    return(
        <Image source={yourPicture}/>
    )
}

The style of your images works as you described


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...