I have been pleased to see SwiftUI’s List performance improve over the years.
However, when using a List that contains DisclosureGroup views, expanding and collapsing items becomes significantly slower as the amount of data grows.
In my case, I need to control the initial expanded/collapsed state of each disclosure item, so I cannot use the recursive List(_:children:) API.
Is there a recommended way to improve the performance of a List containing DisclosureGroup views, or is falling back to AppKit’s NSOutlineView currently the only practical solution? (Yes, for context, my app is for macOS.)
The following code shows the relevant portion of my implementation:
List(self.summary.files, selection: $selection) { file in
DisclosureGroup(isExpanded: $expandedFileURLs.contains(file.id)) {
ForEach(file.matches) { match in
FolderFindMatchView(match: match)
.tag(FolderFind.ResultID.match(fileID: file.id, matchID: match.id))
}
} label: {
FolderFindFileResultView(file: file)
.draggable(item: FolderFindDraggedFile(id: .file(file.id), fileURL: file.fileURL))
}
.listRowSeparator(.hidden)
.tag(FolderFind.ResultID.file(file.id))
}