diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/ViewExtensions.swift b/ui/BankingiOSApp/BankingiOSApp/ui/ViewExtensions.swift index 13becd1b..bc8dd5ea 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/ViewExtensions.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/ViewExtensions.swift @@ -105,6 +105,19 @@ extension View { method() } } + + + func alert(message: Binding) -> some View { + return self.alert(item: message) { message in + if let seconaryButton = message.secondaryButton { + return Alert(title: message.title, message: message.message, primaryButton: message.primaryButton, secondaryButton: seconaryButton) + } + else { + return Alert(title: message.title, message: message.message, dismissButton: message.primaryButton) + } + } + } + } @@ -122,6 +135,8 @@ extension Color { static let tertiarySystemBackground = Color(UIColor.tertiarySystemBackground) static let systemGroupedBackground = Color(UIColor.systemGroupedBackground) + + // There are more.. static var destructive: Color { if UIColor.responds(to: Selector(("_systemDestructiveTintColor"))) { @@ -132,22 +147,20 @@ extension Color { return Color.red } - - // There are more.. } extension Alert.Button { - public static func `default`(_ label: String, _ action: (() -> Void)? = {}) -> Alert.Button { + static func `default`(_ label: String, _ action: (() -> Void)? = {}) -> Alert.Button { return .default(Text(label), action: action) } - public static func ok(_ action: (() -> Void)? = {}) -> Alert.Button { + static func ok(_ action: (() -> Void)? = {}) -> Alert.Button { return .default("OK", action) } - public static func discard(_ action: (() -> Void)? = {}) -> Alert.Button { + static func discard(_ action: (() -> Void)? = {}) -> Alert.Button { return .destructive(Text("Discard"), action: action) } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift index 9b920330..2c634c59 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AccountTransactionsDialog.swift @@ -155,9 +155,7 @@ struct AccountTransactionsDialog: View { .executeMutatingMethod { self.showFetchAllTransactionsOverlay = self.shouldShowFetchAllTransactionsOverlay } - .alert(item: $errorMessage) { message in - Alert(title: message.title, message: message.message, dismissButton: message.primaryButton) - } + .alert(message: $errorMessage) .showNavigationBarTitle(LocalizedStringKey(title)) .navigationBarItems(trailing: UpdateButton { _, executingDone in self.updateTransactions(executingDone) }) } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift index 4f87ae98..abb71bdf 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/AddAccountDialog.swift @@ -58,9 +58,7 @@ struct AddAccountDialog: View { } } - .alert(item: $errorMessage) { message in - Alert(title: message.title, message: message.message, dismissButton: message.primaryButton) - } + .alert(message: $errorMessage) .fixKeyboardCoversLowerPart() .showNavigationBarTitle("Add account") } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountSettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountSettingsDialog.swift index 0f42ebaa..d78aaf5a 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountSettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankAccountSettingsDialog.swift @@ -60,9 +60,7 @@ struct BankAccountSettingsDialog: View { CheckmarkListItem("Supports Instant payment transfer", account.supportsInstantPaymentMoneyTransfer) } } - .alert(item: $unsavedChangesMessage) { message in - Alert(title: message.title, message: message.message, primaryButton: message.primaryButton, secondaryButton: message.secondaryButton!) - } + .alert(message: $unsavedChangesMessage) .fixKeyboardCoversLowerPart() .showNavigationBarTitle(LocalizedStringKey(account.displayName)) .setCancelAndDoneNavigationBarButtons(onCancelPressed: cancelPressed, onDonePressed: donePressed) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankSettingsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankSettingsDialog.swift index 034eb7a8..f1b768c6 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/BankSettingsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/BankSettingsDialog.swift @@ -92,9 +92,7 @@ struct BankSettingsDialog: View { Spacer() } } - .alert(item: $askUserToDeleteAccountOrSaveChangesMessage) { message in - Alert(title: message.title, message: message.message, primaryButton: message.primaryButton, secondaryButton: message.secondaryButton!) - } + .alert(message: $askUserToDeleteAccountOrSaveChangesMessage) .fixKeyboardCoversLowerPart() .showNavigationBarTitle(LocalizedStringKey(bank.displayName)) .setCancelAndDoneNavigationBarButtons(onCancelPressed: cancelPressed, onDonePressed: donePressed) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift index cf77390d..a464e6ee 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/EnterTanDialog.swift @@ -130,9 +130,7 @@ struct EnterTanDialog: View { } } } - .alert(item: $errorMessage) { message in - Alert(title: message.title, message: message.message, dismissButton: message.primaryButton) - } + .alert(message: $errorMessage) .fixKeyboardCoversLowerPart() .showNavigationBarTitle("Enter TAN Dialog Title") .customNavigationBarBackButton { diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/SelectBankDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/SelectBankDialog.swift index eec4e6cc..2de56f83 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/SelectBankDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/SelectBankDialog.swift @@ -85,9 +85,7 @@ struct SelectBankDialog: View { } } } - .alert(item: $errorMessage) { message in - Alert(title: message.title, message: message.message, dismissButton: message.primaryButton) - } + .alert(message: $errorMessage) .fixKeyboardCoversLowerPart() .showNavigationBarTitle("Select Bank Dialog Title") } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsTab.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsTab.swift index 297f521e..37a38edd 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsTab.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/SettingsTab.swift @@ -38,9 +38,7 @@ struct SettingsTab: View { self.navigateToProtectAppSettingsDialog() } } - .alert(item: $askToDeleteAccountMessage) { message in - Alert(title: message.title, message: message.message, primaryButton: message.primaryButton, secondaryButton: message.secondaryButton!) - } + .alert(message: $askToDeleteAccountMessage) .showNavigationBarTitle("Settings") } diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift index 0338e763..0cc1e187 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/TransferMoneyDialog.swift @@ -207,14 +207,7 @@ struct TransferMoneyDialog: View { } } } - .alert(item: $transferMoneyResponseMessage) { message in - if let secondaryButton = message.secondaryButton { - return Alert(title: message.title, message: message.message, primaryButton: message.primaryButton, secondaryButton: secondaryButton) - } - else { - return Alert(title: message.title, message: message.message, dismissButton: message.primaryButton) - } - } + .alert(message: $transferMoneyResponseMessage) .fixKeyboardCoversLowerPart() .showNavigationBarTitle("Transfer Money Dialog Title") }