taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

SubjectInputV.swift (4657B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-26 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.isEmpty
     47         let disabled = summary.isEmpty
     48         ScrollView { VStack(alignment: .leading) {
     49             if !minimalistic {
     50                 Text("Enter subject:")    // Purpose
     51                     .talerFont(.title3)
     52                     .accessibilityAddTraits(.isHeader)
     53                     .accessibilityRemoveTraits(.isStaticText)
     54                     .padding(.top)
     55             }
     56             Group { if #available(iOS 16.4, *) {
     57                 TextField(minimalistic ? "Subject" : EMPTYSTRING, text: $summary, axis: .vertical)
     58                     .focused($isFocused)
     59                     .lineLimit(2...)
     60             } else {
     61                 TextField(minimalistic ? "Subject" : EMPTYSTRING, text: $summary)
     62                     .focused($isFocused)
     63 //                  .lineLimit(2...5)   // lineLimit' is only available in iOS 16.0 or newer
     64             } } // Group for iOS16+ & iOS15
     65             .talerFont(.title3)
     66             .foregroundColor(WalletColors().fieldForeground)     // text color
     67             .background(WalletColors().fieldBackground)
     68             .textFieldStyle(.roundedBorder)
     69             .onAppear {
     70                 if !UIAccessibility.isVoiceOverRunning {
     71                     symLog.log("dispatching kbd...")
     72                     DispatchQueue.main.asyncAfter(deadline: .now() + 0.7) {
     73                         isFocused = true        // make first responder - raise keybord
     74                         symLog.log("...kbd isFocused")
     75                     }
     76                 }
     77             }
     78 //            HStack {
     79 //                Text(amountToTransfer.formatted(currencyInfo, isNegative: false))
     80 //                // TODO: hasFees?
     81 ////                Text(feeLabel)
     82 //            }
     83 //                .talerFont(.body)
     84 // //                .foregroundColor(insufficient ? WalletColors().errorColor : WalletColors().secondary(colorScheme, colorSchemeContrast))
     85 //                .foregroundColor(WalletColors().secondary(colorScheme, colorSchemeContrast))
     86 ////                .accessibility(sortPriority: 1)
     87 //                .padding(4)
     88 //            if insufficient {
     89 //                Text(insufficientLabel)
     90 //                    .talerFont(.body)
     91 //                    .foregroundColor(WalletColors().attention)
     92 //                    .padding(4)
     93 //            }
     94 
     95             NavigationLink("Next", destination: targetView)
     96                 .buttonStyle(TalerButtonStyle(type: .prominent, disabled: disabled))
     97                 .disabled(disabled)
     98 //                .accessibility(sortPriority: 0)
     99                 .padding(.bottom, 333)
    100         }.padding(.horizontal) } // ScrollVStack
    101         .navigationTitle(navTitle)
    102 //        .ignoresSafeArea(.keyboard, edges: .bottom)
    103         .frame(maxWidth: .infinity, alignment: .leading)
    104         .background(WalletColors().backgroundColor.edgesIgnoringSafeArea(.all))
    105         .onAppear() {
    106 //            symLog.log("onAppear")
    107             DebugViewC.shared.setSheetID(SHEET_PAY_TEMPL_SUBJECT)
    108         }
    109     }
    110 }