PhaseAnimator

A container that animates its content by automatically cycling through a collection of phases that you provide, each defining a discrete step within an animation.

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

Declaration

React
import { PhaseAnimator } from 'swiftui-react-native';
Swift
nonisolated struct PhaseAnimator<Phase, Content> where Phase : Equatable, Content : View

Initializers

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

React
<PhaseAnimator
  phases: any[]
  onAnimation?: { returns: SwiftUI.Animation | null; perform?: (arg0: any) => void; }
>
  children?: ReactNode | ((arg0: any) => ReactNode)
</PhaseAnimator>
Swift
nonisolated init(
    _ phases: some Sequence<Phase>,
    @ContentBuilder content: @escaping (Phase) -> Content,
    animation: @escaping (Phase) -> Animation? = { _ in .default }
)
  • phases*any[]

    The sequence of phases to cycle through. Ensure that the sequence isn't empty. If it is, SwiftUI logs a runtime warning and also returns a visual warning as the output view.

  • childrenReactNode | ((arg0: any) => ReactNode)

    A content builder closure that takes the current phase as an input. Return a view that's based on the current phase.

    Swift content: (Phase) -> Content

  • onAnimation{ returns: SwiftUI.Animation | null; perform?: (arg0: any) => void; }

    A closure that takes the current phase as input. Return the animation to use when transitioning to the next phase. If you return nil, the transition doesn't animate. If you don't set this parameter, SwiftUI uses a default animation.

    Default `{ _ in .default }`Swift animation: (Phase) -> Animation?

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

Overview

Use one of the phase animator view modifiers like View.phaseAnimator(_:content:animation:) to create a phased animation in your app.

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

Relationships

Conforms to

  • View

See also

More in Animation.