Using the multiple selection from a list in SwiftUI ioS 14.7.1, 14.6 and 14.5 does not visually retain the selection when scrolled off screen. The selections themselves are retained properly in the variable. A GIF to demonstrate:
This happens both on the device and the sim. It seems like a bug but perhaps I am missing something?
struct RegionDetailView: View {
@EnvironmentObject var model:BrainViewModel
@State private var multiSelection = Set<Int>()
@State private var showSaveScreen = false
@State private var saveName = ""
var body: some View {
List(selection: $multiSelection) {
Section(header: Text("Default Segments")) {
ForEach(model.brainSegments.sorted(by: {$0.fullName < $1.fullName}),id:\.id) { segment in
Text("\(segment.fullName) (\(segment.shortName))")
}
}
Section(header: Text("Custom Segments")) {
ForEach(model.customBrainSegments,id:\.id) { segment in
Text("\(segment.fullName) (\(segment.shortName))")
}
}
}
.environment(\.editMode, .constant(.active))
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
showSaveScreen.toggle()
} label: {
Text("Save")
}
.popover(isPresented: $showSaveScreen) {
}
}
}
.onAppear {
model.loadCustomSegments()
}
}