diff --git a/NativePopup/Animatable/Animatable.swift b/NativePopup/Animatable/Animatable.swift index 638b3fc..0c8b781 100644 --- a/NativePopup/Animatable/Animatable.swift +++ b/NativePopup/Animatable/Animatable.swift @@ -8,11 +8,11 @@ import Foundation -public protocol Animatable { +protocol Animatable { func animate() var duration: TimeInterval { get } } -public extension Animatable { +extension Animatable { var duration: TimeInterval { return 0.3 } } diff --git a/NativePopup/Animatable/AnimatableCrossView.swift b/NativePopup/Animatable/AnimatableCrossView.swift index 42d799d..dc8585d 100644 --- a/NativePopup/Animatable/AnimatableCrossView.swift +++ b/NativePopup/Animatable/AnimatableCrossView.swift @@ -8,10 +8,9 @@ import Foundation -class AnimatableCrossView: UIView, HasAnimatablePath { - let animatableLayer = CAShapeLayer() +class AnimatableCrossView: AnimatablePathView { var duration: TimeInterval { return 0.4 } - var path: UIBezierPath { + override var animatablePath: UIBezierPath { let length = frame.width let path = UIBezierPath() path.move(to: CGPoint(x: length * 0.1, y: length * 0.1)) diff --git a/NativePopup/Animatable/AnimatableDoneView.swift b/NativePopup/Animatable/AnimatableDoneView.swift index e47dd99..1f5ee32 100644 --- a/NativePopup/Animatable/AnimatableDoneView.swift +++ b/NativePopup/Animatable/AnimatableDoneView.swift @@ -8,9 +8,8 @@ import Foundation -class AnimatableDoneView: UIView, HasAnimatablePath { - let animatableLayer = CAShapeLayer() - var path: UIBezierPath { +class AnimatableDoneView: AnimatablePathView { + override var animatablePath: UIBezierPath { let length = frame.width let path = UIBezierPath() path.move(to: CGPoint(x: length * 0.196, y: length * 0.527)) diff --git a/NativePopup/Animatable/HasAnimatableLayer.swift b/NativePopup/Animatable/HasAnimatableLayer.swift index 459fc67..a676dbe 100644 --- a/NativePopup/Animatable/HasAnimatableLayer.swift +++ b/NativePopup/Animatable/HasAnimatableLayer.swift @@ -8,12 +8,12 @@ import Foundation -public protocol HasAnimatableLayer: Animatable { +protocol HasAnimatableLayer: Animatable { var animatableLayer: CAShapeLayer { get } } -public extension HasAnimatableLayer { - public func animate() { +extension HasAnimatableLayer { + func animate() { let animation = CABasicAnimation(keyPath: "strokeEnd") animation.duration = duration animation.fromValue = 0 diff --git a/NativePopup/Animatable/HasAnimatablePath.swift b/NativePopup/Animatable/HasAnimatablePath.swift index 75f0c29..36e2440 100644 --- a/NativePopup/Animatable/HasAnimatablePath.swift +++ b/NativePopup/Animatable/HasAnimatablePath.swift @@ -8,14 +8,11 @@ import Foundation -public protocol HasAnimatablePath: HasAnimatableLayer { - var path: UIBezierPath { get } - func setupLayer() -} - -public extension HasAnimatablePath where Self: UIView { - public func setupLayer() { - animatableLayer.path = path.cgPath +open class AnimatablePathView: UIView, HasAnimatableLayer { + let animatableLayer = CAShapeLayer() + open var animatablePath: UIBezierPath { fatalError("Should be overridden.") } + func setupLayer() { + animatableLayer.path = animatablePath.cgPath animatableLayer.fillColor = UIColor.clear.cgColor animatableLayer.strokeColor = tintColor.cgColor animatableLayer.lineWidth = 9 diff --git a/NativePopup/NativePopup.swift b/NativePopup/NativePopup.swift index 2fb6ede..1a3ad92 100644 --- a/NativePopup/NativePopup.swift +++ b/NativePopup/NativePopup.swift @@ -110,7 +110,7 @@ public class NativePopup: UIView { [self, effectView, imageView, titleLabel, messageLabel].forEach { $0.translatesAutoresizingMaskIntoConstraints = false } - if let animatable = imageView as? HasAnimatablePath { + if let animatable = imageView as? AnimatablePathView { imageView.layoutIfNeeded() animatable.setupLayer() }