99import SwiftUI
1010import SafariServices
1111
12+ // Wrapper to make URL Identifiable for sheet presentation
13+ struct IdentifiableURL : Identifiable {
14+ let id = UUID ( )
15+ let url : URL
16+ }
17+
1218struct SettingsPage : View {
1319 @Environment ( \. dismiss) var dismiss
1420 @State private var showingAlert = false
1521 @State var logingOut : Bool = false
16-
22+ @State private var safariURL : IdentifiableURL ?
23+
1724 var body : some View {
1825 formView
1926 . navBar ( " 设置 " )
27+ . sheet ( item: $safariURL) { item in
28+ SafariView ( url: item. url)
29+ }
2030 }
21-
31+
2232 @ViewBuilder
2333 private var formView : some View {
2434 ScrollView {
2535 VStack ( spacing: 0 ) {
2636 SectionItemView ( " 外观设置 " , showDivider: false )
2737 . padding ( . top, 8 )
2838 . to { AppearanceSettingView ( ) }
29-
39+
3040 SectionItemView ( " 通用设置 " )
3141 . to { OtherSettingsView ( ) }
3242
43+ Button {
44+ if let url = URL ( string: " https://github.com/v2er-app/iOS/issues " ) {
45+ safariURL = IdentifiableURL ( url: url)
46+ }
47+ } label: {
3348 SectionItemView ( " 问题反馈 " )
3449 . padding ( . top, 8 )
35- . to {
36- SafariWebView ( url: " https://github.com/v2er-app/iOS/issues " )
37- }
50+ }
51+
52+ Button {
53+ if let url = URL ( string: " https://www.v2ex.com/help " ) {
54+ safariURL = IdentifiableURL ( url: url)
55+ }
56+ } label: {
3857 SectionItemView ( " V2EX帮助 " )
39- . to {
40- WebBrowserView ( url: " https://www.v2ex.com/help " )
41- }
42- SectionItemView ( " 源码开放 " )
43- . to {
44- WebBrowserView ( url: " https://github.com/v2er-app " )
45- }
58+ }
4659
60+ Button {
61+ if let url = URL ( string: " https://github.com/v2er-app " ) {
62+ safariURL = IdentifiableURL ( url: url)
63+ }
64+ } label: {
65+ SectionItemView ( " 源码开放 " )
66+ }
67+
68+ Button {
69+ if let url = URL ( string: " https://v2er.app " ) {
70+ safariURL = IdentifiableURL ( url: url)
71+ }
72+ } label: {
4773 SectionView ( " 关于 " ) {
4874 HStack {
4975 Text ( " 版本1.0.0 " )
@@ -55,9 +81,7 @@ struct SettingsPage: View {
5581 . padding ( . trailing, 16 )
5682 }
5783 }
58- . to {
59- WebBrowserView ( url: " https://v2er.app " )
60- }
84+ }
6185
6286 Button {
6387 // "https://github.com/v2er-app".openURL()
@@ -108,24 +132,6 @@ struct SettingsPage: View {
108132 }
109133}
110134
111- struct SafariWebView : View {
112- let url : String
113- @State private var showingSafari = false
114-
115- var body : some View {
116- Color . clear
117- . onAppear {
118- if let url = URL ( string: url) {
119- showingSafari = true
120- }
121- }
122- . sheet ( isPresented: $showingSafari) {
123- if let url = URL ( string: url) {
124- SafariView ( url: url)
125- }
126- }
127- }
128- }
129135
130136struct SettingsPage_Previews : PreviewProvider {
131137 static var previews : some View {
0 commit comments