Skip to content
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

Add in AnimationOption Objects #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jacksontaylor13
Copy link
Contributor

Looks like the parameters were getting too large for Spruce. Decided to try and have it with AnimationOptions instead so that the method length is customized based off of how much you need. This way it will be easier to read and add more options in the future like PR #95.

Also added in the documentation for the new features

Looks like the parameters were getting too large for Spruce. Decided to try and have it with AnimationOptions instead so that the method length is customized based off of how much you need. This way it will be easier to read and add more options in the future like PR willowtreeapps#95.

Also added in the documentation for the new features
Copy link
Contributor

@zackdotcomputer zackdotcomputer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to see this and an updated #95 merged in!

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 }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be cleaner to just say:

Suggested change
if optionsObject.excludedViews.reduce(false, { $0 || $1 == timedView.spruceView.view }) {
if optionsObject.excludedViews.contains(timedView.spruceView.view) {

@@ -90,9 +90,11 @@ public extension Spruce {
/// - sortFunction: the `sortFunction` to be used when setting the offsets for each subviews animation
/// - prepare: a `bool` as to whether we should run `prepare` on your view for you. If set to `true`, then we will run `prepare` right before the animation using the stock animations that you provided. If `false`, then `prepare` will not run. (default is `true`)
/// - 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(_ animations: [StockAnimation], duration: TimeInterval = 0.3, animationType: Animation, sortFunction: SortFunction, prepare: Bool = true, completion: CompletionHandler? = nil) {
public func animate(_ animations: [StockAnimation], duration: TimeInterval = 0.3, animationType: Animation, sortFunction: SortFunction, options: [AnimationOption] = [], completion: CompletionHandler? = nil) {
Copy link
Contributor

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:

Suggested change
public func animate(_ animations: [StockAnimation], duration: TimeInterval = 0.3, animationType: Animation, sortFunction: SortFunction, options: [AnimationOption] = [], completion: CompletionHandler? = nil) {
public func animate(_ animations: [StockAnimation], duration: TimeInterval = 0.3, animationType: Animation, sortFunction: SortFunction, options: [AnimationOption] = [.prepare], completion: CompletionHandler? = nil) {

/// - 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, to keep the "prepare by default" behavior:

Suggested change
public func animate(withSortFunction sortFunction: SortFunction, prepare: PrepareHandler? = nil, animation: Animation, options: [AnimationOption] = [], completion: CompletionHandler? = nil) {
public func animate(withSortFunction sortFunction: SortFunction, prepare: PrepareHandler? = nil, animation: Animation, options: [AnimationOption] = [.prepare], completion: CompletionHandler? = nil) {

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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
animationView?.spruce.animate(animations, duration: duration, animationType: animationType, sortFunction: sortFunction)
animationView?.spruce.animate(animations, duration: duration, animationType: animationType, sortFunction: sortFunction, options: [])

Copy link

@jackson13info jackson13info left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha. Whoops!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants