Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Version 2.0
Browse files Browse the repository at this point in the history
- Add back default to nil for completion handler
- Fix inStyle not being set properly
- Added basic tests
- Minor refactoring
- Remove private access, made it internal
  • Loading branch information
Luis Padron authored and Luis Padron committed Jan 28, 2017
1 parent 0f2cf41 commit 214aebf
Show file tree
Hide file tree
Showing 16 changed files with 151 additions and 50 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Version 1.2.0


- Default completion handler to nil for `setProgress(:)`
- Fix issue with module version number, now actually supports __iOS 8__
- Added some basic tests for right now
- Refactor some comments
- Remove `private` access, set to `internal` for unit testing
- Fix default with inCapStyle being sett to wrong value

# Version 1.1.9


Expand Down
2 changes: 1 addition & 1 deletion UICircularProgressRing.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |s|

s.name = "UICircularProgressRing"
s.version = "1.1.9"
s.version = "1.2.0"
s.summary = "A highly customizable circular progress bar for iOS written in Swift 3"

s.description = <<-DESC
Expand Down
4 changes: 2 additions & 2 deletions UICircularProgressRing.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = UICircularProgressRing/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.luispadron.UICircularProgressRing;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -370,7 +370,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = UICircularProgressRing/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.luispadron.UICircularProgressRing;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
28 changes: 13 additions & 15 deletions UICircularProgressRing/UICircularProgressRingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ import UIKit
## Important ##
Default = 0

Recommended to assign value using setProgress(_:) instead as you have more control over what happens
This is public simply for storyboard support
The current value of the progress ring, use setProgress(value:) to alter the value with the option
to animate and have a completion handler.

## Author:
Luis Padron
Expand Down Expand Up @@ -164,7 +164,7 @@ import UIKit
I.e: 90 degrees is at the bottom and 270 degrees is at the top

## Important ##
Default = 0 (degrees)
Default = 360 (degrees)

Values should be in degrees (they're converted to radians internally)

Expand Down Expand Up @@ -244,13 +244,13 @@ import UIKit

/**

A private outerRingCapStyle variable, this is set whenever the
A internal outerRingCapStyle variable, this is set whenever the
IB compatible variable above is set.

Basically in here because IB doesn't support CGLineCap selection.

*/
private var outStyle: CGLineCap = .butt
internal var outStyle: CGLineCap = .butt

// MARK: Inner Ring properties

Expand Down Expand Up @@ -341,13 +341,13 @@ import UIKit

/**

A private innerRingCapStyle variable, this is set whenever the
A internal innerRingCapStyle variable, this is set whenever the
IB compatible variable above is set.

Basically in here because IB doesn't support CGLineCap selection.

*/
private var inStyle: CGLineCap = .butt
internal var inStyle: CGLineCap = .round

// MARK: Label

Expand Down Expand Up @@ -530,7 +530,7 @@ import UIKit
*/
override public init(frame: CGRect) {
super.init(frame: frame)
// Call the private initializer
// Call the internal initializer
initialize()
}

Expand All @@ -539,7 +539,7 @@ import UIKit
*/
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// Call the private initializer
// Call the internal initializer
initialize()
}

