gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 42/54: BalanceRow


From: gnunet
Subject: [taler-taler-ios] 42/54: BalanceRow
Date: Fri, 30 Jun 2023 22:34:14 +0200

This is an automated email from the git hooks/post-receive script.

marc-stibane pushed a commit to branch master
in repository taler-ios.

commit fbb0aa6ec1e32ce5932ee4e4fbcadb56efe11fad
Author: Marc Stibane <marc@taler.net>
AuthorDate: Fri Jun 30 17:29:26 2023 +0200

    BalanceRow
---
 TalerWallet.xcodeproj/project.pbxproj              |  4 +
 .../Views/Balances/BalanceRowButtons.swift         | 51 +++++++++++
 TalerWallet1/Views/Balances/BalanceRowView.swift   | 98 ++++++++++++++--------
 TalerWallet1/Views/HelperViews/Buttons.swift       |  3 +-
 4 files changed, 118 insertions(+), 38 deletions(-)

diff --git a/TalerWallet.xcodeproj/project.pbxproj 
b/TalerWallet.xcodeproj/project.pbxproj
index e2d2818..84a7067 100644
--- a/TalerWallet.xcodeproj/project.pbxproj
+++ b/TalerWallet.xcodeproj/project.pbxproj
@@ -39,6 +39,7 @@
                4EA1ABBE29A3833A008821EA /* PublicConstants.swift in Sources */ 
= {isa = PBXBuildFile; fileRef = 4EA1ABBD29A3833A008821EA /* 
PublicConstants.swift */; };
                4EA551252A2C923600FEC9A8 /* CurrencyInputView.swift in Sources 
*/ = {isa = PBXBuildFile; fileRef = 4EA551242A2C923600FEC9A8 /* 
CurrencyInputView.swift */; };
                4EAD117629F672FA008EDD0B /* KeyboardResponder.swift in Sources 
*/ = {isa = PBXBuildFile; fileRef = 4EAD117529F672FA008EDD0B /* 
KeyboardResponder.swift */; };
+               4EB065442A4CD1A80039B91D /* BalanceRowButtons.swift in Sources 
*/ = {isa = PBXBuildFile; fileRef = 4EB065432A4CD1A80039B91D /* 
BalanceRowButtons.swift */; };
                4EB094D629896CD20043A8A1 /* TalerWalletTests.swift in Sources 
*/ = {isa = PBXBuildFile; fileRef = 4EB094D429896CD20043A8A1 /* 
TalerWalletTests.swift */; };
                4EB094D729896CD20043A8A1 /* WalletBackendTests.swift in Sources 
*/ = {isa = PBXBuildFile; fileRef = 4EB094D529896CD20043A8A1 /* 
WalletBackendTests.swift */; };
                4EB094DC29896D030043A8A1 /* TalerWalletUITestsLaunchTests.swift 
in Sources */ = {isa = PBXBuildFile; fileRef = 4EB094D929896D030043A8A1 /* 
TalerWalletUITestsLaunchTests.swift */; };
@@ -171,6 +172,7 @@
                4EA1ABBD29A3833A008821EA /* PublicConstants.swift */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.swift; path = 
PublicConstants.swift; sourceTree = "<group>"; };
                4EA551242A2C923600FEC9A8 /* CurrencyInputView.swift */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.swift; path = 
CurrencyInputView.swift; sourceTree = "<group>"; };
                4EAD117529F672FA008EDD0B /* KeyboardResponder.swift */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path 
= KeyboardResponder.swift; sourceTree = "<group>"; };
+               4EB065432A4CD1A80039B91D /* BalanceRowButtons.swift */ = {isa = 
PBXFileReference; lastKnownFileType = sourcecode.swift; path = 
BalanceRowButtons.swift; sourceTree = "<group>"; };
                4EB094D429896CD20043A8A1 /* TalerWalletTests.swift */ = {isa = 
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path 
= TalerWalletTests.swift; sourceTree = "<group>"; };
                4EB094D529896CD20043A8A1 /* WalletBackendTests.swift */ = {isa 
= PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; 
path = WalletBackendTests.swift; sourceTree = "<group>"; };
                4EB094D929896D030043A8A1 /* TalerWalletUITestsLaunchTests.swift 
*/ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = 
sourcecode.swift; path = TalerWalletUITestsLaunchTests.swift; sourceTree = 
"<group>"; };
@@ -445,6 +447,7 @@
                                4EB095372989CBFE0043A8A1 /* 
BalancesListView.swift */,
                                4EB0953A2989CBFE0043A8A1 /* 
BalancesSectionView.swift */,
                                4EB095362989CBFE0043A8A1 /* 
BalanceRowView.swift */,
+                               4EB065432A4CD1A80039B91D /* 
BalanceRowButtons.swift */,
                                4EB095382989CBFE0043A8A1 /* 
PendingRowView.swift */,
                                4E87C8742A34B411001C6406 /* 
UncompletedRowView.swift */,
                        );
