jtrivedi / Wave

Wave is a spring-based animation engine for iOS and macOS that makes it easy to create fluid, interruptible animations that feel great.

Home Page:https://jtrivedi.github.io/Wave/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Major wave update

flocked opened this issue · comments

I created a major wave update.. I never submitted a request, so please help me with it.

Extended animation support

  • NSView/UIView:
    • frame, size, origin, center, alpha, backgroundColor, borderColor, borderWidth, shadowColor, shadowOpacity, shadowOffset, shadowRadius, transform, scale, rotation, translation, cornerRadius
  • CALayer
    • frame, bounds, size, origin, center, opacity, backgroundColor, borderColor, borderWidth, shadowColor, shadowOpacity, shadowOffset, shadowRadius, transform, scale, rotation, translation, cornerRadius
  • NSTextField/UITextField, UILabel, UITextView:
    • fontSize, textColor
  • NSScrollView/UIScrollView:
    • contentOffset, zoomFactor
  • NSWindow:
    • frame, size, alpha, backgroundColor
  • NSLayoutConstraint:
    • constant

Spring

  • Feature, properties and functions parity to SwiftUI's Spring.
  • smooth, bouncy, snappy presets
  • Spring(duration: CGFloat, bounce: CGFloat)

SpringAnimator

  • Now uses AnimatableData instead of SpringInterpolatable.
  • Double, Float, CGFloat, CGPoint, CGSize, CGRect, CATransform3D, WaveColor, CGColor, CGAffineTransform support AnimatableData by default.
public protocol AnimatableData: Equatable, Comparable {
    /// The type defining the data to animate.
    associatedtype AnimatableData: VectorArithmetic = Self
    /// The data to animate.
    var animatableData: AnimatableData { get }
    /// Initializes with animatable data.
    init(_ animatableData: AnimatableData)
    /// Scaled integral representation of the value.
    var scaledIntegral: Self { get }
    static var zero: Self { get }
}

##AnimatablePropertyProvider protocol
Extending a class with AnimatablePropertyProvider adds a animator: PropertyAnimator<Class> property.

To set/get a property animated use the keyPath on the animator.

extension NSView: AnimatablePropertyProvider { }

Wave.animate(withSpring: .bouncy) {
        myView.animator[\.frame] = newFrame // sets a new frame animated.
        let currentFrame = myView.animator[\.frame] // current frame (either the target of the spring animation or the frame)
}

This allows modularity. E.g.

extension NSView: AnimatablePropertyProvider { }

extension PropertyAnimator<NSView> {
    var frame: CGRect {
        get { self[\.frame] }
        set { self[\.frame] = newValue }
    }
}

myView.animator.frame = newFrame

extension CALayer: AnimatablePropertyProvider { }

extension PropertyAnimator<CALayer> {
    var opacity: CGFloat {
        get { self[\.opacity] }
        set { self[\.opacity] = newValue }
    }
}

myLayer.animator.opacity = 0.5