Skip to content

Commit e20ed28

Browse files
graycreateclaude
andcommitted
fix: safari view now respects current UI mode (light/dark)
- Added Environment property to track colorScheme in SafariView - Safari view controller now inherits interface style from root view controller - Properly handles system, light, and dark appearance modes - Sets appropriate tint colors based on effective UI style 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 447c8be commit e20ed28

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

V2er/General/Extentions.swift

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,43 @@ extension URL {
277277
// MARK: - Safari View
278278
struct SafariView: UIViewControllerRepresentable {
279279
let url: URL
280+
@Environment(\.colorScheme) var colorScheme
280281

281282
func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController {
282-
return SFSafariViewController(url: url)
283+
let safariVC = SFSafariViewController(url: url)
284+
updateAppearance(safariVC)
285+
return safariVC
283286
}
284287

285288
func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) {
289+
updateAppearance(uiViewController)
290+
}
291+
292+
private func updateAppearance(_ safariVC: SFSafariViewController) {
293+
// Get the actual interface style from the root view controller
294+
let actualStyle = V2erApp.rootViewController?.overrideUserInterfaceStyle ?? .unspecified
295+
296+
// Apply the appropriate style to Safari view
297+
if actualStyle != .unspecified {
298+
// User has explicitly set light or dark mode
299+
safariVC.overrideUserInterfaceStyle = actualStyle
300+
} else {
301+
// Following system setting - use the current colorScheme
302+
safariVC.overrideUserInterfaceStyle = colorScheme == .dark ? .dark : .light
303+
}
304+
305+
// Set tint colors based on the effective style
306+
let effectiveStyle = safariVC.overrideUserInterfaceStyle == .dark ||
307+
(safariVC.overrideUserInterfaceStyle == .unspecified && colorScheme == .dark)
308+
309+
if effectiveStyle {
310+
// Dark mode colors
311+
safariVC.preferredControlTintColor = UIColor.systemBlue
312+
safariVC.preferredBarTintColor = UIColor.systemBackground
313+
} else {
314+
// Light mode colors
315+
safariVC.preferredControlTintColor = UIColor.systemBlue
316+
safariVC.preferredBarTintColor = UIColor.systemBackground
317+
}
286318
}
287319
}

0 commit comments

Comments
 (0)