gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-ios] 20/30: ViewThatFits instead of own computations, iconB


From: gnunet
Subject: [taler-taler-ios] 20/30: ViewThatFits instead of own computations, iconBadge
Date: Sun, 19 Nov 2023 23:53:44 +0100

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 a1a5c84611d67dc4818944c223106cb1c76a0e2e
Author: Marc Stibane <marc@taler.net>
AuthorDate: Sun Nov 19 13:32:01 2023 +0100

    ViewThatFits instead of own computations, iconBadge
---
 TalerWallet1/Views/Balances/PendingRowView.swift   | 143 +++++++--------------
 .../Views/Transactions/TransactionRowView.swift    |  34 +++--
 2 files changed, 68 insertions(+), 109 deletions(-)

diff --git a/TalerWallet1/Views/Balances/PendingRowView.swift 
b/TalerWallet1/Views/Balances/PendingRowView.swift
index 903740e..4b3ce6e 100644
--- a/TalerWallet1/Views/Balances/PendingRowView.swift
+++ b/TalerWallet1/Views/Balances/PendingRowView.swift
@@ -5,35 +5,26 @@
 import SwiftUI
 import taler_swift
 
-struct PendingRowContentV: View {
-    let titles: (String, String?)
-    let isHorizontal: Bool
+/// This view shows a pending transaction row in a currency section
+struct PendingRowView: View {
+    let amount: Amount
     let incoming: Bool
     let shouldConfirm: Bool
     let needsKYC: Bool
 
-    public static func width(titles: (String, String?), isHorizontal: Bool,
-                             sizeCategory: ContentSizeCategory) -> CGFloat {
-        let imageFont = TalerFont.uiFont(.largeTitle)
-        let uiFont = TalerFont.uiFont(.body)
+    @Environment(\.sizeCategory) var sizeCategory
+    @EnvironmentObject private var controller: Controller
+    @AppStorage("iconOnly") var iconOnly: Bool = false
 
-        let image = "++"
-        let imageWidth = image.widthOfString(usingUIFont: imageFont, 
sizeCategory) + 8.0     // spacing: 8
-        let (title1, title2) = titles
-        let title1Width = title1.widthOfString(usingUIFont: uiFont, 
sizeCategory)
-        var title2Width = 0.0
-        var totalWidth = title1Width
-        if let title2 {
-            title2Width = title2.widthOfString(usingUIFont: uiFont, 
sizeCategory)
-            let totalStr = title1 + " " + title2
-            totalWidth = totalStr.widthOfString(usingUIFont: uiFont, 
sizeCategory)
-        }
+    let inTitle0 = String(localized: "TitleIncoming_Short", defaultValue: 
"Incoming",
+                          comment: "Abbreviation of `Pending incoming´ in 
Balances")
+    let inTitle1 = String(localized: "TitleIncoming_Full", defaultValue: 
"Pending\tincoming",
+                          comment: "`Pending incoming´ in Balances - set 
exactly 1 \t for line break")
 
-//    let logStr = String(format: "image: %.2f   title: %.2f   total: %.2f", 
imageWidth, max(title1Width, title2Width), totalWidth)
-//    print(logStr)
-        return imageWidth + (isHorizontal ? totalWidth
-                                          : max(title1Width, title2Width))
-    }
+    let outTitle0 = String(localized: "TitleOutgoing_Short", defaultValue: 
"Outgoing",
+                           comment: "Abbreviation of `Pending outgoing´ in 
Balances")
+    let outTitle1 = String(localized: "TitleOutgoing_Full", defaultValue: 
"Pending\toutgoing",
+                           comment: "`Pending outgoing´ in Balances - set 
exactly 1 \t for line break")
 
     var body: some View {
         let pendingColor = WalletColors().pendingColor(incoming)
@@ -41,87 +32,45 @@ struct PendingRowContentV: View {
                                  : "minus.diamond"      //
         let badgeName = needsKYC ? "star.fill"
                                  : "circle.fill"
-        HStack(spacing: 8) {
-            HStack(alignment: .top, spacing: -8) {      // TODO: adapt spacing 
to dynamic fontsize
-                Image(systemName: imageName)
-                    .foregroundColor(pendingColor)
-                    .accessibilityFont(.largeTitle)
-                    .accessibility(hidden: true)
-                Image(systemName: badgeName)
-                    .accessibilityFont(.caption)
-                    .foregroundColor((needsKYC || shouldConfirm) ? .red : 
.clear)
-            }
-            let pendingAccTitles = accessTitles(titles, isHorizontal)
-            Text(pendingAccTitles.0)
-                .accessibilityLabel(Text(pendingAccTitles.1))
-                .lineLimit(4)
-                .accessibilityFont(.body)
-        }
-        .accessibilityElement(children: .combine)
-        .accessibilityValue(needsKYC ? ". Needs K Y C" :
-                       shouldConfirm ? ". Needs bank confirmation" : 
EMPTYSTRING)
-        .accessibilityHint("Will go to pending transaction list.")
-
-    }
-}
-
-/// This view shows a pending transaction row in a currency section
-struct PendingRowView: View {
-    let amount: Amount
-    let incoming: Bool
-    let shouldConfirm: Bool
-    let needsKYC: Bool
+        let iconBadge = IconBadge(imageName: imageName, foreColor: 
pendingColor, shouldConfirm: shouldConfirm, needsKYC: needsKYC)
 
-    @Environment(\.sizeCategory) var sizeCategory
-    @EnvironmentObject private var controller: Controller
-    @AppStorage("iconOnly") var iconOnly: Bool = false
+        let inTitle = iconOnly ? inTitle0 : inTitle1
+        let outTitle = iconOnly ? outTitle0 : outTitle1
+        let pendingTitle = incoming ? inTitle : outTitle
 
-    let inTitle0 = String(localized: "TitleIncoming_Short", defaultValue: 
"Incoming",
-                            comment: "Abbreviation of `Pending incoming´ in 
Balances")
-    let inTitle1 = String(localized: "TitleIncoming_Top", defaultValue: 
"Pending",
-                            comment: "Top (first half) of line `Pending 
incoming´ in Balances")
-    let inTitle2 = String(localized: "TitleIncoming_Bottom", defaultValue: 
"incoming",
-                            comment: "Bottom (second half) of line `Pending 
incoming´ in Balances")
-    let outTitle0 = String(localized: "TitleOutgoing_Short", defaultValue: 
"Outgoing",
-                             comment: "Abbreviation of `Pending outgoing´ in 
Balances")
-    let outTitle1 = String(localized: "TitleOutgoing_Top", defaultValue: 
"Pending",
-                             comment: "Top (first half) of line `Pending 
outgoing´ in Balances")
-    let outTitle2 = String(localized: "TitleOutgoing_Bottom", defaultValue: 
"outgoing",
-                             comment: "Bottom (second half) of line `Pending 
outgoing´ in Balances")
+        let currencyInfo = controller.info(for: amount.currencyStr, 
controller.currencyTicker)
+        let amountText = Text(amount.string(currencyInfo))
+            .foregroundColor(pendingColor)
+            .accessibilityFont(.title2)
+            .monospacedDigit()
 
-    func needVStack(available: CGFloat, contentWidth: CGFloat, valueWidth: 
CGFloat) -> Bool {
-        if available > 20 {
-            let logStr = String(format: "available: %.2f   sum: %.2f = 
content: %.2f  + value: %.2f",
-                                available, contentWidth + valueWidth, 
contentWidth, valueWidth)
-            print(logStr)
+        // this is the default view for iOS 15
+        let vStack = VStack {
+            Text(pendingTitle.tabbed(oneLine: true))
+            HStack {
+                iconBadge
+                Spacer(minLength: 0)
+                amountText
+            }
         }
-        return available < (contentWidth + valueWidth + 20)
-    }
 
-    var body: some View {
-        let pendingColor = WalletColors().pendingColor(incoming)
-        SingleAxisGeometryReader { width in
-            Group {
-                let currencyInfo = controller.info(for: amount.currencyStr, 
controller.currencyTicker)
-                let amountStr = amount.string(currencyInfo)
-                let amountWidth = amountStr.width(largeAmountFont: false, 
sizeCategory)
-                let inTitles = iconOnly ? (inTitle0, nil)
-                                        : (inTitle1, inTitle2)
-                let outTitles = iconOnly ? (outTitle0, nil)
-                                         : (outTitle1, outTitle2)
-                let titles = incoming ? inTitles
-                                      : outTitles
-                let contentWidth = PendingRowContentV.width(titles: titles,
-                                                      isHorizontal: false,
-                                                      sizeCategory: 
sizeCategory)
-                let needVStack = needVStack(available: width, contentWidth: 
contentWidth, valueWidth: amountWidth)
-                AmountRowV(amountStr: amountStr, amountColor: pendingColor, 
largeAmountFont: false,
-                           fitsHorizontal: !needVStack, vertAlignment: 
.center) {
-                    // isHorizontal=true to try to fit "- Pending outgoing" + 
amount in 1 line
-                    PendingRowContentV(titles: titles, isHorizontal: true, 
incoming: incoming,
-                                       shouldConfirm: shouldConfirm, needsKYC: 
needsKYC)
+        if #available(iOS 16.0, *) {
+            ViewThatFits(in: .horizontal) {
+                HStack {
+                    iconBadge
+                    Text(pendingTitle.tabbed(oneLine: false))
+                    Spacer(minLength: 0)
+                    amountText
+                }
+                vStack
+                VStack {
+                    Text(pendingTitle.tabbed(oneLine: true))
+                    iconBadge
+                    amountText
                 }
             }
+        } else {
+            vStack
         }
     }
 }
diff --git a/TalerWallet1/Views/Transactions/TransactionRowView.swift 
b/TalerWallet1/Views/Transactions/TransactionRowView.swift
index bbdb250..79fc46b 100644
--- a/TalerWallet1/Views/Transactions/TransactionRowView.swift
+++ b/TalerWallet1/Views/Transactions/TransactionRowView.swift
@@ -5,6 +5,26 @@
 import SwiftUI
 import taler_swift
 
+struct IconBadge: View {
+    let imageName: String
+    let foreColor:Color
+    let shouldConfirm: Bool
+    let needsKYC: Bool
+
+    var body: some View {
+        let badgeName = needsKYC ? "star.fill"
+                                 : "circle.fill"
+        HStack(alignment: .top, spacing: -8) {      // TODO: adapt spacing to 
dynamic fontsize
+            Image(systemName: imageName)
+                .foregroundColor(foreColor)
+                .accessibilityFont(.largeTitle)
+                .accessibility(hidden: true)
+            Image(systemName: badgeName)
+                .accessibilityFont(.caption)
+                .foregroundColor((needsKYC || shouldConfirm) ? .red : .clear)
+        }.accessibilityHidden(true)
+    }
+}
 struct TransactionRowContentV: View {
     var centerTop: String
     var centerBottom: String
@@ -41,19 +61,9 @@ struct TransactionRowContentV: View {
     var body: some View {
         let imageName = incoming ? "plus.circle.fill"
                                  : "minus.circle.fill"
-        let badgeName = needsKYC ? "star.fill"
-                                 : "circle.fill"
+        let iconBadge = IconBadge(imageName: imageName, foreColor: foreColor, 
shouldConfirm: shouldConfirm, needsKYC: needsKYC)
         HStack(spacing: 8) {
-            HStack(alignment: .top, spacing: -8) {      // TODO: adapt spacing 
to dynamic fontsize
-                Image(systemName: imageName)
-                    .foregroundColor(foreColor)
-                    .accessibilityFont(.largeTitle)
-                    .accessibility(hidden: true)
-                Image(systemName: badgeName)
-                    .accessibilityFont(.caption)
-                    .foregroundColor((needsKYC || shouldConfirm) ? .red : 
.clear)
-            }.accessibilityHidden(true)
-
+            iconBadge
             VStack(alignment: .leading) {
                 Text(centerTop)
                     .accessibilityFont(.headline)

-- 
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]