Skip to content

Commit 447c8be

Browse files
authored
Merge pull request #19 from v2er-app/feature/improve-ui-theming-consistency
feat: improve UI theming consistency across components
2 parents 6fe26ab + 662199d commit 447c8be

File tree

9 files changed

+77
-8
lines changed

9 files changed

+77
-8
lines changed

V2er/General/Extentions.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Foundation
1010
import SwiftUI
11+
import SafariServices
1112

1213
extension String {
1314
static let `default`: String = ""
@@ -271,3 +272,16 @@ extension URL {
271272
}
272273
}
273274
}
275+
276+
277+
// MARK: - Safari View
278+
struct SafariView: UIViewControllerRepresentable {
279+
let url: URL
280+
281+
func makeUIViewController(context: UIViewControllerRepresentableContext<SafariView>) -> SFSafariViewController {
282+
return SFSafariViewController(url: url)
283+
}
284+
285+
func updateUIViewController(_ uiViewController: SFSafariViewController, context: UIViewControllerRepresentableContext<SafariView>) {
286+
}
287+
}

V2er/View/FeedDetail/FeedDetailPage.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
//
88

99
import SwiftUI
10+
import SafariServices
1011

1112
struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
1213
@Environment(\.isPresented) private var isPresented
1314
@Environment(\.dismiss) var dismiss
1415
@EnvironmentObject private var store: Store
1516
@State var rendered: Bool = false
17+
@State private var showingSafari = false
18+
@State private var safariURL: URL?
1619

1720
var bindingState: Binding<FeedDetailState> {
1821
if store.appState.feedDetailStates[instanceId] == nil {
@@ -57,6 +60,11 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
5760
var body: some View {
5861
contentView
5962
.navigatable()
63+
.sheet(isPresented: $showingSafari) {
64+
if let url = safariURL {
65+
SafariView(url: url)
66+
}
67+
}
6068
}
6169

6270
@ViewBuilder
@@ -134,7 +142,7 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
134142
} label: {
135143
Image(systemName: "arrow.up.circle.fill")
136144
.font(.title.weight(.regular))
137-
.foregroundColor(Color.bodyText.opacity(hasReplyContent ? 1.0 : 0.6))
145+
.foregroundColor(Color.tintColor.opacity(hasReplyContent ? 1.0 : 0.6))
138146
.padding(.trailing, 6)
139147
.padding(.vertical, 3)
140148
}
@@ -231,6 +239,17 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
231239
Label(reported ? "已举报" : "举报", systemImage: "person.crop.circle.badge.exclamationmark")
232240
}
233241
.disabled(reported)
242+
243+
Divider()
244+
245+
Button {
246+
if let url = URL(string: APIService.baseUrlString + "/t/\(id)") {
247+
safariURL = url
248+
showingSafari = true
249+
}
250+
} label: {
251+
Label("使用浏览器打开", systemImage: "safari")
252+
}
234253
} label: {
235254
Image(systemName: "ellipsis")
236255
.padding(8)

V2er/View/FeedDetail/ReplyItemView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ struct ReplyItemView: View {
3030
HStack {
3131
VStack (alignment: .leading, spacing: 4) {
3232
Text(info.userName)
33+
.foregroundColor(.primaryText)
3334
Text(info.time)
3435
.font(.caption2)
36+
.foregroundColor(.secondaryText)
3537
}
3638
Spacer()
3739
// Image(systemName: "heart")

V2er/View/Me/UserDetailPage.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,13 @@ struct UserDetailPage: StateView {
248248
struct ReplyItemView: View {
249249
var data: UserDetailInfo.ReplyInfo.Item
250250
let quoteFont = Style.font(UIFont.prfered(.footnote))
251-
.foregroundColor(Color.bodyText.uiColor)
251+
.foregroundColor(Color.primaryText.uiColor)
252252

253253
var body: some View {
254254
VStack(spacing: 0) {
255255
Text(data.title)
256256
.font(.footnote)
257+
.foregroundColor(.primaryText)
257258
.greedyWidth(.leading)
258259
RichText {
259260
data.content
@@ -272,6 +273,7 @@ struct UserDetailPage: StateView {
272273
.padding(.vertical, 6)
273274
Text(data.time)
274275
.font(.footnote)
276+
.foregroundColor(.secondaryText)
275277
.greedyWidth(.trailing)
276278
}
277279
.padding(12)

V2er/View/Me/UserFeedPage.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct UserFeedPage: StateView, InstanceIdentifiable {
5656
HStack(alignment: .top) {
5757
VStack(alignment: .leading, spacing: 5) {
5858
Text(data.userName)
59+
.foregroundColor(.primaryText)
5960
.lineLimit(1)
6061
Text(data.replyUpdate)
6162
.lineLimit(1)
@@ -67,19 +68,21 @@ struct UserFeedPage: StateView, InstanceIdentifiable {
6768
NavigationLink(destination: TagDetailPage()) {
6869
Text(data.tag)
6970
.font(.footnote)
70-
.foregroundColor(.black)
71+
.foregroundColor(.primaryText)
7172
.lineLimit(1)
7273
.padding(.horizontal, 14)
7374
.padding(.vertical, 8)
7475
.background(Color.lightGray)
7576
}
7677
}
7778
Text(data.title)
79+
.foregroundColor(.primaryText)
7880
.greedyWidth(.leading)
7981
.lineLimit(2)
8082
Text("评论\(data.replyNum)")
8183
.lineLimit(1)
8284
.font(.footnote)
85+
.foregroundColor(.secondaryText)
8386
.greedyWidth(.trailing)
8487
}
8588
.padding(12)

V2er/View/Settings/OtherSettingsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct OtherSettingsView: View {
4545
.foregroundColor(Color.tintColor)
4646
Image(systemName: "chevron.right")
4747
.font(.body.weight(.regular))
48-
.foregroundColor(.gray)
48+
.foregroundColor(.secondaryText)
4949
.padding(.trailing, 16)
5050
}
5151
}

V2er/View/Settings/SettingsPage.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
import SwiftUI
10+
import SafariServices
1011

1112
struct SettingsPage: View {
1213
@Environment(\.dismiss) var dismiss
@@ -29,8 +30,12 @@ struct SettingsPage: View {
2930
SectionItemView("通用设置")
3031
.to { OtherSettingsView() }
3132

32-
SectionItemView("帮助与反馈")
33+
SectionItemView("问题反馈")
3334
.padding(.top, 8)
35+
.to {
36+
SafariWebView(url: "https://github.com/v2er-app/iOS/issues")
37+
}
38+
SectionItemView("V2EX帮助")
3439
.to {
3540
WebBrowserView(url: "https://www.v2ex.com/help")
3641
}
@@ -103,6 +108,25 @@ struct SettingsPage: View {
103108
}
104109
}
105110

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+
}
129+
106130
struct SettingsPage_Previews: PreviewProvider {
107131
static var previews: some View {
108132
SettingsPage()

V2er/View/Widget/MultilineTextField.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fileprivate struct UITextViewWrapper: UIViewRepresentable {
2626
textField.isUserInteractionEnabled = true
2727
textField.isScrollEnabled = false
2828
textField.backgroundColor = UIColor.clear
29-
textField.textColor = Color.bodyText.uiColor
29+
textField.textColor = Color.primaryText.uiColor
3030

3131
// textField.textContainer.maximumNumberOfLines = 5
3232

@@ -42,6 +42,11 @@ fileprivate struct UITextViewWrapper: UIViewRepresentable {
4242
if uiView.text != self.text {
4343
uiView.text = self.text
4444
}
45+
// Update text color to ensure it responds to theme changes
46+
let desiredColor = Color.primaryText.uiColor
47+
if uiView.textColor != desiredColor {
48+
uiView.textColor = desiredColor
49+
}
4550
if uiView.window != nil, !uiView.isFirstResponder {
4651
// uiView.becomeFirstResponder()
4752
}
@@ -127,7 +132,7 @@ struct MultilineTextField: View {
127132
Group {
128133
if showingPlaceholder {
129134
Text(placeholder)
130-
.foregroundColor(.gray)
135+
.foregroundColor(.secondaryText)
131136
.padding(.leading, 4)
132137
}
133138
}

V2er/View/Widget/RichText/RichText.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ struct RichText: View {
3838

3939
struct Styles {
4040
public static let base = Style.font(UIFont.prfered(.body))
41-
.foregroundColor(Color.bodyText.uiColor)
41+
.foregroundColor(Color.primaryText.uiColor)
4242
public static let link = Style("a")
4343
.font(.boldSystemFont(ofSize: 16))
4444
.foregroundColor(Color.url.uiColor, .normal)

0 commit comments

Comments
 (0)