iosimagereact-nativereact-native-imageimagebackground

react native ImageBackground not showing on IOS device


I am using the ImageBackground component of react native, but in IOS (device) it is not displaying the image, in the simulator the image appears What can this be?

code below:

import { ImageBackground } from 'react-native';

const imgSrc = require('../../assets/images/bg-login.png');

<ImageBackground
        resizeMode="cover"
        source={imgSrc}
        style={style.backgroundImage}
      >

style below:

backgroundImage: {
        width: screenWidth,
        height: '100%'
    },

Solution

  • Did you add asset folder to your iOS build ?

    Here the commande to do it :

    react-native bundle --minify --entry-file index.js --platform ios --dev false --bundle-output ./ios/main.jsbundle --assets-dest ./ios 
    

    You will see asset folder and main.jsbundle file in the ios folder. After that go to Xcode -> build phases -> copy bundle resources and then add the asset folder and main.jsbundle file. Don't forget to click on the Copy if needed