commit 5cc946bd500235cbd9fbc59b72162bd2b201a69f
parent ecb2d78a4f11f8dc2e9386c165f47c4954a8aeea
Author: Marc Stibane <marc@taler.net>
Date: Sat, 25 Nov 2023 07:47:00 +0100
ViewThatFits
Diffstat:
3 files changed, 72 insertions(+), 99 deletions(-)
diff --git a/TalerWallet1/Views/Balances/BalanceRowView.swift b/TalerWallet1/Views/Balances/BalanceRowView.swift
@@ -59,48 +59,45 @@ struct BalanceRowView: View {
let sendTitle0 = String(localized: "SendButton_Short", defaultValue: "Send",
comment: "Abbreviation of button `Send Money´")
- let sendTitle1 = String(localized: "SendButton_Top", defaultValue: "Send",
- comment: "Top (first half) of button `Send Money´")
- let sendTitle2 = String(localized: "SendButton_Bottom", defaultValue: "Money",
- comment: "Bottom (second half) of button `Send Money´")
+ let sendTitle1 = String(localized: "SendButton_Full", defaultValue: "Send\tMoney",
+ comment: "`Send Money´ in Balances - set exactly 1 \\t for line break")
+
let requestTitle0 = String(localized: "RequestButton_Short", defaultValue: "Request",
comment: "Abbreviation of button `Request Payment´")
- let requestTitle1 = String(localized: "RequestButton_Top", defaultValue: "Request",
- comment: "Top (first half) of button `Request Payment´")
- let requestTitle2 = String(localized: "RequestButton_Bottom", defaultValue: "Payment",
- comment: "Bottom (second half) of button `Request Payment´")
-
+ let requestTitle1 = String(localized: "RequestButton_Full", defaultValue: "Request\tPayment",
+ comment: "`Request Payment´ in Balances - set exactly 1 \\t for line break")
var body: some View {
- SingleAxisGeometryReader { width in
- VStack (alignment: .trailing) {
- let currencyInfo = controller.info(for: amount.currencyStr, controller.currencyTicker)
- let amountStr = amount.string(currencyInfo)
- BalanceButton(amountStr: amountStr,
- sizeCategory: sizeCategory,
- rowAction: rowAction)
- let uiFont = TalerFont.uiFont(.title3)
- let titles = iconOnly ? [(sendTitle0, uiFont), (requestTitle0, uiFont)]
- : [(sendTitle1, uiFont), (sendTitle2, uiFont), (requestTitle1, uiFont), (requestTitle2, uiFont)]
- let fitsSideBySide = Self.fitsSideBySide(titles, availableWidth: width, sizeCategory: sizeCategory, padding: 10)
- let twoRowButtons = TwoRowButtons(sendTitles: iconOnly ? (sendTitle0, nil) : (sendTitle1, sendTitle2),
- recvTitles: iconOnly ? (requestTitle0, nil) : (requestTitle1, requestTitle2),
- fitsSideBySide: fitsSideBySide,
- lineLimit: 5,
- sendDisabled: amount.isZero,
- sendAction: sendAction,
- recvAction: recvAction)
- if fitsSideBySide {
- HStack(spacing: HSPACING) { twoRowButtons }
- } else {
+ VStack (alignment: .trailing) {
+ let currencyInfo = controller.info(for: amount.currencyStr, controller.currencyTicker)
+ let amountStr = amount.string(currencyInfo)
+ BalanceButton(amountStr: amountStr,
+ sizeCategory: sizeCategory,
+ rowAction: rowAction)
+
+ let sendTitle = iconOnly ? sendTitle0 : sendTitle1
+ let requTitle = iconOnly ? requestTitle0 : requestTitle1
+ let twoRowButtons = TwoRowButtons(sendTitle: sendTitle,
+ recvTitle: requTitle,
+ fitsSideBySide: false,
+ lineLimit: 5,
+ sendDisabled: amount.isZero,
+ sendAction: sendAction,
+ recvAction: recvAction)
+ if #available(iOS 16.0, *) {
+ ViewThatFits(in: .horizontal) {
+ HStack(spacing: HSPACING) {
+ twoRowButtons.makeCopy(fitsSideBySide: true)
+ }
VStack { twoRowButtons }
}
+ } else { // view for iOS 15
+ VStack { twoRowButtons }
}
}
}
}
// MARK: -
#if DEBUG
-
struct BalanceRowView_Previews: PreviewProvider {
@MainActor
struct StateContainer: View {
diff --git a/TalerWallet1/Views/Balances/TwoRowButtons.swift b/TalerWallet1/Views/Balances/TwoRowButtons.swift
@@ -5,42 +5,41 @@
import SwiftUI
import taler_swift
-extension View {
- func accessTitles(_ titles: (String, String?), _ fitsSideBySide: Bool) -> (String, String) {
- let space = " "
- let delimiter = fitsSideBySide ? "\n" : space
- let (title1, title2) = titles
- if let title2 {
- return (title1 + delimiter + title2, title1 + space + title2)
- } else {
- return (title1, title1)
- }
- }
-}
struct TwoRowButtons: View {
- let sendTitles: (String, String?)
- let recvTitles: (String, String?)
+ let sendTitle: String
+ let recvTitle: String
let fitsSideBySide: Bool
let lineLimit: Int
let sendDisabled: Bool
let sendAction: () -> Void
let recvAction: () -> Void
- @Environment(\.sizeCategory) var sizeCategory
+// @Environment(\.sizeCategory) var sizeCategory
+ func makeCopy(fitsSideBySide: Bool) -> TwoRowButtons {
+ TwoRowButtons(sendTitle: sendTitle,
+ recvTitle: recvTitle,
+ fitsSideBySide: fitsSideBySide,
+ lineLimit: lineLimit,
+ sendDisabled: sendDisabled,
+ sendAction: sendAction,
+ recvAction: recvAction)
+ }
var body: some View {
Group {
- let sendAccTitles = accessTitles(sendTitles, fitsSideBySide)
- Button(sendAccTitles.0, action: sendAction)
- .accessibilityLabel(Text(sendAccTitles.1))
+ let sendButtonTitle = sendTitle.tabbed(oneLine: !fitsSideBySide)
+ let sendVoiceOverTitle = sendTitle.tabbed(oneLine: true)
+ Button(sendButtonTitle, action: sendAction)
+ .accessibilityLabel(Text(sendVoiceOverTitle))
.lineLimit(lineLimit)
.disabled(sendDisabled)
.buttonStyle(TalerButtonStyle(type: .bordered,
dimmed: false,
aligned: .center))
- let recvAccTitles = accessTitles(recvTitles, fitsSideBySide)
- Button(recvAccTitles.0, action: recvAction)
- .accessibilityLabel(Text(recvAccTitles.1))
+ let recvButtonTitle = recvTitle.tabbed(oneLine: !fitsSideBySide)
+ let recvVoiceOverTitle = recvTitle.tabbed(oneLine: true)
+ Button(recvButtonTitle, action: recvAction)
+ .accessibilityLabel(Text(recvVoiceOverTitle))
.lineLimit(lineLimit)
.disabled(false)
.buttonStyle(TalerButtonStyle(type: .bordered,
@@ -49,18 +48,19 @@ struct TwoRowButtons: View {
}
}
}
-
+// MARK: -
+#if DEBUG
struct TwoRowButtons_Previews: PreviewProvider {
static var previews: some View {
List {
- TwoRowButtons(sendTitles: ("Send", TESTCURRENCY),
- recvTitles: ("Receive", LONGCURRENCY),
+ TwoRowButtons(sendTitle: "Send " + TESTCURRENCY,
+ recvTitle: "Request" + LONGCURRENCY,
fitsSideBySide: false,
lineLimit: 2, sendDisabled: true,
sendAction: {}, recvAction: {})
.listRowSeparator(.hidden)
- TwoRowButtons(sendTitles: ("Send", DEMOCURRENCY),
- recvTitles: ("Receive", DEMOCURRENCY),
+ TwoRowButtons(sendTitle: "Send" + DEMOCURRENCY,
+ recvTitle: "Request" + DEMOCURRENCY,
fitsSideBySide: true,
lineLimit: 2, sendDisabled: true,
sendAction: {}, recvAction: {})
@@ -68,3 +68,4 @@ struct TwoRowButtons_Previews: PreviewProvider {
}
}
}
+#endif
diff --git a/TalerWallet1/Views/Exchange/ExchangeRowView.swift b/TalerWallet1/Views/Exchange/ExchangeRowView.swift
@@ -28,29 +28,12 @@ struct ExchangeRowView: View {
// }
}
- func titles(_ title: String) -> (String, String?) {
- if let separatorIndex = title.firstIndex(of: "\n") {
- let title1 = String(title[..<separatorIndex])
- let title2 = String(title[title.index(separatorIndex, offsetBy: 1)...])
- return (title1, title2)
- }
- return (title, nil)
- }
-
- func titles(_ titles: (String, String?), uiFont: UIFont) -> [(String, UIFont)] {
- let (title1, title2) = titles
- if let title2 {
- return [(title1, uiFont), (title2, uiFont)]
- }
- return [(title1, uiFont)]
- }
-
var body: some View {
let depositTitle0 = String(localized: "DepositButton_Short", defaultValue: "Deposit",
comment: "Abbreviation of `Deposit (currency)´")
- // TODO: deal with \t
let depositTitle1 = String(localized: "Deposit\t\(currency)",
comment: "Button `Deposit (currency)´, must have ONE \\t and ONE %@")
+
let withdrawTitle0 = String(localized: "WithdrawButton_Short", defaultValue: "Withdraw",
comment: "Abbreviation of `Withdraw (currency)´")
let withdrawTitle1 = String(localized: "Withdraw\t\(currency)",
@@ -60,7 +43,6 @@ struct ExchangeRowView: View {
HStack(spacing: 0) { // can't use the built in Label because it adds the accessory arrow
Text(baseURL.trimURL())
.accessibilityFont(.body)
-
NavigationLink(destination: LazyView {
EmptyView() // TODO: Deposit
}, tag: 1, selection: $buttonSelected
@@ -73,34 +55,27 @@ struct ExchangeRowView: View {
) { EmptyView() }.frame(width: 0).opacity(0)
}.listRowSeparator(.hidden)
- SingleAxisGeometryReader { width in
- Group {
- let uiFont = TalerFont.uiFont(.title3)
- let (deposit1, deposit2) = titles(depositTitle1)
- let (withdraw1, withdraw2) = titles(withdrawTitle1)
- let titles = iconOnly ? [(depositTitle0, uiFont), (withdrawTitle0, uiFont)]
- : titles((deposit1, deposit2), uiFont: uiFont) +
- titles((withdraw1, withdraw2), uiFont: uiFont)
- let fitsSideBySide = Self.fitsSideBySide(titles, availableWidth: width,
- sizeCategory: sizeCategory, padding: 10)
- // TODO: amount.currencyStr
- let twoRowButtons = TwoRowButtons(sendTitles: iconOnly ? (depositTitle0, nil) : (deposit1, deposit2),
- recvTitles: iconOnly ? (withdrawTitle0, nil) : (withdraw1, withdraw2),
- fitsSideBySide: fitsSideBySide,
- lineLimit: 5,
- sendDisabled: true, // TODO: availableAmount.isZero
- sendAction: { selectAndUpdate(1) },
- recvAction: { selectAndUpdate(2) })
- if fitsSideBySide {
- HStack(spacing: HSPACING) { twoRowButtons }
- } else {
- VStack { twoRowButtons }
+ let depositTitle = iconOnly ? depositTitle0 : depositTitle1
+ let withdrawTitle = iconOnly ? withdrawTitle0 : withdrawTitle1
+ let twoRowButtons = TwoRowButtons(sendTitle: depositTitle,
+ recvTitle: withdrawTitle,
+ fitsSideBySide: false,
+ lineLimit: 5,
+ sendDisabled: true, // TODO: availableAmount.isZero
+ sendAction: { selectAndUpdate(1) },
+ recvAction: { selectAndUpdate(2) })
+ if #available(iOS 16.0, *) {
+ ViewThatFits(in: .horizontal) {
+ HStack(spacing: HSPACING) {
+ twoRowButtons.makeCopy(fitsSideBySide: true)
}
+ VStack { twoRowButtons }
}
+ } else { // view for iOS 15
+ VStack { twoRowButtons }
}
}
}
-
// MARK: -
#if DEBUG
fileprivate struct ExchangeRow_Container : View {