From 2db293b848d4c5e10de9c5eabffad8addaf8f91f Mon Sep 17 00:00:00 2001 From: Igor Tarasenko Date: Mon, 3 Apr 2023 18:54:10 +0200 Subject: [PATCH 1/2] Add optional icon property to SettingButton and SettingPagePreviewViewThis commit adds an optional `icon` property to `SettingButton` and `SettingPagePreviewView` structs, allowing for the display of an icon alongside the title in these settings components --- Sources/Views/SettingButton.swift | 9 +++++++++ Sources/Views/SettingPage.swift | 9 +++++++++ Sources/Views/SettingView.swift | 1 + 3 files changed, 19 insertions(+) diff --git a/Sources/Views/SettingButton.swift b/Sources/Views/SettingButton.swift index 891d24c..2defa71 100644 --- a/Sources/Views/SettingButton.swift +++ b/Sources/Views/SettingButton.swift @@ -13,6 +13,7 @@ import SwiftUI */ public struct SettingButton: View, Setting { public var id: AnyHashable? + public var icon: SettingIcon? public var title: String public var indicator: String? = "arrow.up.forward" public var horizontalSpacing = CGFloat(12) @@ -22,6 +23,7 @@ public struct SettingButton: View, Setting { public init( id: AnyHashable? = nil, + icon: SettingIcon? = nil, title: String, indicator: String? = "arrow.up.forward", horizontalSpacing: CGFloat = CGFloat(12), @@ -30,6 +32,7 @@ public struct SettingButton: View, Setting { action: @escaping () -> Void ) { self.id = id + self.icon = icon self.title = title self.indicator = indicator self.horizontalSpacing = horizontalSpacing @@ -40,6 +43,7 @@ public struct SettingButton: View, Setting { public var body: some View { SettingButtonView( + icon: icon, title: title, indicator: indicator, horizontalSpacing: horizontalSpacing, @@ -51,6 +55,7 @@ public struct SettingButton: View, Setting { } struct SettingButtonView: View { + var icon: SettingIcon? let title: String var indicator: String? = "arrow.up.forward" var horizontalSpacing = CGFloat(12) @@ -61,6 +66,10 @@ struct SettingButtonView: View { var body: some View { Button(action: action) { HStack(spacing: horizontalSpacing) { + if let icon { + SettingIconView(icon: icon) + } + Text(title) .fixedSize(horizontal: false, vertical: true) .frame(maxWidth: .infinity, alignment: .leading) diff --git a/Sources/Views/SettingPage.swift b/Sources/Views/SettingPage.swift index 7968ac8..2a5493e 100644 --- a/Sources/Views/SettingPage.swift +++ b/Sources/Views/SettingPage.swift @@ -14,6 +14,7 @@ import SwiftUI public struct SettingPage: Setting { public var id: AnyHashable? public var title: String + public var selectedChoice: String? public var spacing = CGFloat(20) public var verticalPadding = CGFloat(6) public var backgroundColor = SettingTheme.secondaryBackgroundColor @@ -24,6 +25,7 @@ public struct SettingPage: Setting { public init( id: AnyHashable? = nil, title: String, + selectedChoice: String? = nil, spacing: CGFloat = CGFloat(20), verticalPadding: CGFloat = CGFloat(6), backgroundColor: Color = SettingTheme.secondaryBackgroundColor, @@ -33,6 +35,7 @@ public struct SettingPage: Setting { ) { self.id = id self.title = title + self.selectedChoice = selectedChoice self.spacing = spacing self.verticalPadding = verticalPadding self.backgroundColor = backgroundColor @@ -159,6 +162,7 @@ struct SettingPageView: View where Content: View { struct SettingPagePreviewView: View { let title: String + var selectedChoice: String? var icon: SettingIcon? var indicator = "chevron.forward" var horizontalSpacing = CGFloat(12) @@ -176,6 +180,11 @@ struct SettingPagePreviewView: View { .frame(maxWidth: .infinity, alignment: .leading) .padding(.vertical, verticalPadding) + if let selectedChoice { + Text(selectedChoice) + .foregroundColor(SettingTheme.secondaryLabelColor) + } + Image(systemName: indicator) .foregroundColor(SettingTheme.secondaryLabelColor) } diff --git a/Sources/Views/SettingView.swift b/Sources/Views/SettingView.swift index b91f1be..2748b8d 100644 --- a/Sources/Views/SettingView.swift +++ b/Sources/Views/SettingView.swift @@ -37,6 +37,7 @@ struct SettingView: View { } label: { SettingPagePreviewView( title: page.title, + selectedChoice: page.selectedChoice, icon: page.previewConfiguration.icon, indicator: page.previewConfiguration.indicator, horizontalSpacing: page.previewConfiguration.horizontalSpacing, From 68374fd0e86dfdd4c205450a05de642e54030239 Mon Sep 17 00:00:00 2001 From: Igor Tarasenko Date: Mon, 3 Apr 2023 19:00:48 +0200 Subject: [PATCH 2/2] Add icon support to SettingPickerView --- Sources/Views/SettingPicker.swift | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Sources/Views/SettingPicker.swift b/Sources/Views/SettingPicker.swift index 160010f..db73447 100644 --- a/Sources/Views/SettingPicker.swift +++ b/Sources/Views/SettingPicker.swift @@ -13,6 +13,7 @@ import SwiftUI */ public struct SettingPicker: View, Setting { public var id: AnyHashable? + public var icon: SettingIcon? public var title: String public var choices: [String] @Binding public var selectedIndex: Int @@ -23,6 +24,7 @@ public struct SettingPicker: View, Setting { public init( id: AnyHashable? = nil, + icon: SettingIcon? = nil, title: String, choices: [String], selectedIndex: Binding, @@ -32,6 +34,7 @@ public struct SettingPicker: View, Setting { choicesConfiguration: ChoicesConfiguration = ChoicesConfiguration() ) { self.id = id + self.icon = icon self.title = title self.choices = choices self._selectedIndex = selectedIndex @@ -92,6 +95,7 @@ public struct SettingPicker: View, Setting { public var body: some View { SettingPickerView( + icon: icon, title: title, choices: choices, selectedIndex: $selectedIndex, @@ -113,6 +117,7 @@ public extension SettingPicker { } struct SettingPickerView: View { + var icon: SettingIcon? let title: String var choices: [String] @Binding var selectedIndex: Int @@ -130,6 +135,10 @@ struct SettingPickerView: View { isActive = true } label: { HStack(spacing: horizontalSpacing) { + if let icon { + SettingIconView(icon: icon) + } + Text(title) .fixedSize(horizontal: false, vertical: true) .frame(maxWidth: .infinity, alignment: .leading)