taler-ios

iOS apps for GNU Taler (wallet)
Log | Files | Refs | README | LICENSE

commit 967dd208f39d7b74c409a6589e05e44f93152514
parent f405f30e71f48be06f57963bd28d7826f1d72da6
Author: Marc Stibane <marc@taler.net>
Date:   Thu,  8 Aug 2024 06:12:14 +0200

layout

Diffstat:
MTalerWallet1/Views/Balances/TwoRowButtons.swift | 96++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 66 insertions(+), 30 deletions(-)

diff --git a/TalerWallet1/Views/Balances/TwoRowButtons.swift b/TalerWallet1/Views/Balances/TwoRowButtons.swift @@ -8,6 +8,59 @@ import SwiftUI import taler_swift +struct TypeButton: View { + let title: String + let a11y: String + let lineLimit: Int + var type: TransactionType + let disabled: Bool + let action: () -> Void + + var body: some View { + let hLayout = HStack { + ButtonIconBadge(type: type, foreColor: .accentColor, done: false) + Spacer() + Text(title) + Spacer() + } + + let vLayout = VStack { + let fragments = title.components(separatedBy: "\n") + if fragments.count > 1 { + Text(fragments[0]) + HStack { + ButtonIconBadge(type: type, foreColor: .accentColor, done: false) + Spacer() + Text(fragments[1]) + Spacer() + } + if fragments.count > 2 { + Text(fragments[2]) + } + } else { + hLayout + } + } + + Button(action: action) { + if #available(iOS 16.0, *) { + ViewThatFits(in: .horizontal) { + hLayout + vLayout + } + } else { vLayout } // view for iOS 15 + } + .accessibilityLabel(Text(a11y)) + .lineLimit(lineLimit) + .disabled(disabled) + .buttonStyle(TalerButtonStyle(type: .bordered, + dimmed: false, + disabled: disabled, + aligned: .center)) + } +} + + struct TwoRowButtons: View { let stack: CallStack let sendTitle: String @@ -16,7 +69,7 @@ struct TwoRowButtons: View { let recvTitle: String var recvType: TransactionType let recvA11y: String - let fitsSideBySide: Bool + let fitsSideBySide: Bool // whether both buttons fit in one line let lineLimit: Int let sendDisabled: Bool let sendAction: () -> Void @@ -41,36 +94,19 @@ struct TwoRowButtons: View { var body: some View { Group { let sendButtonTitle = sendTitle.tabbed(oneLine: !fitsSideBySide) - Button(action: sendAction) { - HStack { - ButtonIconBadge(type: sendType, foreColor: .accentColor, done: false) - Spacer() - Text(sendButtonTitle) - Spacer() - } - } - .accessibilityLabel(Text(sendA11y)) - .lineLimit(lineLimit) - .disabled(sendDisabled) - .buttonStyle(TalerButtonStyle(type: .bordered, - dimmed: false, - disabled: sendDisabled, - aligned: .center)) + TypeButton(title: sendButtonTitle, + a11y: sendA11y, + lineLimit: lineLimit, + type: sendType, + disabled: sendDisabled, + action: sendAction) let recvButtonTitle = recvTitle.tabbed(oneLine: !fitsSideBySide) - Button(action: recvAction) { - HStack { - ButtonIconBadge(type: recvType, foreColor: .accentColor, done: false) - Spacer() - Text(recvButtonTitle) - Spacer() - } - } - .accessibilityLabel(Text(recvA11y)) - .lineLimit(lineLimit) - .disabled(false) - .buttonStyle(TalerButtonStyle(type: .bordered, - dimmed: false, - aligned: .center)) + TypeButton(title: recvButtonTitle, + a11y: recvA11y, + lineLimit: lineLimit, + type: recvType, + disabled: false, + action: recvAction) } } }