Skip to content

Commit c7081f4

Browse files
committed
Addressing errors in concurrent sheet launches
1 parent 34dc160 commit c7081f4

File tree

11 files changed

+102
-86
lines changed

11 files changed

+102
-86
lines changed

Package.resolved

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sample/Sample/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,30 @@
66
"platform" : "ios",
77
"size" : "1024x1024"
88
},
9+
{
10+
"appearances" : [
11+
{
12+
"appearance" : "luminosity",
13+
"value" : "dark"
14+
}
15+
],
16+
"filename" : "iOS App Icon 1.png",
17+
"idiom" : "universal",
18+
"platform" : "ios",
19+
"size" : "1024x1024"
20+
},
21+
{
22+
"appearances" : [
23+
{
24+
"appearance" : "luminosity",
25+
"value" : "tinted"
26+
}
27+
],
28+
"filename" : "iOS App Icon 2.png",
29+
"idiom" : "universal",
30+
"platform" : "ios",
31+
"size" : "1024x1024"
32+
},
933
{
1034
"filename" : "macOS16.png",
1135
"idiom" : "mac",
47.4 KB
Loading
46.2 KB
Loading

Sample/Sample/ContentView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ struct ContentView: View {
126126
appVersionManager.isMajorVersionUpdated = false
127127
})
128128
}
129-
.sheet(isPresented: $appVersionManager.isMajorOrMinorVersionUpdated) {
129+
.sheet(isPresented: $appVersionManager.isMinorVersionUpdated) {
130130
NewFeatureOnboardingSheetView(action: {
131-
appVersionManager.isMajorOrMinorVersionUpdated = false
131+
appVersionManager.isMinorVersionUpdated = false
132132
})
133133
}
134134
.onboardingSheet(isPresented: $isOpenSheet, WelcomeOnboarding())

Sample/Sample/UI/NewFeatureOnboardingSheetView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import SwiftUI
99
import OnboardingUI
1010

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

1416
init(action: @escaping () -> Void) {
@@ -41,7 +43,9 @@ struct NewFeatureOnboardingSheetView: View {
4143
}
4244
#endif
4345
} button: {
44-
ContinueButton(color: .accentColor, action: action)
46+
ContinueButton(color: .accentColor, action: {
47+
dismiss()
48+
})
4549
}
4650
}
4751
}

Sample/Sample/UI/WelcomeOnboardingSheetView.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import SwiftUI
1010
import OnboardingUI
1111

1212
struct WelcomeOnboardingSheetView: View {
13+
@Environment(\.dismiss) private var dismiss
14+
1315
var action: () -> Void
1416

1517
init(action: @escaping () -> Void) {
@@ -44,7 +46,9 @@ struct WelcomeOnboardingSheetView: View {
4446
} link: {
4547
Link("Check our Privacy Policy…", destination: URL(string: "https://kc-2001ms.github.io/en/privacy.html")!)
4648
} button: {
47-
ContinueButton(color: .accentColor, action: action)
49+
ContinueButton(color: .accentColor, action: {
50+
dismiss()
51+
})
4852
}
4953
}
5054
}

Sources/OnboardingUI/Processing/AppVersionManager.swift

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class AppVersionManager {
2222
userDefaults.set(lastOpenedVersion, forKey: "LastOpenedVersion")
2323
}
2424
}
25-
/// Whether or not this is the first activation.
25+
/// Whether or not this is the first activation
2626
public var isTheFirstLaunch: Bool {
2727
get {
2828
return lastOpenedVersion == ""
@@ -35,22 +35,29 @@ public class AppVersionManager {
3535
/// Variable to detect if the major version number has increased.
3636
public var isMajorVersionUpdated: Bool {
3737
get {
38-
let lastOpenedComponents = filled(splitByDot(lastOpenedVersion), count: 3)
39-
let currentComponents = filled(splitByDot(version), count: 3)
40-
return lastOpenedComponents[0] < currentComponents[0]
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+
}
4145
}
4246

4347
set {
4448
lastOpenedVersion = version
4549
}
4650
}
4751
/// Variable to detect if the minor version number or higher has increased.
48-
public var isMajorOrMinorVersionUpdated: Bool {
52+
public var isMinorVersionUpdated: Bool {
4953
get {
50-
let lastOpenedComponents = filled(splitByDot(lastOpenedVersion), count: 3)
51-
let currentComponents = filled(splitByDot(version), count: 3)
52-
return (lastOpenedComponents[0] < currentComponents[0] && lastOpenedComponents[1] <= currentComponents[1]) ||
53-
(lastOpenedComponents[0] <= currentComponents[0] && lastOpenedComponents[1] < currentComponents[1])
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+
}
5461
}
5562

5663
set {
@@ -59,8 +66,18 @@ public class AppVersionManager {
5966
}
6067
/// Default initializer
6168
public init() {
62-
self.version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String
63-
self.lastOpenedVersion = userDefaults.string(forKey: "LastOpenedVersion") ?? ""
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])
6481
}
6582
}
6683
/// AppVersionManager environment values
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// FeatureBuilder.swift
3+
// OnboardingUI
4+
//
5+
// Created by 茅根啓介 on 2025/04/03.
6+
//
7+
8+
import Foundation
9+
10+
/// Result builder that allows you to freely build Feature structures
11+
@available(iOS 17.0,macOS 14.0,tvOS 17.0,visionOS 1.0,*)
12+
@resultBuilder
13+
public struct FeatureBuilder {
14+
/// Required in resultBuilder
15+
public static func buildBlock(_ parts: Feature...) -> Array<Feature> {
16+
parts
17+
}
18+
/// Enable if
19+
public static func buildOptional(_ parts: [Feature]?) -> Feature {
20+
parts?.first ?? Feature()
21+
}
22+
/// Enable if-else
23+
public static func buildEither(first parts: [Feature]) -> Feature {
24+
parts.first ?? Feature()
25+
}
26+
/// Enable if-else
27+
public static func buildEither(second parts: [Feature]) -> Feature {
28+
parts.first ?? Feature()
29+
}
30+
/// Enable for-in
31+
public static func buildArray(_ parts: [[Feature]]) -> Feature {
32+
parts.first?.first ?? Feature()
33+
}
34+
/// Enable #if
35+
public static func buildLimitedAvailability(_ parts: [Feature]) -> Array<Feature> {
36+
parts
37+
}
38+
}

Sources/OnboardingUI/Processing/Functions.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)