gnunet-svn
[Top][All Lists]
Advanced

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

[taler-taler-ios] 26/30: badge for button


From: gnunet
Subject: [taler-taler-ios] 26/30: badge for button
Date: Sun, 19 Nov 2023 23:53:50 +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 74336e727e14e9830687e3046702795c45bb9b2a
Author: Marc Stibane <marc@taler.net>
AuthorDate: Sun Nov 19 22:08:24 2023 +0100

    badge for button
---
 TalerWallet1/Controllers/PublicConstants.swift     |  4 +-
 TalerWallet1/Views/HelperViews/Buttons.swift       | 66 +++++++++++-----------
 .../Views/Transactions/TransactionDetailView.swift |  6 +-
 .../Views/Transactions/TransactionRowView.swift    |  4 +-
 4 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/TalerWallet1/Controllers/PublicConstants.swift 
b/TalerWallet1/Controllers/PublicConstants.swift
index 69da359..1b5c9ae 100644
--- a/TalerWallet1/Controllers/PublicConstants.swift
+++ b/TalerWallet1/Controllers/PublicConstants.swift
@@ -13,7 +13,9 @@ public let ONEDAY: UInt = 1         // 1..3
 public let SEVENDAYS: UInt = 7      // 3..9
 public let THIRTYDAYS: UInt = 30    // 10..30
 
-public let EMPTYSTRING = ""                        // avoid automatic 
translation of empty "" textLiterals in Text()
+public let EMPTYSTRING = ""                         // avoid automatic 
translation of empty "" textLiterals in Text()
+public let CONFIRM_BANK = "circle.fill"             // badge in PendingRow, 
TransactionRow and TransactionDetail
+public let NEEDS_KYC = "star.fill"                  // badge in PendingRow, 
TransactionRow and TransactionDetail
 public let HTTPS = "https://";
 //public let DEMOBANK = HTTPS + "bAnK.dEmO.tAlEr.nEt"             // should be 
weird to read, but still work
 //public let DEMOEXCHANGE = HTTPS + "eXcHaNgE.dEmO.tAlEr.nEt"
diff --git a/TalerWallet1/Views/HelperViews/Buttons.swift 
b/TalerWallet1/Views/HelperViews/Buttons.swift
index 3e3884c..9ab4a4b 100644
--- a/TalerWallet1/Views/HelperViews/Buttons.swift
+++ b/TalerWallet1/Views/HelperViews/Buttons.swift
@@ -93,7 +93,7 @@ struct ReloadButton : View  {
 
 struct TalerButtonStyle: ButtonStyle {
     @Environment(\.isEnabled) private var isEnabled: Bool
-    func disabled() -> Bool { !isEnabled }
+    var disabled: Bool { !isEnabled }
 
     enum TalerButtonStyleType {
         case plain
@@ -105,6 +105,7 @@ struct TalerButtonStyle: ButtonStyle {
     var dimmed: Bool = false
     var narrow: Bool = false
     var aligned: TextAlignment = .center
+    var badge: String = EMPTYSTRING
 
     public func makeBody(configuration: ButtonStyle.Configuration) -> some 
View {
 //        configuration.role = type == .prominent ? .primary : .normal         
 Only on macOS
@@ -113,36 +114,23 @@ struct TalerButtonStyle: ButtonStyle {
                    backColor: backColor(type: type, pressed: 
configuration.isPressed),
                       dimmed: dimmed,
                configuration: configuration,
-                    disabled: disabled(),
+                    disabled: disabled,
                       narrow: narrow,
-                     aligned: aligned)
+                     aligned: aligned,
+                       badge: badge)
     }
 
     func foreColor(type: TalerButtonStyleType, pressed: Bool) -> Color {
-//        return if type == .plain {
-//            WalletColors().fieldForeground
-//        } else {
-//            WalletColors().buttonForeColor(pressed: pressed,
-//                                          disabled: disabled(),
-//                                         prominent: type == .prominent)
-//        }
         return type == .plain ? WalletColors().fieldForeground :      // 
primary text color
             WalletColors().buttonForeColor(pressed: pressed,
-                                          disabled: disabled(),
+                                          disabled: disabled,
                                          prominent: type == .prominent,
                                            balance: type == .balance)
     }
     func backColor(type: TalerButtonStyleType, pressed: Bool) -> Color {
-//        return if type == .plain {
-//            Color.clear
-//        } else {
-//            WalletColors().buttonBackColor(pressed: pressed,
-//                                           disabled: disabled(),
-//                                           prominent: type == .prominent)
-//        }
         return type == .plain && !pressed ? Color.clear :
             WalletColors().buttonBackColor(pressed: pressed,
-                                          disabled: disabled(),
+                                          disabled: disabled,
                                          prominent: type == .prominent,
                                            balance: type == .balance)
     }
@@ -169,28 +157,40 @@ struct TalerButtonStyle: ButtonStyle {
         let disabled: Bool
         let narrow: Bool
         let aligned: TextAlignment
+        var badge: String
 
         var body: some View {
             let aligned2: Alignment = (aligned == .center) ? Alignment.center
                                     : (aligned == .leading) ? Alignment.leading
                                     : Alignment.trailing
-            configuration.label
-                .multilineTextAlignment(aligned)
-                .accessibilityFont(.title3)
-//                                  narrow ? .title3 : .title2
-                .frame(minWidth: 0, maxWidth: narrow ? nil : .infinity, 
alignment: aligned2)
-                .padding(.vertical, 10)
-                .padding(.horizontal, 6)
-                .foregroundColor(foreColor)
-                .background(BackgroundView(color: backColor, dimmed: dimmed))
-                .contentShape(Rectangle())      // make sure the button can be 
pressed even if backgroundColor == clear
-                .scaleEffect(configuration.isPressed ? 0.95 : 1)
-                .animation(.spring(response: 0.1), value: 
configuration.isPressed)
-                .disabled(disabled)
+            let hasBadge = badge.count > 0
+            let buttonLabel = configuration.label
+                                .multilineTextAlignment(aligned)
+                                .accessibilityFont(.title3)         //   
narrow ? .title3 : .title2
+                                .frame(maxWidth: narrow ? nil : .infinity, 
alignment: aligned2)
+                                .padding(.vertical, 10)
+                                .padding(.horizontal, hasBadge ? 0 : 6)
+                                .foregroundColor(foreColor)
+                                .background(BackgroundView(color: backColor, 
dimmed: dimmed))
+                                .contentShape(Rectangle())      // make sure 
the button can be pressed even if backgroundColor == clear
+                                .scaleEffect(configuration.isPressed ? 0.95 : 
1)
+                                .animation(.spring(response: 0.1), value: 
configuration.isPressed)
+                                .disabled(disabled)
+            if !hasBadge {
+                buttonLabel
+            } else {
+                let badgeV = Image(systemName: badge)
+                                .accessibilityFont(.caption)
+                HStack(alignment: .top, spacing: 0) {
+                    badgeV.foregroundColor(.clear)
+                    buttonLabel
+                    badgeV.foregroundColor(.red)
+                }
+            }
         }
     }
 }
-
+// MARK: -
 #if DEBUG
 fileprivate struct ContentView_Previews: PreviewProvider {
     static var previews: some View {
diff --git a/TalerWallet1/Views/Transactions/TransactionDetailView.swift 
b/TalerWallet1/Views/Transactions/TransactionDetailView.swift
index 5d1c7f9..8d4c988 100644
--- a/TalerWallet1/Views/Transactions/TransactionDetailView.swift
+++ b/TalerWallet1/Views/Transactions/TransactionDetailView.swift
@@ -219,8 +219,7 @@ struct TransactionDetailView: View {
                                                             
.listRowSeparator(.hidden)
                                                     }
                                                     Link("Confirm with bank", 
destination: destination)
-                                                        
.buttonStyle(TalerButtonStyle(type: .prominent, narrow: false, aligned: 
.center))
-                                                        .padding(.horizontal)  
                                                  
+                                                        
.buttonStyle(TalerButtonStyle(type: .prominent, badge: CONFIRM_BANK))
                                                 }
                                             }
                                         }
@@ -235,8 +234,7 @@ struct TransactionDetailView: View {
                                                             
.listRowSeparator(.hidden)
                                                     }
                                                     Link("Open KYC website", 
destination: destination)
-                                                        
.buttonStyle(TalerButtonStyle(type: .prominent, narrow: false, aligned: 
.center))
-                                                        .padding(.horizontal)
+                                                        
.buttonStyle(TalerButtonStyle(type: .prominent, badge: NEEDS_KYC))
                                                 }
                                             }
                                         }
diff --git a/TalerWallet1/Views/Transactions/TransactionRowView.swift 
b/TalerWallet1/Views/Transactions/TransactionRowView.swift
index 79fc46b..b618c66 100644
--- a/TalerWallet1/Views/Transactions/TransactionRowView.swift
+++ b/TalerWallet1/Views/Transactions/TransactionRowView.swift
@@ -12,8 +12,8 @@ struct IconBadge: View {
     let needsKYC: Bool
 
     var body: some View {
-        let badgeName = needsKYC ? "star.fill"
-                                 : "circle.fill"
+        let badgeName = needsKYC ? NEEDS_KYC
+                                 : CONFIRM_BANK
         HStack(alignment: .top, spacing: -8) {      // TODO: adapt spacing to 
dynamic fontsize
             Image(systemName: imageName)
                 .foregroundColor(foreColor)

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