summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Stibane <marc@taler.net>2023-11-19 22:08:24 +0100
committerMarc Stibane <marc@taler.net>2023-11-19 22:19:15 +0100
commit74336e727e14e9830687e3046702795c45bb9b2a (patch)
tree2781d02e1bfbabd9824db4316f6007c7a5c9a1f1
parentda2fe9b573e9287c007cf3d0b1e1e633319ee259 (diff)
downloadtaler-ios-74336e727e14e9830687e3046702795c45bb9b2a.tar.gz
taler-ios-74336e727e14e9830687e3046702795c45bb9b2a.tar.bz2
taler-ios-74336e727e14e9830687e3046702795c45bb9b2a.zip
badge for button
-rw-r--r--TalerWallet1/Controllers/PublicConstants.swift4
-rw-r--r--TalerWallet1/Views/HelperViews/Buttons.swift66
-rw-r--r--TalerWallet1/Views/Transactions/TransactionDetailView.swift6
-rw-r--r--TalerWallet1/Views/Transactions/TransactionRowView.swift4
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)