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

Support timing function for animation. Fix #12 #13 #478

Merged
merged 9 commits into from May 17, 2017

Conversation

phimage
Copy link
Member

@phimage phimage commented May 11, 2017

Re pull #456
Timing function enum added TiminFunctionType

  • Add it to Animatable objects and AnimationConfiguration
  • Use this enum when possible instead of CAMediaTimingFunction

TODO

  • add more type in enum (see extension CAMediaTimingFunction)
  • add more type in enum see CAMediaTimingFunction( contructors in code
  • add custom type with control points in enum ?
  • manage spring animation or not, animation default value
  • Add an example
  • Update CHANGELOG
  • Documentation

@phimage phimage requested review from JakeLin and tbaranes May 11, 2017 06:29
@IBAnimatableBot
Copy link

IBAnimatableBot commented May 11, 2017

2 Warnings
⚠️ Big PR
⚠️ Consider adding supporting documentation to this change. Documentation can be found in the docs directory.

Generated by 🚫 Danger

@phimage phimage changed the title Support timing function for animation. Fix #12 #13 [WIP] Support timing function for animation. Fix #12 #13 May 11, 2017
@phimage phimage changed the title [WIP] Support timing function for animation. Fix #12 #13 Support timing function for animation. Fix #12 #13 May 11, 2017
@phimage phimage mentioned this pull request May 15, 2017
@tbaranes
Copy link
Member

@phimage Sorry it takes me time to review it, it's quite big and a lot to digest!
I have already a first comment: can you update the docs? I think you will the one to update is Documentation/APIs.md

@phimage
Copy link
Member Author

phimage commented May 15, 2017

No problem!

API doc has not been reverted https://github.com/IBAnimatable/IBAnimatable/blob/master/Documentation/APIs.md
I add timingFunction in "Animatable protocol" section.
If you think I can add something elsewhere, I will do it :)

I see x, y, repeat.. attributes in the same section, maybe old parameters, now directly in animationType

Copy link
Member

@tbaranes tbaranes left a comment

Choose a reason for hiding this comment

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

That's a HUGE work, thanks for doing this, it's an awesome feature.
I let a few comments, mainly typos / minor stuff, it looks pretty good to me 👍

Can you add the docs update once more? I think that's enough.

let c2 = (params[2].toFloat() ?? 0, params[3].toFloat() ?? 0)
self = .custom(c1, c2)

case "easeinsine":
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment as the ones above to keep the same structure as the enum?

case easeInExpo, easeOutExpo, easeInOutExpo
case easeInCirc, easeOutCirc, easeInOutCirc
case easeInBack, easeOutBack, easeInOutBack

Copy link
Member

Choose a reason for hiding this comment

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

Typo: there's one newline to remove

case "easeinoutback":
self = .easeInOutBack

default:
Copy link
Member

Choose a reason for hiding this comment

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

Same here, I know it's already explicit, but I think it's better to keep the same structure as the enums. It helps to follow

extension TimingFunctionType {

public var caType: CAMediaTimingFunction {
switch self {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, if you can add the comments to separate the main groups

Copy link
Member

Choose a reason for hiding this comment

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

Github didn't see as fixed, but it's fixed!


}

@available(iOSApplicationExtension 10.0, *)
Copy link
Member

Choose a reason for hiding this comment

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

iOSApplicationExtension, did you mean iOS?


}

internal extension CAAnimation {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to explicitly make it internal?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a way for me to mark dangerous extension
I want to use it internally but never let it public, or someone else does it.

With internal explicitly marked, people ask themselves why and edit carefully


internal extension CAAnimation {

// conveniant setter, getter not implemented
Copy link
Member

Choose a reason for hiding this comment

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

Typo: conveniant -> convenient

func timingFunctionSelected(_ timingFunction: TimingFunctionType)
}

class AnimationsTimingFunctionViewController: UIViewController {
Copy link
Member

Choose a reason for hiding this comment

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

final

@@ -12,13 +12,14 @@ private let fadeWayParams = ParamType(fromEnum: AnimationType.FadeWay.self)
private let axisParams = ParamType(fromEnum: AnimationType.Axis.self)
private let rotationDirectionParams = ParamType(fromEnum: AnimationType.RotationDirection.self)
private let positiveNumberParam = ParamType.number(min: 0, max: 50, interval: 2, ascending: true, unit:"")
private let numberParam = ParamType.number(min: -50, max: 50, interval: 5, ascending: true, unit: "")
private let numberParam = ParamType.number(min: -50, max: 200, interval: 10, ascending: true, unit: "")
private let repeatCountParam = ParamType.number(min: 1, max: 10, interval: 1, ascending: true, unit:"")

class AnimationsViewController: UIViewController {
Copy link
Member

Choose a reason for hiding this comment

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

final

Copy link
Member Author

Choose a reason for hiding this comment

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

I think do a PR to set all final it's a better choice
Because here it's not a new code here. But I copy this code to make my new controller :-)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I know that we didn't add the final at the beginning of this project, we should have this in our roadmap: add all the missing finals 💥

@tbaranes
Copy link
Member

tbaranes commented May 15, 2017

Just tested the example, great one. A few feedbacks:

