SwiftUI Edit Button not working after animation

After animating from a group conditional view, the edit button on my list doesn't work. It works fine if there's no animation, but I'm not sure why an animation would cause the edit button to not work?

struct Overview: View {
    @State var test = true
    var body: some View {
        Group {
            if test {
                Button(action: {
                    test = false
                }) {
                    Text("Button")
                }
            } else {
                NavigationView {
                    SimpleList()
                        .toolbar {
                            ToolbarItem(placement: .navigationBarTrailing) {
                                EditButton()
                            }
                        }
                }
                .navigationViewStyle(StackNavigationViewStyle())
            }
        }
        .animation(.easeOut, value: test)
    }
}

struct SimpleList: View {
    
    let test = ["1", "2", "3", "4"]
    var body: some View {
        List {
            ForEach(test, id: \.self) { t in
                Text(t)
            }
            .onDelete(perform: deleteRow)
        }
    }
    
    func deleteRow(_ :IndexSet) {
        
    }
}

Accepted Reply

In Overview, try moving the .animation from it's current position, to immediately after the .navigationViewStyle

That is, apply it to the NavigationView (which is what you are animating in), not the entire Group

  • Thanks for the reply. I tried that and removed the "value" from the .animation and that worked. Thank you!

Add a Comment

Replies

In Overview, try moving the .animation from it's current position, to immediately after the .navigationViewStyle

That is, apply it to the NavigationView (which is what you are animating in), not the entire Group

  • Thanks for the reply. I tried that and removed the "value" from the .animation and that worked. Thank you!

Add a Comment