Implemented convenience method to show an Alert from a Message
This commit is contained in:
parent
7dc43aa369
commit
6b922fc2c6
|
@ -105,6 +105,19 @@ extension View {
|
|||
method()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func alert(message: Binding<Message?>) -> 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -123,6 +136,8 @@ extension Color {
|
|||
|
||||
static let systemGroupedBackground = Color(UIColor.systemGroupedBackground)
|
||||
|
||||
// There are more..
|
||||
|
||||
static var destructive: Color {
|
||||
if UIColor.responds(to: Selector(("_systemDestructiveTintColor"))) {
|
||||
if let red = UIColor.perform(Selector(("_systemDestructiveTintColor")))?.takeUnretainedValue() as? UIColor {
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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) })
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue