Skip to content

Commit

Permalink
Add enum ContentViewTabs
Browse files Browse the repository at this point in the history
  • Loading branch information
F1248 committed Sep 19, 2024
1 parent f259483 commit 326ac03
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
1 change: 1 addition & 0 deletions Genius/Localization/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
}
},
"Home" : {
"extractionState" : "manual",
"localizations" : {
"de" : {
"stringUnit" : {
Expand Down
4 changes: 4 additions & 0 deletions Genius/Views/Common/TabContentBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ enum TabContentBuilder {
static func buildBlock(_ tabs: TabLegacy...) -> [TabLegacy] {
tabs
}

static func buildBlock(_ tabs: [TabLegacy]) -> [TabLegacy] {
tabs
}
}
34 changes: 12 additions & 22 deletions Genius/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,23 @@ struct ContentView: View {
var body: some View {
if #available(macOS 15, *) {
TabView {
Tab("Home") {
HomeView()
}
Tab("System Information", variesByInterfaceMode: true, viewInvalidator: interfaceMode) {
SystemInformationView()
}
Tab("Maintenance") {
MaintenanceView()
}
Tab("Settings") {
SettingsView()
ForEach(ContentViewTabs.allCases) { tab in
Tab(
tab.localizedStringKey,
variesByInterfaceMode: tab.variesByInterfaceMode,
viewInvalidator: tab.variesByInterfaceMode ? interfaceMode : nil
) { tab.content }
}
}
.frame(minWidth: 686, minHeight: 256)
} else {
TabViewLegacy(entireWindow: true) {
TabLegacy("Home") {
HomeView()
}
TabLegacy("System Information", variesByInterfaceMode: true, viewInvalidator: interfaceMode) {
SystemInformationView()
}
TabLegacy("Maintenance") {
MaintenanceView()
}
TabLegacy("Settings") {
SettingsView()
ContentViewTabs.allCases.map { tab in
TabLegacy(
tab.localizedStringKey,
variesByInterfaceMode: tab.variesByInterfaceMode,
viewInvalidator: tab.variesByInterfaceMode ? interfaceMode : nil
) { tab.content }
}
}
.frame(minWidth: 686, minHeight: 256)
Expand Down
35 changes: 35 additions & 0 deletions Genius/Views/Types/ContentViewTabs.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ContentViewTabs.swift
// Genius
//
// Created by F1248.
//

import SwiftUICore

enum ContentViewTabs: String, CaseIterable, Identifiable {

case home = "Home"
case systemInformation = "System Information"
case maintenance = "Maintenance"
case settings = "Settings"

var id: Self { self }
var localizedStringKey: LocalizedStringKey { LocalizedStringKey(rawValue) }

var content: AnyView {
switch self {
case .home: AnyView(HomeView())
case .systemInformation: AnyView(SystemInformationView())
case .maintenance: AnyView(MaintenanceView())
case .settings: AnyView(SettingsView())
}
}

var variesByInterfaceMode: Bool {
switch self {
case .systemInformation: true
default: false
}
}
}

0 comments on commit 326ac03

Please sign in to comment.