From 1e4376fe9e6d6ebb6012f9f6c3022ee7eec92a6c Mon Sep 17 00:00:00 2001 From: Stephane Peter Date: Fri, 28 Jul 2023 03:30:30 -0700 Subject: [PATCH 1/5] Fix BulletPointView to support larger Dynamic Type variants. --- Sources/WhatsNew/BulletPointView.swift | 20 +++-- .../xcschemes/WhatsNewDemo.xcscheme | 78 +++++++++++++++++++ WhatsNewDemo/WhatsNewDemo/PageView.swift | 3 + 3 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 WhatsNewDemo/WhatsNewDemo.xcodeproj/xcshareddata/xcschemes/WhatsNewDemo.xcscheme diff --git a/Sources/WhatsNew/BulletPointView.swift b/Sources/WhatsNew/BulletPointView.swift index 4b2134d..cd020ac 100644 --- a/Sources/WhatsNew/BulletPointView.swift +++ b/Sources/WhatsNew/BulletPointView.swift @@ -60,14 +60,16 @@ public struct BulletPointView: View { .bulletStyle() .font(.title) } - VStack (alignment: .leading, spacing: 4){ + VStack (alignment: .leading, spacing: 4){ Text(title) .fontWeight(.semibold) Text(text) .foregroundColor(.secondary) } .multilineTextAlignment(.leading) + .fixedSize(horizontal: false, vertical: true) .font(.subheadline) + .padding(.leading, 4) .padding(.bottom, 6) } } @@ -91,13 +93,15 @@ extension View { #if DEBUG struct BulletPointView_Previews: PreviewProvider { static var previews: some View { - VStack (alignment: .leading){ - BulletPointView(systemName: "square.and.pencil") - BulletPointView(systemName: "hare.fill") - BulletPointView(systemName: "circle.fill") - BulletPointView(systemName: "car.2.fill") - BulletPointView(systemName: "switch.2") - BulletPointView(systemName: "ellipsis") + ScrollView { + VStack (alignment: .leading){ + BulletPointView(systemName: "square.and.pencil") + BulletPointView(systemName: "hare.fill") + BulletPointView(systemName: "circle.fill") + BulletPointView(systemName: "car.2.fill") + BulletPointView(systemName: "switch.2") + BulletPointView(systemName: "ellipsis") + } }.padding() } } diff --git a/WhatsNewDemo/WhatsNewDemo.xcodeproj/xcshareddata/xcschemes/WhatsNewDemo.xcscheme b/WhatsNewDemo/WhatsNewDemo.xcodeproj/xcshareddata/xcschemes/WhatsNewDemo.xcscheme new file mode 100644 index 0000000..70ff463 --- /dev/null +++ b/WhatsNewDemo/WhatsNewDemo.xcodeproj/xcshareddata/xcschemes/WhatsNewDemo.xcscheme @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/WhatsNewDemo/WhatsNewDemo/PageView.swift b/WhatsNewDemo/WhatsNewDemo/PageView.swift index d01a648..f879430 100644 --- a/WhatsNewDemo/WhatsNewDemo/PageView.swift +++ b/WhatsNewDemo/WhatsNewDemo/PageView.swift @@ -20,6 +20,9 @@ struct PageView: View { BulletPointView(title: "We now have SEARCH!!!", systemName: "paintbrush.fill", text: "Search to find books that have been on previous best seller lists.") + BulletPointView(title: "We now have OTHER STUFF!!!", + systemName: "ant", + text: "Search to find books that have been on previous best seller lists.") BulletPointView(title: "More bugs squashed.", imageName: "Truck", text: "And the hits keep coming") From 0549f056308404a7b9b9ba8b2409c1372ae35f10 Mon Sep 17 00:00:00 2001 From: Stephane Peter Date: Sat, 5 Aug 2023 03:35:03 -0700 Subject: [PATCH 2/5] Allow to override the app name from the plist --- Sources/WhatsNew/WhatsNewView.swift | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/WhatsNew/WhatsNewView.swift b/Sources/WhatsNew/WhatsNewView.swift index 6bf4de7..c994910 100644 --- a/Sources/WhatsNew/WhatsNewView.swift +++ b/Sources/WhatsNew/WhatsNewView.swift @@ -12,17 +12,22 @@ public struct WhatsNewView: View { @Environment(\.presentationMode) var presentationMode - let appName: String = Bundle.main.localizedInfoDictionary?["CFBundleDisplayName"] as? String ?? "My App" + var appName: String let multiPage: Bool let showVersion: Bool let content: Content private let bundle = Bundle.module - public init(multiPage: Bool = true, showVersion: Bool = true, @ViewBuilder contentProvider: () -> Content) { + public init(multiPage: Bool = true, showVersion: Bool = true, appName: String? = nil, @ViewBuilder contentProvider: () -> Content) { self.multiPage = multiPage self.showVersion = showVersion self.content = contentProvider() + if let appName = appName { + self.appName = appName + } else { + self.appName = Bundle.main.localizedInfoDictionary?["CFBundleDisplayName"] as? String ?? "My App" + } } public var body: some View { @@ -70,7 +75,7 @@ public struct WhatsNewView: View { #if DEBUG struct WhatsNewView_Previews: PreviewProvider { static var previews: some View { - WhatsNewView(multiPage: false) { + WhatsNewView(multiPage: false, appName: "Full App Name") { VStack (alignment: .leading) { BulletPointView(title: "New feature", systemName: "circle.fill", From 4683ab8f392d8da7d91776af29a4b5d04ac76c14 Mon Sep 17 00:00:00 2001 From: Stephane Peter Date: Tue, 15 Aug 2023 19:51:10 -0700 Subject: [PATCH 3/5] Enable text selection in bullet point views. Embed view in a scroll view in the demo. --- Sources/WhatsNew/BulletPointView.swift | 1 + Sources/WhatsNew/WhatsNewView.swift | 1 + WhatsNewDemo/WhatsNewDemo/PageView.swift | 38 +++++++++++++----------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Sources/WhatsNew/BulletPointView.swift b/Sources/WhatsNew/BulletPointView.swift index cd020ac..2ebaa9d 100644 --- a/Sources/WhatsNew/BulletPointView.swift +++ b/Sources/WhatsNew/BulletPointView.swift @@ -66,6 +66,7 @@ public struct BulletPointView: View { Text(text) .foregroundColor(.secondary) } + .textSelection(.enabled) .multilineTextAlignment(.leading) .fixedSize(horizontal: false, vertical: true) .font(.subheadline) diff --git a/Sources/WhatsNew/WhatsNewView.swift b/Sources/WhatsNew/WhatsNewView.swift index c994910..584e244 100644 --- a/Sources/WhatsNew/WhatsNewView.swift +++ b/Sources/WhatsNew/WhatsNewView.swift @@ -38,6 +38,7 @@ public struct WhatsNewView: View { if showVersion, let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String { Text("v\(version)") .font(.footnote) + .textSelection(.enabled) .padding(.top) } } diff --git a/WhatsNewDemo/WhatsNewDemo/PageView.swift b/WhatsNewDemo/WhatsNewDemo/PageView.swift index f879430..734fc39 100644 --- a/WhatsNewDemo/WhatsNewDemo/PageView.swift +++ b/WhatsNewDemo/WhatsNewDemo/PageView.swift @@ -12,25 +12,27 @@ struct PageView: View { let page: Int var body: some View { - VStack (alignment: .leading, spacing: 10){ - Text("This is page \(page)") - .font(.title) - .multilineTextAlignment(.center) - - BulletPointView(title: "We now have SEARCH!!!", - systemName: "paintbrush.fill", - text: "Search to find books that have been on previous best seller lists.") - BulletPointView(title: "We now have OTHER STUFF!!!", - systemName: "ant", - text: "Search to find books that have been on previous best seller lists.") - BulletPointView(title: "More bugs squashed.", - imageName: "Truck", - text: "And the hits keep coming") - - Spacer() + ScrollView { + VStack (alignment: .leading, spacing: 10){ + Text("This is page \(page)") + .font(.title) + .multilineTextAlignment(.center) + + BulletPointView(title: "We now have SEARCH!!!", + systemName: "paintbrush.fill", + text: "Search to find books that have been on previous best seller lists.") + BulletPointView(title: "We now have OTHER STUFF!!!", + systemName: "ant", + text: "Search to find books that have been on previous best seller lists.") + BulletPointView(title: "More bugs squashed.", + imageName: "Truck", + text: "And the hits keep coming") + + Spacer() + } + .padding() + .accentColor(Color.red) } - .padding() - .accentColor(Color.red) } } From 4268affc47caeb60558e86b1384fde8ac483d809 Mon Sep 17 00:00:00 2001 From: Stephane Peter Date: Tue, 5 Sep 2023 19:12:40 -0700 Subject: [PATCH 4/5] Made BulletPointView a view builder so it can take any other type of view as its content. --- README.md | 13 ++++---- Sources/WhatsNew/BulletPointView.swift | 38 ++++++++++++++++-------- Sources/WhatsNew/WhatsNewView.swift | 15 ++++++---- WhatsNewDemo/WhatsNewDemo/PageView.swift | 16 ++++++---- 4 files changed, 51 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index d8e18a5..ddeabd6 100644 --- a/README.md +++ b/README.md @@ -9,19 +9,20 @@ This framework supports iOS, iPadOS, tv)S (15.0 and above) and macOS (12.0 and a 1) In your target's General Settings, make sure your app Display Name is set as you want it. -2) Create the content for each What's New page you want displayed. You can use What's New `BulletPointView` struct to add bullet points with images, bold titles and explanatory text. The component will use whatever accent color you set for the page. +2) Create the content for each What's New page you want displayed. You can use What's New `BulletPointView` struct to add bullet points with images, bold titles and explanatory text (or any other view). The component will use whatever accent color you set for the page. ```swift struct WhatsNewPageView: View { var body: some View { VStack (alignment: .leading, spacing: 10){ BulletPointView(title: "We now have SEARCH!!!", - systemName: "paintbrush.fill", - text: "Search to find books that have been on previous best seller lists.") + systemName: "paintbrush.fill") { + Text("Search to find books that have been on previous best seller lists.") + } BulletPointView(title: "More bugs squashed.", - imageName: "myTruck", - text: "And the hits keep coming") - + imageName: "myTruck") { + Text("And the hits keep coming") + } Spacer() } .padding() diff --git a/Sources/WhatsNew/BulletPointView.swift b/Sources/WhatsNew/BulletPointView.swift index 2ebaa9d..fc4c773 100644 --- a/Sources/WhatsNew/BulletPointView.swift +++ b/Sources/WhatsNew/BulletPointView.swift @@ -11,28 +11,28 @@ import SwiftUI let frameWidth = 50.0 -public struct BulletPointView: View { +public struct BulletPointView: View { let title: String let imageName: String? let systemName: String? - let text : String + let content: Content public init(title: String = "New feature", imageName: String = "circle.fill", - text: String = "This is a new feature for this app. And this text should wrap.") { + @ViewBuilder content: () -> Content) { self.title = title self.imageName = imageName self.systemName = nil - self.text = text + self.content = content() } public init(title: String = "New feature", systemName: String = "circle.fill", - text: String = "This is a new feature for this app with a system icon. And this text should wrap.") { + @ViewBuilder content: () -> Content) { self.title = title self.imageName = nil self.systemName = systemName - self.text = text + self.content = content() } public var body: some View { @@ -63,7 +63,7 @@ public struct BulletPointView: View { VStack (alignment: .leading, spacing: 4){ Text(title) .fontWeight(.semibold) - Text(text) + content .foregroundColor(.secondary) } .textSelection(.enabled) @@ -96,12 +96,24 @@ struct BulletPointView_Previews: PreviewProvider { static var previews: some View { ScrollView { VStack (alignment: .leading){ - BulletPointView(systemName: "square.and.pencil") - BulletPointView(systemName: "hare.fill") - BulletPointView(systemName: "circle.fill") - BulletPointView(systemName: "car.2.fill") - BulletPointView(systemName: "switch.2") - BulletPointView(systemName: "ellipsis") + BulletPointView(systemName: "square.and.pencil") { + Text("Bullet point 1") + } + BulletPointView(systemName: "hare.fill") { + Text("Bullet point 2") + } + BulletPointView(systemName: "circle.fill") { + Text("Bullet point 3") + } + BulletPointView(systemName: "car.2.fill") { + Text("Bullet point 4") + } + BulletPointView(systemName: "switch.2") { + Text("Bullet point 5") + } + BulletPointView(systemName: "ellipsis") { + Text("Bullet point 6") + } } }.padding() } diff --git a/Sources/WhatsNew/WhatsNewView.swift b/Sources/WhatsNew/WhatsNewView.swift index 584e244..851e194 100644 --- a/Sources/WhatsNew/WhatsNewView.swift +++ b/Sources/WhatsNew/WhatsNewView.swift @@ -79,14 +79,17 @@ struct WhatsNewView_Previews: PreviewProvider { WhatsNewView(multiPage: false, appName: "Full App Name") { VStack (alignment: .leading) { BulletPointView(title: "New feature", - systemName: "circle.fill", - text: "This is a new feature for this app. And this text should wrap.") + systemName: "circle.fill") { + Text("This is a new feature for this app. And this text should wrap.") + } BulletPointView(title: "New feature", - systemName: "square.fill", - text: "This is a new feature for this app. And this text should wrap.") + systemName: "square.fill") { + Text("This is a new feature for this app. And this text should wrap.") + } BulletPointView(title: "New feature", - systemName: "triangle.fill", - text: "This is a new feature for this app. And this text should wrap.") + systemName: "triangle.fill") { + Text("This is a new feature for this app. And this text should wrap.") + } } } } diff --git a/WhatsNewDemo/WhatsNewDemo/PageView.swift b/WhatsNewDemo/WhatsNewDemo/PageView.swift index 734fc39..71d8734 100644 --- a/WhatsNewDemo/WhatsNewDemo/PageView.swift +++ b/WhatsNewDemo/WhatsNewDemo/PageView.swift @@ -19,14 +19,18 @@ struct PageView: View { .multilineTextAlignment(.center) BulletPointView(title: "We now have SEARCH!!!", - systemName: "paintbrush.fill", - text: "Search to find books that have been on previous best seller lists.") + systemName: "paintbrush.fill") { + Text("Search to find books that have been on previous best seller lists.") + } BulletPointView(title: "We now have OTHER STUFF!!!", - systemName: "ant", - text: "Search to find books that have been on previous best seller lists.") + systemName: "ant") { + Text("Search to find books that have been on previous best seller lists.") + Toggle("Toggle", isOn: .constant(true)) + } BulletPointView(title: "More bugs squashed.", - imageName: "Truck", - text: "And the hits keep coming") + imageName: "Truck") { + Text("And the hits keep coming") + } Spacer() } From 4fd5113d7efde80dce13dff5ce0d8007ec1a89d4 Mon Sep 17 00:00:00 2001 From: Stephane Peter Date: Tue, 5 Sep 2023 19:51:55 -0700 Subject: [PATCH 5/5] Argument to specify whether the build number is shown (on by default) --- Sources/WhatsNew/WhatsNewView.swift | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sources/WhatsNew/WhatsNewView.swift b/Sources/WhatsNew/WhatsNewView.swift index 31a7eae..d37d27d 100644 --- a/Sources/WhatsNew/WhatsNewView.swift +++ b/Sources/WhatsNew/WhatsNewView.swift @@ -15,13 +15,15 @@ public struct WhatsNewView: View { var appName: String let multiPage: Bool let showVersion: Bool + let showBuild: Bool let content: Content private let bundle = Bundle.module - public init(multiPage: Bool = true, showVersion: Bool = true, appName: String? = nil, @ViewBuilder contentProvider: () -> Content) { + public init(multiPage: Bool = true, showVersion: Bool = true, showBuild: Bool = true, appName: String? = nil, @ViewBuilder contentProvider: () -> Content) { self.multiPage = multiPage self.showVersion = showVersion + self.showBuild = showBuild self.content = contentProvider() if let appName = appName { self.appName = appName @@ -35,8 +37,8 @@ public struct WhatsNewView: View { VStack (alignment: .center) { Text(String(format:NSLocalizedString("What's New\nin %@", bundle: bundle, comment: "Dialog Title"), appName)) .fontWeight(.bold) - if showVersion, let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String, let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String{ - Text("v\(version).\(build)") + if showVersion, let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String, let build = Bundle.main.infoDictionary?["CFBundleVersion"] as? String { + Text(verbatim: showBuild ? "v\(version).\(build)" : "v\(version)") .font(.footnote) .textSelection(.enabled) .padding(.top)