Reorder ListNew
Glass rows you reorder by holding the grip: the row lifts, its grip turns red and the others part, with a tick at each slot.
Live preview
// 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
/// Colors and spacing for `ReorderList`. `.standard` is the house palette.
public struct ReorderListStyle: Sendable {
/// The grip of the row being dragged.
public var accent: Color
/// The grip at rest.
public var grip: Color
/// The gap between rows.
public var spacing: CGFloat
/// The corner radius of a row.
public var cornerRadius: CGFloat
public init(
accent: Color = Color(red: 1, green: 0, blue: 0),
grip: Color = ReorderListStyle.adaptive(light: 0x8B8984, dark: 0x6F6D69),
spacing: CGFloat = 8,
cornerRadius: CGFloat = 18
) {
self.accent = accent
self.grip = grip
self.spacing = spacing
self.cornerRadius = cornerRadius
}
public static let standard = ReorderListStyle()
/// A color that follows the appearance, from two 0xRRGGBB values.
public static func adaptive(light: UInt32, dark: UInt32) -> Color {
Color(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)
})
}
}
/// Glass rows you reorder by holding the grip.
///
/// Rows are laid out at the height of the first row, so keep them one height. The list is not lazy: it is for the
/// short lists people arrange by hand.
///
/// - Parameters:
/// - items: The items, in order. A drop writes the new order back.
/// - style: Colors and spacing. Defaults to the house palette, adapting to light and dark.
/// - row: The content of a row. The grip is added after it.
public struct ReorderList<Item: Identifiable, Row: View>: View {
public typealias Style = ReorderListStyle
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@Environment(\.colorScheme) private var colorScheme
@Binding private var items: [Item]
@State private var rowHeight: CGFloat = 56
/// The row being dragged, where it started and the slot it would land in.
@State private var dragged: Item.ID?
@State private var from = 0
@State private var to = 0
/// How far the dragged row is from its slot. Set straight from the finger, never animated while dragging.
@State private var offset: CGFloat = 0
@State private var lifted = false
@State private var drops = 0
private let style: Style
private let row: (Item) -> Row
public init(_ items: Binding<[Item]>, style: Style = .standard, @ViewBuilder row: @escaping (Item) -> Row) {
self._items = items
self.style = style
self.row = row
}
private var pitch: CGFloat { rowHeight + style.spacing }
public var body: some View {
let motion = PieceMotion(reduceMotion: reduceMotion)
VStack(spacing: style.spacing) {
ForEach(Array(items.enumerated()), id: \.element.id) { index, item in
let isDragged = item.id == dragged
rowView(item, index: index, isDragged: isDragged)
.offset(y: isDragged ? offset : shift(for: index))
.zIndex(isDragged ? 1 : 0)
.animation(isDragged ? nil : motion.snap, value: to)
}
}
.fontWeight(.semibold)
.sensoryFeedback(.selection, trigger: to)
.sensoryFeedback(.impact(weight: .medium), trigger: lifted)
.sensoryFeedback(.success, trigger: drops)
}
/// Rows between the dragged row's start and its slot step aside by one place.
private func shift(for index: Int) -> CGFloat {
guard dragged != nil else { return 0 }
if from < index && index <= to { return -pitch }
if to <= index && index < from { return pitch }
return 0
}
private func rowView(_ item: Item, index: Int, isDragged: Bool) -> some View {
let shape = RoundedRectangle(cornerRadius: style.cornerRadius, style: .continuous)
let up = isDragged && lifted
return HStack(spacing: 12) {
row(item)
.frame(maxWidth: .infinity, alignment: .leading)
Image(systemName: "line.3.horizontal")
.font(.body.weight(.semibold))
.foregroundStyle(up ? style.accent : style.grip)
.frame(width: 44, height: 44)
.contentShape(.rect)
.gesture(grip(item, index: index))
.accessibilityHidden(true)
}
.padding(.leading, 16)
.padding(.trailing, 6)
.frame(minHeight: 52)
.onGeometryChange(for: CGFloat.self) { $0.size.height } action: { height in
if index == 0 { rowHeight = height }
}
.background { PieceLiquidGroup(lift: false) { Color.clear.pieceLiquid(shape, interactive: false) } }
.shadow(color: .black.opacity(up ? (colorScheme == .dark ? 0.45 : 0.16) : 0), radius: up ? 18 : 0, y: up ? 10 : 0)
.scaleEffect(up && !reduceMotion ? 1.03 : 1)
.animation(up ? PieceMotion(reduceMotion: reduceMotion).press : PieceMotion(reduceMotion: reduceMotion).release, value: up)
.accessibilityElement(children: .combine)
.accessibilityAction(named: "Move up") { move(index, by: -1) }
.accessibilityAction(named: "Move down") { move(index, by: 1) }
}
// MARK: Dragging
/// Hold the grip briefly to lift the row, then drag. The row follows the finger exactly; the rows it passes spring
/// aside, and the drop springs it the rest of the way into its slot.
private func grip(_ item: Item, index: Int) -> some Gesture {
LongPressGesture(minimumDuration: 0.18)
.sequenced(before: DragGesture(minimumDistance: 0, coordinateSpace: .global))
.onChanged { value in
switch value {
case .first(true):
begin(item, index: index)
case .second(true, let drag):
begin(item, index: index)
guard let drag else { return }
offset = drag.translation.height
let target = Int((CGFloat(from) + drag.translation.height / pitch).rounded())
to = min(max(target, 0), items.count - 1)
default:
break
}
}
.onEnded { _ in drop() }
}
private func begin(_ item: Item, index: Int) {
guard dragged == nil else { return }
dragged = item.id
from = index
to = index
offset = 0
lifted = true
}
/// Writes the move and keeps every row where it is on screen in the same frame, then springs the dropped row home.
private func drop() {
guard dragged != nil else { return }
let motion = PieceMotion(reduceMotion: reduceMotion)
let landing = offset - CGFloat(to - from) * pitch
var transaction = Transaction()
transaction.disablesAnimations = true
withTransaction(transaction) {
if to != from {
items.move(fromOffsets: IndexSet(integer: from), toOffset: to > from ? to + 1 : to)
drops += 1
}
from = to
offset = landing
}
withAnimation(motion.settle) {
offset = 0
lifted = false
} completion: {
if !lifted { dragged = nil }
}
}
private func move(_ index: Int, by step: Int) {
let target = index + step
guard items.indices.contains(target) else { return }
withAnimation(PieceMotion(reduceMotion: reduceMotion).snap) {
items.move(fromOffsets: IndexSet(integer: index), toOffset: step > 0 ? target + 1 : target)
}
drops += 1
}
}
// MARK: - Example
private struct ReorderListExampleList: Identifiable {
var id: String { name }
var name: String
var color: Color
var count: Int
}
/// Four task lists, in the order you want them.
private struct ReorderListExample: View {
@State private var lists = [
ReorderListExampleList(name: "Inbox", color: Color(red: 0.18, green: 0.545, blue: 1), count: 12),
ReorderListExampleList(name: "Today", color: Color(red: 1, green: 0.761, blue: 0.102), count: 5),
ReorderListExampleList(name: "Upcoming", color: Color(red: 0, green: 0.769, blue: 0.655), count: 8),
ReorderListExampleList(name: "Someday", color: Color(red: 1, green: 0, blue: 0.361), count: 21),
]
var body: some View {
ReorderList($lists) { list in
HStack(spacing: 12) {
Circle().fill(list.color).frame(width: 12, height: 12)
Text(list.name)
Spacer()
Text("\(list.count)")
.foregroundStyle(.secondary)
.monospacedDigit()
}
}
.frame(width: 300)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(ReorderListStyle.adaptive(light: 0xF3F2EE, dark: 0x121212))
}
}
#Preview("Light") {
ReorderListExample()
}
#Preview("Dark") {
ReorderListExample()
.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)
/// 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)
}
}
// 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 (liquid)
/// The liquid glass language: one merge distance, two rest gaps, and the springs a bubble leaves and comes home on.
///
/// Glass shapes inside one `PieceLiquidGroup` melt into each other through a neck when they come within `merge`
/// points. Parts of one control rest `joined`, inside that distance, so the neck holds; separate actions rest
/// `apart`, outside it, so they only goo while one buds out of, or melts back into, another.
private enum PieceLiquid {
/// Glass shapes closer than this share a neck.
static let merge: CGFloat = 20
/// The gap between parts of one control (a stepper's buttons, a progress pill and its stop): the neck holds,
/// short and smooth, about two thirds of the shapes' height at its waist. Joined parts read best at one height.
static let joined: CGFloat = 4
/// The gap between separate actions (menu items, confirm and cancel, chips): they rest as their own bubbles.
static let apart: CGFloat = 26
/// How far a bubble shrinks while it is home inside its parent.
static let homeScale: CGFloat = 0.72
/// A bubble leaving its parent: slow enough that the neck's stretch and snap read.
static func split(reduceMotion: Bool) -> Animation {
reduceMotion ? .easeOut(duration: 0.2) : .spring(duration: 0.62, bounce: 0.22)
}
/// A bubble going home. No bounce: a bounce would carry it out through the far side of its parent.
static func home(reduceMotion: Bool) -> Animation {
reduceMotion ? .easeIn(duration: 0.18) : .spring(duration: 0.5, bounce: 0)
}
}
/// A group of glass shapes that merge into one liquid surface. On iOS 26 it is a `GlassEffectContainer`; before
/// that, and under Reduce Transparency, the shapes draw on their own and simply don't merge. `lift` adds the soft
/// shadow liquid glass floats on in light mode.
private struct PieceLiquidGroup<Content: View>: View {
var spacing: CGFloat = PieceLiquid.merge
var lift = true
@ViewBuilder var content: Content
@Environment(\.accessibilityReduceTransparency) private var reduceTransparency
@Environment(\.colorScheme) private var colorScheme
var body: some View {
container
.shadow(color: .black.opacity(lift && colorScheme == .light ? 0.07 : 0), radius: 18, y: 8)
}
@ViewBuilder private var container: some View {
#if compiler(>=6.2)
if #available(iOS 26, *), !reduceTransparency {
GlassEffectContainer(spacing: spacing) { content }
} else {
content
}
#else
content
#endif
}
}
/// One liquid glass shape: Liquid Glass on iOS 26, carrying `tint` as a solid colour and swelling under a press when
/// `interactive`; a frosted Material with a light rim and a soft shadow before that; a solid fill under Reduce
/// Transparency.
///
/// The tint is painted inside clear glass rather than tinting the glass. Tinted glass in a group bleeds its colour
/// through every neck as a smear, so a red button would glow into the white pill it is joined to; painted inside,
/// the colour stays crisp to the shape's edge, the necks between shapes are clear glass, and a tint change animates
/// like any colour (tinted glass snaps).
private struct PieceLiquidSurface<S: Shape>: ViewModifier {
var shape: S
var tint: Color?
var interactive: Bool
@Environment(\.accessibilityReduceTransparency) private var reduceTransparency
@Environment(\.colorScheme) private var colorScheme
@Environment(\.pieceLiquidScale) private var scale
func body(content: Content) -> some View {
#if compiler(>=6.2)
if #available(iOS 26, *), !reduceTransparency {
// Scaled as two parts, content and outline, about the same centre. A scaleEffect on a glass view inside a
// GlassEffectContainer shrinks the glass but leaves what it carries full size, pinned to its corner.
content
.background { shape.fill(tint ?? .clear) }
.scaleEffect(scale)
.glassEffect(glass, in: shape.scale(scale))
} else {
fallback(content).scaleEffect(scale)
}
#else
fallback(content).scaleEffect(scale)
#endif
}
#if compiler(>=6.2)
@available(iOS 26, *)
private var glass: Glass {
interactive ? Glass.regular.interactive() : .regular
}
#endif
private func fallback(_ content: Content) -> some View {
let dark = colorScheme == .dark
return content
.background {
if reduceTransparency {
shape.fill(tint ?? (dark ? Color(white: 0.17) : Color(white: 0.97)))
} else {
ZStack {
shape.fill(.regularMaterial)
if let tint { shape.fill(tint.opacity(0.88)) }
}
}
}
.overlay { shape.stroke(Color.white.opacity(dark ? 0.14 : 0.7), lineWidth: 0.5) }
.shadow(color: .black.opacity(dark ? 0.32 : 0.08), radius: 10, y: 5)
}
}
private struct PieceLiquidScaleKey: EnvironmentKey {
static let defaultValue: CGFloat = 1
}
private extension EnvironmentValues {
/// How much the liquid shapes below are scaled, about their own centres. Nested scales multiply.
var pieceLiquidScale: CGFloat {
get { self[PieceLiquidScaleKey.self] }
set { self[PieceLiquidScaleKey.self] = newValue }
}
}
private extension View {
/// Draws this view on a liquid glass `shape`. Put it inside a `PieceLiquidGroup` so it can merge with its neighbours.
func pieceLiquid<S: Shape>(_ shape: S, tint: Color? = nil, interactive: Bool = true) -> some View {
modifier(PieceLiquidSurface(shape: shape, tint: tint, interactive: interactive))
}
/// Scales the liquid glass shapes in this view, content and outline together, about their own centres. Use it
/// instead of `scaleEffect` on a glass view (a press, a lift, a swell): inside a group a plain `scaleEffect` shrinks
/// the glass but leaves its content full size and off centre. Animates like any other value.
func pieceLiquidScale(_ scale: CGFloat) -> some View {
transformEnvironment(\.pieceLiquidScale) { $0 *= scale }
}
}
// swiftpieces-liquid: end- Type
- ReorderList
- Files
- ReorderList.swift
- Depends on
- Nothing (Apple frameworks only)
- Version
- 1.0.0
Colors and spacing for ReorderList. .standard is the house palette.
Notes
- Give it a binding to an array of
Identifiableitems and a row builder. A glass grip is added at the end of each row; the drop writes the new order back to the array. - Hold the grip briefly and the row lifts: a slight scale, a deeper shadow and a red grip, with a medium haptic. It follows the finger exactly while the rows it passes spring aside, with a selection tick at each new slot.
- On release the move is written in the same frame the rows settle, so nothing jumps, and the dropped row springs the last few points into its slot with a success haptic.
- Rows are spaced by the height of the first row, so keep them one height. It is a plain stack, not a
List, for the short lists people arrange by hand. - VoiceOver gets Move up and Move down actions on every row, so it can be reordered without dragging.
- Under Reduce Motion the lift does not scale and the rows settle without overshoot.
Usage
ReorderListExample()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 lists
All lists →Build it yourself: SwiftUI loading states guide · SwiftUI cards guide









