0

I m on my way to create a scroll view for all countries with each one have a flag as an image and a name, my data that I am basing on is relading from an API, after API response I set the countries data in the state object and I call this.setSatet(newstate) to update the scroller view.

so, I am using this code to show up the flag of every country :

 {
  this.state.data_countries.map((country, index) => (
    <View key={country._id} style={styles.item}>
      <Image
        source={{
          uri: country.countryInfo.flag,
        }}
        style={{
          maxWidth: 40,
          maxHeight: 30,
          flex: 1,
        }}
        onError={this.test_error}
      ></Image>
      <Text
        style={{
          textAlign: "center",
          flex: 1,
        }}
      >
        {country.country}
      </Text>
    </View>
  ));
}

I made sure that the URI given is correct, I had added all the following network security to my android project :

    <?xml version="1.0" encoding="utf-8"?>
    <network-security-config>
    
        <domain-config cleartextTrafficPermitted="true">
<!-- THIS FOR THE DOMAIN OF MY IMAGES SOURCE  example : https://disease.sh/assets/img/flags/us.png-->
            <domain includeSubdomains="true">disease.sh</domain>
<!-- THIS FOR THE DOMAIN OF MY API -->
            <domain includeSubdomains="true">nepalcorona.info</domain>
        </domain-config>
        <base-config cleartextTrafficPermitted="true">
            <trust-anchors>
                <certificates src="system" />
            </trust-anchors>
        </base-config>
    </network-security-config>

I tested my application on an emulator and it is working fine, but it is not working on my real device I got image not showing an empty Image View, please who have any idea can help me, please share it. I have many hours looking for a solution but no way, please help.

1 Answers1

0

You should build your app with this command. react-native bundle --platform android --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --dev false --reset-cache --assets-dest android/app/src/main/res/ I also used URI for Imagebackground on my app and it worked well. Hope this helps you.

  • hi, thank you for your answer, I got this error with ur command ,Error: ENOENT: no such file or directory, open 'D:\Developpement\Applications\Android\Statistics Covid\workspace\covidstat\android\app\src\main\assets\index.android.bundle' , dos this means something to you ? – Med Mahdi Maarouf Jul 03 '20 at 16:32
  • Sorry, I forgot something. You should create `assets` folder manually before run the script. – Bogdan Jiang Jul 07 '20 at 22:18