Skip to content

Commit

Permalink
Revert "Change to AnimatablePathView class from HasAnimatablePath pro…
Browse files Browse the repository at this point in the history
…tocol🙇"
  • Loading branch information
mono0926 committed May 21, 2017
1 parent f7937ac commit aa30c5a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 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

protocol Animatable {
public protocol Animatable {
func animate()
var duration: TimeInterval { get }
}

extension Animatable {
public extension Animatable {
var duration: TimeInterval { return 0.3 }
}
5 changes: 3 additions & 2 deletions NativePopup/Animatable/AnimatableCrossView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

import Foundation

class AnimatableCrossView: AnimatablePathView {
class AnimatableCrossView: UIView, HasAnimatablePath {
let animatableLayer = CAShapeLayer()
var duration: TimeInterval { return 0.4 }
override var animatablePath: UIBezierPath {
var path: UIBezierPath {
let length = frame.width
let path = UIBezierPath()
path.move(to: CGPoint(x: length * 0.1, y: length * 0.1))
Expand Down
5 changes: 3 additions & 2 deletions NativePopup/Animatable/AnimatableDoneView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

import Foundation

class AnimatableDoneView: AnimatablePathView {
override var animatablePath: UIBezierPath {
class AnimatableDoneView: UIView, HasAnimatablePath {
let animatableLayer = CAShapeLayer()
var path: 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

protocol HasAnimatableLayer: Animatable {
public protocol HasAnimatableLayer: Animatable {
var animatableLayer: CAShapeLayer { get }
}

extension HasAnimatableLayer {
func animate() {
public extension HasAnimatableLayer {
public func animate() {
let animation = CABasicAnimation(keyPath: "strokeEnd")
animation.duration = duration
animation.fromValue = 0
Expand Down
13 changes: 8 additions & 5 deletions NativePopup/Animatable/HasAnimatablePath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@

import Foundation

open class AnimatablePathView: UIView, HasAnimatableLayer {
let animatableLayer = CAShapeLayer()
open var animatablePath: UIBezierPath { fatalError("Should be overridden.") }
func setupLayer() {
animatableLayer.path = animatablePath.cgPath
public protocol HasAnimatablePath: HasAnimatableLayer {
var path: UIBezierPath { get }
func setupLayer()
}

public extension HasAnimatablePath where Self: UIView {
public func setupLayer() {
animatableLayer.path = path.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? AnimatablePathView {
if let animatable = imageView as? HasAnimatablePath {
imageView.layoutIfNeeded()
animatable.setupLayer()
}
Expand Down

0 comments on commit aa30c5a

Please sign in to comment.