Skip to content

Commit 63972fa

Browse files
authored
Update SwiftUI Navigation to support new alert mappings (#1865)
* wip * wip * wip * Bump * Update AlertStateUIKit.swift
1 parent 761ab29 commit 63972fa

File tree

6 files changed

+73
-38
lines changed

6 files changed

+73
-38
lines changed

ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved

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

Package.resolved

Lines changed: 18 additions & 9 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
@@ -44,7 +44,11 @@ private struct NewAlertModifier<Action>: ViewModifier {
4444
presenting: viewStore.state,
4545
actions: {
4646
ForEach($0.buttons) {
47-
Button($0) { viewStore.send($0) }
47+
Button($0) { action in
48+
if let action = action {
49+
viewStore.send(action)
50+
}
51+
}
4852
}
4953
},
5054
message: { $0.message.map { Text($0) } }
@@ -58,7 +62,11 @@ private struct OldAlertModifier<Action>: ViewModifier {
5862

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

Sources/ComposableArchitecture/SwiftUI/ConfirmationDialog.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ private struct NewConfirmationDialogModifier<Action>: ViewModifier {
5151
presenting: viewStore.state,
5252
actions: {
5353
ForEach($0.buttons) {
54-
Button($0, action: { viewStore.send($0) })
54+
Button($0) { action in
55+
if let action = action {
56+
viewStore.send(action)
57+
}
58+
}
5559
}
5660
},
5761
message: { $0.message.map { Text($0) } }
@@ -70,7 +74,11 @@ private struct OldConfirmationDialogModifier<Action>: ViewModifier {
7074
func body(content: Content) -> some View {
7175
#if !os(macOS)
7276
return content.actionSheet(item: viewStore.binding(send: dismiss)) {
73-
ActionSheet($0) { viewStore.send($0) }
77+
ActionSheet($0) { action in
78+
if let action = action {
79+
viewStore.send(action)
80+
}
81+
}
7482
}
7583
#else
7684
return EmptyView()

Sources/ComposableArchitecture/UIKit/AlertStateUIKit.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
/// - send: A function that wraps an alert action in the view store's action type.
4444
public convenience init<Action>(
4545
state: AlertState<Action>,
46-
send: @escaping (Action) -> Void
46+
send: @escaping (Action?) -> Void
4747
) {
4848
self.init(
4949
title: String(state: state.title),
@@ -61,7 +61,7 @@
6161
/// - state: The state of dialog that can be shown to the user.
6262
/// - send: A function that wraps a dialog action in the view store's action type.
6363
public convenience init<Action>(
64-
state: ConfirmationDialogState<Action>, send: @escaping (Action) -> Void
64+
state: ConfirmationDialogState<Action>, send: @escaping (Action?) -> Void
6565
) {
6666
self.init(
6767
title: String(state: state.title),
@@ -80,7 +80,7 @@
8080
@available(tvOS 13, *)
8181
@available(watchOS, unavailable)
8282
extension UIAlertAction.Style {
83-
init<Action>(_ role: ButtonState<Action>.Role) {
83+
init(_ role: ButtonStateRole) {
8484
switch role {
8585
case .cancel:
8686
self = .cancel
@@ -98,13 +98,14 @@
9898
extension UIAlertAction {
9999
convenience init<Action>(
100100
_ button: ButtonState<Action>,
101-
action: @escaping (Action) -> Void
101+
action handler: @escaping (Action?) -> Void
102102
) {
103103
self.init(
104104
title: String(state: button.label),
105-
style: button.role.map(UIAlertAction.Style.init) ?? .default,
106-
handler: button.action.map { _ in { _ in button.withAction(action) } }
107-
)
105+
style: button.role.map(UIAlertAction.Style.init) ?? .default
106+
) { _ in
107+
button.withAction(handler)
108+
}
108109
}
109110
}
110111
#endif

0 commit comments

Comments
 (0)