Improve navigation in 'More' tab: Use NavigationLink for native list navigation behavior in PhoneTabView (Phone TabView now consistent with Sidebar)

This commit is contained in:
Ilyas Hallak 2025-07-02 16:38:06 +02:00
parent be68538da3
commit a5ccc75036

View File

@ -8,38 +8,70 @@
import SwiftUI
struct PhoneTabView: View {
private let mainTabs: [SidebarTab] = [.all, .unread, .favorite, .archived]
private let moreTabs: [SidebarTab] = [.article, .videos, .pictures, .tags, .settings]
@State private var selectedMoreTab: SidebarTab? = nil
@State private var selectedTabIndex: Int = 0
var body: some View {
TabView {
NavigationStack {
BookmarksView(state: .unread, type: [.article, .video, .photo], selectedBookmark: .constant(nil))
}
.tabItem {
Label("Alle", systemImage: "list.bullet")
TabView(selection: $selectedTabIndex) {
ForEach(Array(mainTabs.enumerated()), id: \.element) { idx, tab in
NavigationStack {
tabView(for: tab)
}
.tabItem {
Label(tab.label, systemImage: tab.systemImage)
}
.tag(idx)
}
NavigationStack {
BookmarksView(state: .unread, type: [.article], selectedBookmark: .constant(nil))
List(moreTabs, id: \.self, selection: $selectedMoreTab) { tab in
NavigationLink(tag: tab, selection: $selectedMoreTab) {
tabView(for: tab)
.navigationTitle(tab.label)
} label: {
Label(tab.label, systemImage: tab.systemImage)
}
}
.navigationTitle("Mehr")
}
.tabItem {
Label("Ungelesen", systemImage: "house")
Label("Mehr", systemImage: "ellipsis")
}
BookmarksView(state: .favorite, type: [.article], selectedBookmark: .constant(nil))
.tabItem {
Label("Favoriten", systemImage: "heart")
}
BookmarksView(state: .archived, type: [.article], selectedBookmark: .constant(nil))
.tabItem {
Label("Archiv", systemImage: "archivebox")
}
SettingsView()
.tabItem {
Label("Settings", systemImage: "gear")
.tag(mainTabs.count)
.onAppear {
// Wenn der Mehr-Tab aktiv wird und wir in einer Detailansicht sind, zurücksetzen
if selectedTabIndex == mainTabs.count && selectedMoreTab != nil {
selectedMoreTab = nil
}
}
}
.accentColor(.accentColor)
}
@ViewBuilder
private func tabView(for tab: SidebarTab) -> some View {
switch tab {
case .all:
BookmarksView(state: .all, type: [.article, .video, .photo], selectedBookmark: .constant(nil))
case .unread:
BookmarksView(state: .unread, type: [.article], selectedBookmark: .constant(nil))
case .favorite:
BookmarksView(state: .favorite, type: [.article], selectedBookmark: .constant(nil))
case .archived:
BookmarksView(state: .archived, type: [.article], selectedBookmark: .constant(nil))
case .settings:
SettingsView()
case .article:
BookmarksView(state: .all, type: [.article], selectedBookmark: .constant(nil))
case .videos:
BookmarksView(state: .all, type: [.video], selectedBookmark: .constant(nil))
case .pictures:
BookmarksView(state: .all, type: [.photo], selectedBookmark: .constant(nil))
case .tags:
Text("Tags")
}
}
}