Krisiacik / ImageViewer

An image viewer à la Twitter
MIT License
2.53k stars 385 forks source link

Load URL direct #230

Open cchamnab opened 4 years ago

cchamnab commented 4 years ago

is it possible to load image using URL instead of download to UIImageView first ?

KevinLiou commented 4 years ago

is it possible to load image using URL instead of download to UIImageView first ?

My working code like this, using Kingfisher 5.0

import Kingfisher
// ...
let imgView = UIImageView()
let galleryItem = GalleryItem.image { imageCompletion in
    let pictureURL = URL(string: message.pictureURL)
    imgView.kf.setImage(with: pictureURL, options: nil) { result in
        guard let image = try? result.get().image else {
            return
        }
        imageCompletion(image)
    }
}
self.items.append(DataItem(imageView: imgView, galleryItem: galleryItem))
fukemy commented 4 years ago

@KevinLiou your code seem load all image url before push to gallery show, sorry for my bad question, does it cause delay before present galleryVC ?

KevinLiou commented 4 years ago

@KevinLiou your code seem load all image url before push to gallery show, sorry for my bad question, does it cause delay before present galleryVC ?

NO, because the picture files are downloaded asynchronously :)

fukemy commented 4 years ago

thanks, your code help me a lot