AccountPicker.swift (1684B)
1 /* 2 * This file is part of GNU Taler, ©2022-25 Taler Systems S.A. 3 * See LICENSE.md 4 */ 5 /** 6 * @author Marc Stibane 7 */ 8 import SwiftUI 9 10 struct AccountPicker: View { 11 let title: String 12 @Binding var value: Int 13 let accountDetails: [ExchangeAccountDetails] 14 let action: (Int) -> Void 15 16 @State private var selected = 0 17 18 var body: some View { 19 Picker(title, selection: $selected) { 20 ForEach(0..<accountDetails.count, id: \.self) { index in 21 let detail = accountDetails[index] 22 if let amount = detail.transferAmount { 23 let amountStr = amount.formatted(specs: detail.currencySpecification, 24 isNegative: false, 25 scope: detail.scope, 26 useISO: false) 27 // let _ = print(amountStr) 28 if let bankName = detail.bankLabel { 29 Text(bankName + ": " + amountStr.0) 30 .accessibilityLabel(bankName + ": " + amountStr.1) 31 .tag(index) 32 } else { 33 Text(amountStr.0) 34 .accessibilityLabel(amountStr.1) 35 .tag(index) 36 } 37 } 38 } 39 } 40 .talerFont(.title3) 41 // .pickerStyle(.menu) 42 .onAppear() { 43 withAnimation { selected = value } 44 } 45 .onChange(of: selected) { newValue in 46 action(newValue) 47 } 48 } 49 }