comparison Simoleon/ContentView.swift @ 15:a02f463aa906

Testing three column ipad navigation
author Dennis Concepción Martín <dennisconcepcionmartin@gmail.com>
date Thu, 15 Jul 2021 10:58:29 +0100
parents 03ce7421c6f4
children aec2e86e5dbd
comparison
equal deleted inserted replaced
14:03ce7421c6f4 15:a02f463aa906
16 @State private var popularSelectedCurrencyPairQuote: CurrencyQuoteModel? = nil 16 @State private var popularSelectedCurrencyPairQuote: CurrencyQuoteModel? = nil
17 17
18 let currencyMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json") 18 let currencyMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json")
19 19
20 var body: some View { 20 var body: some View {
21 if showingView { 21 NavigationView {
22 NavigationView { 22 if showingView {
23 ScrollView(showsIndicators: false) { 23 ScrollView(showsIndicators: false) {
24 VStack(spacing: 30) { 24 VStack(spacing: 20) {
25 SearchBar(text: $text, isEditing: $isEditing) 25 SearchBar(text: $text, isEditing: $isEditing)
26 .padding(.top) 26 .padding(.top)
27 27
28 if text.isEmpty { 28 if text.isEmpty {
29 ForEach(popularCurrencyPairsQuote, id: \.self) { currencyQuote in 29 ForEach(popularCurrencyPairsQuote, id: \.self) { currencyQuote in
37 .padding(.vertical) 37 .padding(.vertical)
38 .sheet(item: self.$popularSelectedCurrencyPairQuote) { currencyQuote in 38 .sheet(item: self.$popularSelectedCurrencyPairQuote) { currencyQuote in
39 CurrencyConversion(currencyQuote: currencyQuote) 39 CurrencyConversion(currencyQuote: currencyQuote)
40 } 40 }
41 } 41 }
42 .navigationTitle("Simoleon") 42 .navigationTitle("Currencies")
43 .toolbar { 43 .toolbar {
44 ToolbarItem(placement: .cancellationAction) { 44 ToolbarItem(placement: .cancellationAction) {
45 if isEditing { 45 if isEditing {
46 Button("Cancel", action: { 46 Button("Cancel", action: {
47 text = "" 47 text = ""
49 UIApplication.shared.dismissKeyboard() 49 UIApplication.shared.dismissKeyboard()
50 }) 50 })
51 } 51 }
52 } 52 }
53 } 53 }
54 } else {
55 ProgressView()
56 .onAppear(perform: requestCurrencyPairsQuote)
54 } 57 }
55 } else {
56 ProgressView()
57 .onAppear(perform: requestCurrencyPairsQuote)
58 } 58 }
59 } 59 }
60 60
61 /* 61 /*
62 Request API 62 Request API
80 } 80 }
81 /* 81 /*
82 Dismiss keyboard on cancel textfield 82 Dismiss keyboard on cancel textfield
83 */ 83 */
84 extension UIApplication { 84 extension UIApplication {
85 func dismissKeyboard() { 85 func dismissKeyboard() {
86 sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) 86 sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
87 }
88 } 87 }
88 }
89 89
90 90
91 struct ContentView_Previews: PreviewProvider { 91 struct ContentView_Previews: PreviewProvider {
92 static var previews: some View { 92 static var previews: some View {
93 ContentView() 93 ContentView()