Extracted SearchBarWithLabel

This commit is contained in:
dankito 2020-09-09 14:00:49 +02:00
parent d84da617ba
commit 96b6f4a718
3 changed files with 64 additions and 21 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -0,0 +1,56 @@
import SwiftUI
struct SearchBarWithLabel<Label: View>: 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<String>, 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")
})
}
}