FYI: We found a way using Introspect (not sure if in any way legal). However, as Apple Engineers noted, we should not rely on implementation details of a framework. Unfortunately, we are now in the stupid situation of having done exactly that in the past and now having to find a workaround. Otherwise our app looks extremely broken...
extension View {
@warn_unqualified_access
@ViewBuilder
func listBackgroundColor(_ color: Color) -> some View {
introspectViewController { inspectSubView($0.view, backgroundColor: .init(color)) }
}
// MARK: Helper
private func inspectSubView(_ view: UIView, backgroundColor: UIColor) {
for subview in view.subviews {
if NSStringFromClass(type(of: subview)).contains("UICollectionViewListLayoutSectionBackgroundColorDecorationView") {
subview.backgroundColor = backgroundColor
return
}
inspectSubView(subview, backgroundColor: backgroundColor)
}
}
}