Skip to content

Commit 202c48e

Browse files
iampatbrownp4checo
authored andcommitted
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 (cherry picked from commit fe5603ec380e2a312cbf8ff45e12e81eea5c072b)
1 parent 4c092a8 commit 202c48e

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
@@ -63,14 +63,19 @@ struct Animations: ReducerProtocol {
6363
.cancellable(id: CancelID.self)
6464

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

7681
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
@@ -112,9 +112,9 @@ struct WebSocket: ReducerProtocol {
112112
.cancellable(id: WebSocketID.self)
113113

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

120120
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
@@ -86,29 +86,31 @@ struct DownloadComponent: ReducerProtocol {
8686
}
8787

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

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

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

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

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

5959
case let .response(.failure(error)):
60-
state.alert = AlertState(title: TextState(error.localizedDescription))
60+
state.alert = AlertState { TextState(error.localizedDescription) }
6161
return .none
6262

6363
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

0 commit comments

Comments
 (0)