Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native: image not show when not set width or height

rn version : 0.38

just specify the image style using flex, no width and height, but Image will not show on mobile screen. How to do this.

<View style={styles.container}>
    <Image style={styles.image} source={{uri : 'https://www.baidu.com/img/bd_logo1.png'}}>
    </Image>
</View>



const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  image: {
     flex: 1,
    resizeMode: 'contain'
  },
});
like image 977
youhan26 Avatar asked Dec 01 '16 12:12

youhan26


1 Answers

Network images require you to set height/width style props.

React Native Documentation.

Many of the images you will display in your app will not be available at compile time, or you will want to load some dynamically to keep the binary size down. Unlike with static resources, you will need to manually specify the dimensions of your image.

// GOOD
<Image source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}}
       style={{width: 400, height: 400}} />

// BAD
<Image source={{uri: 'https://facebook.github.io/react/img/logo_og.png'}} />
like image 92
BradByte Avatar answered Oct 15 '22 22:10

BradByte