Search code examples
androidreact-nativereact-native-iosreact-native-image

React Native Image doesn't change


when I open the profile tab it loads an image (profile image) from an URL and if a user wants to change his image he can but when he does the image is changed on the Server but on the App it doesn't change but if I refresh the App it does change.

The URL doesn't change when the user logs he has a image on the URL and when he updates the image the URL is the same but the picture is different.

<Image style={{height: 70, width:70,borderRadius: 35}} source={{uri:'http://********************/'+GLOBAL.api_token}} />

Solution

  • if(imagechanged(localparam)) {
      <Image source={{uri:ImageURL}} /> 
    } else { 
      <Image source={{uri:ImageURL}} /> 
    }
    

    In if else you need to do same image URL but change is in condition.

    you just need to set local param to know image is changed in URL or not.

    For cache issue just add date param after the URL so every time its take new image. like follow

    imageURL = "http://localhost/image/id/image.jpg?time=" + new Date();