Have edit button for edit mode just with icon and when pressing button then changes and icon, but if I move rove or delete, then edit mode turns off but button stays the same in the isEditing active, and if need again use isEditing then need to press two times and not one like suppose to be. For earlier versions for iOS than 16.0
@Environment(\.editMode) var editMode
private var isEditing: Bool {
editMode?.wrappedValue.isEditing ?? false
}
var body: some View {
NavigationView {
List {
Section(header: Text("Example View.")) {
ForEach(examples) { example in
NavigationLink(destination: ExampleView(example: example)) {
RowView(example: example)
}
}
.onDelete(perform: deleteRow)
.onMove(perform: moveRow)
}
.toolbar {
ToolbarItemGroup(placement: .navigationBarTrailing) {
if #unavailable(iOS 16.0) {
Button(action: {
withAnimation {
editMode?.wrappedValue = isEditing ? .inactive : .active
}
}, label: {
Image(systemName: isEditing ? "list.bullet.rectangle.fill" : "list.bullet.rectangle")
.resizable()
.scaledToFit()
.foregroundColor(.secondary)
})
} else {
// For iOS 16 without editing button
}
}
}
}
}
}
Tried change line in:
Image(systemName: isEditing ? "list.bullet.rectangle.fill" : "list.bullet.rectangle", !isEditing, "list.bullet.rectangle")
but then get error on .toolbar view, "Trailing closure passed to parameter of type 'Visibility' that does not accept a closure" so how to do if wanna after isEditing action icon changes together?