-
Notifications
You must be signed in to change notification settings - Fork 202
Add in AnimationOption Objects #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -49,20 +49,22 @@ public extension Spruce { | |||||
| /// - sortFunction: the `SortFunction` used to determine the animation offsets for each subview | ||||||
| /// - prepare: a closure that will be called with each subview of `this` parent view | ||||||
| /// - animation: a `Animation` that will be used to animate each subview | ||||||
| /// - exclude: an array of views that the animation should skip over | ||||||
| /// - options: an array of AnimationOptions that should be applied to the Spruce animation | ||||||
| /// - recursiveDepth: an int describing how deep into the view hiearchy the subview search should go, defaults to 0 | ||||||
| /// - completion: a closure that is called upon the final animation completing. A `Bool` is passed into the closure letting you know if the animation has completed. **Note:** If you stop animations on the whole animating view, then `false` will be passed into the completion closure. However, if the final animation is allowed to proceed then `true` will be the value passed into the completion closure. | ||||||
| public func animate(withSortFunction sortFunction: SortFunction, prepare: PrepareHandler? = nil, animation: Animation, exclude: [UIView]? = nil, recursiveDepth: Int = 0, completion: CompletionHandler? = nil) { | ||||||
| var timedViews = sortFunction.timeOffsets(view: self.view, recursiveDepth: recursiveDepth) | ||||||
| public func animate(withSortFunction sortFunction: SortFunction, prepare: PrepareHandler? = nil, animation: Animation, options: [AnimationOption] = [], completion: CompletionHandler? = nil) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, to keep the "prepare by default" behavior:
Suggested change
|
||||||
|
|
||||||
| let optionsObject = AnimationOptionObject(options: options) | ||||||
|
|
||||||
| var timedViews = sortFunction.timeOffsets(view: self.view, recursiveDepth: optionsObject.recursiveDepth) | ||||||
| timedViews = timedViews.sorted { (left, right) -> Bool in | ||||||
| return left.timeOffset < right.timeOffset | ||||||
| } | ||||||
| for (index, timedView) in timedViews.enumerated() { | ||||||
| if let exclude = exclude, exclude.reduce(false, { $0 || $1 == timedView.spruceView.view }) { | ||||||
| if optionsObject.excludedViews.reduce(false, { $0 || $1 == timedView.spruceView.view }) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might it be cleaner to just say:
Suggested change
|
||||||
| continue | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
| guard let animatedView = timedView.spruceView.view else { | ||||||
| continue | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -67,6 +67,6 @@ open class ViewController: UIViewController { | |||||
| override open func viewDidAppear(_ animated: Bool) { | ||||||
| super.viewDidAppear(animated) | ||||||
|
|
||||||
| animationView?.spruce.animate(animations, duration: duration, animationType: animationType, sortFunction: sortFunction, prepare: false) | ||||||
| animationView?.spruce.animate(animations, duration: duration, animationType: animationType, sortFunction: sortFunction) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you accept the above suggestions restoring the "prepare by default" behavior, then this should be:
Suggested change
|
||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // | ||
| // Spruce.swift | ||
| // Spruce | ||
| // | ||
| // Copyright (c) 2017 WillowTree, Inc. | ||
|
|
||
| // 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 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. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| /// Defines the options for handling a Spruce animation | ||
| /// | ||
| /// - excludeViews: the views that should be excluded in the Spruce animation | ||
| /// - prepare: If set, then Spruce will handle the preparation of the animation for you. Meaning a reverse | ||
| /// transform will be applied so that the animation runs smoothly | ||
| /// - recursiveDepth: how far into the view hierarchy the animation should run | ||
| public enum AnimationOption { | ||
| case excludedViews([UIView]) | ||
| case prepare | ||
| case recursiveDepth(Int) | ||
| } | ||
|
|
||
|
|
||
| /// An internal object that is used to interpret the AnimationOption's | ||
| struct AnimationOptionObject { | ||
| var excludedViews: [UIView] = [] | ||
| var shouldPrepare: Bool = false | ||
| var recursiveDepth: Int = 0 | ||
|
|
||
| init(options: [AnimationOption]) { | ||
| for option in options { | ||
| switch option { | ||
| case .excludedViews(let views): | ||
| self.excludedViews = views | ||
| case .prepare: | ||
| self.shouldPrepare = true | ||
| case .recursiveDepth(let depth): | ||
| self.recursiveDepth = depth | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've reversed the default behavior here. Is that intentional? If not, this should be: