Skip to content

Commit d4d88fa

Browse files
committed
Add UIHostingView.traitCollectionDidChange
1 parent a1e2a38 commit d4d88fa

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Sources/OpenSwiftUI/Integration/Hosting/UIKit/Controller/UIHostingController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ public import UIKit
77
@preconcurrency
88
open class UIHostingController<Content>: UIViewController where Content : View {
99
var host: _UIHostingView<Content>
10-
10+
11+
var alwaysOnBridge: AlwaysOnBridge<Content>?
12+
1113
override open dynamic var keyCommands: [UIKeyCommand]? {
1214
// TODO
1315
nil

Sources/OpenSwiftUI/Integration/Hosting/UIKit/View/UIHostingView.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,18 @@ open class _UIHostingView<Content>: UIView, XcodeViewDebugDataProvider where Con
271271
base.tintColorDidChange()
272272
}
273273

274+
open override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
275+
updateBackgroundColor()
276+
if shouldDisableUIKitAnimations,
277+
Semantics.TraitCollectionAnimations.isEnabled,
278+
var transaction = Transaction.currentUIViewTransaction(canDisableAnimations: true) {
279+
if let viewController, let alwaysOnBridge = viewController.alwaysOnBridge {
280+
alwaysOnBridge.configureTransaction(&transaction)
281+
}
282+
viewGraph.emptyTransaction(transaction)
283+
}
284+
}
285+
274286
open override func safeAreaInsetsDidChange() {
275287
_safeAreaInsetsDidChange()
276288
}

0 commit comments

Comments
 (0)