2

Expanding a SwiftUI View causes the LazyVGrid to remove all the items that will not be seen when the animation is completed. Additionally, when scrolling down the items animate from their original position to their actual position.

Here is the code I wrote to replicate the problem:

struct TestView: View {
    @State var isOpen: Bool = false
    
    var body: some View {
        ScrollView {
            VStack {
                Color.green
                    .onTapGesture {
                        withAnimation {
                            isOpen.toggle()
                        }
                    }
                    .frame(height: 500)
                    .frame(height: isOpen ? nil : 50, alignment: .top)
                    .clipped()

                
                LazyVGrid(columns: [GridItem(.adaptive(minimum: 75, maximum: 100))]) {
                    ForEach(0..<100) { index in
                        Color.black
                            .frame(height: 30)
                            .overlay {
                                Text("index: \(index)")
                                    .foregroundStyle(.white)
                            }
                    }
                }
            }
            .frame(maxWidth: .infinity, maxHeight: .infinity)
        }
    }
}

I am expecting the LazyVGrid items to first be removed from the grid when the animation is completed, also the items shouldn't animate to their new position.

Any help is appreciated

Edit: Here is a link to a Video of the problem: git link

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.