@@ -762,6 +765,7 @@
                                4EB0956C2989CBFE0043A8A1 /* AmountView.swift in 
Sources */,
                                4E3B4BC32A42252300CC88B8 /* P2pAcceptDone.swift 
in Sources */,
                                4E363CBE2A23CB2100D7E98C /* 
AnyTransition+backslide.swift in Sources */,
+                               4EB065442A4CD1A80039B91D /* 
BalanceRowButtons.swift in Sources */,
                                4EB095592989CBFE0043A8A1 /* 
Model+Transactions.swift in Sources */,
                                4E578E922A481D8600F21F1C /* playSound.swift in 
Sources */,
                                4EB0955F2989CBFE0043A8A1 /* 
WalletEmptyView.swift in Sources */,
diff --git a/TalerWallet1/Views/Balances/BalanceRowButtons.swift 
b/TalerWallet1/Views/Balances/BalanceRowButtons.swift
new file mode 100644
index 0000000..1eb0a61
--- /dev/null
+++ b/TalerWallet1/Views/Balances/BalanceRowButtons.swift
@@ -0,0 +1,51 @@
+/*
+ * This file is part of GNU Taler, ©2022-23 Taler Systems S.A.
+ * See LICENSE.md
+ */
+import SwiftUI
+import taler_swift
+
+struct BalanceRowButtons: View {
+    let amount: Amount
+    let narrow: Bool
+    let lineLimit: Int
+    let sendAction: () -> Void
+    let recvAction: () -> Void
+    @Environment(\.sizeCategory) var sizeCategory
+
+    var body: some View {
+        let currency = amount.currencyStr
+        Group {
+            Button("Request\nPayment", action: recvAction)
+                .lineLimit(lineLimit)
+                .disabled(false)
+                .buttonStyle(TalerButtonStyle(type: .bordered, narrow: narrow, 
aligned: .center))
+            Button("Send\n\(currency)", action: sendAction)
+                .lineLimit(lineLimit)
+                .disabled(amount.isZero)
+                .buttonStyle(TalerButtonStyle(type: .bordered, narrow: narrow, 
aligned: .center))
+
+        }
+    }
+}
+
+struct BalanceRowButtons_Previews: PreviewProvider {
+    static var previews: some View {
+        List {
+            VStack {
+                let amount = try! Amount(fromString: LONGCURRENCY + ":1234.56")
+                BalanceRowButtons(amount: Amount(currency: "TestKUDOS", value: 
1234),
+                                  narrow: false, lineLimit: 0,
+                                  sendAction: {}, recvAction: {})
+                BalanceButton(amount: amount, rowAction: {})
+            }
+            HStack {
+                let amount = try! Amount(fromString: "KUDOS" + ":1234.56")
+                BalanceRowButtons(amount: amount,
+                                  narrow: true, lineLimit: 2,
+                                  sendAction: {}, recvAction: {})
+                BalanceButton(amount: amount, rowAction: {})
+            }
+        }
+    }
+}
diff --git a/TalerWallet1/Views/Balances/BalanceRowView.swift 
b/TalerWallet1/Views/Balances/BalanceRowView.swift
index 940ca35..6f51790 100644
--- a/TalerWallet1/Views/Balances/BalanceRowView.swift
+++ b/TalerWallet1/Views/Balances/BalanceRowView.swift
@@ -8,6 +8,30 @@ import taler_swift
 /// This view shows the currency row in a currency section
 /// [Send Coins]  [Receive Coins]     Balance
 
+struct BalanceButton: View {
+    let amount: Amount
+    let rowAction: () -> Void
+
+    var body: some View {
+        Button(action: rowAction) {
+            VStack(alignment: .trailing, spacing: 0) {
+                HStack(alignment: .firstTextBaseline, spacing: 0) {
+                    Text("B", comment: "the first letter of Balance - or leave 
empty")
+                        .font(.title2)
+                    Text("alance", comment: "the remaining letters of Balance 
- or all if you left B empty")
+                        .font(.footnote).bold()
+                }
+                Text("\(amount.valueStr)")  // TODO: CurrencyFormatter?
+                    .font(.title)
+            }
+        }   .disabled(false)
+            .accessibilityElement(children: 
/*@START_MENU_TOKEN@*/.ignore/*@END_MENU_TOKEN@*/)
+            .accessibilityLabel("Balance \(amount.readableDescription)")    // 
TODO: CurrencyFormatter!
+            .buttonStyle(TalerButtonStyle(type: .plain, aligned: .trailing))
+//                .background(Color.yellow)
+    }
+}
+
 struct BalanceRowView: View {
     let amount: Amount
     let sendAction: () -> Void
@@ -15,48 +39,46 @@ struct BalanceRowView: View {
     let rowAction: () -> Void
     @Environment(\.sizeCategory) var sizeCategory
 
+    func needVStack(_ amount: Amount) -> Bool {
+        // Sizes: 320 (SE), 375 (X, Xs, 12, 13 mini), 390 (12,13,14), 414 
(Plus, Max), 428 (Pro Max)
+        guard 350 < UIScreen.main.bounds.width else {return true}   // always 
for iPhone SE 1st Gen
+        var count = amount.currencyStr.count
+//        print(sizeCategory)
+        switch sizeCategory {
+            case ContentSizeCategory.extraSmall:
+                count += 0
+            case ContentSizeCategory.small:
+                count += 1
+            case ContentSizeCategory.medium:
+                count += 2
+            case ContentSizeCategory.large:
+                count += 3
+            case ContentSizeCategory.extraLarge:
+                count += 4
+            default:
+                count += 5
+        }
+        return count > 9
+    }
+
     var body: some View {
-        let currency = amount.currencyStr
-        HStack {
-            if sizeCategory > ContentSizeCategory.large {
-                VStack {
-                    Button("Request\nPayment", action: recvAction)
-                        .disabled(false)
-                        .buttonStyle(TalerButtonStyle(type: .bordered, narrow: 
false, aligned: .leading))
-                    Button("Send\n\(currency)", action: sendAction)
-                        .disabled(amount.isZero)
-                        .buttonStyle(TalerButtonStyle(type: .bordered, narrow: 
false, aligned: .leading))
+        Group {
+            if needVStack(amount) {
+                VStack (alignment: .trailing) {
+                    BalanceButton(amount: amount, rowAction: rowAction)
+                    HStack {
+                        BalanceRowButtons(amount: amount, narrow: false, 
lineLimit: 5,
+                                          sendAction: sendAction, recvAction: 
recvAction)
+                    }
                 }
-                .fixedSize(horizontal: true, vertical: false)   // make the 
buttons equal width
             } else {
                 HStack {
-                    Button("Request\nPayment", action: recvAction)
-                        .lineLimit(2)
-                        .disabled(false)
-                        .buttonStyle(TalerButtonStyle(type: .bordered, narrow: 
true, aligned: .leading))
-                    Button("Send\n\(currency)", action: sendAction)
-                        .lineLimit(2)
-                        .disabled(amount.isZero)
-                        .buttonStyle(TalerButtonStyle(type: .bordered, narrow: 
true, aligned: .leading))
+                    BalanceRowButtons(amount: amount, narrow: true, lineLimit: 
5,
+                                      sendAction: sendAction, recvAction: 
recvAction)
+                    BalanceButton(amount: amount, rowAction: rowAction)
                 }
-                .fixedSize(horizontal: true, vertical: true)   // should make 
all buttons equal height - but doesn't
+//                .fixedSize(horizontal: true, vertical: true)   // should 
make all buttons equal height - but doesn't
             }
-            Button(action: rowAction) {
-                VStack(alignment: .trailing, spacing: 0) {
-                    HStack(alignment: .firstTextBaseline, spacing: 0) {
-                        Text("B")
-                            .font(.title2)
-                        Text("alance")
-                            .font(.footnote).bold()
-                        .accessibility(sortPriority: 2)
-                    }
-                    Text("\(amount.valueStr)")  // TODO: CurrencyFormatter?
-                        .font(.title)
-                        .accessibility(sortPriority: 1)
-                }
-            }   .disabled(false)
-                .buttonStyle(TalerButtonStyle(type: .plain, aligned: 
.trailing))
-//                .background(Color.yellow)
         }
         .accessibilityElement(children: .combine)
     }
@@ -66,7 +88,9 @@ struct BalanceRowView: View {
 struct BalanceRowView_Previews: PreviewProvider {
     static var previews: some View {
         List {
-            BalanceRowView(amount: try! Amount(fromString: LONGCURRENCY + 
":0.1"),
+            BalanceRowView(amount: try! Amount(fromString: "TestKUDOS" + 
":1234.56"),
+                           sendAction: {}, recvAction: {}, rowAction: {})
+            BalanceRowView(amount: try! Amount(fromString: "KUDOS" + 
":1234.56"),
                            sendAction: {}, recvAction: {}, rowAction: {})
         }
     }
diff --git a/TalerWallet1/Views/HelperViews/Buttons.swift 
b/TalerWallet1/Views/HelperViews/Buttons.swift
index 3d06b25..c3d0fe8 100644
--- a/TalerWallet1/Views/HelperViews/Buttons.swift
+++ b/TalerWallet1/Views/HelperViews/Buttons.swift
@@ -171,7 +171,8 @@ struct TalerButtonStyle: ButtonStyle {
                                     : Alignment.trailing
             configuration.label
                 .multilineTextAlignment(aligned)
-                .font(.title2)
+                .font(.title3)
+//                .font(narrow ? .title3 : .title2)
                 .frame(minWidth: 0, maxWidth: narrow ? nil : .infinity, 
alignment: aligned2)
                 .padding(.vertical, 10)
                 .padding(.horizontal, 6)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]