comparison Simoleon/ConversionView.swift @ 188:e4f5dcf4d596

add keyboard resign option
author Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com>
date Thu, 23 Dec 2021 16:23:16 +0100
parents 13d5a8deb6c2
children
comparison
equal deleted inserted replaced
187:13d5a8deb6c2 188:e4f5dcf4d596
24 @State private var latestRate = CurrencyLatestRateResponse(message: [CurrencyLatestRateResult]()) 24 @State private var latestRate = CurrencyLatestRateResponse(message: [CurrencyLatestRateResult]())
25 25
26 // Update currency rates 26 // Update currency rates
27 @State private var timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect() 27 @State private var timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
28 28
29 // CurrencyTextfield variables
30 @FocusState private var textfieldIsFocused: Bool
31
29 var body: some View { 32 var body: some View {
30 ScrollView(showsIndicators: false) { 33 ScrollView(showsIndicators: false) {
31 VStack(alignment: .leading, spacing: 20) { 34 VStack(alignment: .leading, spacing: 20) {
32 // MARK: - Currency selector 35 // MARK: - Currency selector
33 HStack { 36 HStack {
49 Text("\(baseCurrency.code) - \(baseCurrency.name)") 52 Text("\(baseCurrency.code) - \(baseCurrency.name)")
50 .font(.callout) 53 .font(.callout)
51 .fontWeight(.semibold) 54 .fontWeight(.semibold)
52 55
53 CurrencyTextfield(currencyCode: baseCurrency.code, amount: $amount) 56 CurrencyTextfield(currencyCode: baseCurrency.code, amount: $amount)
57 .focused($textfieldIsFocused)
54 58
55 Divider() 59 Divider()
56 Text("\(quoteCurrency.code) - \(quoteCurrency.name)") 60 Text("\(quoteCurrency.code) - \(quoteCurrency.name)")
57 .font(.callout) 61 .font(.callout)
58 .fontWeight(.semibold) 62 .fontWeight(.semibold)
64 ) 68 )
65 } 69 }
66 .padding(.horizontal) 70 .padding(.horizontal)
67 .sheet(isPresented: $showingCurrencyList) { 71 .sheet(isPresented: $showingCurrencyList) {
68 CurrencyList(baseCurrency: $baseCurrency, quoteCurrency: $quoteCurrency, selecting: selecting) 72 CurrencyList(baseCurrency: $baseCurrency, quoteCurrency: $quoteCurrency, selecting: selecting)
73 }
74 }
75 .toolbar {
76 ToolbarItem(placement: .confirmationAction) {
77 if textfieldIsFocused {
78 Button("Done") {
79 textfieldIsFocused = false
80 }
81 }
69 } 82 }
70 } 83 }
71 .onAppear { 84 .onAppear {
72 getConversion() 85 getConversion()
73 timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect() 86 timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()