Skip to content

Commit

Permalink
Removed the Requirement to Define Size, Added Changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
ljw980105 committed Oct 6, 2018
1 parent 9fb03ff commit 88bbc76
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 15 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Change Log

This document lists changes made to this project for each new version.

## 1.2
### Changes
* Migrated to Swift 4.2
* Added the feature to add a gray backdrop
* Added the feature to reverse the direction of animation
* Removed the requirement to define the size property for the `.path` mode
1 change: 0 additions & 1 deletion JLActivityIndicator/ActivityIndicating.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ protocol ActivityIndicating {
var view: UIView? { get set }
var paths: [JLBezierPath] { get set }
var duration: Double { get set }
var size: CGSize { get set }
var reverseDirection: Bool { get set }
var enableBackdrop: Bool { get set }

Expand Down
1 change: 0 additions & 1 deletion JLActivityIndicator/ImageSpinner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class ImageSpinner: ActivityIndicating {
var paths: [JLBezierPath] = []
var image: UIImageView?
var duration: Double = 1
var size: CGSize = CGSize.zero
var view: UIView?
var reverseDirection: Bool = false
var enableBackdrop: Bool = false
Expand Down
5 changes: 0 additions & 5 deletions JLActivityIndicator/JLActivityIndicator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ public class JLActivityIndicator: UIView {
didSet { spinner.duration = duration }
}

/** The frame of the activity indicator will be a rectangle defined by this property. Only applies to the path mode. */
public var size: CGSize = CGSize(width: 60, height: 60) {
didSet { spinner.size = size }
}

/** Determines whether or not to reverse the direction of the animation. Applicable to both modes. */
public var reverseDirection: Bool = false {
didSet { spinner.reverseDirection = reverseDirection }
Expand Down
10 changes: 9 additions & 1 deletion JLActivityIndicator/PathSpinner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ class PathSpinner: ActivityIndicating {
var paths: [JLBezierPath] = [JLBezierPath()]
var shapeLayers: [CAShapeLayer] = []
var duration: Double = 1
var size: CGSize = CGSize(width: 60, height: 60)
var view: UIView?
var reverseDirection: Bool = false
var animatedView: UIView?
var enableBackdrop: Bool = false

private var animationKeys = [String]()

private lazy var size: CGSize = {
var maxWidth: CGFloat = 0, maxHeight: CGFloat = 0
for path in paths {
if maxWidth < path.strokePath.bounds.width { maxWidth = path.strokePath.bounds.width }
if maxHeight < path.strokePath.bounds.height { maxHeight = path.strokePath.bounds.height }
}
return CGSize(width: maxWidth, height: maxHeight)
}()

private lazy var backgroundSize: CGSize = {
return CGSize(width: size.width * 1.4, height: size.height * 1.4)
}()
Expand Down
15 changes: 12 additions & 3 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ MIT License

Copyright (c) 2018 Jing Wei Li and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 1 addition & 4 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ Supply custom `UIBezierPath` objects, and the code will draw one or many custom
// The code below produces the circular animation with the red color, as shown in the beginning.
let spinner = JLActivityIndicator(on: view, mode: .path)
spinner.paths = [JLBezierPath(strokeColor: UIColor.red, strokePath: UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 60, height: 60)))],
spinner.size = CGSize(width: 60, height: 60)
spinner.start()
DispatchQueue.global(qos: .userInitiated).async {
// time consuming task
Expand All @@ -90,7 +89,6 @@ path.addLine(to: CGPoint(x: 100, y: 60))

let spinner = JLActivityIndicator(on: view, mode: .path)
spinner.paths = [JLBezierPath(strokeColor: UIColor.red, strokePath: path)]
spinner.size = CGSize(width: 100, height: 100)
spinner.start()
```
![](https://raw.githubusercontent.com/ljw980105/JLActivityIndicator/master/Demos/Heartbeat.gif)
Expand All @@ -105,7 +103,7 @@ spinner.duration = 1.0 // defaults to 1 second
spinner.reverseDirection = false // defaults to false
spinner.enableBackdrop = false // defaults to false
```
For the `.path` mode, there are more customizable options. Adding more items to the `paths` array will cause all paths contained in the array to animate at the same time. Please make sure that the any paths contained in the `paths` array are contained within a rectangle defined by the `size` property.
For the `.path` mode, there are more customizable options. Adding more items to the `paths` array will cause all paths contained in the array to animate at the same time.

In addition, the `JLBezierPath` struct is a wrapper for the `UIBezierPath` that this library requests. You can customize the color, width and the actual bezier path of `JLBezierPath`.

Expand All @@ -117,7 +115,6 @@ let bezierPath = JLBezierPath(strokeWidth: 5.0,
strokeColor: UIColor.blue,
strokePath: UIBezierPath(ovalIn: CGRect(x: 0, y: 0, width: 40, height: 40)))

spinner.size = CGSize(width: 60, height: 60) // the spinner will be drawn in a rectangle defined by this property. Defaults to 60x60
spinner.duration = 1.0 // defaults to 1 second
spinner.reverseDirection = false // defaults to false
spinner.enableBackdrop = false // defaults to false
Expand Down

0 comments on commit 88bbc76

Please sign in to comment.