Skip to content

Commit f10106c

Browse files
authored
Merge pull request #1 from KC-2001MS/next
Initial support for the next OS (version 26)
2 parents c7081f4 + 33e584c commit f10106c

24 files changed

+1196
-415
lines changed

Sample/Sample/UI/NewFeatureOnboardingSheetView.swift

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import SwiftUI
99
import OnboardingUI
1010

1111
struct NewFeatureOnboardingSheetView: View {
12-
@Environment(\.dismiss) private var dismiss
13-
1412
var action: () -> Void
1513

1614
init(action: @escaping () -> Void) {
@@ -19,33 +17,31 @@ struct NewFeatureOnboardingSheetView: View {
1917

2018
var body: some View {
2119
OnboardingSheetView {
22-
OnboardingTitle("What's New in\nOnboardingUI")
20+
Text("What's New in\nOnboardingUI")
21+
.onboardingTextFormatting(style: .title)
2322
} content: {
24-
OnboardingItem(systemName: "tree",shape: .green) {
25-
OnboardingSubtitle("New AppVersionManager environment variable")
26-
OnboardingContent("The new AppVersionManager environment variable allows you to display onboarding at the intended time.")
23+
OnboardingItem(systemName: "wrench.and.screwdriver",shape: .red) {
24+
Text("New AppVersionManager environment variable")
25+
.onboardingTextFormatting(style: .subtitle)
26+
Text("The new AppVersionManager environment variable allows you to display onboarding at the intended time.")
27+
.onboardingTextFormatting(style: .content)
2728
}
2829

2930
OnboardingItem(systemName: "building.columns",shape: .blue) {
30-
OnboardingSubtitle("New Onboarding protocol and Feature structure")
31-
OnboardingContent("The new Onboarding protocol and Feature structure make it easier to create onboarding. There is no need to build views.")
31+
Text("New Onboarding protocol and Feature structure")
32+
.onboardingTextFormatting(style: .subtitle)
33+
Text("The new Onboarding protocol and Feature structure make it easier to create onboarding. There is no need to build views.")
34+
.onboardingTextFormatting(style: .content)
3235
}
3336

3437
OnboardingItem(systemName: "wrench.and.screwdriver",shape: .orange) {
35-
OnboardingSubtitle("Customize the look and feel")
36-
OnboardingContent("Of course, it is also customizable. You can build onboarding at will.")
37-
}
38-
39-
#if os(tvOS)
40-
OnboardingItem(systemName: "ellipsis",shape: .white) {
41-
OnboardingSubtitle("Many other benefits")
42-
OnboardingContent("Now, tvOS is also supported, making it easy to create onboarding. Now you can create onboarding for all platforms except watchOS.")
38+
Text("Customize the look and feel")
39+
.onboardingTextFormatting(style: .subtitle)
40+
Text("Of course, it is also customizable. You can build onboarding at will.")
41+
.onboardingTextFormatting(style: .content)
4342
}
44-
#endif
4543
} button: {
46-
ContinueButton(color: .accentColor, action: {
47-
dismiss()
48-
})
44+
ContinueButton(color: .accentColor, action: action)
4945
}
5046
}
5147
}

Sample/Sample/UI/WelcomeOnboardingSheetView.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,28 @@ struct WelcomeOnboardingSheetView: View {
2020

2121
var body: some View {
2222
OnboardingSheetView {
23-
OnboardingTitle("Welcome to\nOnboardingUI")
23+
Text("Welcome to\nOnboardingUI")
24+
.onboardingTextFormatting(style: .title)
2425
} content: {
2526
OnboardingItem(systemName: "applescript",shape: .red) {
26-
OnboardingSubtitle("Easy to Make")
27-
OnboardingContent("Onboarding screens like Apple's stock apps can be easily created with SwiftUI.")
27+
Text("Easy to Make")
28+
.onboardingTextFormatting(style: .subtitle)
29+
Text("Onboarding screens like Apple's stock apps can be easily created with SwiftUI.")
30+
.onboardingTextFormatting(style: .content)
2831
}
2932

3033
OnboardingItem(systemName: "apple.logo") {
31-
OnboardingSubtitle("Not only for iPhone, but also for Mac, iPad, Vision Pro")
32-
OnboardingContent("It supports not only iPhone, but also Mac, iPad, and Vision Pro. Therefore, there is no need to rewrite the code for each device.")
34+
Text("Not only for iPhone, but also for Mac, iPad, Vision Pro")
35+
.onboardingTextFormatting(style: .subtitle)
36+
Text("It supports not only iPhone, but also Mac, iPad, and Vision Pro. Therefore, there is no need to rewrite the code for each device.")
37+
.onboardingTextFormatting(style: .content)
3338
}
3439

3540
OnboardingItem(systemName: "circle.badge.checkmark",mode: .palette,primary: .primary,secondary: .blue) {
36-
OnboardingSubtitle("Customize SF Symbols")
37-
OnboardingContent("When using a highly customizable implementation method, multi-color and SF symbol hierarchies are supported and can be freely customized.")
41+
Text("Customize SF Symbols")
42+
.onboardingTextFormatting(style: .subtitle)
43+
Text("When using a highly customizable implementation method, multi-color and SF symbol hierarchies are supported and can be freely customized.")
44+
.onboardingTextFormatting(style: .content)
3845
}
3946

4047
#if os(tvOS)

Sources/OnboardingUI/Processing/AppVersionManager.swift

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class AppVersionManager {
2222
userDefaults.set(lastOpenedVersion, forKey: "LastOpenedVersion")
2323
}
2424
}
25-
/// Whether or not this is the first activation
26-
public var isTheFirstLaunch: Bool {
25+
/// Whether or not this is the first activation.
26+
public var isTheFirstActivation: Bool {
2727
get {
2828
return lastOpenedVersion == ""
2929
}
@@ -35,53 +35,62 @@ public class AppVersionManager {
3535
/// Variable to detect if the major version number has increased.
3636
public var isMajorVersionUpdated: Bool {
3737
get {
38-
if !lastOpenedVersion.isEmpty {
39-
let lastOpenedComponents = parseVersion(lastOpenedVersion)
40-
let currentComponents = parseVersion(version)
41-
return lastOpenedComponents.major < currentComponents.major
42-
} else {
43-
return false
44-
}
38+
let lastOpenedComponents = filled(splitByDot(lastOpenedVersion), count: 3)
39+
let currentComponents = filled(splitByDot(version), count: 3)
40+
return lastOpenedComponents[0] < currentComponents[0]
4541
}
4642

4743
set {
4844
lastOpenedVersion = version
4945
}
5046
}
5147
/// Variable to detect if the minor version number or higher has increased.
52-
public var isMinorVersionUpdated: Bool {
48+
public var isMinorOrPatchVersionUpdated: Bool {
5349
get {
54-
if !lastOpenedVersion.isEmpty {
55-
let lastOpenedComponents = parseVersion(lastOpenedVersion)
56-
let currentComponents = parseVersion(version)
57-
return lastOpenedComponents.major == currentComponents.major && lastOpenedComponents.minor < currentComponents.minor
58-
} else {
59-
return false
60-
}
50+
let lastOpenedComponents = filled(splitByDot(lastOpenedVersion), count: 3)
51+
let currentComponents = filled(splitByDot(version), count: 3)
52+
return lastOpenedComponents[0] == currentComponents[0] &&
53+
(lastOpenedComponents[1] < currentComponents[1] ||
54+
(lastOpenedComponents[1] == currentComponents[1] && lastOpenedComponents[2] < currentComponents[2]))
6155
}
6256

6357
set {
6458
lastOpenedVersion = version
6559
}
6660
}
6761
/// Default initializer
62+
/// Creates a new AppVersionManager instance.
6863
public init() {
69-
self.version = Bundle.main
70-
.object(
71-
forInfoDictionaryKey: "CFBundleShortVersionString"
72-
) as! String
73-
self.lastOpenedVersion = userDefaults
74-
.string(forKey: "LastOpenedVersion") ?? ""
75-
}
76-
77-
func parseVersion(_ versionString: String) -> (major: Int, minor: Int, patch: Int) {
78-
var components = versionString.split(separator: ".").compactMap { Int($0) }
79-
components = (0..<3).map { $0 < components.count ? components[$0] : 0 }
80-
return (major: components[0], minor: components[1], patch: components[2])
64+
self.version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
65+
self.lastOpenedVersion = userDefaults.string(forKey: "LastOpenedVersion") ?? ""
8166
}
8267
}
83-
/// AppVersionManager environment values
68+
/// AppVersionManager environment key
69+
/// The environment key for the AppVersionManager.
8470
@available(iOS 17.0,macOS 14.0,watchOS 10.0,tvOS 17.0,visionOS 1.0,*)
71+
public struct AppVersionManagerKey: EnvironmentKey {
72+
public static var defaultValue = AppVersionManager()
73+
}
74+
/// AppVersionManager environment values
8575
public extension EnvironmentValues {
86-
@Entry var appVersionManager: AppVersionManager = AppVersionManager()
76+
/// Accessor for the AppVersionManager value in EnvironmentValues.
77+
var appVersionManager: AppVersionManager {
78+
get { self[AppVersionManagerKey.self] }
79+
set { self[AppVersionManagerKey.self] = newValue }
80+
}
8781
}
82+
/// Function to split the version number dot by dot
83+
@available(iOS 17.0,macOS 14.0,watchOS 10.0,tvOS 17.0,visionOS 1.0,*)
84+
func splitByDot(_ versionNumber: String) -> [Int] {
85+
return versionNumber.split(separator: ".").map { string -> Int in
86+
return Int(string) ?? 0
87+
}
88+
}
89+
/// Function to unify the number of elements in an array
90+
@available(iOS 17.0,macOS 14.0,watchOS 10.0,tvOS 17.0,visionOS 1.0,*)
91+
func filled(_ target: [Int], count: Int) -> [Int] {
92+
return (0..<count).map { i -> Int in
93+
(i < target.count) ? target[i] : 0
94+
}
95+
}
96+

0 commit comments

Comments
 (0)