Spring

A representation of a spring's motion.

StructureiOS 17.0+macOS 14.0+tvOS 17.0+watchOS 10.0+Spring in SwiftUI

Declaration

React
type Spring =
  | 'bouncy'
  | 'smooth'
  | 'snappy'
  | { bouncy: { duration?: number; extraBounce?: number; }; }
  | { duration?: number; bounce?: number; }
  | { mass?: number; stiffness: number; damping: number; allowOverDamping?: boolean; }
  | { response: number; dampingRatio: number; }
  | { settlingDuration: number; dampingRatio: number; epsilon?: number; }
  | { smooth: { duration?: number; extraBounce?: number; }; }
  | { snappy: { duration?: number; extraBounce?: number; }; };
Swift
struct Spring

Pass a literal, or build one with SwiftUI.Spring from import { SwiftUI } from 'swiftui-react-native'.

Type properties

  • 'bouncy'SwiftUI.Spring.bouncy

    A spring with a predefined duration and higher amount of bounce.

  • 'smooth'SwiftUI.Spring.smooth

    A smooth spring with a predefined duration and no bounce.

  • 'snappy'SwiftUI.Spring.snappy

    A spring with a predefined duration and small amount of bounce that feels more snappy.

Type methods

Overview

Use this type to convert between different representations of spring parameters:

let spring = Spring(duration: 0.5, bounce: 0.3)
let (mass, stiffness, damping) = (spring.mass, spring.stiffness, spring.damping)
// (1.0, 157.9, 17.6)

let spring2 = Spring(mass: 1, stiffness: 100, damping: 10)
let (duration, bounce) = (spring2.duration, spring2.bounce)
// (0.63, 0.5)

You can also use it to query for a spring's position and its other properties for a given set of inputs:

func unitPosition(time: TimeInterval) -> Double {
    let spring = Spring(duration: 0.5, bounce: 0.3)
    return spring.position(target: 1.0, time: time)
}

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

See also

More in Animation.