malkouz / ListPlaceholder

ListPlaceholder is a swift library allows you to easily add facebook style animated loading placeholder to your tableviews or collection views.
MIT License
638 stars 71 forks source link

allow duplicate cutout in cell #8

Open teonicel opened 6 years ago

teonicel commented 6 years ago

Hi i encountered an issue with the library unfortunately it allows you add multiple cutouts to cell which creates an visual bug by taking the previous cutout into the draw function the solution is below

fileprivate func addCutoutView()
    {

        var hasCutout: Bool = false

        for view in self.subviews {
            if !(view is CutoutView) {
                view.alpha = 0
            } else {
                hasCutout = true
            }
        }
        if !hasCutout {
            let cutout = CutoutView()
            cutout.frame = self.bounds
            cutout.backgroundColor = UIColor.clear

            self.addSubview(cutout)
            cutout.setNeedsDisplay()
            cutout.boundInside(self)
            self.ld_setCutoutView(cutout)
        }

    }
teonicel commented 6 years ago

Also an similar issue with visual deffect modified working code below

fileprivate func ld_addLoader()
    {
        if self.ld_getCutoutView() == nil {
            let gradient: CAGradientLayer = CAGradientLayer()
            gradient.frame = CGRect(x: 0, y: 0, width: self.bounds.size.width , height: self.bounds.size.height)
            self.layer.insertSublayer(gradient, at:0)
            self.configureAndAddAnimationToGradient(gradient)
        }

        self.addCutoutView()
    }
malkouz commented 6 years ago

please fork the library, then put your updates, then make a pull request.

I will be happy to accept your changes 😄