KeyframeAnimator

A container that animates its content with keyframes.

ComponentiOS 17.0+macOS 14.0+tvOS 17.0+watchOS 10.0+KeyframeAnimator in SwiftUI

Declaration

React
import { KeyframeAnimator } from 'swiftui-react-native';
Swift
nonisolated struct KeyframeAnimator<Value, KeyframePath, Content> where Value == KeyframePath.Value, KeyframePath : Keyframes, Content : View

Initializers

2 SwiftUI initializers back <KeyframeAnimator>. The props you pass pick one.

React
<KeyframeAnimator
  initialValue: any
  trigger: string | number | boolean
  content: (value: any) => ViewModifierChain
  keyframes: KeyframeTracks
>
  children?: ReactNode
</KeyframeAnimator>
Swift
nonisolated init(
    initialValue: Value,
    trigger: some Equatable,
    @ContentBuilder content: @escaping (Value) -> Content,
    @KeyframesBuilder<Value> keyframes: @escaping (Value) -> KeyframePath
)
  • initialValue*any

    The initial value that the keyframes will animate from.

  • trigger*string | number | boolean

    A value to observe for changes.

  • content*(value: any) => ViewModifierChain

    A content builder closure that takes the interpolated value generated by the keyframes as its single argument. Runs once, ahead of SwiftUI: numbers of the value it receives are symbolic, so nothing crosses to JavaScript on a frame.

  • childrenReactNode

    Content. The chain applies to it.

  • keyframes*KeyframeTracks

    Keyframes defining how the value changes over time. The current value of the animator is the single argument, which is equal to initialValue when the view first appears, then is equal to the end value of the previous keyframe animation on subsequent calls.

Also takes the common view props: modifiers, style and testID.

Overview

The content closure updates every frame while animating, so avoid performing any expensive operations directly within content.

From Apple’s SwiftUI documentation. Code samples there are Swift.

Relationships

Conforms to

  • View

See also

More in Animation.