SubjectInputV.swift (4783B)
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 import taler_swift 10 import SymLog 11 12 struct SubjectInputV<TargetView: View>: View { 13 private let symLog = SymLogV(0) 14 let stack: CallStack 15 // the scanned URL 16 let url: URL? 17 let amountAvailable: Amount? // TODO: getMaxDepositAmountM, getMaxPeerPushDebitAmountM 18 @Binding var amountToTransfer: Amount 19 let amountLabel: String 20 @Binding var summary: String 21 // @Binding var insufficient: Bool 22 // @Binding var feeAmount: Amount? 23 let feeIsNotZero: Bool? // nil = no fees at all, false = no fee for this tx 24 25 var targetView: TargetView 26 27 // let destination: Destination 28 29 @EnvironmentObject private var controller: Controller 30 @EnvironmentObject private var model: WalletModel 31 @Environment(\.colorScheme) private var colorScheme 32 @Environment(\.colorSchemeContrast) private var colorSchemeContrast 33 @AppStorage("minimalistic") var minimalistic: Bool = false 34 35 let navTitle = String(localized: "Custom Summary", comment:"pay merchant") 36 37 @FocusState private var isFocused: Bool 38 39 var body: some View { 40 let currency = amountToTransfer.currencyStr 41 // let feeStr = feeAmount?.string(currencyInfo) ?? EMPTYSTRING 42 // let insufficientLabel = String(localized: "You don't have enough \(currency).") 43 // let feeLabel = insufficient ? insufficientLabel 44 // : feeLabel(feeStr) 45 // let available = amountAvailable?.formatted(scope, isNegative: false) ?? nil 46 // let disabled = insufficient || summary.count == 0 47 let disabled = summary.count == 0 48 ScrollView { VStack(alignment: .leading) { 49 // if let available { 50 // Text("Available:\t\(available)") 51 // .talerFont(.title3) 52 // .padding(.bottom, 2) 53 //// .accessibility(sortPriority: 3) 54 // } 55 56 if !minimalistic { 57 Text("Enter subject:") // Purpose 58 .talerFont(.title3) 59 .accessibilityAddTraits(.isHeader) 60 .accessibilityRemoveTraits(.isStaticText) 61 .padding(.top) 62 } 63 Group { if #available(iOS 16.4, *) { 64 TextField(minimalistic ? "Subject" : EMPTYSTRING, text: $summary, axis: .vertical) 65 .focused($isFocused) 66 .lineLimit(2...) 67 } else { 68 TextField("Subject", text: $summary) 69 .focused($isFocused) 70 // .lineLimit(2...5) // lineLimit' is only available in iOS 16.0 or newer 71 } } // Group for iOS16+ & iOS15 72 .talerFont(.title2) 73 .foregroundColor(WalletColors().fieldForeground) // text color 74 .background(WalletColors().fieldBackground) 75 .textFieldStyle(.roundedBorder) 76 .onAppear { 77 if !UIAccessibility.isVoiceOverRunning { 78 symLog.log("dispatching kbd...") 79 DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) { 80 isFocused = true // make first responder - raise keybord 81 symLog.log("...kbd isFocused") 82 } 83 } 84 } 85 // HStack { 86 // Text(amountToTransfer.formatted(currencyInfo, isNegative: false)) 87 // // TODO: hasFees? 88 //// Text(feeLabel) 89 // } 90 // .talerFont(.body) 91 // // .foregroundColor(insufficient ? WalletColors().errorColor : WalletColors().secondary(colorScheme, colorSchemeContrast)) 92 // .foregroundColor(WalletColors().secondary(colorScheme, colorSchemeContrast)) 93 //// .accessibility(sortPriority: 1) 94 // .padding(4) 95 // if insufficient { 96 // Text(insufficientLabel) 97 // .talerFont(.body) 98 // .foregroundColor(WalletColors().attention) 99 // .padding(4) 100 // } 101 102 NavigationLink("Next", destination: targetView) 103 .buttonStyle(TalerButtonStyle(type: .prominent, disabled: disabled)) 104 .disabled(disabled) 105 // .accessibility(sortPriority: 0) 106 }.padding(.horizontal) } // ScrollVStack 107 .navigationTitle(navTitle) 108 .frame(maxWidth: .infinity, alignment: .leading) 109 .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all)) 110 .onAppear() { 111 // symLog.log("onAppear") 112 DebugViewC.shared.setSheetID(SHEET_PAY_TEMPL_SUBJECT) 113 } 114 } 115 }