alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
307 stars 19 forks source link

Updating image file only works after app reboot #35

Closed Bernard996 closed 2 years ago

Bernard996 commented 2 years ago

I'm trying to updating or deleting an image dynamically based on user preferences, but the name must be the same. So, if I try ti use unlink, for exsample, to delete the image, the Image component keeps displaying it till I close and reopen the app. Same if I change the image but keep the name. Is there a way to make it work? Even updating the states doesn't work

alpha0010 commented 2 years ago

I am presuming https://reactnative.dev/docs/image . From what I can tell, there is no built in reload from file api. You could try:

  1. replace file on disk
  2. unmount <Image /> (conditionally render null)
  3. remount <Image />

Or:

  1. replace file on disk
  2. change <Image /> source to target some placeholder/blank file
  3. change <Image /> source back to the original target

The thing is, react native is designed to mimic how interactions work on websites. When loading an image from a specific path, browsers tend to assume the same uri always yields the same image. I would recommend considering your app design, to see if it really is necessary to use the same name, or if using a unique name per image can work.

Bernard996 commented 2 years ago

Got it, thank you