SwiftUI Edit Button not working after animation

Viewed 147

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

Without animation: Without animation

With animation: With animation

1 Answers

Moving the .animation from the group to the navigation view fixes this issue. I moved .animation to directly under .navigationViewStyle and removed the value:

Answered on apple developer forums:

https://developer.apple.com/forums/thread/698407

Related