  • At first, I though that the timing function will update the animation. Since it doesn't, you should either do it, or refactoring makes a subsections to "Animations" to have two possibilities: "View Animations", and "Timing functions"
  • The image in the navigation bar isn't explicit enough (I didn't get it at first), if you choose option 1 from the previous point, we should replace the image by a text, or move the button in a place even more visible / explicit
  • Since some timingFunctions are quite long, they are truncated in the picker. Can we add the selected name somewhere? Below the graph for example. I think we have this issue in others picker as well, time to take care of this by starting with this one? 😬
  • I know there's a few incoherence about this in the playground: should we have a "back" text and no title, or no "back" text and a title? By using "TimingFunctions", I would go for option 2 to make it more explicit, but it's up to you. Some day it would be great to uniformise that behaviour

@phimage
Copy link
Member Author

phimage commented May 15, 2017

The animation is updated in the previous view, TimingFunctionPickDelegate do it

But not all animation are compatible ie. Spring animation are not compatible
In the same way velocity, dumping are only for spring animation and update it will not affect a lot of animations
Maybe a documentation file with a list of animation with two columns: Spring animation and timing function animation(or cubic animation) will be necessary, to check option compatibility

I edit moveTo and moveBy to be compliant with the two modes.


Yes, the image is not explicit
I take an available image, a timer. I think about putting a timing function graph but failed to create it using my TimingFunctionView in navigation bar items.

…rable by timing function

Redesign back button and title for timing function picker controller
Typo, comment on TimingFunctiontType
@phimage
Copy link
Member Author

phimage commented May 15, 2017

So new change added

  • back button and navigation title for the timing function picker
  • icon changed to a Gear, and the button is enabled only if the selected animation is configurable using the timing function

Added on AnimationType two compute boolean variables to know is the animation use velocity and damping or use timing function
This method could help for future animation documentations

@SD10
Copy link
Member

SD10 commented May 15, 2017

@phimage this is great work! I may be able to leverage this approach to do more cleanup or adopt a similar strategy. love it!

Copy link
Member

@tbaranes tbaranes left a comment

Choose a reason for hiding this comment

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

@phimage Awesome! I agree with you that a docs about timing function compatibility would be great, but we can merged that one first. So, just the missing entry in the docs and that's ready to go 👍

@phimage
Copy link
Member Author

phimage commented May 16, 2017

For the doc, as I say, I do already something in main branch, see Animatable protocol
https://github.com/IBAnimatable/IBAnimatable/blob/master/Documentation/APIs.md

Copy link
Member

@tbaranes tbaranes left a comment

Choose a reason for hiding this comment

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

My bad, I misunderstood 😶

Copy link
Member

@JakeLin JakeLin left a comment

Choose a reason for hiding this comment

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

All good, great work 👍👍👍. Look forward to using it.

opacityAnimation.keyTimes = [0, 0.45, 1]
ring1ScaleAnimation.timingFunctions = [CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear), timingFunction]
opacityAnimation.timingFunctionsType = [.linear, .easeOutExpo]
Copy link
Member

Choose a reason for hiding this comment

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

good to encapsulate to an extension for timing function.

}

public extension Animatable where Self: UIView {
public extension Animatable {
Copy link
Member

Choose a reason for hiding this comment

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

I hope Swift can support the syntax like public extension Animatable where Self: UIView or UIBarItem later.

path.move(to: position)
path.addLine(to: CGPoint(x: xToMove, y: yToMove))

animatePosition(path: path, configuration: configuration, completion: completion)
Copy link
Member

Choose a reason for hiding this comment

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

Cool, before iOS 10, only Core Animation can apply custom timing.

}

/// This animation use timing function parameter.
public var isCubic: Bool {
Copy link
Member

Choose a reason for hiding this comment

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

Should it call something like doesSupportTimingFunction? I am not good at naming though 😂

@@ -41,6 +41,12 @@ open class AnimatableBarButtonItem: UIBarButtonItem, BarButtonItemDesignable, An
@IBInspectable open var damping: CGFloat = CGFloat.nan
@IBInspectable open var velocity: CGFloat = CGFloat.nan
@IBInspectable open var force: CGFloat = CGFloat.nan
@IBInspectable open var _timingFunction: String = "" {
Copy link
Member

Choose a reason for hiding this comment

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

This one should not be open. It only is used in Interface Builder. Please have a look at the comment around #218 (comment) . We don't want the _ properties be used in programmatical APIs.

@@ -47,8 +47,7 @@ public extension AnimatedTransitioning {
transition.subtype = subtype
}
transition.duration = self.transitionDuration(using: transitionContext)
// Use `EaseOutQubic` for system built-in transition animations. Thanks to @lexrus
transition.timingFunction = CAMediaTimingFunction(controlPoints: 0.215, 0.61, 0.355, 1)
transition.timingFunctionType = .easeOutCubic
Copy link
Member

Choose a reason for hiding this comment

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

Great 🎉

case custom((x: Float, y: Float), (x: Float, y: Float))
case spring(damping: Float)

// from http://easings.net/
Copy link
Member

Choose a reason for hiding this comment

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

👍


@available(iOS 10.0, *)
extension TimingFunctionType {
var cubicTimingParameters: UICubicTimingParameters {
Copy link
Member

Choose a reason for hiding this comment

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

Supper cool to support UIPropertyAnimator API.

@JakeLin
Copy link
Member

JakeLin commented May 17, 2017

@phimage thanks for such a great PR. I think PR is ready to go. Please have a look at this comment #478 (comment) for the _timingFunction. It should be internal like the other _ properties.

@phimage phimage merged commit 91a8338 into master May 17, 2017
@phimage phimage deleted the revert-473-revert-456-feature/timingfunction branch May 17, 2017 08:09
@phimage phimage added this to the 5.0 milestone May 17, 2017
@JakeLin
Copy link
Member

JakeLin commented May 18, 2017

@phimage Well done 🎉🎉🎉🎉🎉🎉

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

6 participants