RxSwiftCommunity / RxKingfisher

Reactive extension for the Kingfisher image downloading and caching library
MIT License
223 stars 39 forks source link
image-downloader ios kingfisher reactivex rxswift sdwebimage swift

RxKingfisher

RxKingfisher is a Reactive Extension for Kingfisher - a lightweight, pure-Swift library for downloading and caching images from the web.

RxKingfisher Example It provides Reactive Extensions on top of Kingfisher's `.kf` namespace, via `.kf.rx` and introduces two main usages: #### Bind URL to Image View by `Resource` or `Source` Every Image view supports two different options for binding a URL to an Image view. ```swift optionSelected // Observable or Observable .bind(to: image.kf.rx.image(options: [.transition(.fade(0.2))]) .disposed(by: disposeBag) ``` OR ```swift optionSelected // Observable or Observable .flatMap { url in imageView.kf.rx.setImage(with: url, options: [.transition(.fade(0.2))]) } .subscribe(onNext: { image in print("Image successfully loaded and set on Image view: \(image)") }) .disposed(by: disposeBag) ``` > ### Refer > `URL` is implementing `Resource` (See [Kingfisher.Resource.swift](https://github.com/onevcat/Kingfisher/blob/c598ab7a7b3f3a4778ab18076b3449a30fc8c0d3/Sources/General/ImageSource/Resource.swift#L71-L74)) ### Retrieve an Image without an Image View Every `KingfisherManager` supports fetching an image from a URL, returning a `Single`: ```swift tappedButton .flatMapLatest { KingfisherManager.shared.rx.retrieveImage(with: urlToImage) } .subscribe(onNext: { image in print("Image successfully loaded: \(image)") }) .disposed(by: disposeBag) ``` ### License RxKingfisher is released under the MIT license. See LICENSE for details.