5

I am trying to animate the expansion of cells in a swiftUI list when the user taps on the cell. However the animation is faulty.

I came across this answer (https://stackoverflow.com/a/60873883/13296730) to help with the animation however it requires already knowing the expected height of the cell after it is expanded. In my case this would depend on the data in note.text:

List{
    ForEach(notes){ note in
        VStack{
            HStack{
                Text(note.title)
                    .fontWeight(.bold)
                    .foregroundColor(.gray)
                Spacer()
                Image(systemName: "chevron.right.circle")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .foregroundColor(.gray)
                    .frame(width: 20, height: 20)
            }
            .padding(.vertical)
            .contentShape(Rectangle())
            .onTapGesture{
                selectedNote = note
            }
            if isSelected(note) {
                Text(note.text)
            }
        }
        .padding([.bottom, .leading, .trailing], 20)
        .background(
            RoundedRectangle(cornerRadius: 25, style: .continuous)
                .foregroundColor(isSelected(noteSection) ? .red : .clear)
        )
        .animation(.default)
    }
    .onMove(perform: move)
}

As you can see from the code above, I need to use a list so that I can make use of the .onMove functionality.

Is there a way to get the same smooth list animations in the linked answer but for dynamic expanded sizes?

Thanks.

santi.gs
  • 476
  • 3
  • 11
  • I am struggling with the exact same challenge... disheartened to see a year old question unanswered. – spentag Feb 28 '22 at 21:26
  • @spentag maybe this approach might work for you: https://stackoverflow.com/a/60890312/1016508 – iMaddin Mar 28 '22 at 08:55

0 Answers0