Expand All @@ -548,7 +548,7 @@ import UIKit
For some reason didSet doesnt get called during initializing, so
has to be done manually in here or else nothing would be drawn.
*/
private func initialize() {
internal func initialize() {
// Helps with pixelation and blurriness on retina devices
self.layer.contentsScale = UIScreen.main.scale
self.layer.shouldRasterize = true
Expand Down Expand Up @@ -589,7 +589,7 @@ import UIKit
/**
Typealias for the setProgress(:) method closure
*/
public typealias ProgressCompletion = (() -> Void)?
public typealias ProgressCompletion = (() -> Void)

/**
Sets the current value for the progress ring
Expand All @@ -604,7 +604,7 @@ import UIKit
## Author:
Luis Padron
*/
public func setProgress(value: CGFloat, animationDuration: TimeInterval, completion: ProgressCompletion = nil) {
public func setProgress(value: CGFloat, animationDuration: TimeInterval, completion: ProgressCompletion? = nil) {
// Only animte if duration sent is greater than zero
self.ringLayer.animated = animationDuration > 0
self.ringLayer.animationDuration = animationDuration
Expand All @@ -613,9 +613,7 @@ import UIKit
CATransaction.setCompletionBlock {
// Call the closure block
self.delegate?.finishedUpdatingProgress(forRing: self)
if let comp = completion {
comp()
}
completion?()
}
self.value = value
self.ringLayer.value = value
Expand Down
116 changes: 105 additions & 11 deletions UICircularProgressRingTests/UICircularProgressRingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,120 @@ import XCTest

class UICircularProgressRingTests: XCTestCase {

var progressRing: UICircularProgressRingView!

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.

progressRing = UICircularProgressRingView(frame: CGRect(x: 0, y: 0, width: 100, height: 200))
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()

progressRing = nil
}

func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}

func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
func testApiAndAnimations() {

progressRing.setProgress(value: 20, animationDuration: 2) {
XCTAssertEqual(self.progressRing.value, 20)
}

progressRing.setProgress(value: 23.1, animationDuration: 0)
XCTAssertEqual(progressRing.value, 23.1)

progressRing.setProgress(value: 17.9, animationDuration: 0, completion: nil)
XCTAssertEqual(progressRing.value, 17.9)

progressRing.setProgress(value: 100, animationDuration: 2) {
XCTAssertEqual(self.progressRing.value, 100) // Value should be set
XCTAssertEqual(self.progressRing.isAnimating, false) // No longer animating, this should be false
self.progressRing.setProgress(value: 25.32, animationDuration: 3, completion: {
XCTAssertEqual(self.progressRing.value, 25.32) // Value set
XCTAssertEqual(self.progressRing.isAnimating, false) // No longer animating, this should be false
})
}

// Since animation takes 2 seconds and happens concurrently, isAnimating should be true here
XCTAssertEqual(progressRing.isAnimating, true)
}

func testDefaultsAndSetters() {
// Check the defaults for the view, change them, then make sure they changed
XCTAssertNil(progressRing.delegate)

XCTAssertEqual(progressRing.value, 0)
progressRing.value = 50
XCTAssertEqual(progressRing.value, 50)

XCTAssertEqual(progressRing.maxValue, 100)
progressRing.maxValue = 200
XCTAssertEqual(progressRing.maxValue, 200)

XCTAssertEqual(progressRing.viewStyle, 1)
progressRing.viewStyle = 2
XCTAssertEqual(progressRing.viewStyle, 2)

XCTAssertEqual(progressRing.patternForDashes, [7.0, 7.0])
progressRing.patternForDashes = [6.0, 5.0]
XCTAssertEqual(progressRing.patternForDashes, [6.0, 5.0])

XCTAssertEqual(progressRing.startAngle, 0)
progressRing.startAngle = 90
XCTAssertEqual(progressRing.startAngle, 90)

XCTAssertEqual(progressRing.endAngle, 360)
progressRing.endAngle = 180
XCTAssertEqual(progressRing.endAngle, 180)


XCTAssertEqual(progressRing.outerRingWidth, 10)
progressRing.outerRingWidth = 5
XCTAssertEqual(progressRing.outerRingWidth, 5)

XCTAssertEqual(progressRing.outerRingColor, UIColor.gray)
progressRing.outerRingColor = UIColor.red
XCTAssertEqual(progressRing.outerRingColor, UIColor.red)

XCTAssertEqual(progressRing.outerRingCapStyle, 1)
XCTAssertEqual(progressRing.outStyle, .butt)
progressRing.outerRingCapStyle = 2
XCTAssertEqual(progressRing.outerRingCapStyle, 2)
XCTAssertEqual(progressRing.outStyle, .round)

XCTAssertEqual(progressRing.innerRingWidth, 5.0)
progressRing.innerRingWidth = 10.0
XCTAssertEqual(progressRing.innerRingWidth, 10.0)

XCTAssertEqual(progressRing.innerRingColor, UIColor.blue)
progressRing.innerRingColor = UIColor.green
XCTAssertEqual(progressRing.innerRingColor, UIColor.green)

XCTAssertEqual(progressRing.innerRingSpacing, 1)
progressRing.innerRingSpacing = 2
XCTAssertEqual(progressRing.innerRingSpacing, 2)

XCTAssertEqual(progressRing.innerRingCapStyle, 2)
XCTAssertEqual(progressRing.inStyle, .round)
progressRing.innerRingCapStyle = 3
XCTAssertEqual(progressRing.innerRingCapStyle, 3)
XCTAssertEqual(progressRing.inStyle, .square)

XCTAssertEqual(progressRing.shouldShowValueText, true)
progressRing.shouldShowValueText = false
XCTAssertEqual(progressRing.shouldShowValueText, false)

XCTAssertEqual(progressRing.fontColor, UIColor.black)
progressRing.fontColor = UIColor.darkText
XCTAssertEqual(progressRing.fontColor, UIColor.darkText)

XCTAssertEqual(progressRing.fontSize, 18)
progressRing.fontSize = 20
XCTAssertEqual(progressRing.fontSize, 20)

XCTAssertEqual(progressRing.animationStyle, kCAMediaTimingFunctionEaseIn)
progressRing.animationStyle = kCAMediaTimingFunctionLinear
XCTAssertEqual(progressRing.animationStyle, kCAMediaTimingFunctionLinear)
}
}
2 changes: 1 addition & 1 deletion docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-20)</p>
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-27)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
12 changes: 6 additions & 6 deletions docs/Classes/UICircularProgressRingView.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h3 class="section-name">Delegate</h3>
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">typealias</span> <span class="kt">ProgressCompletion</span> <span class="o">=</span> <span class="p">(()</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)?</span></code></pre>
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">typealias</span> <span class="kt">ProgressCompletion</span> <span class="o">=</span> <span class="p">(()</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>

</div>
</div>
Expand Down Expand Up @@ -196,8 +196,8 @@ <h3 class="section-name">Value Properties</h3>

<p>Default = 0</p>

<p>Recommended to assign value using setProgress(_:) instead as you have more control over what happens
This is public simply for storyboard support</p>
<p>The current value of the progress ring, use setProgress(value:) to alter the value with the option
to animate and have a completion handler.</p>

<p><a href='#author' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='author'>Author:</h2></p>

Expand Down Expand Up @@ -403,7 +403,7 @@ <h4>Declaration</h4>

<p><a href='#important' class='anchor' aria-hidden=true><span class="header-anchor"></span></a><h2 id='important'>Important</h2></p>

<p>Default = 0 (degrees)</p>
<p>Default = 360 (degrees)</p>

<p>Values should be in degrees (they&rsquo;re converted to radians internally)</p>

Expand Down Expand Up @@ -1233,7 +1233,7 @@ <h4>Declaration</h4>
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">setProgress</span><span class="p">(</span><span class="nv">value</span><span class="p">:</span> <span class="kt">CGFloat</span><span class="p">,</span> <span class="nv">animationDuration</span><span class="p">:</span> <span class="kt">TimeInterval</span><span class="p">,</span> <span class="nv">completion</span><span class="p">:</span> <span class="kt"><a href="../Classes/UICircularProgressRingView.html#/s:C22UICircularProgressRing26UICircularProgressRingView18ProgressCompletion">ProgressCompletion</a></span><span class="p">)</span></code></pre>
<pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">setProgress</span><span class="p">(</span><span class="nv">value</span><span class="p">:</span> <span class="kt">CGFloat</span><span class="p">,</span> <span class="nv">animationDuration</span><span class="p">:</span> <span class="kt">TimeInterval</span><span class="p">,</span> <span class="nv">completion</span><span class="p">:</span> <span class="kt"><a href="../Classes/UICircularProgressRingView.html#/s:C22UICircularProgressRing26UICircularProgressRingView18ProgressCompletion">ProgressCompletion</a></span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span></code></pre>

</div>
</div>
Expand Down Expand Up @@ -1294,7 +1294,7 @@ <h4>Parameters</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-20)</p>
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-27)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-20)</p>
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-27)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
2 changes: 1 addition & 1 deletion docs/Protocols/UICircularProgressRingDelegate.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ <h4>Parameters</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-20)</p>
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-27)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-20)</p>
<p>&copy; 2017 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2017-01-27)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.7.2</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
Loading

0 comments on commit 214aebf

Please sign in to comment.