I am working on converting an application I wrote for iOS from using UIKit to using SwiftUI. So far, it looks like I’ve been able to get just about everything working with SwiftUI except for one thing.
I have a table view that displays several rows of information in a few columns. The table has a single header at the top containing titles for each column. However, there is an aspect of the table view that introduced an undesirable behavior. When scrolling the content, row scrolling upward would appear underneath the header row. The desire was to have the header row be opaque with regard to the table content yet still allow background content underneath the header to show through.
In UIKit I ended up implementing a hack of sorts to prevent content of scrolling rows from appearing directly behind the header. To do this, during scrolling the code was calling the UITableView.rectForHeader method and applying a mask to the layer of any rows that might be intersecting that header rectangle. That mask had a gradient applied to it to make the portion of the row inside the header completely translucent, while allowing the rest of the row to display as normal.
In SwiftUI, I have the same issue with the scrolling content appearing underneath the headers, yet am unsure how to prevent that from happening. I don’t know if it would involve using a transparency hack like I did for UIKit, or if there might be some other way to prevent the content from showing up. In any case,I have been unable to find a solution that could provide the desired behavior.
What could be done in SwiftUI to allow the table header to be opaque with respect to scrolling table rows?