From ffbd03e35e1e7e6d869a318354f8aaf6faefad44 Mon Sep 17 00:00:00 2001 From: Masayuki Ono Date: Sun, 21 May 2017 12:18:39 +0900 Subject: [PATCH 1/6] Change to AnimatablePathView class from HasAnimatablePath protocol --- NativePopup/Animatable/AnimatableCrossView.swift | 5 ++--- NativePopup/Animatable/AnimatableDoneView.swift | 5 ++--- NativePopup/Animatable/HasAnimatablePath.swift | 11 ++++------- NativePopup/NativePopup.swift | 2 +- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/NativePopup/Animatable/AnimatableCrossView.swift b/NativePopup/Animatable/AnimatableCrossView.swift index 42d799d..18b0ac0 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 path: 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..f696bb9 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 path: 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/HasAnimatablePath.swift b/NativePopup/Animatable/HasAnimatablePath.swift index 75f0c29..024dcd3 100644 --- a/NativePopup/Animatable/HasAnimatablePath.swift +++ b/NativePopup/Animatable/HasAnimatablePath.swift @@ -8,13 +8,10 @@ import Foundation -public protocol HasAnimatablePath: HasAnimatableLayer { - var path: UIBezierPath { get } - func setupLayer() -} - -public extension HasAnimatablePath where Self: UIView { - public func setupLayer() { +open class AnimatablePathView: UIView, HasAnimatableLayer { + public let animatableLayer = CAShapeLayer() + open var path: UIBezierPath { return UIBezierPath() } + func setupLayer() { animatableLayer.path = path.cgPath animatableLayer.fillColor = UIColor.clear.cgColor animatableLayer.strokeColor = tintColor.cgColor 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() } From a728fd53f6412348a7f5dd17a46ad9642b503a39 Mon Sep 17 00:00:00 2001 From: Masayuki Ono Date: Sun, 21 May 2017 12:25:53 +0900 Subject: [PATCH 2/6] Chage Animatable protocol to internal from public --- NativePopup/Animatable/Animatable.swift | 4 ++-- NativePopup/Animatable/HasAnimatableLayer.swift | 6 +++--- NativePopup/Animatable/HasAnimatablePath.swift | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) 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/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 024dcd3..7e845a6 100644 --- a/NativePopup/Animatable/HasAnimatablePath.swift +++ b/NativePopup/Animatable/HasAnimatablePath.swift @@ -12,6 +12,7 @@ open class AnimatablePathView: UIView, HasAnimatableLayer { public let animatableLayer = CAShapeLayer() open var path: UIBezierPath { return UIBezierPath() } func setupLayer() { + let path = self.path animatableLayer.path = path.cgPath animatableLayer.fillColor = UIColor.clear.cgColor animatableLayer.strokeColor = tintColor.cgColor From a7b375ff7dcd310fb6f409aba171c84be82cfeff Mon Sep 17 00:00:00 2001 From: Masayuki Ono Date: Sun, 21 May 2017 12:27:46 +0900 Subject: [PATCH 3/6] Rename to animatablePath from path --- NativePopup/Animatable/AnimatableCrossView.swift | 2 +- NativePopup/Animatable/AnimatableDoneView.swift | 2 +- NativePopup/Animatable/HasAnimatablePath.swift | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NativePopup/Animatable/AnimatableCrossView.swift b/NativePopup/Animatable/AnimatableCrossView.swift index 18b0ac0..dc8585d 100644 --- a/NativePopup/Animatable/AnimatableCrossView.swift +++ b/NativePopup/Animatable/AnimatableCrossView.swift @@ -10,7 +10,7 @@ import Foundation class AnimatableCrossView: AnimatablePathView { var duration: TimeInterval { return 0.4 } - override 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 f696bb9..1f5ee32 100644 --- a/NativePopup/Animatable/AnimatableDoneView.swift +++ b/NativePopup/Animatable/AnimatableDoneView.swift @@ -9,7 +9,7 @@ import Foundation class AnimatableDoneView: AnimatablePathView { - override var path: UIBezierPath { + 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/HasAnimatablePath.swift b/NativePopup/Animatable/HasAnimatablePath.swift index 7e845a6..f54b9e8 100644 --- a/NativePopup/Animatable/HasAnimatablePath.swift +++ b/NativePopup/Animatable/HasAnimatablePath.swift @@ -10,9 +10,9 @@ import Foundation open class AnimatablePathView: UIView, HasAnimatableLayer { public let animatableLayer = CAShapeLayer() - open var path: UIBezierPath { return UIBezierPath() } + open var animatablePath: UIBezierPath { return UIBezierPath() } func setupLayer() { - let path = self.path + let path = self.animatablePath animatableLayer.path = path.cgPath animatableLayer.fillColor = UIColor.clear.cgColor animatableLayer.strokeColor = tintColor.cgColor From f9e8d6fb99d52597eebaa96388d457a23f633950 Mon Sep 17 00:00:00 2001 From: Masayuki Ono Date: Sun, 21 May 2017 12:28:20 +0900 Subject: [PATCH 4/6] Change to fatalError from empty UIBezierPath --- NativePopup/Animatable/HasAnimatablePath.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NativePopup/Animatable/HasAnimatablePath.swift b/NativePopup/Animatable/HasAnimatablePath.swift index f54b9e8..5059860 100644 --- a/NativePopup/Animatable/HasAnimatablePath.swift +++ b/NativePopup/Animatable/HasAnimatablePath.swift @@ -10,7 +10,7 @@ import Foundation open class AnimatablePathView: UIView, HasAnimatableLayer { public let animatableLayer = CAShapeLayer() - open var animatablePath: UIBezierPath { return UIBezierPath() } + open var animatablePath: UIBezierPath { fatalError("Should be overridden.") } func setupLayer() { let path = self.animatablePath animatableLayer.path = path.cgPath From 399443b725dd46cbe49b2f20167a1665d0590cf1 Mon Sep 17 00:00:00 2001 From: Masayuki Ono Date: Sun, 21 May 2017 12:28:30 +0900 Subject: [PATCH 5/6] Refactor --- NativePopup/Animatable/HasAnimatablePath.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/NativePopup/Animatable/HasAnimatablePath.swift b/NativePopup/Animatable/HasAnimatablePath.swift index 5059860..d024363 100644 --- a/NativePopup/Animatable/HasAnimatablePath.swift +++ b/NativePopup/Animatable/HasAnimatablePath.swift @@ -12,8 +12,7 @@ open class AnimatablePathView: UIView, HasAnimatableLayer { public let animatableLayer = CAShapeLayer() open var animatablePath: UIBezierPath { fatalError("Should be overridden.") } func setupLayer() { - let path = self.animatablePath - animatableLayer.path = path.cgPath + animatableLayer.path = animatablePath.cgPath animatableLayer.fillColor = UIColor.clear.cgColor animatableLayer.strokeColor = tintColor.cgColor animatableLayer.lineWidth = 9 From e14d890372550c4a3f89b600a49505399eccbea1 Mon Sep 17 00:00:00 2001 From: Masayuki Ono Date: Sun, 21 May 2017 12:29:32 +0900 Subject: [PATCH 6/6] Change animatableLayer to internal --- NativePopup/Animatable/HasAnimatablePath.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NativePopup/Animatable/HasAnimatablePath.swift b/NativePopup/Animatable/HasAnimatablePath.swift index d024363..36e2440 100644 --- a/NativePopup/Animatable/HasAnimatablePath.swift +++ b/NativePopup/Animatable/HasAnimatablePath.swift @@ -9,7 +9,7 @@ import Foundation open class AnimatablePathView: UIView, HasAnimatableLayer { - public let animatableLayer = CAShapeLayer() + let animatableLayer = CAShapeLayer() open var animatablePath: UIBezierPath { fatalError("Should be overridden.") } func setupLayer() { animatableLayer.path = animatablePath.cgPath