Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mono0926 committed May 21, 2017
1 parent 208a5dc commit 7f17837
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 31 deletions.
6 changes: 5 additions & 1 deletion NativePopup.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
FE4CECF61ED1171400D5DB31 /* AnimatableCrossView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE4CECF51ED1171400D5DB31 /* AnimatableCrossView.swift */; };
FE4CECF81ED119F800D5DB31 /* HasAnimatablePath.swift in Sources */ = {isa = PBXBuildFile; fileRef = FE4CECF71ED119F800D5DB31 /* HasAnimatablePath.swift */; };
FE8533901EAC7C92004BB756 /* NativePopup.h in Headers */ = {isa = PBXBuildFile; fileRef = FE85338E1EAC7C92004BB756 /* NativePopup.h */; settings = {ATTRIBUTES = (Public, ); }; };
FEB0316D1ECFF6770039A1C6 /* Preset.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEB0316C1ECFF6770039A1C6 /* Preset.swift */; };
FEB031711ECFF6A30039A1C6 /* Bundle.extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEB031701ECFF6A30039A1C6 /* Bundle.extension.swift */; };
Expand Down Expand Up @@ -56,6 +57,7 @@

/* Begin PBXFileReference section */
FE4CECF51ED1171400D5DB31 /* AnimatableCrossView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnimatableCrossView.swift; sourceTree = "<group>"; };
FE4CECF71ED119F800D5DB31 /* HasAnimatablePath.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HasAnimatablePath.swift; sourceTree = "<group>"; };
FE85338B1EAC7C92004BB756 /* NativePopup.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = NativePopup.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FE85338E1EAC7C92004BB756 /* NativePopup.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NativePopup.h; sourceTree = "<group>"; };
FE85338F1EAC7C92004BB756 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -129,9 +131,10 @@
FEB0316C1ECFF6770039A1C6 /* Preset.swift */,
FEB031721ECFF6E00039A1C6 /* InitialEffectType.swift */,
FEB031741ECFFB6C0039A1C6 /* Animatable.swift */,
FEB031761ECFFE120039A1C6 /* AnimatableDoneView.swift */,
FEB031781ED014D70039A1C6 /* HasAnimatableLayer.swift */,
FEB031761ECFFE120039A1C6 /* AnimatableDoneView.swift */,
FE4CECF51ED1171400D5DB31 /* AnimatableCrossView.swift */,
FE4CECF71ED119F800D5DB31 /* HasAnimatablePath.swift */,
);
path = NativePopup;
sourceTree = "<group>";
Expand Down Expand Up @@ -285,6 +288,7 @@
FEB031791ED014D70039A1C6 /* HasAnimatableLayer.swift in Sources */,
FEB031751ECFFB6C0039A1C6 /* Animatable.swift in Sources */,
FECA87E31EACC7F000D07CB1 /* UIImageConvertible.swift in Sources */,
FE4CECF81ED119F800D5DB31 /* HasAnimatablePath.swift in Sources */,
FECA87F21EADBA3C00D07CB1 /* Extension.swift in Sources */,
FECA87D81EAC7D9E00D07CB1 /* NativePopup.swift in Sources */,
FEB0316D1ECFF6770039A1C6 /* Preset.swift in Sources */,
Expand Down
19 changes: 3 additions & 16 deletions NativePopup/AnimatableCrossView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,16 @@

import Foundation

class AnimatableCrossView: UIView, HasAnimatableLayer {

class AnimatableCrossView: UIView, HasAnimatablePath {
let animatableLayer = CAShapeLayer()

var duration: TimeInterval { return 0.4 }

override func layoutSubviews() {
super.layoutSubviews()

var path: UIBezierPath {
let length = frame.width
let path = UIBezierPath()
path.move(to: CGPoint(x: length * 0.1, y: length * 0.1))
path.addLine(to: CGPoint(x: length * 0.9, y: length * 0.9))
path.move(to: CGPoint(x: length * 0.9, y: length * 0.1))
path.addLine(to: CGPoint(x: length * 0.1, y: length * 0.9))

animatableLayer.path = path.cgPath
animatableLayer.fillColor = UIColor.clear.cgColor
animatableLayer.strokeColor = tintColor.cgColor
animatableLayer.lineWidth = 9
animatableLayer.lineCap = kCALineCapRound
animatableLayer.lineJoin = kCALineCapRound
animatableLayer.strokeEnd = 0
layer.addSublayer(animatableLayer)
return path
}
}
17 changes: 3 additions & 14 deletions NativePopup/AnimatableDoneView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,14 @@

import Foundation

class AnimatableDoneView: UIView, HasAnimatableLayer {

class AnimatableDoneView: UIView, HasAnimatablePath {
let animatableLayer = CAShapeLayer()
override func layoutSubviews() {
super.layoutSubviews()

var path: UIBezierPath {
let length = frame.width
let path = UIBezierPath()
path.move(to: CGPoint(x: length * 0.196, y: length * 0.527))
path.addLine(to: CGPoint(x: length * 0.47, y: length * 0.777))
path.addLine(to: CGPoint(x: length * 0.99, y: length * 0.25))

animatableLayer.path = path.cgPath
animatableLayer.fillColor = UIColor.clear.cgColor
animatableLayer.strokeColor = tintColor.cgColor
animatableLayer.lineWidth = 9
animatableLayer.lineCap = kCALineCapRound
animatableLayer.lineJoin = kCALineCapRound
animatableLayer.strokeEnd = 0
layer.addSublayer(animatableLayer)
return path
}
}
27 changes: 27 additions & 0 deletions NativePopup/HasAnimatablePath.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// HasAnimatablePath.swift
// NativePopup
//
// Created by mono on 2017/05/21.
// Copyright © 2017 mono. All rights reserved.
//

import Foundation

protocol HasAnimatablePath: HasAnimatableLayer {
var path: UIBezierPath { get }
func setupLayer()
}

extension HasAnimatablePath where Self: UIView {
func setupLayer() {
animatableLayer.path = path.cgPath
animatableLayer.fillColor = UIColor.clear.cgColor
animatableLayer.strokeColor = tintColor.cgColor
animatableLayer.lineWidth = 9
animatableLayer.lineCap = kCALineCapRound
animatableLayer.lineJoin = kCALineCapRound
animatableLayer.strokeEnd = 0
layer.addSublayer(animatableLayer)
}
}
5 changes: 5 additions & 0 deletions NativePopup/NativePopup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public class NativePopup: UIView {
}

[self, effectView, imageView, titleLabel, messageLabel].forEach { $0.translatesAutoresizingMaskIntoConstraints = false }

if let animatable = imageView as? HasAnimatablePath {
imageView.layoutIfNeeded()
animatable.setupLayer()
}
}

private func show(duration: TimeInterval, initialEffectType: InitialEffectType) {
Expand Down

0 comments on commit 7f17837

Please sign in to comment.