diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AccountTransactionsDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AccountTransactionsDialog.swift index 05541fca..07c255f0 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AccountTransactionsDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/AccountTransactionsDialog.swift @@ -86,21 +86,16 @@ struct AccountTransactionsDialog: View { VStack { Form { Section { - VStack { - UIKitSearchBar(text: searchTextBinding) - + SearchBarWithLabel(searchTextBinding) { HStack { - Text("\(String(filteredTransactions.count)) transactions") + Text("\(String(self.filteredTransactions.count)) transactions") .styleAsDetail() Spacer() - AmountLabel(amount: balanceOfFilteredTransactions) + AmountLabel(amount: self.balanceOfFilteredTransactions) } - .padding(.horizontal) - .padding(.bottom, 8) } - .listRowInsets(EdgeInsets()) } Section { diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/SelectBankDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/SelectBankDialog.swift index 74caf676..e88ec119 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/SelectBankDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/SelectBankDialog.swift @@ -44,20 +44,12 @@ struct SelectBankDialog: View { var body: some View { Form { Section { - VStack { - UIKitSearchBar(text: searchTextBinding, placeholder: "Bank code, bank name or city", focusOnStart: true) - - HStack { - Text("Search by bank code, bank name or city") - .font(.caption) - .styleAsDetail() - - Spacer() - } - .padding(.horizontal) - .padding(.bottom, 8) + SearchBarWithLabel(searchTextBinding, placeholder: "Bank code, bank name or city", focusOnStart: true) { + Text("Search by bank code, bank name or city") + .font(.caption) + .styleAsDetail() + .alignHorizontally(.leading) } - .listRowInsets(EdgeInsets()) } if supportedBanksSearchResults.isEmpty { diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/views/SearchBarWithLabel.swift b/ui/BankingiOSApp/BankingiOSApp/ui/views/SearchBarWithLabel.swift new file mode 100644 index 00000000..9d3f7c44 --- /dev/null +++ b/ui/BankingiOSApp/BankingiOSApp/ui/views/SearchBarWithLabel.swift @@ -0,0 +1,56 @@ +import SwiftUI + + +struct SearchBarWithLabel: View { + + @Binding private var searchText: String + + private var placeholder: String + + private var focusOnStart = false + + private var actionOnReturnKeyPress: (() -> Bool)? = nil + + private var textChanged: ((String) -> Void)? = nil + + private let label: () -> Label + + + init(_ searchText: Binding, placeholder: String = "", focusOnStart: Bool = false, actionOnReturnKeyPress: (() -> Bool)? = nil, + textChanged: ((String) -> Void)? = nil, @ViewBuilder _ label: @escaping () -> Label) { + + _searchText = searchText + self.placeholder = placeholder + + self.focusOnStart = focusOnStart + + self.actionOnReturnKeyPress = actionOnReturnKeyPress + self.textChanged = textChanged + + self.label = label + } + + + var body: some View { + VStack { + UIKitSearchBar(text: $searchText, placeholder: placeholder, focusOnStart: focusOnStart, actionOnReturnKeyPress: actionOnReturnKeyPress, textChanged: textChanged) + + label() + .padding(.horizontal) + .padding(.bottom, 8) + } + .listRowInsets(EdgeInsets()) + } + +} + + +struct SearchBarWithLabel_Previews: PreviewProvider { + + static var previews: some View { + SearchBarWithLabel(.constant(""), { + Text("Label") + }) + } + +}