AnimatableListRow
is a Swift package that solves the long-standing issue of smooth height transitions for SwiftUI List rows. It provides an elegant and flexible solution for animating height changes in List views without relying on hardcoded values or deprecated APIs.
Note: Requires iOS 18 and aligned releases
SwiftUI's List component doesn't natively support smooth height animations for its rows. The traditional workaround, as discussed in this Stack Overflow post, had limitations:
- It required hardcoded "magic numbers" for cell heights.
- It used
AnimatableModifier
, which has been deprecated as of iOS 18.1 and aligned releases.
AnimatableListRow
addresses these issues, providing a more robust and future-proof solution.
- π Smooth, automatic height transitions for
List
rows - π No hardcoded height values required
- π οΈ Easy to implement with a simple view modifier
- π¨ Customizable animations
Add the following line to your Package.swift
file's dependencies:
.package(url: "https://github.com/JPToroDev/AnimatableListRow.git", from: "1.0.0")
To use AnimatableListRow
in your SwiftUI views:
import SwiftUI
import AnimatableListRow
struct ContentView: View {
@State private var isExpanded = false
var body: some View {
List {
VStack {
Text("Expandable Row")
if isExpanded {
Text("Additional content")
}
}
.animatableListRow() // Apply the modifier here
.onTapGesture {
withAnimation {
isExpanded.toggle()
}
}
}
}
}
When using .default
for the animation, scrolling the list before the animation completes will cause jittering.
This project is licensed under the MIT License - see the LICENSE file for details.