Transparency in Sheet differs in SwiftUI and UIKit+UIHostingContrller

My app is a UIKit app with a lot of SwiftUI mixed in. A common scenario is that a UIViewController presents a sheet with a SwiftUI view wrapped in a UIHostingController.

When I present the exact same SwiftUI View it looks different in a SwiftUI sheet compared to when it's wrapped in a UIHostingController and presented from a view controller.

I'm using a hacky workaround in which I loop through all subviews of the hosting controller in viewWillLayoutSubviews and look for a NavigationStackHostingController<SwiftUI.AnyView> to manually set the background color, but it feels like it could brake easily.

Has anyone found a better way to fix this?

Feedback: FB22028838

Transparency in Sheet differs in SwiftUI and UIKit&#43;UIHostingContrller
 
 
Q