BalanceCellV.swift (4411B)
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 BalanceCellV: View { 13 let stack: CallStack 14 let scope: ScopeInfo 15 let amount: Amount 16 let isLegacy: Bool 17 // let sizeCategory: ContentSizeCategory 18 // let rowAction: () -> Void 19 @Binding var historyTapped: Int? 20 let balanceIndex: Int 21 let balanceDest: TransactionsListView 22 23 @Environment(\.colorScheme) private var colorScheme 24 @Environment(\.colorSchemeContrast) private var colorSchemeContrast 25 @AppStorage("minimalistic") var minimalistic: Bool = false 26 27 private func baseURL(_ url: String?) -> String { 28 if let url { 29 return url.trimURL 30 } else { 31 return String(localized: "Unknown payment service", comment: "exchange url") 32 } 33 } 34 35 private func buttonAction() { historyTapped = balanceIndex } 36 37 /// Renders the Balance button. "Balance" leading, amountStr trailing. If it doesn't fit in one row then 38 /// amount (trailing) goes underneath "Balance" (leading). 39 var body: some View { 40 #if PRINT_CHANGES 41 let _ = Self._printChanges() 42 // let _ = symLog.vlog() // just to get the # to compare it with .onAppear & onDisappear 43 #endif 44 #if DEBUG 45 let debug = 1==0 46 let red = debug ? Color.red : Color.clear 47 let green = debug ? Color.green : Color.clear 48 let blue = debug ? Color.blue : Color.clear 49 let orange = debug ? Color.orange : Color.clear 50 #endif 51 let amountV = AmountV(stack: stack.push("AmountV"), 52 scope: scope, 53 amount: amount, 54 isNegative: nil, // don't show the + sign 55 strikethrough: isLegacy, 56 large: true) 57 .foregroundColor(.primary) 58 let hLayout = HStack { 59 amountV 60 .frame(maxWidth: .infinity, alignment: .trailing) 61 Text(Image(systemName: CHEVRON)) 62 .talerFont(.table) 63 .foregroundColor(.secondary) 64 } 65 let balanceCell = Group { 66 if minimalistic { 67 hLayout 68 } else { 69 let balanceText = Text("Balance:", comment: "Main view") 70 .talerFont(.title2) 71 .foregroundColor(WalletColors().secondary(colorScheme, colorSchemeContrast)) 72 let vLayout = VStack(alignment: .leading, spacing: 0) { 73 balanceText 74 hLayout 75 } 76 77 if #available(iOS 16.4, *) { 78 ViewThatFits(in: .horizontal) { 79 HStack(spacing: HSPACING) { 80 balanceText 81 hLayout 82 } 83 vLayout 84 } 85 } else { vLayout } // view for iOS 15 86 } 87 } 88 let actions = Group { 89 NavLink(balanceIndex, $historyTapped) { balanceDest } 90 } 91 92 Button(action: buttonAction) { 93 balanceCell 94 .background(actions) 95 .accessibilityElement(children: .combine) 96 .accessibilityHint(String(localized: "Will go to main transactions list.", comment: "a11y")) 97 // .accessibilityLabel(balanceTitleStr + SPACE + amountStr) // TODO: CurrencyFormatter! 98 } 99 } 100 } 101 // MARK: - 102 #if false 103 struct BalanceCellV_Previews: PreviewProvider { 104 @MainActor 105 struct StateContainer: View { 106 var body: some View { 107 let test = Amount(currency: TESTCURRENCY, cent: 123) 108 let demo = Amount(currency: DEMOCURRENCY, cent: 123456) 109 110 List { 111 Section { 112 BalanceCellV(stack: CallStack("Preview"), currencyName: DEMOCURRENCY, amount: demo, 113 sendAction: {}, recvAction: {}, rowAction: {}, balanceDest: nil) 114 } 115 BalanceCellV(stack: CallStack("Preview"), currencyName: TESTCURRENCY, amount: test, 116 sendAction: {}, recvAction: {}, rowAction: {}, balanceDest: nil) 117 } 118 } 119 } 120 121 static var previews: some View { 122 StateContainer() 123 // .environment(\.sizeCategory, .extraExtraLarge) Canvas Device Settings 124 } 125 } 126 #endif