Skip to content

Commit

Permalink
Add option to set preferred color scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
david-swift committed May 18, 2024
1 parent a4f3b11 commit ea8f7e8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Sources/SettingsKit/Components/SettingsKitScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ struct SettingsKitScene<Content>: Scene where Content: Scene {
var symbolVariant: SymbolVariants
/// The design of the settings window.
var design: SettingsWindowDesign
/// The preferred color scheme.
var colorScheme: ColorScheme?
/// The filter in the sidebar design.
@State private var search = ""
/// The binding controlling the selection.
Expand Down Expand Up @@ -51,6 +53,7 @@ struct SettingsKitScene<Content>: Scene where Content: Scene {
.onChange(of: model.selectedTab) { newValue in
selectedTab?.wrappedValue = newValue
}
.preferredColorScheme(colorScheme)
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/SettingsKit/Model/Extensions/SwiftUI/Scene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extension Scene {
/// - Parameters:
/// - design: Whether the default or sidebar design is used.
/// - symbolVariant: The way symbols should be displayed.
/// - preferredColorScheme: Force either light or dark mode.
/// - selectedTab: The currently selected tab.
/// - settings: The settings tabs in the settings window.
/// - Returns: The scene with the settings.
Expand All @@ -32,6 +33,7 @@ extension Scene {
public func settings(
design: SettingsWindowDesign = .default,
symbolVariant: SymbolVariants = .none,
preferredColorScheme: ColorScheme? = nil,
selectedTab: Binding<String>? = nil,
@ArrayBuilder<SettingsTab> _ settings: () -> [SettingsTab]
) -> some Scene {
Expand All @@ -42,6 +44,7 @@ extension Scene {
standardID: standardID,
symbolVariant: symbolVariant,
design: design,
colorScheme: preferredColorScheme,
selectedTab: selectedTab
)
}
Expand Down
16 changes: 13 additions & 3 deletions Tests/TestApp/TestApp/TestAppApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ struct TestAppApp: App {
/// The currently selected tab.
@AppStorage("tab")
var selectedTab = ""
/// The preferred color scheme.
@AppStorage("scheme")
var forceDark = false

/// The main view of the test app.
var body: some Scene {
Expand All @@ -30,16 +33,23 @@ struct TestAppApp: App {
selectedTab = "test"
}
}
.settings(design: sidebarDesign ? .sidebar : .default, selectedTab: $selectedTab) {
.settings(
design: sidebarDesign ? .sidebar : .default,
preferredColorScheme: forceDark ? .dark : nil,
selectedTab: $selectedTab
) {
for settingsTab in appModel.allSettings {
settingsTab
}
SettingsTab(.new(title: "Test", icon: .arrowLeftCircle), id: "test") {
SettingsSubtab(.noSelection, id: "subtab") {
let width = 500.0
let height = 100.0
Toggle("Sidebar Design", isOn: $sidebarDesign)
.frame(width: width, height: height)
Form {
Toggle("Sidebar Design", isOn: $sidebarDesign)
Toggle("Force Dark Design", isOn: $forceDark)
}
.frame(width: width, height: height)
}
}
.frame()
Expand Down
Empty file removed xcodebuild.log
Empty file.

0 comments on commit ea8f7e8

Please sign in to comment.