Skip to content

Commit

Permalink
Update SwiftUI Navigation to support new alert mappings (#1865)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* Bump

* Update AlertStateUIKit.swift

(cherry picked from commit 63972fa9ea670405011ddc76a09f11e924341fca)

# Conflicts:
#	ComposableArchitecture.xcworkspace/xcshareddata/swiftpm/Package.resolved
#	Package.resolved
  • Loading branch information
stephencelis authored and p4checo committed Jan 26, 2023
1 parent 9aba1cc commit 2bf9e8b
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "9f39744e025c7d377987f30b03770805dcb0bcd1",
"version" : "1.1.4"
"revision" : "4ad606ba5d7673ea60679a61ff867cc1ff8c8e86",
"version" : "1.2.1"
}
},
{
Expand All @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-case-paths",
"state" : {
"revision" : "15bba50ebf3a2065388c8d12210debe4f6ada202",
"version" : "0.10.0"
"revision" : "c3a42e8d1a76ff557cf565ed6d8b0aee0e6e75af",
"version" : "0.11.0"
}
},
{
Expand All @@ -59,34 +59,43 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "f504716c27d2e5d4144fa4794b12129301d17729",
"version" : "1.0.3"
"revision" : "937e904258d22af6e447a0b72c0bc67583ef64a2",
"version" : "1.0.4"
}
},
{
"identity" : "swift-custom-dump",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "819d9d370cd721c9d87671e29d947279292e4541",
"version" : "0.6.0"
"revision" : "ead7d30cc224c3642c150b546f4f1080d1c411a8",
"version" : "0.6.1"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "7a094fcc6a4fcb34fbe625ecd3acd81b881a6dfb",
"version" : "0.1.3"
"revision" : "8282b0c59662eb38946afe30eb403663fc2ecf76",
"version" : "0.1.4"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "3303b164430d9a7055ba484c8ead67a52f7b74f6",
"revision" : "10bc670db657d11bdd561e07de30a9041311b2b1",
"version" : "1.1.0"
}
},
{
"identity" : "swift-docc-symbolkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"state" : {
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
}
},
Expand All @@ -95,17 +104,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-identified-collections",
"state" : {
"revision" : "bfb0d43e75a15b6dfac770bf33479e8393884a36",
"version" : "0.4.1"
"revision" : "fd34c544ad27f3ba6b19142b348005bfa85b6005",
"version" : "0.6.0"
}
},
{
"identity" : "swiftui-navigation",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation",
"state" : {
"revision" : "46acf5ecc1cabdb28d7fe03289f6c8b13a023f52",
"version" : "0.4.5"
"revision" : "bf0fb9d53019cbde1a1e0cf290b560a0a0411282",
"version" : "0.6.0"
}
},
{
Expand Down
23 changes: 16 additions & 7 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "9f39744e025c7d377987f30b03770805dcb0bcd1",
"version" : "1.1.4"
"revision" : "4ad606ba5d7673ea60679a61ff867cc1ff8c8e86",
"version" : "1.2.1"
}
},
{
Expand Down Expand Up @@ -77,16 +77,25 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "e9e82b5302025092ab8358e794f89a0f0397dd9d",
"version" : "0.1.2"
"revision" : "8282b0c59662eb38946afe30eb403663fc2ecf76",
"version" : "0.1.4"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "3303b164430d9a7055ba484c8ead67a52f7b74f6",
"revision" : "10bc670db657d11bdd561e07de30a9041311b2b1",
"version" : "1.1.0"
}
},
{
"identity" : "swift-docc-symbolkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"state" : {
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
}
},
Expand All @@ -104,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation",
"state" : {
"revision" : "ddc01cdcddfd30ef7a966049b2e1d251e224ad93",
"version" : "0.5.0"
"revision" : "bf0fb9d53019cbde1a1e0cf290b560a0a0411282",
"version" : "0.6.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "0.6.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "0.1.2"),
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "0.4.1"),
.package(url: "https://github.com/pointfreeco/swiftui-navigation", from: "0.4.5"),
.package(url: "https://github.com/pointfreeco/swiftui-navigation", from: "0.6.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "0.5.0"),
],
targets: [
Expand Down
12 changes: 10 additions & 2 deletions Sources/ComposableArchitecture/SwiftUI/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ private struct NewAlertModifier<Action>: ViewModifier {
presenting: viewStore.state,
actions: {
ForEach($0.buttons) {
Button($0) { viewStore.send($0) }
Button($0) { action in
if let action = action {
viewStore.send(action)
}
}
}
},
message: { $0.message.map { Text($0) } }
Expand All @@ -59,7 +63,11 @@ private struct OldAlertModifier<Action>: ViewModifier {

func body(content: Content) -> some View {
content.alert(item: viewStore.binding(send: dismiss)) { state in
Alert(state) { viewStore.send($0) }
Alert(state) { action in
if let action = action {
viewStore.send(action)
}
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions Sources/ComposableArchitecture/SwiftUI/ConfirmationDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ private struct NewConfirmationDialogModifier<Action>: ViewModifier {
presenting: viewStore.state,
actions: {
ForEach($0.buttons) {
Button($0, action: { viewStore.send($0) })
Button($0) { action in
if let action = action {
viewStore.send(action)
}
}
}
},
message: { $0.message.map { Text($0) } }
Expand All @@ -72,7 +76,11 @@ private struct OldConfirmationDialogModifier<Action>: ViewModifier {
func body(content: Content) -> some View {
#if !os(macOS)
return content.actionSheet(item: viewStore.binding(send: dismiss)) {
ActionSheet($0) { viewStore.send($0) }
ActionSheet($0) { action in
if let action = action {
viewStore.send(action)
}
}
}
#else
return EmptyView()
Expand Down
15 changes: 8 additions & 7 deletions Sources/ComposableArchitecture/UIKit/AlertStateUIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/// - send: A function that wraps an alert action in the view store's action type.
public convenience init<Action>(
state: AlertState<Action>,
send: @escaping (Action) -> Void
send: @escaping (Action?) -> Void
) {
self.init(
title: String(state: state.title),
Expand All @@ -58,7 +58,7 @@
/// - state: The state of dialog that can be shown to the user.
/// - send: A function that wraps a dialog action in the view store's action type.
public convenience init<Action>(
state: ConfirmationDialogState<Action>, send: @escaping (Action) -> Void
state: ConfirmationDialogState<Action>, send: @escaping (Action?) -> Void
) {
self.init(
title: String(state: state.title),
Expand All @@ -74,7 +74,7 @@
@available(macOS, unavailable)
@available(watchOS, unavailable)
extension UIAlertAction.Style {
init<Action>(_ role: ButtonState<Action>.Role) {
init(_ role: ButtonStateRole) {
switch role {
case .cancel:
self = .cancel
Expand All @@ -89,13 +89,14 @@
extension UIAlertAction {
convenience init<Action>(
_ button: ButtonState<Action>,
action: @escaping (Action) -> Void
action handler: @escaping (Action?) -> Void
) {
self.init(
title: String(state: button.label),
style: button.role.map(UIAlertAction.Style.init) ?? .default,
handler: button.action.map { _ in { _ in button.withAction(action) } }
)
style: button.role.map(UIAlertAction.Style.init) ?? .default
) { _ in
button.withAction(handler)
}
}
}
#endif

0 comments on commit 2bf9e8b

Please sign in to comment.