Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion V2er/General/Extentions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,43 @@ extension URL {
// MARK: - Safari View
struct SafariView: UIViewControllerRepresentable {
let url: URL
@Environment(\.colorScheme) var colorScheme

func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController {
return SFSafariViewController(url: url)
let safariVC = SFSafariViewController(url: url)
updateAppearance(safariVC)
return safariVC
}

func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) {
updateAppearance(uiViewController)
}

private func updateAppearance(_ safariVC: SFSafariViewController) {
// Get the actual interface style from the root view controller
let actualStyle = V2erApp.rootViewController?.overrideUserInterfaceStyle ?? .unspecified

// Apply the appropriate style to Safari view
if actualStyle != .unspecified {
// User has explicitly set light or dark mode
safariVC.overrideUserInterfaceStyle = actualStyle
} else {
// Following system setting - use the current colorScheme
safariVC.overrideUserInterfaceStyle = colorScheme == .dark ? .dark : .light
}

// Set tint colors based on the effective style
let effectiveStyle = safariVC.overrideUserInterfaceStyle == .dark ||
(safariVC.overrideUserInterfaceStyle == .unspecified && colorScheme == .dark)

if effectiveStyle {
// Dark mode colors
safariVC.preferredControlTintColor = UIColor.systemBlue
safariVC.preferredBarTintColor = UIColor.systemBackground
} else {
// Light mode colors
safariVC.preferredControlTintColor = UIColor.systemBlue
safariVC.preferredBarTintColor = UIColor.systemBackground
}
Comment on lines +309 to +317
Copy link

Copilot AI Sep 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tint color configuration is identical for both dark and light modes. This duplicated logic should be extracted outside the conditional or the conditional should be removed entirely since both branches set the same values.

Suggested change
if effectiveStyle {
// Dark mode colors
safariVC.preferredControlTintColor = UIColor.systemBlue
safariVC.preferredBarTintColor = UIColor.systemBackground
} else {
// Light mode colors
safariVC.preferredControlTintColor = UIColor.systemBlue
safariVC.preferredBarTintColor = UIColor.systemBackground
}
// Tint color configuration is identical for both dark and light modes
safariVC.preferredControlTintColor = UIColor.systemBlue
safariVC.preferredBarTintColor = UIColor.systemBackground

Copilot uses AI. Check for mistakes.
}
}
74 changes: 40 additions & 34 deletions V2er/View/Settings/SettingsPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,67 @@
import SwiftUI
import SafariServices

// Wrapper to make URL Identifiable for sheet presentation
struct IdentifiableURL: Identifiable {
let id = UUID()
let url: URL
}

struct SettingsPage: View {
@Environment(\.dismiss) var dismiss
@State private var showingAlert = false
@State var logingOut: Bool = false

@State private var safariURL: IdentifiableURL?

var body: some View {
formView
.navBar("设置")
.sheet(item: $safariURL) { item in
SafariView(url: item.url)
}
}

@ViewBuilder
private var formView: some View {
ScrollView {
VStack(spacing: 0) {
SectionItemView("外观设置", showDivider: false)
.padding(.top, 8)
.to { AppearanceSettingView() }

SectionItemView("通用设置")
.to { OtherSettingsView() }

Button {
if let url = URL(string: "https://github.com/v2er-app/iOS/issues") {
safariURL = IdentifiableURL(url: url)
}
} label: {
SectionItemView("问题反馈")
.padding(.top, 8)
.to {
SafariWebView(url: "https://github.com/v2er-app/iOS/issues")
}
}

Button {
if let url = URL(string: "https://www.v2ex.com/help") {
safariURL = IdentifiableURL(url: url)
}
} label: {
SectionItemView("V2EX帮助")
.to {
WebBrowserView(url: "https://www.v2ex.com/help")
}
SectionItemView("源码开放")
.to {
WebBrowserView(url: "https://github.com/v2er-app")
}
}

Button {
if let url = URL(string: "https://github.com/v2er-app") {
safariURL = IdentifiableURL(url: url)
}
} label: {
SectionItemView("源码开放")
}

Button {
if let url = URL(string: "https://v2er.app") {
safariURL = IdentifiableURL(url: url)
}
} label: {
SectionView("关于") {
HStack {
Text("版本1.0.0")
Expand All @@ -55,9 +81,7 @@ struct SettingsPage: View {
.padding(.trailing, 16)
}
}
.to {
WebBrowserView(url: "https://v2er.app")
}
}

Button {
// "https://github.com/v2er-app".openURL()
Expand Down Expand Up @@ -108,24 +132,6 @@ struct SettingsPage: View {
}
}

struct SafariWebView: View {
let url: String
@State private var showingSafari = false

var body: some View {
Color.clear
.onAppear {
if let url = URL(string: url) {
showingSafari = true
}
}
.sheet(isPresented: $showingSafari) {
if let url = URL(string: url) {
SafariView(url: url)
}
}
}
}

struct SettingsPage_Previews: PreviewProvider {
static var previews: some View {
Expand Down
Loading