Skip to content

Commit a0ede33

Browse files
authored
Leverage alert(item:) in alert(_ state:) (pointfreeco#156)
1 parent 72dbb2a commit a0ede33

File tree

2 files changed

+42
-46
lines changed

2 files changed

+42
-46
lines changed

Sources/SwiftUINavigation/Alert.swift

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,15 @@
2020
_ state: Binding<AlertState<Value>?>,
2121
action handler: @escaping (Value?) -> Void = { (_: Never?) in }
2222
) -> some View {
23-
self.alert(
24-
(state.wrappedValue?.title).map(Text.init) ?? Text(verbatim: ""),
25-
isPresented: state.isPresent(),
26-
presenting: state.wrappedValue,
27-
actions: {
28-
ForEach($0.buttons) {
29-
Button($0, action: handler)
30-
}
31-
},
32-
message: { $0.message.map { Text($0) } }
33-
)
23+
alert(item: state) {
24+
Text($0.title)
25+
} actions: {
26+
ForEach($0.buttons) {
27+
Button($0, action: handler)
28+
}
29+
} message: {
30+
$0.message.map(Text.init)
31+
}
3432
}
3533

3634
/// Presents an alert from a binding to optional alert state.
@@ -52,17 +50,15 @@
5250
_ state: Binding<AlertState<Value>?>,
5351
action handler: @escaping (Value?) async -> Void = { (_: Never?) async in }
5452
) -> some View {
55-
self.alert(
56-
(state.wrappedValue?.title).map(Text.init) ?? Text(verbatim: ""),
57-
isPresented: state.isPresent(),
58-
presenting: state.wrappedValue,
59-
actions: {
60-
ForEach($0.buttons) {
61-
Button($0, action: handler)
62-
}
63-
},
64-
message: { $0.message.map { Text($0) } }
65-
)
53+
alert(item: state) {
54+
Text($0.title)
55+
} actions: {
56+
ForEach($0.buttons) {
57+
Button($0, action: handler)
58+
}
59+
} message: {
60+
$0.message.map(Text.init)
61+
}
6662
}
6763
}
6864
#endif // canImport(SwiftUI)

Sources/SwiftUINavigation/ConfirmationDialog.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
_ state: Binding<ConfirmationDialogState<Value>?>,
2020
action handler: @escaping (Value?) -> Void = { (_: Never?) in }
2121
) -> some View {
22-
self.confirmationDialog(
23-
state.wrappedValue.flatMap { Text($0.title) } ?? Text(verbatim: ""),
24-
isPresented: state.isPresent(),
25-
titleVisibility: state.wrappedValue.map { .init($0.titleVisibility) } ?? .automatic,
26-
presenting: state.wrappedValue,
27-
actions: {
28-
ForEach($0.buttons) {
29-
Button($0, action: handler)
30-
}
31-
},
32-
message: { $0.message.map { Text($0) } }
33-
)
22+
confirmationDialog(
23+
item: state,
24+
titleVisibility: state.wrappedValue.map { .init($0.titleVisibility) } ?? .automatic
25+
) {
26+
Text($0.title)
27+
} actions: {
28+
ForEach($0.buttons) {
29+
Button($0, action: handler)
30+
}
31+
} message: {
32+
$0.message.map(Text.init)
33+
}
3434
}
3535

3636
/// Presents a confirmation dialog from a binding to optional confirmation dialog state.
@@ -53,18 +53,18 @@
5353
_ state: Binding<ConfirmationDialogState<Value>?>,
5454
action handler: @escaping (Value?) async -> Void = { (_: Never?) async in }
5555
) -> some View {
56-
self.confirmationDialog(
57-
state.wrappedValue.flatMap { Text($0.title) } ?? Text(verbatim: ""),
58-
isPresented: state.isPresent(),
59-
titleVisibility: state.wrappedValue.map { .init($0.titleVisibility) } ?? .automatic,
60-
presenting: state.wrappedValue,
61-
actions: {
62-
ForEach($0.buttons) {
63-
Button($0, action: handler)
64-
}
65-
},
66-
message: { $0.message.map { Text($0) } }
67-
)
56+
confirmationDialog(
57+
item: state,
58+
titleVisibility: state.wrappedValue.map { .init($0.titleVisibility) } ?? .automatic
59+
) {
60+
Text($0.title)
61+
} actions: {
62+
ForEach($0.buttons) {
63+
Button($0, action: handler)
64+
}
65+
} message: {
66+
$0.message.map(Text.init)
67+
}
6868
}
6969
}
7070
#endif // canImport(SwiftUI)

0 commit comments

Comments
 (0)