Skip to content

Commit

Permalink
Update ErrorAlert
Browse files Browse the repository at this point in the history
  • Loading branch information
mbernson committed May 13, 2024
1 parent 70d0bbc commit 0990582
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions TemplateApp/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"sourceLanguage" : "en",
"strings" : {
"Error" : {
"An error occurred" : {
"localizations" : {
"nl" : {
"stringUnit" : {
"state" : "translated",
"value" : "Fout"
"value" : "Er is een fout opgetreden"
}
}
}
Expand All @@ -30,9 +30,6 @@
}
}
}
},
"Preview error title" : {

},
"Refresh" : {
"localizations" : {
Expand Down
8 changes: 4 additions & 4 deletions TemplateApp/ViewModifiers/ErrorAlert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftUI
extension View {
/// Presents an alert when an error is present, with custom actions.
func alert<E: Error, Actions: View>(
_ title: LocalizedStringKey?,
_ title: LocalizedStringKey,
error: Binding<E?>,
@ViewBuilder actions: @escaping () -> Actions
) -> some View {
Expand All @@ -35,15 +35,15 @@ extension View {
/// A modifier that presents an alert when an error is present.
private struct ErrorAlert<E: Error, ActionButton: View>: ViewModifier {
@Binding var error: E?
let title: LocalizedStringKey?
let title: LocalizedStringKey
@ViewBuilder let actions: () -> ActionButton

var isPresented: Bool {
error != nil
}

func body(content: Content) -> some View {
content.alert(title ?? "Error", isPresented: .constant(isPresented), actions: actions) {
content.alert(title, isPresented: .constant(isPresented), actions: actions) {
Text(error?.localizedDescription ?? "")
}
}
Expand All @@ -52,7 +52,7 @@ private struct ErrorAlert<E: Error, ActionButton: View>: ViewModifier {
#Preview("Error alert") {
let error = TemplateAppError(message: "Failed to load all the things")
return Text(verbatim: "Preview text")
.alert("Preview error title", error: .constant(error)) {
.alert("An error occurred", error: .constant(error)) {
Button("Ok") {}
}
}

0 comments on commit 0990582

Please sign in to comment.