sparrowcode / AlertKit

Native alert from Apple Music & Feedback. Contains Done, Heart & Message and other presets.

Home Page:https://sparrowcode.io/frameworks

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I needed to add a delegate or a completionHandler for when animation is done

waelsaad opened this issue · comments

commented

Hi,

Very nice library, I was just a bit suprised because the library didn't have a delegate that is triggered when the animation is complete. I am hoping something like this could be added so I can integrate the library using Swift Package Manager.

    /**
     Use this method for force dismiss controller. By default it call automatically.
     */
    @objc public func dismiss() {
        UIView.animate(withDuration: 0.2, animations: {
            self.alpha = 0
            self.transform = self.transform.scaledBy(x: 0.8, y: 0.8)
        }, completion: { finished in
            self.delegate?.didFinishAnimation()
            self.removeFromSuperview()
        })
    }

or adding a completionHandler
    public func present(completionHandler: @escaping (() -> Void)) {
        haptic.impact()
        keyWindow.addSubview(self)
        layoutIfNeeded()
        layoutSubviews()
        alpha = 0
        transform = transform.scaledBy(x: 0.8, y: 0.8)

        UIView.animate(withDuration: 0.2, animations: {
            self.alpha = 1
            self.transform = CGAffineTransform.identity
        }, completion: { _ in
            if let iconView = self.iconView as? SPAlertIconAnimatable {
                iconView.animate()
            }
            DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + self.duration) {
                self.dismiss(completionHandler: completionHandler)
            }
        })
    }

Very nice feature

Available in 3.0!