You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+68Lines changed: 68 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,6 +123,74 @@ When the user switches the theme, apply it by assigning it to the `current` inst
123
123
Theme.current= halloweenTheme
124
124
```
125
125
126
+
**Handling Theme Changes**
127
+
128
+
When changing themes dynamically, you may need to **update the UI** to reflect the new theme. Below are approaches for handling this in different environments.
129
+
130
+
**SwiftUI**
131
+
132
+
For SwiftUI apps, you can use `ThemeChangeObserver` to automatically refresh views when the theme updates.
133
+
134
+
```swift
135
+
@main
136
+
structRoot: App {
137
+
var body: some Scene {
138
+
WindowGroup {
139
+
ThemeChangeObserver {
140
+
Content()
141
+
}
142
+
}
143
+
}
144
+
}
145
+
```
146
+
147
+
We recommend using this helper in the root of your app to redraw everything at once.
148
+
149
+
**UIKit**
150
+
151
+
For UIKit apps, use the `observeThemeChange(_:)` method to update elements that depend on the properties from the library.
0 commit comments