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
Conversation
…ublic-changes"
Generated by 🚫 Danger |
With TimingFunction position is animated using centre point
@phimage Sorry it takes me time to review it, it's quite big and a lot to digest! |
No problem! API doc has not been reverted https://github.com/IBAnimatable/IBAnimatable/blob/master/Documentation/APIs.md I see x, y, repeat.. attributes in the same section, maybe old parameters, now directly in animationType |
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.
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": |
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.
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 | ||
|
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.
Typo: there's one newline to remove
case "easeinoutback": | ||
self = .easeInOutBack | ||
|
||
default: |
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.
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 { |
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.
Same as above, if you can add the comments to separate the main groups
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.
Github didn't see as fixed, but it's fixed!
|
||
} | ||
|
||
@available(iOSApplicationExtension 10.0, *) |
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.
iOSApplicationExtension
, did you mean iOS
?
|
||
} | ||
|
||
internal extension CAAnimation { |
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.
Is there a reason to explicitly make it internal
?
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.
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 |
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.
Typo: conveniant
-> convenient
func timingFunctionSelected(_ timingFunction: TimingFunctionType) | ||
} | ||
|
||
class AnimationsTimingFunctionViewController: UIViewController { |
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.
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 { |
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.
final
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.
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 :-)
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.
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 💥
Just tested the example, great one. A few feedbacks:
|
The animation is updated in the previous view, But not all animation are compatible ie. Spring animation are not compatible I edit moveTo and moveBy to be compliant with the two modes. Yes, the image is not explicit |
…rable by timing function Redesign back button and title for timing function picker controller Typo, comment on TimingFunctiontType
So new change added
Added on AnimationType two compute boolean variables to know is the animation use velocity and damping or use timing function |
@phimage this is great work! I may be able to leverage this approach to do more cleanup or adopt a similar strategy. love it! |
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.
@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 👍
For the doc, as I say, I do already something in main branch, see Animatable protocol |
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.
My bad, I misunderstood 😶
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.
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] |
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.
good to encapsulate to an extension for timing function.
} | ||
|
||
public extension Animatable where Self: UIView { | ||
public extension Animatable { |
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.
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) |
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.
Cool, before iOS 10, only Core Animation can apply custom timing.
} | ||
|
||
/// This animation use timing function parameter. | ||
public var isCubic: Bool { |
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.
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 = "" { |
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.
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 |
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.
Great 🎉
case custom((x: Float, y: Float), (x: Float, y: Float)) | ||
case spring(damping: Float) | ||
|
||
// from http://easings.net/ |
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.
👍
|
||
@available(iOS 10.0, *) | ||
extension TimingFunctionType { | ||
var cubicTimingParameters: UICubicTimingParameters { |
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.
Supper cool to support UIPropertyAnimator
API.
@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 |
@phimage Well done 🎉🎉🎉🎉🎉🎉 |
Re pull #456
Timing function enum added
TiminFunctionType
Animatable
objects andAnimationConfiguration
CAMediaTimingFunction
TODO
extension CAMediaTimingFunction
)CAMediaTimingFunction(
contructors in code