Step TrayNew
One tray for a short flow: each step resizes the same surface on a spring while the red button morphs its label.
By Saivion
Live preview

Step Tray, a SwiftUI Multi-Step Bottom Sheet for iOS 17+, in its live preview. Open Code for the Swift source.
// Copyright (c) 2026 Saivion Hayes
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, and distribute the Software as part of
// an application, website, or product, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// Commons Clause Restriction
//
// You may use this Software, including for any commercial purpose, so long as
// you do not sell, sublicense, or redistribute the components themselves, whether
// alone, in a bundle, or as a ported version.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
import SwiftUI
import UIKit
/// Colors and shape of a `StepTray`. `.standard` is the house palette.
public struct StepTrayStyle: Sendable {
/// The tray's surface.
public var surface: Color
/// The hairline around the tray.
public var edge: Color
/// The button's fill: signal, the brand red.
public var action: Color
/// The button's text.
public var ink: Color
/// The tray's corner radius.
public var cornerRadius: CGFloat
/// Pass only what you want to change; `nil` keeps the house value.
public init(surface: Color? = nil, edge: Color? = nil, action: Color? = nil, ink: Color? = nil, cornerRadius: CGFloat = 36) {
self.surface = surface ?? stepTrayColor(light: 0xFFFFFF, dark: 0x1C1C1C)
self.edge = edge ?? Color(uiColor: .separator)
self.action = action ?? Color(red: 1, green: 0, blue: 0)
self.ink = ink ?? Color(red: 0x14 / 255, green: 0x14 / 255, blue: 0x14 / 255)
self.cornerRadius = cornerRadius
}
public static let standard = StepTrayStyle()
}
/// A tray that walks through a few steps in one surface: it resizes to each step's content on a spring, the steps
/// blur across, and its button keeps its place and morphs its label.
///
/// ```swift
/// @State private var step = 0
///
/// StepTray(step: step, button: ["Continue", "Send $40", "Done"][step]) {
/// if step < 2 { step += 1 } else { dismiss() }
/// } content: { step in
/// switch step {
/// case 0: AmountStep()
/// case 1: ReviewStep()
/// default: SentStep()
/// }
/// }
/// .padding()
/// .frame(maxHeight: .infinity, alignment: .bottom)
/// ```
///
/// - Parameters:
/// - step: Which step to show. Change it (from the button's action or anywhere) and the tray moves to it.
/// - button: The button's label for this step. It morphs letter by letter when it changes.
/// - style: Colors and corner radius. Defaults to the SwiftPieces house palette, adapting to light and dark.
/// - action: Runs when the button is tapped.
/// - content: The step's content, above the button. Give each step its natural height; the tray fits it.
public struct StepTray<Content: View>: View {
public typealias Style = StepTrayStyle
private let step: Int
private let button: String
private let style: Style
private let action: () -> Void
private let content: (Int) -> Content
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@State private var pressed = false
public init(step: Int, button: String, style: Style = .standard, action: @escaping () -> Void, @ViewBuilder content: @escaping (Int) -> Content) {
self.step = step
self.button = button
self.style = style
self.action = action
self.content = content
}
private var motion: PieceMotion { PieceMotion(reduceMotion: reduceMotion) }
public var body: some View {
let shape = RoundedRectangle(cornerRadius: style.cornerRadius, style: .continuous)
VStack(spacing: 20) {
ZStack(alignment: .top) {
content(step)
.frame(maxWidth: .infinity, alignment: .leading)
.id(step)
.transition(.asymmetric(
insertion: .modifier(active: StepTrayBlur(amount: 1), identity: StepTrayBlur(amount: 0)).animation(motion.reveal.delay(reduceMotion ? 0 : 0.12)),
removal: .modifier(active: StepTrayBlur(amount: 1), identity: StepTrayBlur(amount: 0)).animation(.easeOut(duration: 0.16))
))
}
.frame(maxWidth: .infinity, alignment: .top)
Button(action: action) {
PieceMorphText(text: button, font: .system(size: 17, weight: .semibold))
.foregroundStyle(style.ink)
.frame(maxWidth: .infinity)
.frame(height: 54)
.background(style.action, in: Capsule())
.contentShape(Capsule())
}
.buttonStyle(PiecePressStyle())
.accessibilityLabel(button)
}
.padding(.horizontal, 20)
.padding(.top, 24)
.padding(.bottom, 18)
.background(style.surface, in: shape)
.overlay { shape.strokeBorder(style.edge, lineWidth: 0.5) }
.clipShape(shape)
.shadow(color: .black.opacity(0.08), radius: 22, y: 10)
.fontWeight(.semibold)
.animation(motion.morph, value: step)
.sensoryFeedback(.impact(weight: .light), trigger: step)
.accessibilityElement(children: .contain)
}
}
/// A step coming or going: blurred, faded and nudged down a little. Under Reduce Motion the tray's spring is a
/// plain cross-fade, so this only fades.
private struct StepTrayBlur: ViewModifier {
var amount: CGFloat
func body(content: Content) -> some View {
content
.blur(radius: 8 * amount)
.opacity(1 - amount)
.offset(y: 8 * amount)
}
}
/// A house-palette colour that follows the interface style.
private func stepTrayColor(light: UInt32, dark: UInt32) -> Color {
Color(uiColor: UIColor { @Sendable traits in
let hex = traits.userInterfaceStyle == .dark ? dark : light
return UIColor(red: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: 1)
})
}
// MARK: - Example
/// Sending money in three steps: the amount, a review, and done. It walks through them on its own so the resize and
/// the label morph can be watched.
private struct StepTrayExample: View {
@State private var step = 0
var body: some View {
StepTray(step: step, button: ["Continue", "Send $40", "Done"][step]) {
step = (step + 1) % 3
} content: { step in
switch step {
case 0:
VStack(alignment: .leading, spacing: 14) {
HStack(spacing: 10) {
Text("MC")
.font(.caption)
.frame(width: 32, height: 32)
.background(Color(red: 1, green: 0.757, blue: 0.839), in: Circle())
.foregroundStyle(Color(red: 0x14 / 255, green: 0x14 / 255, blue: 0x14 / 255))
Text("Send to Maya")
}
Text("$40")
.font(.system(size: 56, weight: .semibold))
.frame(maxWidth: .infinity)
}
case 1:
VStack(alignment: .leading, spacing: 0) {
Text("Review")
.font(.title3)
.padding(.bottom, 8)
let rows = [["To", "Maya Chen"], ["Amount", "$40.00"], ["Fee", "Free"], ["Arrives", "Instantly"]]
ForEach(rows.indices, id: \.self) { index in
HStack {
Text(rows[index][0]).foregroundStyle(.secondary)
Spacer()
Text(rows[index][1])
}
.font(.subheadline)
.padding(.vertical, 9)
Divider()
}
}
default:
VStack(spacing: 8) {
Image(systemName: "checkmark.circle")
.font(.system(size: 48, weight: .semibold))
.foregroundStyle(Color(red: 1, green: 0, blue: 0))
.symbolEffect(.bounce, value: step)
Text("Sent")
.font(.title2)
Text("Maya gets it instantly")
.font(.subheadline)
.foregroundStyle(.secondary)
}
.frame(maxWidth: .infinity)
}
}
.padding(16)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
.background(stepTrayColor(light: 0xF3F2EE, dark: 0x121212))
.task {
while !Task.isCancelled {
try? await Task.sleep(for: .seconds(1.8))
step = (step + 1) % 3
}
}
}
}
#Preview("Light") {
StepTrayExample()
}
#Preview("Dark") {
StepTrayExample()
.preferredColorScheme(.dark)
}
// MARK: - Piece motion
//
// The SwiftPieces motion language: shared spring tokens and gesture physics, with the same values in every
// piece. Each piece carries a copy of only the parts it uses, so this file stands alone. Generated from
// registry/foundation/PieceMotion.swift in the SwiftPieces repo; edit it there, not here.
// swiftpieces-motion: 1.1.0 (core, pressMath, press, pressStyle)
/// The SwiftPieces motion language: five spring tiers, and a named role for every moment a piece moves,
/// each with its Reduce Motion substitute.
///
/// Build one from the environment, `PieceMotion(reduceMotion: reduceMotion)`, and pick the role that names
/// what just happened. Never animate the tracking of a finger: set gesture state directly in `onChanged`, so the
/// surface stays under the finger, and spring only the release.
private struct PieceMotion {
var reduceMotion = false
// Tiers. Overshoot and settle times are measured from rest with SwiftUI's Spring.
/// No overshoot, 90% in about 90ms. A press arriving under the finger.
static var tight: Spring { Spring(duration: 0.14, bounce: 0) }
/// About 2.8% overshoot, 90% in about 140ms. Snapping to a detent, page or segment.
static var responsive: Spring { Spring(duration: 0.32, bounce: 0.25) }
/// About 8.4% overshoot. Visible give: a release, a return from past an edge, a drag settling home.
static var elastic: Spring { Spring(duration: 0.42, bounce: 0.38) }
/// About 15% overshoot. A resolved action landing. At most once per interaction.
static var expressive: Spring { Spring(duration: 0.48, bounce: 0.48) }
/// About 1.5% overshoot, unhurried. Opening large surfaces and ambient change.
static var calm: Spring { Spring(duration: 0.5, bounce: 0.2) }
/// Reduce Motion: settles become this short spring with no overshoot.
private static var still: Animation { .spring(duration: 0.25, bounce: 0) }
// Roles.
/// Touch-down. Starts on the same frame and never bounces under the finger.
var press: Animation { .spring(Self.tight) }
/// The finger lifts off a pressed surface, which springs back through rest.
var release: Animation { reduceMotion ? Self.still : .spring(Self.elastic) }
/// A dragged thing comes to rest. With a gesture's velocity, use `settle(velocity:from:to:)` instead.
var settle: Animation { reduceMotion ? Self.still : .spring(Self.elastic) }
/// Lands on a detent, page or segment.
var snap: Animation { reduceMotion ? Self.still : .spring(Self.responsive) }
/// A number, a chart value or anything else people read moves to its new value. Never overshoots, so it
/// never shows a value that isn't true.
var value: Animation { reduceMotion ? Self.still : .spring(duration: 0.35, bounce: 0) }
/// Comes back from past a limit: a pull beyond the edge, a value pushed against its bound.
var rebound: Animation { reduceMotion ? Self.still : .spring(Self.elastic) }
/// A shape or container changes size, corner radius or form, with a little give at the end.
var morph: Animation { reduceMotion ? Self.still : .spring(duration: 0.4, bounce: 0.2) }
/// Something appears, opens or expands. Opening is a little slower than closing.
var reveal: Animation { reduceMotion ? .easeOut(duration: 0.2) : .spring(Self.calm) }
/// Something leaves, closes or collapses. Quick and firm, out of the way.
var dismiss: Animation { reduceMotion ? .easeIn(duration: 0.18) : .spring(duration: 0.3, bounce: 0.08) }
/// A resolved action lands: a check, a sent state, a reaction.
var success: Animation { reduceMotion ? .easeOut(duration: 0.24) : .spring(Self.expressive) }
/// A refused action. Firm, no wobble; `pieceShake` adds the movement.
var error: Animation { reduceMotion ? .easeOut(duration: 0.2) : .spring(Self.responsive) }
/// Slow ambient change. Loops themselves stop under Reduce Motion: check `allowsAmbient`.
var ambient: Animation { reduceMotion ? .easeInOut(duration: 0.3) : .spring(Self.calm) }
/// Loops, drifts, idle breathing and parallax run only when this is true.
var allowsAmbient: Bool { !reduceMotion }
/// A moving transition, or a plain fade under Reduce Motion.
func transition(_ transition: AnyTransition) -> AnyTransition {
reduceMotion ? .opacity : transition
}
/// For content replaced inside a container that stays put (a label, a glyph, a count): the old content
/// blurs out as the new one sharpens in. A fade under Reduce Motion.
@MainActor var swap: AnyTransition {
reduceMotion ? .opacity : AnyTransition(.blurReplace)
}
}
extension PieceMotion {
/// About `depth` points per edge, not a fixed percentage: an icon sinks to 0.92, a pill 0.95, a card 0.985.
nonisolated static func pressScale(for size: CGSize, depth: CGFloat = 2.5) -> CGFloat {
let side = (max(size.width, 1) * max(size.height, 1)).squareRoot()
return min(max(1 - depth * 2 / side, 0.92), 0.985)
}
/// An anchor partway from the center toward the touch, so the press leans into the finger without tipping.
nonisolated static func pressAnchor(touch: CGPoint?, in size: CGSize, lean: CGFloat = 0.6) -> UnitPoint {
guard let touch, size.width > 0, size.height > 0 else { return .center }
let x = min(max(touch.x / size.width, 0), 1)
let y = min(max(touch.y / size.height, 0), 1)
return UnitPoint(x: 0.5 + (x - 0.5) * lean, y: 0.5 + (y - 0.5) * lean)
}
}
/// Sinks on touch-down, leaning toward the touch if given, and springs back from the same lean. Under Reduce
/// Motion it shades instead of moving (darker in light mode, lighter in dark), without turning transparent.
private struct PiecePress: ViewModifier {
let pressed: Bool
var touch: CGPoint?
var depth: CGFloat = 2.5
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@Environment(\.colorScheme) private var colorScheme
@State private var size: CGSize = .zero
@State private var anchor: UnitPoint = .center
func body(content: Content) -> some View {
let motion = PieceMotion(reduceMotion: reduceMotion)
let scale = pressed && !reduceMotion ? PieceMotion.pressScale(for: size, depth: depth) : 1
content
.onGeometryChange(for: CGSize.self) { $0.size } action: { size = $0 }
.brightness(pressed && reduceMotion ? (colorScheme == .dark ? 0.1 : -0.08) : 0)
.scaleEffect(scale, anchor: anchor)
.animation(pressed ? motion.press : motion.release, value: pressed)
.onChange(of: pressed) { _, isPressed in
if isPressed { anchor = PieceMotion.pressAnchor(touch: touch, in: size) }
}
.onChange(of: touch) { _, touch in
if pressed, let touch { anchor = PieceMotion.pressAnchor(touch: touch, in: size) }
}
}
}
private extension View {
/// Sinks this view while `pressed`, leaning toward `touch` (in this view's coordinates) when given.
func piecePress(_ pressed: Bool, touch: CGPoint? = nil, depth: CGFloat = 2.5) -> some View {
modifier(PiecePress(pressed: pressed, touch: touch, depth: depth))
}
}
/// Only the press, centered: for chips, rows and tiles, and anything in scrolling content.
private struct PiecePressStyle: ButtonStyle {
var depth: CGFloat = 2.5
func makeBody(configuration: Configuration) -> some View {
configuration.label.piecePress(configuration.isPressed, depth: depth)
}
}
// swiftpieces-motion: end
// MARK: - Piece liquid
//
// The SwiftPieces liquid glass language: glass shapes that merge through a neck, bubbles that bud out of
// and melt back into each other, and the frosted fallback before iOS 26. Each piece carries a copy of only
// the parts it uses, so this file stands alone. Generated from registry/foundation/PieceLiquid.swift in the
// SwiftPieces repo; edit it there, not here. The rules are in LIQUID_GLASS.md.
// swiftpieces-liquid: 1.8.0 (morphText)
/// A label that changes letter by letter: letters both strings share hold still, the rest blur out and the new ones
/// blur in a few milliseconds apart. Under Reduce Motion it cross-fades. VoiceOver reads the whole string.
///
/// Only text whose letters stand on their own is cut into letters: Latin, Greek, Cyrillic, CJK, digits and symbols.
/// Those letters are laid out left to right whatever the layout direction, the order they read in, so "1.5×" stays
/// "1.5×" in an Arabic or Hebrew interface instead of coming out backwards. Text in a right-to-left script, or in one
/// whose letters join or reorder (Arabic, Hebrew, Devanagari, Thai and their neighbours), can't be cut apart without
/// breaking it, so it changes as one: the old string blurs out where it stood while the new one blurs in.
private struct PieceMorphText: View {
var text: String
var font: Font = .body.weight(.semibold)
@Environment(\.accessibilityReduceMotion) private var reduceMotion
var body: some View {
// The morphing label at its full size when it fits. When it doesn't (a long label at an accessibility text
// size, a narrow screen), the same words wrap onto a second line and shrink a little instead of running past
// the screen's edge; that one changes as a whole rather than letter by letter. A single word never splits
// across lines: it stays on one and shrinks further.
let oneWord = !text.contains(where: \.isWhitespace)
ViewThatFits(in: .horizontal) {
morphing.fixedSize()
Text(text)
.lineLimit(oneWord ? 1 : 2)
.multilineTextAlignment(.center)
.minimumScaleFactor(oneWord ? 0.5 : 0.75)
.fixedSize(horizontal: false, vertical: true)
.id(text)
.transition(transition(0, scale: 0.9))
}
.font(font)
.accessibilityElement(children: .ignore)
.accessibilityLabel(text)
}
@ViewBuilder private var morphing: some View {
if Self.splits(text) {
let glyphs = Array(text)
HStack(spacing: 0) {
ForEach(glyphs.indices, id: \.self) { i in
Text(String(glyphs[i]))
.id("\(i)\(glyphs[i])")
.transition(transition(i, scale: 0.6))
}
}
// The letters' reading order, not the layout's: an HStack lays its children out backwards under a
// right-to-left layout.
.environment(\.layoutDirection, .leftToRight)
} else {
ZStack(alignment: .leading) {
Text(text)
.id(text)
.transition(transition(0, scale: 0.9))
}
}
}
private func transition(_ i: Int, scale: CGFloat) -> AnyTransition {
guard !reduceMotion else { return .opacity }
return AnyTransition(.blurReplace(.downUp)).combined(with: .scale(scale: scale, anchor: .bottom))
.animation(.spring(duration: 0.42, bounce: 0.3).delay(Double(i) * 0.022))
}
/// Whether `text` can be cut into letters that each read left to right on their own: no right-to-left script, no
/// script that joins or reorders its letters, and no bidirectional control characters.
private static func splits(_ text: String) -> Bool {
!text.unicodeScalars.contains { scalar in
switch scalar.value {
case 0x0590...0x08FF, // Hebrew, Arabic, Syriac, Thaana, NKo, Samaritan, Mandaic
0x0900...0x0DFF, // Devanagari to Sinhala
0x0E00...0x0FFF, // Thai, Lao, Tibetan
0x1000...0x109F, // Myanmar
0x1780...0x17FF, // Khmer
0xA8E0...0xA8FF, // Devanagari Extended
0xFB1D...0xFDFF, // Hebrew and Arabic presentation forms
0xFE70...0xFEFF, // Arabic presentation forms B
0x200E...0x200F, 0x202A...0x202E, 0x2066...0x2069, // bidirectional marks, embeddings and isolates
0x10800...0x10FFF, // historic right-to-left scripts
0x1E800...0x1EFFF: // Adlam and other right-to-left scripts
return true
default:
return false
}
}
}
}
// swiftpieces-liquid: end- Type
- StepTray
- Files
- StepTray.swift
- Depends on
- Nothing (Apple frameworks only)
- Version
- 1.0.0
Colors and shape of a StepTray. .standard is the house palette.
Notes
StepTray(step:button:action:content:)shows one step of a short flow in a single tray: an amount, a review, a done state. You ownstep. Change it from the button's action, or from anywhere else, and the tray moves to that step.- The tray takes on each step's natural height on a spring. The step that is leaving blurs out quickly, and the new step blurs in just after, so you never see two at once.
- The red button stays at the bottom, where the thumb is. Its label is the
buttonyou pass, and it changes letter by letter: letters the old and new labels share hold still, and the rest blur across. - Place the tray at the bottom of its space, for example
.frame(maxHeight: .infinity, alignment: .bottom), so it grows and shrinks upward. - Each step change plays a light haptic tick.
- Under Reduce Motion the tray resizes without a spring, and the steps cross-fade.
Usage
StepTrayExample()Install
Pick one. Run it from the folder that contains your .xcodeproj and the files land inside your app.
Terminal
Or ask your coding agent · Claude Code, Cursor or Xcode, once the MCP server is connected
Or copy the source above into your app.
New to SwiftUI?If you know React, CSS or Tailwind, SwiftUI is easier to pick up than it looks.Try real app patterns first
Building a whole app? See SwiftPieces Pro →
More SwiftUI sheets
All sheets →Build it yourself: SwiftUI haptics guide
