pedroabreu / ion-gallery

Ionic gallery directive
MIT License
124 stars 61 forks source link

Unable to update the pictures within the gallery #44

Closed MichaelApproved closed 8 years ago

MichaelApproved commented 8 years ago

I'm trying to change the src attribute of a gallery item after it was initially set. In version 0.1.8, I was able to change the item within the $scope array and the gallery would change the picture.

However, the current version, it doesn't make a difference in the gallery when I change the $scope.items[x].src value after it was initially set to something.

pedroabreu commented 8 years ago

I believe it's because of the thumbnail. The items.thumb is what's shown in the gallery view and because you're changing the src, it won't update the thumb property. Try updating the $scope.items[x].thumb as well

But this is an interesting use case. I'll have a think on how to change this, never liked the original implementation I made for it

MichaelApproved commented 8 years ago

Bingo! That did the trick. Thanks for the suggestion and creating the plugin.

The reason I'm updating the image is because I'm managing the cache myself. To load an image, I download it to the device and then feed the image data url because Android has a problem with the webview reading the file system directly. So, I initialize the gallery array with blank SRC attribute then load the image data URL and populate the gallery array with the data URL when I get the file system promise back.

In the future, I'll probably initialize the gallery array with a loading gif that's included with the app (Android webview can access files included with the app but not downloaded) and then switch to the data URL once that's been loaded.

This solution works well for my application. I'll leave it to you to decide if you'd like to close this or leave it open because you're considering changing the implementation for it.

Thanks again!

pedroabreu commented 8 years ago

Great! I'll leave it open for now because I want to have a second look at it.

I implemented the thumbnails a bit in a rush and it's probably a good time to have a second go at it.