Skip to content

Commit

Permalink
Merge pull request #10 from mono0926/refactor
Browse files Browse the repository at this point in the history
Change to AnimatablePathView class from HasAnimatablePath protocol馃檱
  • Loading branch information
mono0926 committed May 21, 2017
2 parents ebf72a7 + e14d890 commit f7937ac
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 20 deletions.
4 changes: 2 additions & 2 deletions NativePopup/Animatable/Animatable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
5 changes: 2 additions & 3 deletions NativePopup/Animatable/AnimatableCrossView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 2 additions & 3 deletions NativePopup/Animatable/AnimatableDoneView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions NativePopup/Animatable/HasAnimatableLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions NativePopup/Animatable/HasAnimatablePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion NativePopup/NativePopup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit f7937ac

Please sign in to comment.