evgenyneu / Auk

An image slideshow for iOS written in Swift.
MIT License
277 stars 44 forks source link

predownload images? #20

Closed valentinjahanmanesh closed 8 years ago

valentinjahanmanesh commented 8 years ago

hi i dont know if this lib could predownload remote images...mean, while user see the first image, other images in scrollview,download concurrently to speed up showing the images

is there any option for that?

evgenyneu commented 8 years ago

Hi, there is no option for this currently. It has been already asked at #8 so this is probably the feature worth implementing. We could do something like this:

scrollView.auk.settings.nextPagesToPreload = 2 // Default is 0.

This will ask Auk to start loading the next two images from the current one. For example, if we are viewing the first image it will preload 2 and 3. If we are viewing 5th, then it will load 4 and 6 (unless they already loaded). It would also need to be smart about cancelling the load requests as well. Right now if the images has not finished loading and user switch to the next, the network request for that image is cancelled (to give way for the current image to load quickly). This will need to be taken into consideration as well.

I have experimented with concurrent loading of images in the past and found that it is sometimes better to load images one by one rather than many at the same time. When you are outside of the WiFi and there is bad connection (which frequently happens on mobile), it is better to show just one first image quickly than spread this thin bandwidth on say 5 images. Either way, this could also be controller with an option:

scrollView.auk.settings.preloadImagesSimultaneously = true // Default is false.
valentinjahanmanesh commented 8 years ago

that would be great and i'll wait for those options <3 thanks good job, keep moving

evgenyneu commented 8 years ago

Thanks, @farshadjahanmanesh

evgenyneu commented 8 years ago

I will keep this open until it is implemented.

evgenyneu commented 8 years ago

The image preload settings has been implemented.

// Set the property before showing remote images
scrollView.auk.settings.preloadRemoteImagesAround = 1

More info here: https://github.com/evgenyneu/Auk#preloading-remote-images

Thanks for your feedback, @farshadjahanmanesh, I think it can be useful to many people.