Bad: OutlineGroup is not lazy loading children?

This appears to severely limit the usefulness of hierarchical lists in SwiftUI.

I want to use the new hierarchical list/outline to display a filesystem tree. For data to pass to OutlineGroup, I created a class named FileSystemNode, and gave it a computed children property. When the getter is first called, it will read its directory contents to return a list (if it is a directory).

Problem is, when the OutlineGroup is first displayed, even though it is collapsed on-screen to a single node, it calls children and recurses over the entire filesystem.

Is there a way to stop this? If not, I hope it gets fixed before release.

(This is on macOS Big Sur beta)
Post not yet marked as solved Up vote post of rnikander Down vote post of rnikander
1.4k views

Replies

I filed a Feedback about it: FB8782243.


Hello,

Did you ever receive a response to this? It seems to still be the situation (Monterey 12.4). I've tried a few approaches but I've not found anything satisfactory. This approach using DisclosureGroup doesn't seem to function correctly for even modestly deep lists and sometimes doesn't properly open or close.

  • No. I ended up writing my own outline view from scratch, that dealt with lazy disclosure. Maybe I should open source it? I don't know if there is a better way. If you find one, please share it here.

  • This is still an issue as of macOS 13 beta 2 also

  • I put the code that I wrote before in a package. See my answer.

Add a Comment

I created an OutlineView package here: https://github.com/EncodiaDotCo/OutlineView to address this.

It's the first time I've created a public github repo for a Swift package, so hopefully it's usable.

It's not pretty yet but it lazy loads children. Maybe we can cooperate and improve it. Feel free to create bug/feature requests.