react-nativeimagebackground

React Native - set image as background using ImageBackground


I'm trying to render an Image as background, but is not working, I don't know why. Here is my code.

<ImageBackground
      source={require('../assets/images/logos/AFC.svg')}
      resizeMode="cover"
      style={styles.style}>
 </ImageBackground>

Solution

  • React Native does not directly support using SVG format images. In order to use SVG Images you must use 3rd party libraries. I suggest using react-native-svg. Which is a great library and here is a tutorial you can use to set it up.

    Your use case is to set it as a background image. It would be better to use png or jpg formats for use with Image Background component in react native. If you only have svg format of the image, then you can set it in View and control the view