How to clear List background color in SwiftUI for macOS
Issue #680
For List in SwiftUI for macOS, it has default background color because of the enclosing NSScrollView via NSTableView that List uses under the hood. Using listRowBackground also gives no effect
The solution is to use a library like SwiftUI-Introspect
1 | import Introspect |
then
1 | List { |
Or we can add extension on NSTableView to alter its content when it moves to superview
1 | extension NSTableView { |
This works OK for me on macOS 10.15.5, 10.15.7 and macOS 10.11 beta. But it was reported crash during review on macOS 10.15.6
The app launches briefly and then quits without error message.
After inspecting crash log, it is because of viewDidMoveToWindow. So it’s wise not to mess with NSTableView for now
1 | Thread 0 Crashed:: Dispatch queue: com.apple.main-thread |
Updated at 2020-10-09 03:49:39