Skip to content

Commit 2bf9e8b

Browse files
stephencelisp4checo
authored andcommitted
Update SwiftUI Navigation to support new alert mappings (#1865)
* wip * wip * wip * Bump * Update AlertStateUIKit.swift (cherry picked from commit 63972fa9ea670405011ddc76a09f11e924341fca) # Conflicts: # ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved # Package.resolved
1 parent 9aba1cc commit 2bf9e8b

File tree

6 files changed

+69
-34
lines changed

6 files changed

+69
-34
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

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

Package.resolved

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

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ let package = Package(
2525
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.6.0"),
2626
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "0.1.2"),
2727
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "0.4.1"),
28-
.package(url: "https://github.com/pointfreeco/swiftui-navigation", from: "0.4.5"),
28+
.package(url: "https://github.com/pointfreeco/swiftui-navigation", from: "0.6.0"),
2929
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.5.0"),
3030
],
3131
targets: [

Sources/ComposableArchitecture/SwiftUI/Alert.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ private struct NewAlertModifier<Action>: ViewModifier {
4545
presenting: viewStore.state,
4646
actions: {
4747
ForEach($0.buttons) {
48-
Button($0) { viewStore.send($0) }
48+
Button($0) { action in
49+
if let action = action {
50+
viewStore.send(action)
51+
}
52+
}
4953
}
5054
},
5155
message: { $0.message.map { Text($0) } }
@@ -59,7 +63,11 @@ private struct OldAlertModifier<Action>: ViewModifier {
5963

6064
func body(content: Content) -> some View {
6165
content.alert(item: viewStore.binding(send: dismiss)) { state in
62-
Alert(state) { viewStore.send($0) }
66+
Alert(state) { action in
67+
if let action = action {
68+
viewStore.send(action)
69+
}
70+
}
6371
}
6472
}
6573
}

Sources/ComposableArchitecture/SwiftUI/ConfirmationDialog.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ private struct NewConfirmationDialogModifier<Action>: ViewModifier {
5353
presenting: viewStore.state,
5454
actions: {
5555
ForEach($0.buttons) {
56-
Button($0, action: { viewStore.send($0) })
56+
Button($0) { action in
57+
if let action = action {
58+
viewStore.send(action)
59+
}
60+
}
5761
}
5862
},
5963
message: { $0.message.map { Text($0) } }
@@ -72,7 +76,11 @@ private struct OldConfirmationDialogModifier<Action>: ViewModifier {
7276
func body(content: Content) -> some View {
7377
#if !os(macOS)
7478
return content.actionSheet(item: viewStore.binding(send: dismiss)) {
75-
ActionSheet($0) { viewStore.send($0) }
79+
ActionSheet($0) { action in
80+
if let action = action {
81+
viewStore.send(action)
82+
}
83+
}
7684
}
7785
#else
7886
return EmptyView()

Sources/ComposableArchitecture/UIKit/AlertStateUIKit.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
/// - send: A function that wraps an alert action in the view store's action type.
4141
public convenience init<Action>(
4242
state: AlertState<Action>,
43-
send: @escaping (Action) -> Void
43+
send: @escaping (Action?) -> Void
4444
) {
4545
self.init(
4646
title: String(state: state.title),
@@ -58,7 +58,7 @@
5858
/// - state: The state of dialog that can be shown to the user.
5959
/// - send: A function that wraps a dialog action in the view store's action type.
6060
public convenience init<Action>(
61-
state: ConfirmationDialogState<Action>, send: @escaping (Action) -> Void
61+
state: ConfirmationDialogState<Action>, send: @escaping (Action?) -> Void
6262
) {
6363
self.init(
6464
title: String(state: state.title),
@@ -74,7 +74,7 @@
7474
@available(macOS, unavailable)
7575
@available(watchOS, unavailable)
7676
extension UIAlertAction.Style {
77-
init<Action>(_ role: ButtonState<Action>.Role) {
77+
init(_ role: ButtonStateRole) {
7878
switch role {
7979
case .cancel:
8080
self = .cancel
@@ -89,13 +89,14 @@
8989
extension UIAlertAction {
9090
convenience init<Action>(
9191
_ button: ButtonState<Action>,
92-
action: @escaping (Action) -> Void
92+
action handler: @escaping (Action?) -> Void
9393
) {
9494
self.init(
9595
title: String(state: button.label),
96-
style: button.role.map(UIAlertAction.Style.init) ?? .default,
97-
handler: button.action.map { _ in { _ in button.withAction(action) } }
98-
)
96+
style: button.role.map(UIAlertAction.Style.init) ?? .default
97+
) { _ in
98+
button.withAction(handler)
99+
}
99100
}
100101
}
101102
#endif

0 commit comments

Comments
 (0)