Чтобы удалить элементы управления удалением, я использую этот .deleteDisabled(editMode?.wrappedValue.isEditing == true). Но когда я добавляю эту строку, при входе в режим редактирования анимация становится странной, как будто список подпрыгивает.
Пример кода можно найти здесь:
Код: Выделить всё
import SwiftUI
struct ContentView: View {
@State private var items = ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]
@State private var selection: Set = []
var body: some View {
NavigationStack {
List(selection: $selection) {
ItemsList(items: $items)
}
.toolbar {
ToolbarItem(placement: .topBarLeading) {
EditButton()
}
ToolbarItem(placement: .topBarTrailing) {
if !selection.isEmpty {
Button("Delete", role: .destructive) {
items.removeAll { selection.contains($0) }
selection.removeAll()
}
}
}
}
}
}
}
private struct ItemsList: View {
@Binding var items: [String]
@Environment(\.editMode) private var editMode
var body: some View {
ForEach(items, id: \.self) { item in
Text(item)
}
.onDelete { offsets in
items.remove(atOffsets: offsets)
}
.deleteDisabled(editMode?.wrappedValue.isEditing == true) // the bug appears with this line
}
}
#Preview {
ContentView()
}

Подробнее здесь: https://stackoverflow.com/questions/798 ... e-disabled
Мобильная версия