Extracted SearchBarWithLabel
This commit is contained in:
parent
d84da617ba
commit
96b6f4a718
|
@ -86,21 +86,16 @@ struct AccountTransactionsDialog: View {
|
||||||
VStack {
|
VStack {
|
||||||
Form {
|
Form {
|
||||||
Section {
|
Section {
|
||||||
VStack {
|
SearchBarWithLabel(searchTextBinding) {
|
||||||
UIKitSearchBar(text: searchTextBinding)
|
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
Text("\(String(filteredTransactions.count)) transactions")
|
Text("\(String(self.filteredTransactions.count)) transactions")
|
||||||
.styleAsDetail()
|
.styleAsDetail()
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
AmountLabel(amount: balanceOfFilteredTransactions)
|
AmountLabel(amount: self.balanceOfFilteredTransactions)
|
||||||
}
|
}
|
||||||
.padding(.horizontal)
|
|
||||||
.padding(.bottom, 8)
|
|
||||||
}
|
}
|
||||||
.listRowInsets(EdgeInsets())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Section {
|
Section {
|
||||||
|
|
|
@ -44,20 +44,12 @@ struct SelectBankDialog: View {
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Form {
|
Form {
|
||||||
Section {
|
Section {
|
||||||
VStack {
|
SearchBarWithLabel(searchTextBinding, placeholder: "Bank code, bank name or city", focusOnStart: true) {
|
||||||
UIKitSearchBar(text: searchTextBinding, placeholder: "Bank code, bank name or city", focusOnStart: true)
|
Text("Search by bank code, bank name or city")
|
||||||
|
.font(.caption)
|
||||||
HStack {
|
.styleAsDetail()
|
||||||
Text("Search by bank code, bank name or city")
|
.alignHorizontally(.leading)
|
||||||
.font(.caption)
|
|
||||||
.styleAsDetail()
|
|
||||||
|
|
||||||
Spacer()
|
|
||||||
}
|
|
||||||
.padding(.horizontal)
|
|
||||||
.padding(.bottom, 8)
|
|
||||||
}
|
}
|
||||||
.listRowInsets(EdgeInsets())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if supportedBanksSearchResults.isEmpty {
|
if supportedBanksSearchResults.isEmpty {
|
||||||
|
|
|
@ -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")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue