Restore nested TabView for dashboard on iOS < 26

This commit is contained in:
世界
2025-12-03 19:57:15 +08:00
parent 727136f187
commit 2e58f37fe1
3 changed files with 85 additions and 29 deletions
@@ -57,7 +57,24 @@ import SwiftUI
}
@ViewBuilder private var content: some View {
overviewPage
Group {
#if os(iOS)
if useLegacyTabView {
if ApplicationLibrary.inPreview || profile.status.isConnectedStrict {
VStack {
pageSelector
pageContent
}
} else {
overviewPage
}
} else {
overviewPage
}
#else
overviewPage
#endif
}
#if os(iOS) || os(tvOS)
.toolbar {
toolbar
@@ -139,10 +156,20 @@ import SwiftUI
#if os(iOS) || os(tvOS)
.onReceive(environments.commandClient.$groups) { _ in
updateButtonVisibility()
#if os(iOS)
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
coordinator.selection = .overview
}
#endif
}.onReceive(environments.commandClient.$connections) { _ in
updateButtonVisibility()
}.onReceive(profile.$status) { _ in
updateButtonVisibility()
#if os(iOS)
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
coordinator.selection = .overview
}
#endif
}.onAppear {
updateButtonVisibility()
}
@@ -171,6 +198,44 @@ import SwiftUI
}
return false
}
private var useLegacyTabView: Bool {
!isTabViewBottomAccessoryAvailable
}
private var enabledPages: [DashboardPage] {
DashboardPage.enabledCases(hasGroups: buttonState.showGroupsButton)
}
@ViewBuilder
private var pageSelector: some View {
Picker("Page", selection: $coordinator.selection) {
ForEach(enabledPages) { page in
page.label
}
}
.pickerStyle(.segmented)
.padding([.leading, .trailing])
.navigationBarTitleDisplayMode(.inline)
}
@ViewBuilder
private var pageContent: some View {
TabView(selection: $coordinator.selection) {
ForEach(enabledPages) { page in
page.contentView(
$coordinator.profileList,
$coordinator.selectedProfileID,
$coordinator.systemProxyAvailable,
$coordinator.systemProxyEnabled,
externalCardConfigurationVersion ?? cardConfigurationVersion
)
.tag(page)
}
}
.navigationBarTitleDisplayMode(.inline)
.tabViewStyle(.page(indexDisplayMode: .never))
}
#endif
@ToolbarContentBuilder private var toolbar: some ToolbarContent {
@@ -223,33 +288,10 @@ import SwiftUI
@available(iOS 16.0, *) @ViewBuilder private var cardManagementButton: some View {
#if os(iOS)
Menu {
if !isTabViewBottomAccessoryAvailable {
if buttonState.showGroupsButton {
Button {
showGroups = true
} label: {
Label("Groups (\(buttonState.groupsCount))", systemImage: "rectangle.3.group.fill")
}
}
if buttonState.showConnectionsButton {
Button {
showConnections = true
} label: {
Label("Connections (\(buttonState.connectionsCount))", systemImage: "list.bullet.rectangle.portrait.fill")
}
}
if buttonState.showGroupsButton || buttonState.showConnectionsButton {
Divider()
}
}
Button {
showCardManagement = true
} label: {
Label("Dashboard Items", systemImage: "square.grid.2x2")
}
Button {
showCardManagement = true
} label: {
Label("Others", systemImage: "line.3.horizontal.circle")
Label("Dashboard Items", systemImage: "square.grid.2x2")
}
#elseif os(tvOS)
Button {
@@ -18,7 +18,20 @@ public extension DashboardPage {
.overview,
.groups,
]
#if !tvOS
#if !os(tvOS)
if Variant.isBeta {
cases.append(.connections)
}
#endif
return cases
}
static func enabledCases(hasGroups: Bool) -> [DashboardPage] {
var cases: [DashboardPage] = [.overview]
if hasGroups {
cases.append(.groups)
}
#if !os(tvOS)
if Variant.isBeta {
cases.append(.connections)
}