Skip to content

Commit 8bbd843

Browse files
graycreateclaude
andauthored
fix: restore tag navigation and fix navbar filter refresh (#83)
- Restore tag element background color and navigation in FeedItemView - Add tag navigation to RecentItemView (最近浏览) - Fix UserFeedPage tag crash by adding missing tagId parameter - Fix navbar title not updating when filter menu selection changes by moving TopBar outside TabView content - Unify tag styling across all list views 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <[email protected]>
1 parent bd6bab6 commit 8bbd843

File tree

5 files changed

+66
-62
lines changed

5 files changed

+66
-62
lines changed

V2er/View/Feed/FeedItemView.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ struct FeedItemView<Data: FeedItemProtocol>: View {
2424
.lineLimit(1)
2525
.foregroundColor(Color.tintColor)
2626
Spacer()
27-
Text(data.nodeName.safe)
28-
.font(.footnote)
29-
.foregroundColor(.gray)
27+
NavigationLink(destination: TagDetailPage(tagId: data.nodeId.safe)) {
28+
Text(data.nodeName.safe)
29+
.font(.footnote)
30+
.foregroundColor(Color.dynamic(light: .hex(0x666666), dark: .hex(0xCCCCCC)))
31+
.lineLimit(1)
32+
.padding(.horizontal, 10)
33+
.padding(.vertical, 6)
34+
.background(Color.dynamic(light: Color.hex(0xF5F5F5), dark: Color.hex(0x2C2C2E)))
35+
}
36+
.buttonStyle(.plain)
3037
}
3138
Text(data.title.safe)
3239
// .fontWeight(.medium)

V2er/View/MainPage.swift

Lines changed: 33 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -60,49 +60,47 @@ struct MainPage: StateView {
6060
var body: some View {
6161
NavigationStack {
6262
ZStack {
63-
TabView(selection: tabSelection) {
64-
// Feed Tab
65-
pageWithTopBar(
63+
VStack(spacing: 0) {
64+
// TopBar outside TabView to ensure it updates immediately
65+
TopBar(selectedTab: state.selectedTab, feedFilterTab: store.appState.feedState.selectedTab)
66+
67+
TabView(selection: tabSelection) {
68+
// Feed Tab
6669
FeedPage(selecedTab: state.selectedTab)
67-
)
68-
.tabItem {
69-
Label("最新", systemImage: "newspaper")
70-
}
71-
.tag(TabId.feed)
70+
.tabItem {
71+
Label("最新", systemImage: "newspaper")
72+
}
73+
.tag(TabId.feed)
7274

73-
// Explore Tab
74-
pageWithTopBar(
75+
// Explore Tab
7576
ExplorePage(selecedTab: state.selectedTab)
76-
)
77-
.tabItem {
78-
Label("发现", systemImage: "safari")
79-
}
80-
.tag(TabId.explore)
77+
.tabItem {
78+
Label("发现", systemImage: "safari")
79+
}
80+
.tag(TabId.explore)
8181

82-
// Message Tab
83-
pageWithTopBar(
82+
// Message Tab
8483
MessagePage(selecedTab: state.selectedTab)
85-
)
86-
.tabItem {
87-
if unReadNums > 0 {
88-
Label("通知", systemImage: "bell")
89-
.badge(unReadNums)
90-
} else {
91-
Label("通知", systemImage: "bell")
92-
}
93-
}
94-
.tag(TabId.message)
95-
96-
// Me Tab
97-
pageWithTopBar(
84+
.tabItem {
85+
if unReadNums > 0 {
86+
Label("通知", systemImage: "bell")
87+
.badge(unReadNums)
88+
} else {
89+
Label("通知", systemImage: "bell")
90+
}
91+
}
92+
.tag(TabId.message)
93+
94+
// Me Tab
9895
MePage(selecedTab: state.selectedTab)
99-
)
100-
.tabItem {
101-
Label("", systemImage: "person")
96+
.tabItem {
97+
Label("", systemImage: "person")
98+
}
99+
.tag(TabId.me)
102100
}
103-
.tag(TabId.me)
101+
.accentColor(Color.primary) // This controls the selected icon color in TabView
104102
}
105-
.accentColor(Color.primary) // This controls the selected icon color in TabView
103+
.ignoresSafeArea(.container, edges: .top)
106104

107105
// Filter menu overlay - only render when needed
108106
if state.selectedTab == .feed && store.appState.feedState.showFilterMenu {
@@ -127,15 +125,6 @@ struct MainPage: StateView {
127125
}
128126
}
129127

130-
@ViewBuilder
131-
private func pageWithTopBar<Content: View>(_ content: Content) -> some View {
132-
VStack(spacing: 0) {
133-
TopBar(selectedTab: state.selectedTab)
134-
content
135-
}
136-
.ignoresSafeArea(.container, edges: .top)
137-
}
138-
139128
}
140129

141130

V2er/View/Me/MyRecentPage.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,16 @@ struct RecentItemView<Data: FeedItemProtocol>: View {
5555
.foregroundColor(Color.tintColor)
5656
}
5757
Spacer()
58-
Text(data.nodeName.safe)
59-
.font(.footnote)
60-
.foregroundColor(.gray)
58+
NavigationLink(destination: TagDetailPage(tagId: data.nodeId.safe)) {
59+
Text(data.nodeName.safe)
60+
.font(.footnote)
61+
.foregroundColor(Color.dynamic(light: .hex(0x666666), dark: .hex(0xCCCCCC)))
62+
.lineLimit(1)
63+
.padding(.horizontal, 10)
64+
.padding(.vertical, 6)
65+
.background(Color.dynamic(light: Color.hex(0xF5F5F5), dark: Color.hex(0x2C2C2E)))
66+
}
67+
.buttonStyle(.plain)
6168
}
6269
Text(data.title.safe)
6370
.greedyWidth(.leading)

V2er/View/Me/UserFeedPage.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,16 @@ struct UserFeedPage: StateView, InstanceIdentifiable {
6565
.foregroundColor(Color.tintColor)
6666
}
6767
Spacer()
68-
NavigationLink(destination: TagDetailPage()) {
68+
NavigationLink(destination: TagDetailPage(tagId: data.tagId)) {
6969
Text(data.tag)
7070
.font(.footnote)
71-
.foregroundColor(.primaryText)
71+
.foregroundColor(Color.dynamic(light: .hex(0x666666), dark: .hex(0xCCCCCC)))
7272
.lineLimit(1)
73-
.padding(.horizontal, 14)
74-
.padding(.vertical, 8)
75-
.background(Color.lightGray)
73+
.padding(.horizontal, 10)
74+
.padding(.vertical, 6)
75+
.background(Color.dynamic(light: Color.hex(0xF5F5F5), dark: Color.hex(0x2C2C2E)))
7676
}
77+
.buttonStyle(.plain)
7778
}
7879
Text(data.title)
7980
.foregroundColor(.primaryText)

V2er/View/Widget/TopBar.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ import SwiftUI
1010

1111
struct TopBar: View {
1212
@EnvironmentObject private var store: Store
13-
var selectedTab : TabId
13+
var selectedTab: TabId
14+
var feedFilterTab: Tab // Explicit parameter to trigger SwiftUI re-render
1415
@State private var rotationAngle: Double = 0
15-
16+
1617
private var isHomePage: Bool {
1718
return selectedTab == .feed
1819
}
19-
20+
2021
private var title: String {
2122
switch selectedTab {
2223
case .feed:
23-
let selectedTab = store.appState.feedState.selectedTab
24-
return selectedTab == .all ? "V2EX" : selectedTab.displayName()
24+
return feedFilterTab == .all ? "V2EX" : feedFilterTab.displayName()
2525
case .explore:
2626
return "发现"
2727
case .message:
@@ -104,10 +104,10 @@ struct TopBar: View {
104104
struct TopBar_Previews: PreviewProvider {
105105
// @State static var selecedTab = TabId.feed
106106
static var selecedTab = TabId.explore
107-
107+
108108
static var previews: some View {
109109
VStack {
110-
TopBar(selectedTab: selecedTab)
110+
TopBar(selectedTab: selecedTab, feedFilterTab: .all)
111111
Spacer()
112112
}
113113
.ignoresSafeArea(.container)

0 commit comments

Comments
 (0)