diff --git a/Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIHostingView.swift b/Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIHostingView.swift index 6a1e680a6..cc03a5395 100644 --- a/Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIHostingView.swift +++ b/Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIHostingView.swift @@ -386,6 +386,12 @@ open class _UIHostingView: UIView, XcodeViewDebugDataProvider where Con if wantsTransparentBackground { super.backgroundColor = nil } else { + #if os(visionOS) + if traitCollection.userInterfaceIdiom == .vision { + super.backgroundColor = nil + return + } + #endif setBackground(.systemBackground) } } diff --git a/Tests/OpenSwiftUICompatibilityTests/Integration/Hosting/UIKit/UIHostingControllerCompatibilityTests.swift b/Tests/OpenSwiftUICompatibilityTests/Integration/Hosting/UIKit/UIHostingControllerCompatibilityTests.swift new file mode 100644 index 000000000..235871cb2 --- /dev/null +++ b/Tests/OpenSwiftUICompatibilityTests/Integration/Hosting/UIKit/UIHostingControllerCompatibilityTests.swift @@ -0,0 +1,21 @@ +// +// UIHostingControllerCompatibilityTests.swift +// OpenSwiftUICompatibilityTests + +#if os(visionOS) +import Testing +import UIKit + +@MainActor +struct UIHostingControllerCompatibilityTests { + @Test(arguments: [UIUserInterfaceStyle.light, .dark]) + func visionBackgroundIsTransparent(style: UIUserInterfaceStyle) { + let controller = UIHostingController(rootView: EmptyView()) + controller.overrideUserInterfaceStyle = style + controller.loadViewIfNeeded() + + #expect(controller.view.traitCollection.userInterfaceIdiom == .vision) + #expect(controller.view.backgroundColor == nil) + } +} +#endif