Mercurial > public > simoleon
view Simoleon/ContentView.swift @ 17:4a81e39186f1 v1.0
Minor UI changes
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Thu, 15 Jul 2021 20:24:13 +0100 |
parents | aec2e86e5dbd |
children | 94fd7ac93060 |
line wrap: on
line source
// // ContentView.swift // Simoleon // // Created by Dennis Concepción Martín on 15/07/2021. // import SwiftUI struct ContentView: View { @State var searchText = "" @State var searching = false @State private var refreshView = 0 let currencyPairs: [String] = parseJson("CurrencyPairs.json") var body: some View { VStack { SearchBar(searchText: $searchText, searching: $searching) List(filterCurrencies(), id: \.self) { currency in NavigationLink(destination: CurrencyConversion(currency: currency)) { CurrencyRow(currency: currency) } } .id(UUID()) .listStyle(InsetListStyle()) .gesture(DragGesture() .onChanged({ _ in UIApplication.shared.dismissKeyboard() }) ) } .navigationTitle(searching ? "Search" : "Popular currencies") .toolbar { if searching { Button("Cancel") { searchText = "" withAnimation { searching = false UIApplication.shared.dismissKeyboard() } } } } } private func filterCurrencies() -> [String] { if searchText.isEmpty { return currencyPairs } else { return currencyPairs.filter { $0.contains(searchText.uppercased()) } } } } extension UIApplication { func dismissKeyboard() { sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }