AnimationRunner

public final class AnimationRunner<Value> where Value: VectorConvertible

This class is used to drive a single animation to completion. It is one-shot, so a runner is no longer useful after the animation that it is driving completes.

  • They begin in a pending state.
  • Then enter the running state after start() is called.
  • If the animation finishes, the runner enters the completed (finished) state.
  • If cancel() is called on the runner while in a running state, the runner enters the completed (cancelled) state.
import Advance

let animation = 0.0.animation(
    to: 100.0,
    duration: 0.6,
    timingFunction: UnitBezier.easeIn)

let runner = AnimationRunner(animation: animation)
    .onChange { value in
        /// Do something with the value.
    }
    .onCancel {
        /// The animation was cancelled before it could finish.
    }
    .onFinish {
        /// The animation finished successfully.
     }

/// Kick off the animation
runner()

The resulting runner can be used to cancel the animation or to add additional observers or completion handlers.

  • Undocumented

    Declaration

    Swift

    private (set) public var state: State
  • Instantiates a new runner for the given animation.

    Declaration

    Swift

    public init<T>(animation: T) where T: Animation, T.Value == Value
  • Adds a handler that will be called every time the animation’s value changes.

    Newly added handlers are invoked immediately when they are added with the latest value from the animation.

    Declaration

    Swift

    public func onChange(_ handler: @escaping (Value) -> Void) -> AnimationRunner<Value>
  • Adds a handler that will be called when the animation completes (in either a finished or cancelled state).

    If the runner is already in a completed state, the given handler will be called immediately.

    Declaration

    Swift

    public func onCompletion(_ handler: @escaping (Result) -> Void) -> AnimationRunner<Value>
  • Adds a handler that will be called when the animation completes in a finished state.

    If the runner is already in a finished state, the given handler will be called immediately.

    Declaration

    Swift

    public func onFinish(_ handler: @escaping () -> Void) -> AnimationRunner<Value>
  • Adds a handler that will be called when the animation completes in a cancelled state.

    If the runner is already in a cancelled state, the given handler will be called immediately.

    Declaration

    Swift

    public func onCancel(_ handler: @escaping () -> Void) -> AnimationRunner<Value>
  • Starts the animation.

    If the runner is not in the pending state, calls to start() will have no effect.

    Declaration

    Swift

    public func start()
  • Cancels the animation.

    If the runner is not in the running state, calls to cancel() will have no effect.

    Declaration

    Swift

    public func cancel()
  • Undocumented

    Declaration

    Swift

    public var value: Value
  • Undocumented

    Declaration

    Swift

    public var velocity: Value
  • Undocumented

    Declaration

    Swift

    public func bound<T>(to object: T, keyPath: ReferenceWritableKeyPath<T, Value>) -> AnimationRunner<Value>