Skip to content

Commit fe5603e

Browse files
authored
Bump SwiftUINavigation and update examples (#1760)
* bump navigation * bump swiftui-navigation * Add SearchView preview * make login sendable * use button state builder * format * bump swift and platform version * remove unused test clock * Add quotes to scheme
1 parent d0b1444 commit fe5603e

26 files changed

+200
-158
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

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

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-AlertsAndConfirmationDialogs.swift

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,41 +40,53 @@ struct AlertAndConfirmationDialog: ReducerProtocol {
4040
func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
4141
switch action {
4242
case .alertButtonTapped:
43-
state.alert = AlertState(
44-
title: TextState("Alert!"),
45-
message: TextState("This is an alert"),
46-
primaryButton: .cancel(TextState("Cancel")),
47-
secondaryButton: .default(TextState("Increment"), action: .send(.incrementButtonTapped))
48-
)
43+
state.alert = AlertState {
44+
TextState("Alert!")
45+
} actions: {
46+
ButtonState(role: .cancel) {
47+
TextState("Cancel")
48+
}
49+
ButtonState(action: .incrementButtonTapped) {
50+
TextState("Increment")
51+
}
52+
} message: {
53+
TextState("This is an alert")
54+
}
4955
return .none
5056

5157
case .alertDismissed:
5258
state.alert = nil
5359
return .none
5460

5561
case .confirmationDialogButtonTapped:
56-
state.confirmationDialog = ConfirmationDialogState(
57-
title: TextState("Confirmation dialog"),
58-
message: TextState("This is a confirmation dialog."),
59-
buttons: [
60-
.cancel(TextState("Cancel")),
61-
.default(TextState("Increment"), action: .send(.incrementButtonTapped)),
62-
.default(TextState("Decrement"), action: .send(.decrementButtonTapped)),
63-
]
64-
)
62+
state.confirmationDialog = ConfirmationDialogState {
63+
TextState("Confirmation dialog")
64+
} actions: {
65+
ButtonState(role: .cancel) {
66+
TextState("Cancel")
67+
}
68+
ButtonState(action: .incrementButtonTapped) {
69+
TextState("Increment")
70+
}
71+
ButtonState(action: .decrementButtonTapped) {
72+
TextState("Decrement")
73+
}
74+
} message: {
75+
TextState("This is a confirmation dialog.")
76+
}
6577
return .none
6678

6779
case .confirmationDialogDismissed:
6880
state.confirmationDialog = nil
6981
return .none
7082

7183
case .decrementButtonTapped:
72-
state.alert = AlertState(title: TextState("Decremented!"))
84+
state.alert = AlertState { TextState("Decremented!") }
7385
state.count -= 1
7486
return .none
7587

7688
case .incrementButtonTapped:
77-
state.alert = AlertState(title: TextState("Incremented!"))
89+
state.alert = AlertState { TextState("Incremented!") }
7890
state.count += 1
7991
return .none
8092
}

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-Animations.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,19 @@ struct Animations: ReducerProtocol {
6262
.cancellable(id: CancelID.self)
6363

6464
case .resetButtonTapped:
65-
state.alert = AlertState(
66-
title: TextState("Reset state?"),
67-
primaryButton: .destructive(
68-
TextState("Reset"),
65+
state.alert = AlertState {
66+
TextState("Reset state?")
67+
} actions: {
68+
ButtonState(
69+
role: .destructive,
6970
action: .send(.resetConfirmationButtonTapped, animation: .default)
70-
),
71-
secondaryButton: .cancel(TextState("Cancel"))
72-
)
71+
) {
72+
TextState("Reset")
73+
}
74+
ButtonState(role: .cancel) {
75+
TextState("Cancel")
76+
}
77+
}
7378
return .none
7479

7580
case .resetConfirmationButtonTapped:

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-SharedState.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ struct SharedState: ReducerProtocol {
107107
return .none
108108

109109
case .isPrimeButtonTapped:
110-
state.alert = AlertState(
111-
title: TextState(
110+
state.alert = AlertState {
111+
TextState(
112112
isPrime(state.count)
113113
? "👍 The number \(state.count) is prime!"
114114
: "👎 The number \(state.count) is not prime :("
115115
)
116-
)
116+
}
117117
return .none
118118
}
119119
}

Examples/CaseStudies/SwiftUICaseStudies/02-Effects-WebSocket.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ struct WebSocket: ReducerProtocol {
111111
.cancellable(id: WebSocketID.self)
112112

113113
case .sendResponse(didSucceed: false):
114-
state.alert = AlertState(
115-
title: TextState(
116-
"Could not send socket message. Connect to the server first, and try again."))
114+
state.alert = AlertState {
115+
TextState("Could not send socket message. Connect to the server first, and try again.")
116+
}
117117
return .none
118118

119119
case .sendResponse(didSucceed: true):

Examples/CaseStudies/SwiftUICaseStudies/04-HigherOrderReducers-ResuableOfflineDownloads/DownloadComponent.swift

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,31 @@ struct DownloadComponent: ReducerProtocol {
8585
}
8686

8787
private var deleteAlert: AlertState<AlertAction> {
88-
AlertState(
89-
title: TextState("Do you want to delete this map from your offline storage?"),
90-
primaryButton: .destructive(
91-
TextState("Delete"),
92-
action: .send(.deleteButtonTapped, animation: .default)
93-
),
94-
secondaryButton: self.nevermindButton
95-
)
88+
AlertState {
89+
TextState("Do you want to delete this map from your offline storage?")
90+
} actions: {
91+
ButtonState(role: .destructive, action: .send(.deleteButtonTapped, animation: .default)) {
92+
TextState("Delete")
93+
}
94+
self.nevermindButton
95+
}
9696
}
9797

9898
private var stopAlert: AlertState<AlertAction> {
99-
AlertState(
100-
title: TextState("Do you want to stop downloading this map?"),
101-
primaryButton: .destructive(
102-
TextState("Stop"),
103-
action: .send(.stopButtonTapped, animation: .default)
104-
),
105-
secondaryButton: self.nevermindButton
106-
)
99+
AlertState {
100+
TextState("Do you want to stop downloading this map?")
101+
} actions: {
102+
ButtonState(role: .destructive, action: .send(.stopButtonTapped, animation: .default)) {
103+
TextState("Stop")
104+
}
105+
self.nevermindButton
106+
}
107107
}
108108

109-
private var nevermindButton: AlertState<AlertAction>.Button {
110-
.cancel(TextState("Nevermind"), action: .send(.nevermindButtonTapped))
109+
private var nevermindButton: ButtonState<AlertAction> {
110+
ButtonState(role: .cancel, action: .nevermindButtonTapped) {
111+
TextState("Nevermind")
112+
}
111113
}
112114
}
113115

Examples/CaseStudies/SwiftUICaseStudies/04-HigherOrderReducers-ReusableFavoriting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct Favoriting<ID: Hashable & Sendable>: ReducerProtocol {
5656
.cancellable(id: CancelID(id: state.id), cancelInFlight: true)
5757

5858
case let .response(.failure(error)):
59-
state.alert = AlertState(title: TextState(error.localizedDescription))
59+
state.alert = AlertState { TextState(error.localizedDescription) }
6060
return .none
6161

6262
case let .response(.success(isFavorite)):

Examples/CaseStudies/SwiftUICaseStudiesTests/01-GettingStarted-AlertsAndConfirmationDialogsTests.swift

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ final class AlertsAndConfirmationDialogsTests: XCTestCase {
1212
)
1313

1414
await store.send(.alertButtonTapped) {
15-
$0.alert = AlertState(
16-
title: TextState("Alert!"),
17-
message: TextState("This is an alert"),
18-
primaryButton: .cancel(TextState("Cancel")),
19-
secondaryButton: .default(TextState("Increment"), action: .send(.incrementButtonTapped))
20-
)
15+
$0.alert = AlertState {
16+
TextState("Alert!")
17+
} actions: {
18+
ButtonState(role: .cancel) {
19+
TextState("Cancel")
20+
}
21+
ButtonState(action: .incrementButtonTapped) {
22+
TextState("Increment")
23+
}
24+
} message: {
25+
TextState("This is an alert")
26+
}
2127
}
2228
await store.send(.incrementButtonTapped) {
23-
$0.alert = AlertState(title: TextState("Incremented!"))
29+
$0.alert = AlertState { TextState("Incremented!") }
2430
$0.count = 1
2531
}
2632
await store.send(.alertDismissed) {
@@ -35,18 +41,24 @@ final class AlertsAndConfirmationDialogsTests: XCTestCase {
3541
)
3642

3743
await store.send(.confirmationDialogButtonTapped) {
38-
$0.confirmationDialog = ConfirmationDialogState(
39-
title: TextState("Confirmation dialog"),
40-
message: TextState("This is a confirmation dialog."),
41-
buttons: [
42-
.cancel(TextState("Cancel")),
43-
.default(TextState("Increment"), action: .send(.incrementButtonTapped)),
44-
.default(TextState("Decrement"), action: .send(.decrementButtonTapped)),
45-
]
46-
)
44+
$0.confirmationDialog = ConfirmationDialogState {
45+
TextState("Confirmation dialog")
46+
} actions: {
47+
ButtonState(role: .cancel) {
48+
TextState("Cancel")
49+
}
50+
ButtonState(action: .incrementButtonTapped) {
51+
TextState("Increment")
52+
}
53+
ButtonState(action: .decrementButtonTapped) {
54+
TextState("Decrement")
55+
}
56+
} message: {
57+
TextState("This is a confirmation dialog.")
58+
}
4759
}
4860
await store.send(.incrementButtonTapped) {
49-
$0.alert = AlertState(title: TextState("Incremented!"))
61+
$0.alert = AlertState { TextState("Incremented!") }
5062
$0.count = 1
5163
}
5264
await store.send(.confirmationDialogDismissed) {

Examples/CaseStudies/SwiftUICaseStudiesTests/01-GettingStarted-AnimationsTests.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,19 @@ final class AnimationTests: XCTestCase {
7878
}
7979

8080
await store.send(.resetButtonTapped) {
81-
$0.alert = AlertState(
82-
title: TextState("Reset state?"),
83-
primaryButton: .destructive(
84-
TextState("Reset"),
81+
$0.alert = AlertState {
82+
TextState("Reset state?")
83+
} actions: {
84+
ButtonState(
85+
role: .destructive,
8586
action: .send(.resetConfirmationButtonTapped, animation: .default)
86-
),
87-
secondaryButton: .cancel(TextState("Cancel"))
88-
)
87+
) {
88+
TextState("Reset")
89+
}
90+
ButtonState(role: .cancel) {
91+
TextState("Cancel")
92+
}
93+
}
8994
}
9095

9196
await store.send(.resetConfirmationButtonTapped) {

Examples/CaseStudies/SwiftUICaseStudiesTests/01-GettingStarted-SharedStateTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ final class SharedStateTests: XCTestCase {
7676
)
7777

7878
await store.send(.isPrimeButtonTapped) {
79-
$0.alert = AlertState(
80-
title: TextState("👍 The number \($0.count) is prime!")
81-
)
79+
$0.alert = AlertState {
80+
TextState("👍 The number 3 is prime!")
81+
}
8282
}
8383
await store.send(.alertDismissed) {
8484
$0.alert = nil
@@ -94,9 +94,9 @@ final class SharedStateTests: XCTestCase {
9494
)
9595

9696
await store.send(.isPrimeButtonTapped) {
97-
$0.alert = AlertState(
98-
title: TextState("👎 The number \($0.count) is not prime :(")
99-
)
97+
$0.alert = AlertState {
98+
TextState("👎 The number 6 is not prime :(")
99+
}
100100
}
101101
await store.send(.alertDismissed) {
102102
$0.alert = nil

Examples/CaseStudies/SwiftUICaseStudiesTests/02-Effects-WebSocketTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ final class WebSocketTests: XCTestCase {
9292
$0.messageToSend = ""
9393
}
9494
await store.receive(.sendResponse(didSucceed: false)) {
95-
$0.alert = AlertState(
96-
title: TextState(
97-
"Could not send socket message. Connect to the server first, and try again."))
95+
$0.alert = AlertState {
96+
TextState("Could not send socket message. Connect to the server first, and try again.")
97+
}
9898
}
9999

100100
// Disconnect from the socket

Examples/CaseStudies/SwiftUICaseStudiesTests/04-HigherOrderReducers-ReusableFavoritingTests.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ final class ReusableComponentsFavoritingTests: XCTestCase {
5252
}
5353

5454
func testUnhappyPath() async {
55-
let clock = TestClock()
56-
5755
let episodes: IdentifiedArrayOf<Episode.State> = [
5856
Episode.State(
5957
id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!,
@@ -76,9 +74,9 @@ final class ReusableComponentsFavoritingTests: XCTestCase {
7674
.episode(
7775
id: episodes[0].id, action: .favorite(.response(.failure(FavoriteError()))))
7876
) {
79-
$0.episodes[id: episodes[0].id]?.alert = AlertState(
80-
title: TextState("Favoriting failed.")
81-
)
77+
$0.episodes[id: episodes[0].id]?.alert = AlertState {
78+
TextState("Favoriting failed.")
79+
}
8280
}
8381

8482
await store.send(.episode(id: episodes[0].id, action: .favorite(.alertDismissed))) {

0 commit comments

Comments
 (0)