Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom activity indicator issue Swift 4 #872

Closed
3 tasks done
alfasolutions opened this issue Mar 3, 2018 · 7 comments · Fixed by #878
Closed
3 tasks done

Custom activity indicator issue Swift 4 #872

alfasolutions opened this issue Mar 3, 2018 · 7 comments · Fixed by #878

Comments

@alfasolutions
Copy link

alfasolutions commented Mar 3, 2018

Check List

Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked.

Issue Description

When creating struct conforming to Indicator protocol as described in Cheat Sheet the view is empty and nothing happens.

What

The func startAnimatingView() never gets called and logging imageView.kf.indicator prints out nil.

Reproduce

override func viewDidLoad() {
    super.viewDidLoad()
    //Set image
    struct MyIndicator: Indicator {
        let view: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
        
        func startAnimatingView() { print("start"); view.isHidden = false }
        func stopAnimatingView() { view.isHidden = true }
        
        init() {
            view.backgroundColor = UIColor.blue
        }
    }
    
    galleryImageView.kf.indicatorType = .custom(indicator: MyIndicator())
    galleryImageView.kf.setImage(with: media.image, completionHandler: { (image,error, cacheType, url) in
        if let image = image {
            let scale = image.scale
            self.imageWidthConstraint.constant = image.size.width * scale
            self.imageHeightConstraint.constant = image.size.height * scale
            self.updateMinZoomScaleForSize(self.view.bounds.size)
            self.updateConstraintsForSize(self.view.bounds.size)
            self.scrollView.setZoomScale(self.minimumZoomScale, animated: false)
            self.view.setNeedsLayout()
            self.view.layoutIfNeeded()
        }
    })

Other Comment

Am I doing something wrong here, or is this an issue with the current version of swift or something.

Thanks in advance.

@onevcat
Copy link
Owner

onevcat commented Mar 16, 2018

@alfasolutions It seems that associated object does not work well with Swift protocol, even it is marked to receive Any? now.

A workaround is in #878 and I think we could release it later as an update.

@onevcat
Copy link
Owner

onevcat commented Mar 16, 2018

Thanks for reporting this!

@chyrta
Copy link

chyrta commented Mar 19, 2018

Thanks for resolving the issue.
@onevcat When are you going to release a new version?

@onevcat
Copy link
Owner

onevcat commented Mar 20, 2018

@chyrta Sorry for the delay. But I guess I could not do a release until approximate 10hrs later. I would release it tonight (JST)!

@chyrta
Copy link

chyrta commented Mar 20, 2018

@onevcat Nice to hear that. Thanks for maintaining this cool library 👍

@manas-somoy
Copy link

manas-somoy commented Dec 25, 2018

hello. my custom indicator position is wrong. is this issue fixed? i made it as instructed in the documentation.

struct ImageIndicator: Indicator {
    let view: UIView = UIView()
    let lottie = LOTAnimationView(name: "mamaLoader")
    
    func startAnimatingView() {
        view.isHidden = false
        lottie.play()
    }
    func stopAnimatingView() {
        lottie.stop()
        view.isHidden = true
    }
    
    init() {
        view.backgroundColor = .clear
        view.layout(lottie).topBottom().leftRight()
    }
}

@onevcat
Copy link
Owner

onevcat commented Jan 13, 2019

@CHONUMAN Kingfisher will use the centerOffset and the image intrinsic size to determine the position. See this for more. You need to implement centerOffset for layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants