Skip to content

Commit 492a66e

Browse files
authored
Merge pull request #15 from v2er-app/feature/mock-feed-debug
Fix: Dark mode support improvements
2 parents 513442d + 204e099 commit 492a66e

File tree

16 files changed

+103
-49
lines changed

16 files changed

+103
-49
lines changed

V2er/General/V2erApp.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ struct V2erApp: App {
3434
.preferredColorScheme(store.appState.settingState.appearance.colorScheme)
3535
.onAppear {
3636
updateNavigationBarAppearance(for: store.appState.settingState.appearance)
37+
updateWindowInterfaceStyle(for: store.appState.settingState.appearance)
3738
}
3839
.onChange(of: store.appState.settingState.appearance) { newValue in
3940
updateNavigationBarAppearance(for: newValue)
41+
updateWindowInterfaceStyle(for: newValue)
4042
}
4143
}
4244
}
@@ -68,6 +70,26 @@ struct V2erApp: App {
6870
navAppearance.backgroundColor = .clear
6971
navAppearance.tintColor = tintColor
7072
}
73+
74+
private func updateWindowInterfaceStyle(for appearance: AppearanceMode) {
75+
// Get all windows and update their interface style
76+
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene else { return }
77+
78+
let style: UIUserInterfaceStyle
79+
switch appearance {
80+
case .light:
81+
style = .light
82+
case .dark:
83+
style = .dark
84+
case .system:
85+
style = .unspecified
86+
}
87+
88+
// Update all windows in the scene
89+
windowScene.windows.forEach { window in
90+
window.overrideUserInterfaceStyle = style
91+
}
92+
}
7193

7294
static func changeStatusBarStyle(_ style: UIStatusBarStyle) {
7395
guard style != statusBarState else { return }

V2er/View/Explore/SearchPage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct SearchPage: StateView {
4747
HStack(spacing: 0) {
4848
HStack {
4949
Image(systemName: "magnifyingglass")
50-
.foregroundColor(.gray)
50+
.foregroundColor(.secondaryText)
5151
TextField("sov2ex", text: bindingState.keyword)
5252
.disableAutocorrection(true)
5353
.autocapitalization(.none)
@@ -83,7 +83,7 @@ struct SearchPage: StateView {
8383
Divider()
8484
}
8585
.visualBlur()
86-
.background(Color.gray.opacity(0.35))
86+
.background(Color.secondaryText.opacity(0.35))
8787
}
8888

8989
@ViewBuilder

V2er/View/Feed/FeedItemView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct FeedItemView<Data: FeedItemProtocol>: View {
3030
}
3131
Text(data.title.safe)
3232
// .fontWeight(.medium)
33-
.foregroundColor(.bodyText)
33+
.foregroundColor(.primaryText)
3434
.greedyWidth(.leading)
3535
.lineLimit(2)
3636
.padding(.top, 6)

V2er/View/Feed/FeedPage.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,23 @@ struct FeedPage: BaseHomePageView {
3333

3434
@ViewBuilder
3535
private var contentView: some View {
36-
LazyVStack(spacing: 0) {
37-
ForEach(state.feedInfo.items) { item in
38-
NavigationLink(destination: FeedDetailPage(initData: item)) {
39-
FeedItemView(data: item)
36+
VStack(spacing: 0) {
37+
LazyVStack(spacing: 0) {
38+
ForEach(state.feedInfo.items) { item in
39+
NavigationLink(destination: FeedDetailPage(initData: item)) {
40+
FeedItemView(data: item)
41+
}
4042
}
4143
}
4244
}
4345
.updatable(autoRefresh: state.showProgressView, hasMoreData: state.hasMoreData, scrollTop(tab: .feed)) {
44-
await run(action: FeedActions.FetchData.Start())
46+
if AccountState.hasSignIn() {
47+
await run(action: FeedActions.FetchData.Start())
48+
}
4549
} loadMore: {
46-
await run(action: FeedActions.LoadMore.Start(state.willLoadPage))
50+
if AccountState.hasSignIn() {
51+
await run(action: FeedActions.LoadMore.Start(state.willLoadPage))
52+
}
4753
}
4854
.background(Color.bgColor)
4955
}

V2er/View/FeedDetail/AuthorInfoView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct AuthorInfoView: View {
6060
NavigationLink(destination: TagDetailPage(tag: tag, tagId: tagId)) {
6161
Text(tag)
6262
.font(.footnote)
63-
.foregroundColor(.black)
63+
.foregroundColor(.primaryText)
6464
.lineLimit(1)
6565
.padding(.horizontal, 14)
6666
.padding(.vertical, 8)

V2er/View/FeedDetail/FeedDetailPage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ struct FeedDetailPage: StateView, KeyboardReadable, InstanceIdentifiable {
150150
.padding(.bottom, isKeyboardVisiable ? 0 : topSafeAreaInset().bottom * 0.9)
151151
.padding(.top, 10)
152152
.padding(.horizontal, 10)
153-
.background(Color.white)
153+
.background(Color.itemBg)
154154
}
155155
}
156156

V2er/View/FeedDetail/HtmlView.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ struct HtmlView: View {
2727

2828
var body: some View {
2929
GeometryReader { geo in
30-
Webview(html: html, imgs: imgs,height: $height, rendered: $rendered)
30+
Webview(html: html, imgs: imgs, height: $height, rendered: $rendered)
31+
.environmentObject(Store.shared)
3132
}
3233
.frame(height: height)
3334
}
@@ -39,6 +40,8 @@ fileprivate struct Webview: UIViewRepresentable, WebViewHandlerDelegate {
3940
@Binding var height: CGFloat
4041
@Binding var rendered: Bool
4142
@State var loaded: Bool = false
43+
@EnvironmentObject var store: Store
44+
@Environment(\.colorScheme) var colorScheme
4245

4346
// Make a coordinator to co-ordinate with WKWebView's default delegate functions
4447
func makeCoordinator() -> Coordinator {
@@ -70,8 +73,17 @@ fileprivate struct Webview: UIViewRepresentable, WebViewHandlerDelegate {
7073
print("------updateUIView--------: \(self.rendered)")
7174
// if rendered { return }
7275
var content = Bundle.readString(name: "v2er", type: "html")
73-
// TODO: dark mode
74-
let isDark = false
76+
// Determine dark mode based on app appearance setting
77+
let isDark: Bool
78+
let appearance = store.appState.settingState.appearance
79+
switch appearance {
80+
case .dark:
81+
isDark = true
82+
case .light:
83+
isDark = false
84+
case .system:
85+
isDark = colorScheme == .dark
86+
}
7587
let fontSize = 16
7688
let params = "\(isDark), \(fontSize)"
7789
content = content?.replace(segs: "{injecttedContent}", with: html ?? .empty)

V2er/View/FeedDetail/ReplyItemView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct ReplyItemView: View {
2222
.font(.system(size: 8))
2323
.padding(.horizontal, 4)
2424
.padding(.vertical, 2)
25-
.cornerBorder(radius: 3, borderWidth: 0.8, color: .black)
25+
.cornerBorder(radius: 3, borderWidth: 0.8, color: .primaryText)
2626
.padding(.top, 2)
2727
.hide(!info.isOwner)
2828
}

V2er/View/Login/TwoStepLoginPage.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,34 @@ struct TwoStepLoginPage: View {
1919
VStack(spacing: 16) {
2020
Text("两步验证")
2121
.font(.subheadline)
22+
.foregroundColor(.primaryText)
2223
TextField("2FA码", text: $twoStepCode)
24+
.textFieldStyle(RoundedBorderTextFieldStyle())
25+
.keyboardType(.numberPad)
26+
.foregroundColor(.primaryText)
2327
.padding(.vertical, 6)
2428
.padding(.horizontal)
25-
.background(Color.white.opacity(0.8))
26-
.cornerBorder(radius: 8)
2729
HStack(spacing: 16) {
2830
Spacer()
2931
Button {
3032
dispatch(LoginActions.TwoStepLoginCancel())
31-
} label: { Text("取消").opacity(0.8) }
33+
} label: {
34+
Text("取消")
35+
.foregroundColor(.secondaryText)
36+
}
3237
Button {
3338
dispatch(LoginActions.TwoStepLogin(input: twoStepCode))
34-
} label: { Text("确定") }
39+
} label: {
40+
Text("确定")
41+
.foregroundColor(.tintColor)
42+
.fontWeight(.medium)
43+
}
3544
.disabled(twoStepCode.isEmpty)
3645
}
37-
.foregroundColor(.bodyText)
3846
}
3947
.padding(20)
40-
.visualBlur()
41-
.cornerBorder(radius: 20, borderWidth: 0)
48+
.background(Color.secondaryBackground)
49+
.cornerRadius(20)
4250
.padding(50)
4351
}
4452

V2er/View/Me/CreateTopicPage.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct CreateTopicPage: StateView {
6666
} label: {
6767
Text(isPreviewing ? "编辑" : "预览")
6868
.font(.callout)
69-
.foregroundColor(Color.white)
69+
.foregroundColor(Color.background)
7070
.padding(.horizontal, 12)
7171
.padding(.vertical, 8)
7272
.background(Color.tintColor)
@@ -106,7 +106,7 @@ struct CreateTopicPage: StateView {
106106
// show placeholder
107107
Text("如果标题能够表达完整内容, 此处可为空")
108108
.greedyFrame(.topLeading)
109-
.foregroundColor(.gray)
109+
.foregroundColor(.secondaryText)
110110
.debug()
111111
} else if isPreviewing {
112112
Text(state.content.attributedString)
@@ -135,7 +135,7 @@ struct CreateTopicPage: StateView {
135135
} label: {
136136
Text("发布主题")
137137
.font(.callout)
138-
.foregroundColor(Color.white)
138+
.foregroundColor(Color.background)
139139
.padding(.horizontal, 12)
140140
.padding(.vertical, 8)
141141
.background(Color.tintColor)
@@ -156,12 +156,12 @@ struct CreateTopicPage: StateView {
156156
private var sectionItemView: some View {
157157
HStack {
158158
Image(systemName: "grid.circle")
159-
.foregroundColor(.gray)
159+
.foregroundColor(.secondaryText)
160160
Text(state.selectedNode?.text ?? "选择节点")
161161
Spacer()
162162
Image(systemName: "chevron.right")
163163
.font(.body.weight(.regular))
164-
.foregroundColor(.gray)
164+
.foregroundColor(.secondaryText)
165165
.padding(.trailing)
166166
}
167167
.padding()

0 commit comments

Comments
 (0)