Coder Social home page Coder Social logo

rxswiftcommunity / rxkingfisher Goto Github PK

View Code? Open in Web Editor NEW
222.0 8.0 38.0 1.07 MB

Reactive extension for the Kingfisher image downloading and caching library

License: MIT License

Swift 84.97% Ruby 11.44% Shell 3.59%
swift ios image-downloader kingfisher rxswift reactivex sdwebimage

rxkingfisher's Introduction

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.

optionSelected // Observable<Resource> or Observable<Source>
    .bind(to: image.kf.rx.image(options: [.transition(.fade(0.2))])
    .disposed(by: disposeBag)

OR

optionSelected // Observable<Resource> or Observable<Source>    
    .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)

Retrieve an Image without an Image View

Every KingfisherManager supports fetching an image from a URL, returning a Single<Image>:

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.

rxkingfisher's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxkingfisher's Issues

sdwebimage?

Not an issue but why there is a "sdwebimage" tag while this is an extension for Kingfisher?

Reentrancy anomaly detected when using KingfisherManager

I'm trying to retrieve an image using the KingfisherManager like so:

func getImage(with path: String) -> Single<UIImage> {
        guard let url = URL(string: NetworkManager.getBaseUrl()) else {
            return Single.error(BaseError.doNothing)
        }
        let imageUrl = url.appendingPathComponent(path)
        
        guard let authToken = baseRepository.getLocalManager().getSessionData() else {
            return Single.error(BaseError.noSession)
        }
        
        let modifier = AnyModifier { request in
            var r = request
            r.setValue("Bearer \(authToken)", forHTTPHeaderField: "Authorization")
            return r
        }

        return KingfisherManager.shared.rx.retrieveImage(with: imageUrl,
                                                         options: [.requestModifier(modifier)])
    }

When the image is not valid, for example:

  • It's a svg image
  • token not sent

I get the following error:

⚠️ Reentrancy anomaly was detected.
  > Debugging: To debug this issue you can set a breakpoint in /[MyProject]/Pods/RxSwift/RxSwift/Rx.swift:96 and observe the call stack.
  > Problem: This behavior is breaking the observable sequence grammar. `next (error | completed)?`
    This behavior breaks the grammar because there is overlapping between sequence events.
    Observable sequence is trying to send an event before sending of previous event has finished.
  > Interpretation: This could mean that there is some kind of unexpected cyclic dependency in your code,
    or that the system is not behaving in the expected way.
  > Remedy: If this is the expected behavior this message can be suppressed by adding `.observeOn(MainScheduler.asyncInstance)`
    or by enqueuing sequence events in some other way.

With the following log, depending on which error I had. For example, in case it's a svg image:

Unhandled error happened: processorError(reason: Kingfisher.KingfisherError.ProcessorErrorReason.processingFailed(processor: Kingfisher.DefaultImageProcessor(identifier: ""), item: Kingfisher.ImageProcessItem.data(1368 bytes)))

I tried to silence the Reentrancy anomaly warning adding .observeOn(MainScheduler.asyncInstance) but it won't work.

Could this be in issue when detecting an error in the RxKingfisher library?

Thank you!

Not support with Kingfisher 5

I'm currently considering of moving from using Kingfisher 4 to 5, but I found that RxKingfisher only supported till 4. The reason to move is that there is better performance with more customization. I'd love to hear when the update is finally release to supper Kingfisher 5. Thanks

Allow Resource to be nil

..to match original Kingfisher

public func setImage(with resource: Resource?,
                     placeholder: Placeholder? = nil,
                     options: KingfisherOptionsInfo? = nil,
                     progressBlock: DownloadProgressBlock? = nil,
                     completionHandler: CompletionHandler? = nil) -> RetrieveImageTask

Cannot invoke 'bind' with an argument list of type '(to: Binder<Resource?>)'

Hi there, I'm just following the doc and receive "Cannot invoke 'bind' with an argument list of type '(to: Binder<Resource?>)'" error. Please help me check if my code have any issue

viewModel.user.map { user -> NSURL in return NSURL.init(string: user.avatar) ?? NSURL.init() } .bind(to: avatarImageView.kf.rx.image()) .disposed(by: rx.disposeBag)

RxSwift 6 support

Any idea when this is supposed to be up ? Previously in RxSwift 5 the Reactive struct didn't have any constraint on its Base but in RxSwift 6 however there's a new requirement for Base to be AnyObject and KingfisherWrapper is a struct therefore incompatible.

Update Cartfile to support Kingfisher v6

While Kingfisher 6 is supported since 2.0 version, Cartfile has not been updated since then.
Because of that, the wrong version is being installed.

Could you please update Cartfile and Cartfile.resolved accordingly?

Thank you in advance

Dependency version conflicts in Carthage

Installing RxKingfisher's 1.0.0 version causes to install RxSwift's 3.0.0.alpha.1 version in Carthage. I need to remove the RxKingfisher from the Cartfile.

Is anyone experiencing this in Xcode 11.1?

Do not compile because of `Use of undeclared type 'Image'`

Hi,

This library does not compile since a Kingfisher update I believe.
I replaced the ImageView type with KFCrossPlatformImageView
and Image type with KFCrossPlatformImage

Will it be updated?
I can create a PR for that if needed. (I am testing right now)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.