6

I want to consider all possible cases for loading an image.

My project allows the user to answer some questions based on some images. In ANDROID I have had problems in some occasions when these images are loaded. This causes a great negative impact, since the user has no idea what to answer.

Example code:

<Image
    style={styles.imageBackground}
    source={{ uri: obj.question }}/>

After many tests, it seems to fail for some strange reason. I have seen some topics about this here

Whatever the case (the above mentioned or simply in the process of loading the internet connection fails), I would like to be able to reload the images again.

It occurred to me to use onError event and put something there that would allow me to set the source for the second time

<Image
    ref={'image' + key}
    style={styles.imageBackground}
    source={{ uri: obj.question }}
    onError={(e) => {
        this.refs['image' + key].setNativeProps({ src: [{ uri: obj.question }] })
    }} />

The line inside the onError does not work for me. Even if it worked, there are some aspects that should be considered. For example, it could be causing an infinite loop and you would have to have a variable to control how many times the line would be in the onError line.

I would like to ask if this idea makes sense or if they have any other better.

PDTA:

1) Setting a defaultSource is not an option, as it would seriously affect the ux.

2) All images should load without problem, since they are previously stored in the server with fixed paths. This makes it very unlikely that images can not load. The only 2 shapes I can think of are the ones I mentioned above

jose920405
  • 7,982
  • 6
  • 45
  • 71

0 Answers0