Skip to content

Commit

Permalink
Leverage alert(item:) in alert(_ state:) (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis authored May 28, 2024
1 parent 72dbb2a commit a0ede33
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 46 deletions.
40 changes: 18 additions & 22 deletions Sources/SwiftUINavigation/Alert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@
_ state: Binding<AlertState<Value>?>,
action handler: @escaping (Value?) -> Void = { (_: Never?) in }
) -> some View {
self.alert(
(state.wrappedValue?.title).map(Text.init) ?? Text(verbatim: ""),
isPresented: state.isPresent(),
presenting: state.wrappedValue,
actions: {
ForEach($0.buttons) {
Button($0, action: handler)
}
},
message: { $0.message.map { Text($0) } }
)
alert(item: state) {
Text($0.title)
} actions: {
ForEach($0.buttons) {
Button($0, action: handler)
}
} message: {
$0.message.map(Text.init)
}
}

/// Presents an alert from a binding to optional alert state.
Expand All @@ -52,17 +50,15 @@
_ state: Binding<AlertState<Value>?>,
action handler: @escaping (Value?) async -> Void = { (_: Never?) async in }
) -> some View {
self.alert(
(state.wrappedValue?.title).map(Text.init) ?? Text(verbatim: ""),
isPresented: state.isPresent(),
presenting: state.wrappedValue,
actions: {
ForEach($0.buttons) {
Button($0, action: handler)
}
},
message: { $0.message.map { Text($0) } }
)
alert(item: state) {
Text($0.title)
} actions: {
ForEach($0.buttons) {
Button($0, action: handler)
}
} message: {
$0.message.map(Text.init)
}
}
}
#endif // canImport(SwiftUI)
48 changes: 24 additions & 24 deletions Sources/SwiftUINavigation/ConfirmationDialog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
_ state: Binding<ConfirmationDialogState<Value>?>,
action handler: @escaping (Value?) -> Void = { (_: Never?) in }
) -> some View {
self.confirmationDialog(
state.wrappedValue.flatMap { Text($0.title) } ?? Text(verbatim: ""),
isPresented: state.isPresent(),
titleVisibility: state.wrappedValue.map { .init($0.titleVisibility) } ?? .automatic,
presenting: state.wrappedValue,
actions: {
ForEach($0.buttons) {
Button($0, action: handler)
}
},
message: { $0.message.map { Text($0) } }
)
confirmationDialog(
item: state,
titleVisibility: state.wrappedValue.map { .init($0.titleVisibility) } ?? .automatic
) {
Text($0.title)
} actions: {
ForEach($0.buttons) {
Button($0, action: handler)
}
} message: {
$0.message.map(Text.init)
}
}

/// Presents a confirmation dialog from a binding to optional confirmation dialog state.
Expand All @@ -53,18 +53,18 @@
_ state: Binding<ConfirmationDialogState<Value>?>,
action handler: @escaping (Value?) async -> Void = { (_: Never?) async in }
) -> some View {
self.confirmationDialog(
state.wrappedValue.flatMap { Text($0.title) } ?? Text(verbatim: ""),
isPresented: state.isPresent(),
titleVisibility: state.wrappedValue.map { .init($0.titleVisibility) } ?? .automatic,
presenting: state.wrappedValue,
actions: {
ForEach($0.buttons) {
Button($0, action: handler)
}
},
message: { $0.message.map { Text($0) } }
)
confirmationDialog(
item: state,
titleVisibility: state.wrappedValue.map { .init($0.titleVisibility) } ?? .automatic
) {
Text($0.title)
} actions: {
ForEach($0.buttons) {
Button($0, action: handler)
}
} message: {
$0.message.map(Text.init)
}
}
}
#endif // canImport(SwiftUI)

0 comments on commit a0ede33

Please sign in to comment.