taler-ios

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

PendingRowView.swift (3771B)


      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 
     11 /// This view shows a pending transaction row in a currency section
     12 struct PendingRowView: View {
     13     let scope: ScopeInfo
     14     let amount: Amount
     15     let incoming: Bool
     16     let shouldConfirm: Bool
     17     let needsKYC: Bool
     18 
     19 //    @Environment(\.sizeCategory) var sizeCategory
     20     @AppStorage("minimalistic") var minimalistic: Bool = false
     21 
     22     let inTitle0 = String(localized: "TitleIncoming_Short", defaultValue: "Incoming",
     23                           comment: "Abbreviation of `Pending incoming´ in Balances")
     24     let inTitle1 = String(localized: "TitleIncoming_Full", defaultValue: "Pending\tincoming",
     25                           comment: "`Pending incoming´ in Balances - set exactly 1 \\t for line break")
     26 
     27     let outTitle0 = String(localized: "TitleOutgoing_Short", defaultValue: "Outgoing",
     28                            comment: "Abbreviation of `Pending outgoing´ in Balances")
     29     let outTitle1 = String(localized: "TitleOutgoing_Full", defaultValue: "Pending\toutgoing",
     30                            comment: "`Pending outgoing´ in Balances - set exactly 1 \\t for line break")
     31 
     32     var body: some View {
     33         let pendingColor = WalletColors().pendingColor(incoming)
     34         let iconBadge = PendingIconBadge(foreColor: pendingColor, done: false, incoming: incoming,
     35                                      shouldConfirm: shouldConfirm, needsKYC: needsKYC)
     36                             .talerFont(.title2)
     37         let inTitle = minimalistic ? inTitle0 : inTitle1
     38         let outTitle = minimalistic ? outTitle0 : outTitle1
     39         let pendingTitle = incoming ? inTitle : outTitle
     40 
     41         let amountText = AmountV(scope, amount, isNegative: nil)
     42             .foregroundColor(pendingColor)
     43 
     44         // this is the default view for iOS 15
     45         let vLayout = VStack {
     46             Text(pendingTitle.tabbed(oneLine: true))
     47             HStack {
     48                 iconBadge
     49                 amountText.frame(maxWidth: .infinity, alignment: .trailing)
     50             }
     51         }
     52 
     53         if #available(iOS 16.4, *) {
     54             ViewThatFits(in: .horizontal) {
     55                 HStack {
     56                     iconBadge
     57                     Text(pendingTitle.tabbed(oneLine: false))
     58                     amountText.frame(maxWidth: .infinity, alignment: .trailing)
     59                 }
     60                 vLayout
     61                 VStack {
     62                     Text(pendingTitle.tabbed(oneLine: true))
     63                     iconBadge
     64                     amountText
     65                 }
     66             }
     67         } else {
     68             vLayout
     69         }
     70     }
     71 }
     72 // MARK: -
     73 #if DEBUG
     74 //@MainActor
     75 //fileprivate struct Preview_Content: View {
     76 //    @State private var previewD: CurrencyInfo = CurrencyInfo.zero(DEMOCURRENCY)
     77 //    @State private var previewT: CurrencyInfo = CurrencyInfo.zero(TESTCURRENCY)
     78 //    var body: some View {
     79 //        let test = Amount(currency: TESTCURRENCY, cent: 123)
     80 //        let demo = Amount(currency: DEMOCURRENCY, cent: 123456)
     81 //        List {
     82 //            PendingRowView(amount: test, incoming: true, shouldConfirm: true, needsKYC: false)
     83 //            PendingRowView(amount: demo, incoming: false, shouldConfirm: false, needsKYC: true)
     84 //        }
     85 //    }
     86 //}
     87 //fileprivate struct Previews: PreviewProvider {
     88 //    @MainActor
     89 //    struct StateContainer: View {
     90 ////        @StateObject private var controller = Controller.shared
     91 //        var body: some View {
     92 //            let hello = "Hello"
     93 //            Text(hello)
     94 ////            Preview_Content()
     95 ////                .environmentObject(controller)
     96 //        }
     97 //    }
     98 //    static var previews: some View {
     99 //        StateContainer()
    100 //    }
    101 //}
    102 #endif