Implemented String extensions like isBlank
This commit is contained in:
parent
448ce54ae9
commit
f09ba7cf00
|
@ -1,6 +1,35 @@
|
|||
import SwiftUI
|
||||
|
||||
|
||||
extension String {
|
||||
|
||||
var isNotEmpty: Bool {
|
||||
return !isEmpty
|
||||
}
|
||||
|
||||
var isBlank: Bool {
|
||||
return isEmpty || trimmingCharacters(in: .whitespaces).isEmpty
|
||||
}
|
||||
|
||||
var isNotBlank: Bool {
|
||||
return !isBlank
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Optional where Wrapped == String {
|
||||
|
||||
var isNullOrEmpty: Bool {
|
||||
return self?.isEmpty ?? true
|
||||
}
|
||||
|
||||
var isNullOrBlank: Bool {
|
||||
return self?.isBlank ?? true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
extension NSDecimalNumber {
|
||||
|
||||
func isPositive() -> Bool {
|
||||
|
|
|
@ -80,7 +80,7 @@ struct AccountTransactionsDialog: View {
|
|||
private func filterTransactions(_ query: String) {
|
||||
self.filteredTransactions = presenter.searchSelectedAccountTransactions(query: query)
|
||||
|
||||
self.balanceOfFilteredTransactions = query.isEmpty ? balanceOfAllTransactions : filteredTransactions.sumAmounts()
|
||||
self.balanceOfFilteredTransactions = query.isBlank ? balanceOfAllTransactions : filteredTransactions.sumAmounts()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -63,8 +63,8 @@ struct AddAccountDialog: View {
|
|||
|
||||
func isRequiredDataEntered() -> Bool {
|
||||
return bank != nil
|
||||
&& customerId.isEmpty == false
|
||||
&& password.isEmpty == false
|
||||
&& customerId.isNotBlank
|
||||
&& password.isNotBlank
|
||||
}
|
||||
|
||||
func addAccount() {
|
||||
|
|
|
@ -136,7 +136,7 @@ struct EnterTanDialog: View {
|
|||
Spacer()
|
||||
Button(action: { self.enteringTanDone() },
|
||||
label: { Text("OK") })
|
||||
.disabled(self.enteredTan.isEmpty)
|
||||
.disabled(self.enteredTan.isBlank)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
|
@ -202,7 +202,7 @@ struct EnterTanDialog: View {
|
|||
|
||||
private func enteringTanDone() {
|
||||
let companion = EnterTanResult.Companion()
|
||||
let result = enteredTan.isEmpty ? companion.userDidNotEnterTan() : companion.userEnteredTan(enteredTan: enteredTan)
|
||||
let result = enteredTan.isBlank ? companion.userDidNotEnterTan() : companion.userEnteredTan(enteredTan: enteredTan)
|
||||
|
||||
sendEnterTanResult(result)
|
||||
}
|
||||
|
|
|
@ -72,9 +72,19 @@ struct TransferMoneyDialog: View {
|
|||
Section {
|
||||
TextField("Remittee Name", text: $remitteeName)
|
||||
.onReceive(Just(remitteeName)) { newValue in
|
||||
self.isValidRemitteeNameEntered = self.remitteeName.isEmpty == false
|
||||
self.isValidRemitteeNameEntered = self.remitteeName.isNotBlank
|
||||
}
|
||||
|
||||
if self.showRemitteeAutocompleteList {
|
||||
Section {
|
||||
List(self.remitteeSearchResults) { remittee in
|
||||
RemitteeListItem(remittee: remittee)
|
||||
.onTapGesture { self.remitteeSelected(remittee) }
|
||||
}
|
||||
.padding(.vertical, 12)
|
||||
}
|
||||
}
|
||||
|
||||
TextField("Remittee IBAN", text: $remitteeIban)
|
||||
.onReceive(Just(remitteeIban)) { newValue in
|
||||
self.isValidRemitteeIbanEntered = newValue.count > 14 // TODO: implement real check if IBAN is valid
|
||||
|
@ -91,7 +101,7 @@ struct TransferMoneyDialog: View {
|
|||
self.amount = filtered
|
||||
}
|
||||
|
||||
self.isValidAmountEntered = self.amount.isEmpty == false
|
||||
self.isValidAmountEntered = self.amount.isNotBlank
|
||||
}
|
||||
|
||||
TextField("Usage", text: $usage)
|
||||
|
|
Loading…
Reference in New Issue