summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Stibane <marc@taler.net>2023-10-29 12:17:00 +0100
committerMarc Stibane <marc@taler.net>2023-10-29 12:17:00 +0100
commit5d0072f0095dae9b5b8b76aefe2f04d1dac5fc60 (patch)
tree49a9d0b28a8b43a8e184eb28bdddbc1d6ac401e5
parent9f7de5c7468c36626139f245da49ee07f5e4d104 (diff)
downloadtaler-ios-5d0072f0095dae9b5b8b76aefe2f04d1dac5fc60.tar.gz
taler-ios-5d0072f0095dae9b5b8b76aefe2f04d1dac5fc60.tar.bz2
taler-ios-5d0072f0095dae9b5b8b76aefe2f04d1dac5fc60.zip
AmountRowV
-rw-r--r--TalerWallet.xcodeproj/project.pbxproj6
-rw-r--r--TalerWallet1/Views/HelperViews/AmountRowV.swift82
2 files changed, 88 insertions, 0 deletions
diff --git a/TalerWallet.xcodeproj/project.pbxproj b/TalerWallet.xcodeproj/project.pbxproj
index 16114b3..0259c6c 100644
--- a/TalerWallet.xcodeproj/project.pbxproj
+++ b/TalerWallet.xcodeproj/project.pbxproj
@@ -10,6 +10,8 @@
4E16E12329F3BB99008B9C86 /* CurrencySpecification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16E12229F3BB99008B9C86 /* CurrencySpecification.swift */; };
4E2254972A822B8100E41D29 /* payment_received.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 4E2254952A822B8100E41D29 /* payment_received.m4a */; };
4E2254982A822B8100E41D29 /* payment_sent.m4a in Resources */ = {isa = PBXBuildFile; fileRef = 4E2254962A822B8100E41D29 /* payment_sent.m4a */; };
+ 4E2E5F7F2AEE30DA0027FA8A /* AmountRowV.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2E5F7E2AEE30DA0027FA8A /* AmountRowV.swift */; };
+ 4E2E5F802AEE30DA0027FA8A /* AmountRowV.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2E5F7E2AEE30DA0027FA8A /* AmountRowV.swift */; };
4E3327BA2AD1635100BF5AD6 /* AsyncSemaphore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3327B92AD1635100BF5AD6 /* AsyncSemaphore.swift */; };
4E3327BB2AD1635100BF5AD6 /* AsyncSemaphore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E3327B92AD1635100BF5AD6 /* AsyncSemaphore.swift */; };
4E363CBC2A237E0900D7E98C /* URL+id+iban.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E363CBB2A237E0900D7E98C /* URL+id+iban.swift */; };
@@ -296,6 +298,7 @@
4E16E12229F3BB99008B9C86 /* CurrencySpecification.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CurrencySpecification.swift; sourceTree = "<group>"; };
4E2254952A822B8100E41D29 /* payment_received.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = payment_received.m4a; sourceTree = "<group>"; };
4E2254962A822B8100E41D29 /* payment_sent.m4a */ = {isa = PBXFileReference; lastKnownFileType = file; path = payment_sent.m4a; sourceTree = "<group>"; };
+ 4E2E5F7E2AEE30DA0027FA8A /* AmountRowV.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AmountRowV.swift; sourceTree = "<group>"; };
4E3327B92AD1635100BF5AD6 /* AsyncSemaphore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AsyncSemaphore.swift; sourceTree = "<group>"; };
4E363CBB2A237E0900D7E98C /* URL+id+iban.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "URL+id+iban.swift"; sourceTree = "<group>"; };
4E363CBD2A23CB2100D7E98C /* AnyTransition+backslide.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "AnyTransition+backslide.swift"; sourceTree = "<group>"; };
@@ -734,6 +737,7 @@
isa = PBXGroup;
children = (
4E97968F2A3765ED006F73BC /* AgePicker.swift */,
+ 4E2E5F7E2AEE30DA0027FA8A /* AmountRowV.swift */,
4E605DB92AB05FB6002FB9A7 /* BarGraph.swift */,
4EB095472989CBFE0043A8A1 /* Buttons.swift */,
4EF840A62A0B85F400EE0D47 /* CopyShare.swift */,
@@ -1108,6 +1112,7 @@
4E3EAE592A990778009F1BE8 /* Model+Settings.swift in Sources */,
4EC4008C2AE5664100DF72C7 /* CharacterSet+contains.swift in Sources */,
4E3EAE5A2A990778009F1BE8 /* ErrorView.swift in Sources */,
+ 4E2E5F7F2AEE30DA0027FA8A /* AmountRowV.swift in Sources */,
4E3EAE5B2A990778009F1BE8 /* View+Notification.swift in Sources */,
4E3EAE5C2A990778009F1BE8 /* Model+Pending.swift in Sources */,
4E3EAE5D2A990778009F1BE8 /* ExchangeListView.swift in Sources */,
@@ -1216,6 +1221,7 @@
4EB095152989CBB00043A8A1 /* Model+Settings.swift in Sources */,
4EC4008D2AE5664100DF72C7 /* CharacterSet+contains.swift in Sources */,
4EB095692989CBFE0043A8A1 /* ErrorView.swift in Sources */,
+ 4E2E5F802AEE30DA0027FA8A /* AmountRowV.swift in Sources */,
4E3B4BC72A429F2A00CC88B8 /* View+Notification.swift in Sources */,
4EB0956E2989CBFE0043A8A1 /* Model+Pending.swift in Sources */,
4EB095522989CBFE0043A8A1 /* ExchangeListView.swift in Sources */,
diff --git a/TalerWallet1/Views/HelperViews/AmountRowV.swift b/TalerWallet1/Views/HelperViews/AmountRowV.swift
new file mode 100644
index 0000000..36ae4e0
--- /dev/null
+++ b/TalerWallet1/Views/HelperViews/AmountRowV.swift
@@ -0,0 +1,82 @@
+/*
+ * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
+ * See LICENSE.md
+ */
+import SwiftUI
+import taler_swift
+
+// calculate the width of the amountStr (with Font)
+// calculate the width of 'content' in compact form
+// if it fits side by side, then render HStack(content(compact), Spacer(), amountStr)
+// else render VStack(content(wide), HStack(Spacer(), amountStr))
+
+struct AmountRowV<Content: View>: View {
+ let amountStr: String
+ let largeAmountFont: Bool
+ let fitsHorizontal: Bool
+
+ var content: () -> Content
+
+ var body: some View {
+ if fitsHorizontal {
+ HStack(alignment: .lastTextBaseline, spacing: 0) {
+ content()
+ Spacer(minLength: 0)
+ Text(amountStr)
+ .accessibilityFont(largeAmountFont ? .title : .title2)
+ .monospacedDigit()
+ }
+ } else {
+ VStack(alignment: .leading, spacing: 0) {
+ content()
+ HStack {
+ Spacer(minLength: 0)
+ Text(amountStr)
+ .accessibilityFont(largeAmountFont ? .title : .title2)
+ .monospacedDigit()
+ }
+ }
+ }
+ }
+}
+// MARK: -
+#if DEBUG
+
+struct SectionWithAmountRow: View {
+ @Environment(\.sizeCategory) var sizeCategory
+ var body: some View {
+ let testInfo = PreviewCurrencyInfo(TESTCURRENCY, digits: 0)
+ let demoInfo = PreviewCurrencyInfo(DEMOCURRENCY, digits: 2)
+ let test = try! Amount(fromString: TESTCURRENCY + ":1.23")
+ let demo = try! Amount(fromString: DEMOCURRENCY + ":1234.12")
+ let testStr = testInfo.string(for: test.valueAsTuple)
+ let demoStr = demoInfo.string(for: demo.valueAsTuple)
+ List {
+ Section {
+ AmountRowV(amountStr: demoStr, largeAmountFont: true, fitsHorizontal: true) {
+ Text("Balance")
+ .accessibilityFont(.title2)
+ }
+ AmountRowV(amountStr: demoStr, largeAmountFont: true, fitsHorizontal: false) {
+ Text("Balance")
+ .accessibilityFont(.title2)
+ }
+ }
+ Section {
+ AmountRowV(amountStr: testStr, largeAmountFont: false, fitsHorizontal: true) {
+ Text("Balance")
+ .accessibilityFont(.title2)
+ }
+ AmountRowV(amountStr: testStr, largeAmountFont: false, fitsHorizontal: false) {
+ Text("Balance")
+ .accessibilityFont(.title2)
+ }
+ }
+ }
+ }
+}
+
+#Preview {
+ SectionWithAmountRow()
+}
+#endif