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 { @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) #if os(iOS) || os(tvOS)
.toolbar { .toolbar {
toolbar toolbar
@@ -139,10 +156,20 @@ import SwiftUI
#if os(iOS) || os(tvOS) #if os(iOS) || os(tvOS)
.onReceive(environments.commandClient.$groups) { _ in .onReceive(environments.commandClient.$groups) { _ in
updateButtonVisibility() updateButtonVisibility()
#if os(iOS)
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
coordinator.selection = .overview
}
#endif
}.onReceive(environments.commandClient.$connections) { _ in }.onReceive(environments.commandClient.$connections) { _ in
updateButtonVisibility() updateButtonVisibility()
}.onReceive(profile.$status) { _ in }.onReceive(profile.$status) { _ in
updateButtonVisibility() updateButtonVisibility()
#if os(iOS)
if useLegacyTabView, coordinator.selection == .groups, !buttonState.showGroupsButton {
coordinator.selection = .overview
}
#endif
}.onAppear { }.onAppear {
updateButtonVisibility() updateButtonVisibility()
} }
@@ -171,6 +198,44 @@ import SwiftUI
} }
return false 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 #endif
@ToolbarContentBuilder private var toolbar: some ToolbarContent { @ToolbarContentBuilder private var toolbar: some ToolbarContent {
@@ -223,33 +288,10 @@ import SwiftUI
@available(iOS 16.0, *) @ViewBuilder private var cardManagementButton: some View { @available(iOS 16.0, *) @ViewBuilder private var cardManagementButton: some View {
#if os(iOS) #if os(iOS)
Menu { Button {
if !isTabViewBottomAccessoryAvailable { showCardManagement = true
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")
}
} label: { } label: {
Label("Others", systemImage: "line.3.horizontal.circle") Label("Dashboard Items", systemImage: "square.grid.2x2")
} }
#elseif os(tvOS) #elseif os(tvOS)
Button { Button {
@@ -18,7 +18,20 @@ public extension DashboardPage {
.overview, .overview,
.groups, .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 { if Variant.isBeta {
cases.append(.connections) cases.append(.connections)
} }
+2 -1
View File
@@ -348,6 +348,7 @@
} }
}, },
"Connections (%lld)" : { "Connections (%lld)" : {
"extractionState" : "stale",
"localizations" : { "localizations" : {
"zh-Hans" : { "zh-Hans" : {
"stringUnit" : { "stringUnit" : {
@@ -814,6 +815,7 @@
} }
}, },
"Groups (%lld)" : { "Groups (%lld)" : {
"extractionState" : "stale",
"localizations" : { "localizations" : {
"zh-Hans" : { "zh-Hans" : {
"stringUnit" : { "stringUnit" : {
@@ -1353,7 +1355,6 @@
} }
}, },
"Page" : { "Page" : {
"extractionState" : "stale",
"localizations" : { "localizations" : {
"zh-Hans" : { "zh-Hans" : {
"stringUnit" : { "stringUnit" : {