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