Fixed that in BankInfoListItem only taps on text have fired, not e.g. on white space to the right

This commit is contained in:
dankito 2020-08-12 23:05:59 +02:00
parent 9d2df6fba7
commit 4d247bc43b
3 changed files with 40 additions and 23 deletions

View File

@ -25,7 +25,7 @@ struct AddAccountDialog: View {
NavigationLink(destination: SelectBankDialog($bank)) { NavigationLink(destination: SelectBankDialog($bank)) {
if bank != nil { if bank != nil {
bank.map { bank in bank.map { bank in
BankInfoListItem(bank: bank) BankInfoListItem(bank)
} }
} }
else { else {

View File

@ -4,10 +4,24 @@ import BankingUiSwift
struct BankInfoListItem: View { struct BankInfoListItem: View {
let bank: BankInfo private let bank: BankInfo
private let onBankSelected: (() -> Void)?
init(_ bank: BankInfo, _ onBankSelected: @escaping () -> Void) {
self.bank = bank
self.onBankSelected = onBankSelected
}
init(_ bank: BankInfo) {
self.bank = bank
self.onBankSelected = nil
}
var body: some View { var body: some View {
ZStack {
VStack { VStack {
HStack { HStack {
Text(bank.name) Text(bank.name)
@ -29,6 +43,10 @@ struct BankInfoListItem: View {
.styleAsDetail() .styleAsDetail()
.padding(.top, 6.0) .padding(.top, 6.0)
} }
// SwiftUI doesn't stretch item to whole width so tap on places without text are not detected -> add a button and pass to caller when tapped on item
Button("") { self.onBankSelected?() }
}
.opacity(bank.supportsFinTs3_0 ? 1.0 : 0.25) .opacity(bank.supportsFinTs3_0 ? 1.0 : 0.25)
.accentColor(bank.supportsFinTs3_0 ? .label : .secondaryLabel) .accentColor(bank.supportsFinTs3_0 ? .label : .secondaryLabel)
} }
@ -38,7 +56,7 @@ struct BankInfoListItem: View {
struct BankInfoListItem_Previews: PreviewProvider { struct BankInfoListItem_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
BankInfoListItem(bank: BankInfo(name: "Abzockbank Berlin", bankCode: "12345678", bic: "ABZODEBBXXX", postalCode: "12345", city: "Berlin", checksumMethod: "", pinTanAddress: nil, pinTanVersion: "FinTS 3.0", oldBankCode: nil)) BankInfoListItem(BankInfo(name: "Abzockbank Berlin", bankCode: "12345678", bic: "ABZODEBBXXX", postalCode: "12345", city: "Berlin", checksumMethod: "", pinTanAddress: nil, pinTanVersion: "FinTS 3.0", oldBankCode: nil))
} }
} }

View File

@ -57,8 +57,7 @@ struct SelectBankDialog: View {
Section { Section {
// TODO: showing only the first 100 items is a workaround as SwiftUI tries to compare the two lists (to be able to animate them!) which takes extremely long for the full data set // TODO: showing only the first 100 items is a workaround as SwiftUI tries to compare the two lists (to be able to animate them!) which takes extremely long for the full data set
List(searchResult.prefix(100), id: \.self) { bank in List(searchResult.prefix(100), id: \.self) { bank in
BankInfoListItem(bank: bank) BankInfoListItem(bank) {
.onTapGesture {
self.handleSelectedBank(bank) self.handleSelectedBank(bank)
} }
} }