Skip to content

Smooth, automatic height transitions for SwiftUI List rows. No magic numbers, no deprecated APIs. AnimatableListRow offers an elegant solution for animating List row heights in iOS and macOS, enhancing UI fluidity with minimal code. πŸš€πŸ“±

License

Notifications You must be signed in to change notification settings

JPToroDev/AnimatableListRow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AnimatableListRow πŸ“±βœ¨

Swift License Platform

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

Background πŸ”

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:

  1. It required hardcoded "magic numbers" for cell heights.
  2. 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.

Features 🌟

  • πŸ”„ Smooth, automatic height transitions for List rows
  • πŸ“ No hardcoded height values required
  • πŸ› οΈ Easy to implement with a simple view modifier
  • 🎨 Customizable animations

Installation πŸ’»

Add the following line to your Package.swift file's dependencies:

.package(url: "https://github.com/JPToroDev/AnimatableListRow.git", from: "1.0.0")

Usage πŸš€

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()
                }
            }
        }
    }
}

Note on Animations ⚠️

When using .default for the animation, scrolling the list before the animation completes will cause jittering.

License πŸ“„

This project is licensed under the MIT License - see the LICENSE file for details.

About

Smooth, automatic height transitions for SwiftUI List rows. No magic numbers, no deprecated APIs. AnimatableListRow offers an elegant solution for animating List row heights in iOS and macOS, enhancing UI fluidity with minimal code. πŸš€πŸ“±

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages