Skip to content

Commit 0020599

Browse files
committed
Add time zone listener for UIKitBackend
1 parent 8d7c888 commit 0020599

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Sources/UIKitBackend/UIKitBackend.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public final class UIKitBackend: AppBackend {
1010
static var mainWindow: UIWindow?
1111
static var hasReturnedAWindow = false
1212

13+
private var timeZoneObserver: NSObjectProtocol?
14+
1315
public let scrollBarWidth = 0
1416
public let defaultPaddingAmount = 15
1517
public let requiresToggleSwitchSpacer = true
@@ -87,6 +89,7 @@ public final class UIKitBackend: AppBackend {
8789
var environment = defaultEnvironment
8890

8991
environment.toggleStyle = .switch
92+
environment.timeZone = .current
9093

9194
switch UITraitCollection.current.userInterfaceStyle {
9295
case .light:
@@ -102,6 +105,17 @@ public final class UIKitBackend: AppBackend {
102105

103106
public func setRootEnvironmentChangeHandler(to action: @escaping () -> Void) {
104107
onTraitCollectionChange = action
108+
if timeZoneObserver == nil {
109+
timeZoneObserver = NotificationCenter.default.addObserver(
110+
forName: .NSSystemTimeZoneDidChange,
111+
object: nil,
112+
queue: .main
113+
) { [unowned self] _ in
114+
MainActor.assumeIsolated {
115+
self.onTraitCollectionChange?()
116+
}
117+
}
118+
}
105119
}
106120

107121
public func computeWindowEnvironment(

0 commit comments

Comments
 (0)