Search code examples
imagereact-nativerequirereact-native-flexbox

React Native require() network vs. static image resize


How come when I use a network image,

<View style={{flex: 1, alignItems: 'stretch'}}>
          <Image
           style={{flex: 1}}
           source={{uri: 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'}} />
</View>

it fills the page: Google logo stretched across screen

but when I use require() for a static image:

<View style={{flex: 1, alignItems: 'stretch'}}>
 <Image
  style={{flex: 1}}
  source={require('./googlelogo.png')} />
</View>

it doesn't? enter image description here

Running react-native 0.37.0. This code was added straight into a freshly react-native init-ed project, no 3rd party libraries or anything.


Solution

  • Probably you were having the same issue as this.

    Try setting the Image's width to null:

    <Image
      style={{flex: 1, width: null}}
      source={require('./googlelogo.png')} />