I am attempting to have an edit button on a listing to have the ability to delete a number of objects on the similar time with out the purple delete controls in the beginning of every row.
To take away the delete controls I take advantage of this .deleteDisabled(editMode?.wrappedValue.isEditing == true). However once I add this line the animation is unusual when coming into edit mode, it is just like the checklist bounces.
Yow will discover an instance code right here:
import SwiftUI
struct ContentView: View {
@State personal var objects = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
@State personal var choice: Set<String> = []
var physique: some View {
NavigationStack {
Record(choice: $choice) {
ItemsList(objects: $objects)
}
.toolbar {
ToolbarItem(placement: .topBarLeading) {
EditButton()
}
ToolbarItem(placement: .topBarTrailing) {
if !choice.isEmpty {
Button("Delete", position: .harmful) {
objects.removeAll { choice.comprises($0) }
choice.removeAll()
}
}
}
}
}
}
}
personal struct ItemsList: View {
@Binding var objects: [String]
@Atmosphere(.editMode) personal var editMode
var physique: some View {
ForEach(objects, id: .self) { merchandise in
Textual content(merchandise)
}
.onDelete { offsets in
objects.take away(atOffsets: offsets)
}
.deleteDisabled(editMode?.wrappedValue.isEditing == true) // the bug seems with this line
}
}
#Preview {
ContentView()
}


