Skip to content

Bump SwiftUINavigation and update examples #1760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,53 @@ struct AlertAndConfirmationDialog: ReducerProtocol {
func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
switch action {
case .alertButtonTapped:
state.alert = AlertState(
title: TextState("Alert!"),
message: TextState("This is an alert"),
primaryButton: .cancel(TextState("Cancel")),
secondaryButton: .default(TextState("Increment"), action: .send(.incrementButtonTapped))
)
state.alert = AlertState {
TextState("Alert!")
} actions: {
ButtonState(role: .cancel) {
TextState("Cancel")
}
ButtonState(action: .incrementButtonTapped) {
TextState("Increment")
}
} message: {
TextState("This is an alert")
}
return .none

case .alertDismissed:
state.alert = nil
return .none

case .confirmationDialogButtonTapped:
state.confirmationDialog = ConfirmationDialogState(
title: TextState("Confirmation dialog"),
message: TextState("This is a confirmation dialog."),
buttons: [
.cancel(TextState("Cancel")),
.default(TextState("Increment"), action: .send(.incrementButtonTapped)),
.default(TextState("Decrement"), action: .send(.decrementButtonTapped)),
]
)
state.confirmationDialog = ConfirmationDialogState {
TextState("Confirmation dialog")
} actions: {
ButtonState(role: .cancel) {
TextState("Cancel")
}
ButtonState(action: .incrementButtonTapped) {
TextState("Increment")
}
ButtonState(action: .decrementButtonTapped) {
TextState("Decrement")
}
} message: {
TextState("This is a confirmation dialog.")
}
return .none

case .confirmationDialogDismissed:
state.confirmationDialog = nil
return .none

case .decrementButtonTapped:
state.alert = AlertState(title: TextState("Decremented!"))
state.alert = AlertState { TextState("Decremented!") }
state.count -= 1
return .none

case .incrementButtonTapped:
state.alert = AlertState(title: TextState("Incremented!"))
state.alert = AlertState { TextState("Incremented!") }
state.count += 1
return .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,19 @@ struct Animations: ReducerProtocol {
.cancellable(id: CancelID.self)

case .resetButtonTapped:
state.alert = AlertState(
title: TextState("Reset state?"),
primaryButton: .destructive(
TextState("Reset"),
state.alert = AlertState {
TextState("Reset state?")
} actions: {
ButtonState(
role: .destructive,
action: .send(.resetConfirmationButtonTapped, animation: .default)
),
secondaryButton: .cancel(TextState("Cancel"))
)
) {
TextState("Reset")
}
ButtonState(role: .cancel) {
TextState("Cancel")
}
}
return .none

case .resetConfirmationButtonTapped:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ struct SharedState: ReducerProtocol {
return .none

case .isPrimeButtonTapped:
state.alert = AlertState(
title: TextState(
state.alert = AlertState {
TextState(
isPrime(state.count)
? "👍 The number \(state.count) is prime!"
: "👎 The number \(state.count) is not prime :("
)
)
}
return .none
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ struct WebSocket: ReducerProtocol {
.cancellable(id: WebSocketID.self)

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

case .sendResponse(didSucceed: true):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,31 @@ struct DownloadComponent: ReducerProtocol {
}

private var deleteAlert: AlertState<AlertAction> {
AlertState(
title: TextState("Do you want to delete this map from your offline storage?"),
primaryButton: .destructive(
TextState("Delete"),
action: .send(.deleteButtonTapped, animation: .default)
),
secondaryButton: self.nevermindButton
)
AlertState {
TextState("Do you want to delete this map from your offline storage?")
} actions: {
ButtonState(role: .destructive, action: .send(.deleteButtonTapped, animation: .default)) {
TextState("Delete")
}
self.nevermindButton
}
}

private var stopAlert: AlertState<AlertAction> {
AlertState(
title: TextState("Do you want to stop downloading this map?"),
primaryButton: .destructive(
TextState("Stop"),
action: .send(.stopButtonTapped, animation: .default)
),
secondaryButton: self.nevermindButton
)
AlertState {
TextState("Do you want to stop downloading this map?")
} actions: {
ButtonState(role: .destructive, action: .send(.stopButtonTapped, animation: .default)) {
TextState("Stop")
}
self.nevermindButton
}
}

private var nevermindButton: AlertState<AlertAction>.Button {
.cancel(TextState("Nevermind"), action: .send(.nevermindButtonTapped))
private var nevermindButton: ButtonState<AlertAction> {
ButtonState(role: .cancel, action: .nevermindButtonTapped) {
TextState("Nevermind")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct Favoriting<ID: Hashable & Sendable>: ReducerProtocol {
.cancellable(id: CancelID(id: state.id), cancelInFlight: true)

case let .response(.failure(error)):
state.alert = AlertState(title: TextState(error.localizedDescription))
state.alert = AlertState { TextState(error.localizedDescription) }
return .none

case let .response(.success(isFavorite)):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ final class AlertsAndConfirmationDialogsTests: XCTestCase {
)

await store.send(.alertButtonTapped) {
$0.alert = AlertState(
title: TextState("Alert!"),
message: TextState("This is an alert"),
primaryButton: .cancel(TextState("Cancel")),
secondaryButton: .default(TextState("Increment"), action: .send(.incrementButtonTapped))
)
$0.alert = AlertState {
TextState("Alert!")
} actions: {
ButtonState(role: .cancel) {
TextState("Cancel")
}
ButtonState(action: .incrementButtonTapped) {
TextState("Increment")
}
} message: {
TextState("This is an alert")
}
}
await store.send(.incrementButtonTapped) {
$0.alert = AlertState(title: TextState("Incremented!"))
$0.alert = AlertState { TextState("Incremented!") }
$0.count = 1
}
await store.send(.alertDismissed) {
Expand All @@ -35,18 +41,24 @@ final class AlertsAndConfirmationDialogsTests: XCTestCase {
)

await store.send(.confirmationDialogButtonTapped) {
$0.confirmationDialog = ConfirmationDialogState(
title: TextState("Confirmation dialog"),
message: TextState("This is a confirmation dialog."),
buttons: [
.cancel(TextState("Cancel")),
.default(TextState("Increment"), action: .send(.incrementButtonTapped)),
.default(TextState("Decrement"), action: .send(.decrementButtonTapped)),
]
)
$0.confirmationDialog = ConfirmationDialogState {
TextState("Confirmation dialog")
} actions: {
ButtonState(role: .cancel) {
TextState("Cancel")
}
ButtonState(action: .incrementButtonTapped) {
TextState("Increment")
}
ButtonState(action: .decrementButtonTapped) {
TextState("Decrement")
}
} message: {
TextState("This is a confirmation dialog.")
}
}
await store.send(.incrementButtonTapped) {
$0.alert = AlertState(title: TextState("Incremented!"))
$0.alert = AlertState { TextState("Incremented!") }
$0.count = 1
}
await store.send(.confirmationDialogDismissed) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ final class AnimationTests: XCTestCase {
}

await store.send(.resetButtonTapped) {
$0.alert = AlertState(
title: TextState("Reset state?"),
primaryButton: .destructive(
TextState("Reset"),
$0.alert = AlertState {
TextState("Reset state?")
} actions: {
ButtonState(
role: .destructive,
action: .send(.resetConfirmationButtonTapped, animation: .default)
),
secondaryButton: .cancel(TextState("Cancel"))
)
) {
TextState("Reset")
}
ButtonState(role: .cancel) {
TextState("Cancel")
}
}
}

await store.send(.resetConfirmationButtonTapped) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ final class SharedStateTests: XCTestCase {
)

await store.send(.isPrimeButtonTapped) {
$0.alert = AlertState(
title: TextState("👍 The number \($0.count) is prime!")
)
$0.alert = AlertState {
TextState("👍 The number 3 is prime!")
}
}
await store.send(.alertDismissed) {
$0.alert = nil
Expand All @@ -94,9 +94,9 @@ final class SharedStateTests: XCTestCase {
)

await store.send(.isPrimeButtonTapped) {
$0.alert = AlertState(
title: TextState("👎 The number \($0.count) is not prime :(")
)
$0.alert = AlertState {
TextState("👎 The number 6 is not prime :(")
}
}
await store.send(.alertDismissed) {
$0.alert = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ final class WebSocketTests: XCTestCase {
$0.messageToSend = ""
}
await store.receive(.sendResponse(didSucceed: false)) {
$0.alert = AlertState(
title: TextState(
"Could not send socket message. Connect to the server first, and try again."))
$0.alert = AlertState {
TextState("Could not send socket message. Connect to the server first, and try again.")
}
}

// Disconnect from the socket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ final class ReusableComponentsFavoritingTests: XCTestCase {
}

func testUnhappyPath() async {
let clock = TestClock()

let episodes: IdentifiedArrayOf<Episode.State> = [
Episode.State(
id: UUID(uuidString: "00000000-0000-0000-0000-000000000000")!,
Expand All @@ -76,9 +74,9 @@ final class ReusableComponentsFavoritingTests: XCTestCase {
.episode(
id: episodes[0].id, action: .favorite(.response(.failure(FavoriteError()))))
) {
$0.episodes[id: episodes[0].id]?.alert = AlertState(
title: TextState("Favoriting failed.")
)
$0.episodes[id: episodes[0].id]?.alert = AlertState {
TextState("Favoriting failed.")
}
}

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