From 834d4e539b5fd931d88360b10ecda05af7503830 Mon Sep 17 00:00:00 2001 From: Thibault Le Cornec Date: Sun, 22 Sep 2024 02:09:06 +0200 Subject: [PATCH] Add ability to display the version as a footnote --- .../WhatsNew+VersionTextConfiguration.swift | 34 +++++++++++++++++++ Sources/Models/WhatsNew.swift | 9 +++-- Sources/View/WhatsNewView.swift | 10 ++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 Sources/Models/WhatsNew+VersionTextConfiguration.swift diff --git a/Sources/Models/WhatsNew+VersionTextConfiguration.swift b/Sources/Models/WhatsNew+VersionTextConfiguration.swift new file mode 100644 index 0000000..b974251 --- /dev/null +++ b/Sources/Models/WhatsNew+VersionTextConfiguration.swift @@ -0,0 +1,34 @@ +import SwiftUI + +// MARK: - WhatsNew+VersionTextConfiguration + +public extension WhatsNew { + + /// The WhatsNew VersionTextConfiguration + struct VersionTextConfiguration { + + // MARK: Properties + + /// The version text font + public var font: Font + + /// The foreground color + public var foregroundColor: Color + + // MARK: Initializer + + /// Creates a new instance of `WhatsNew.VersionTextConfiguration` + /// - Parameters: + /// - font: The version text font. Default value `.footnote` + /// - foregroundColor: The foreground color. Default value `.primary` + public init( + font: Font = .footnote, + foregroundColor: Color = .primary + ) { + self.font = font + self.foregroundColor = foregroundColor + } + + } + +} diff --git a/Sources/Models/WhatsNew.swift b/Sources/Models/WhatsNew.swift index 662b037..0f8061c 100644 --- a/Sources/Models/WhatsNew.swift +++ b/Sources/Models/WhatsNew.swift @@ -21,7 +21,9 @@ public struct WhatsNew { /// The optional SecondaryAction public var secondaryAction: SecondaryAction? - + + public var versionTextConfiguration: WhatsNew.VersionTextConfiguration? + // MARK: Initializer /// Creates a new instance of `WhatsNew` @@ -31,18 +33,21 @@ public struct WhatsNew { /// - items: The Features /// - primaryAction: The PrimaryAction. Default value `.init()` /// - secondaryAction: The optional SecondaryAction. Default value `nil` + /// - versionTextConfiguration: The optional version text configuration. Default value `nil` public init( version: Version = .current(), title: Title, features: [Feature], primaryAction: PrimaryAction = .init(), - secondaryAction: SecondaryAction? = nil + secondaryAction: SecondaryAction? = nil, + versionTextConfiguration: WhatsNew.VersionTextConfiguration? = nil ) { self.version = version self.title = title self.features = features self.primaryAction = primaryAction self.secondaryAction = secondaryAction + self.versionTextConfiguration = versionTextConfiguration } } diff --git a/Sources/View/WhatsNewView.swift b/Sources/View/WhatsNewView.swift index c692b9c..6d17785 100644 --- a/Sources/View/WhatsNewView.swift +++ b/Sources/View/WhatsNewView.swift @@ -103,6 +103,16 @@ extension WhatsNewView: View { #endif } .edgesIgnoringSafeArea(.bottom) + + // Version number + if let versionTextConfiguration = whatsNew.versionTextConfiguration { + VStack { + Spacer() + Text("v.\(whatsNew.version.description)") + .font(versionTextConfiguration.font) + .foregroundColor(versionTextConfiguration.foregroundColor) + } + } } .sheet( item: self.$secondaryActionPresentedView,