commit 733f1ff441d1220e153ca183cecce46d1ca4133a
parent 68b98dd40c0f7a4f3f97f5531127cf8523d36639
Author: Marc Stibane <marc@taler.net>
Date: Tue, 19 Aug 2025 08:35:23 +0200
Refactor to files
Diffstat:
3 files changed, 132 insertions(+), 115 deletions(-)
diff --git a/TalerWallet1/Views/HelperViews/AccountPicker.swift b/TalerWallet1/Views/HelperViews/AccountPicker.swift
@@ -0,0 +1,49 @@
+/*
+ * This file is part of GNU Taler, ©2022-25 Taler Systems S.A.
+ * See LICENSE.md
+ */
+/**
+ * @author Marc Stibane
+ */
+import SwiftUI
+
+struct AccountPicker: View {
+ let title: String
+ @Binding var value: Int
+ let accountDetails: [ExchangeAccountDetails]
+ let action: (Int) -> Void
+
+ @State private var selected = 0
+
+ var body: some View {
+ Picker(title, selection: $selected) {
+ ForEach(0..<accountDetails.count, id: \.self) { index in
+ let detail = accountDetails[index]
+ if let amount = detail.transferAmount {
+ let amountStr = amount.formatted(specs: detail.currencySpecification,
+ isNegative: false,
+ scope: detail.scope,
+ useISO: false)
+// let _ = print(amountStr)
+ if let bankName = detail.bankLabel {
+ Text(bankName + ": " + amountStr.0)
+ .accessibilityLabel(bankName + ": " + amountStr.1)
+ .tag(index)
+ } else {
+ Text(amountStr.0)
+ .accessibilityLabel(amountStr.1)
+ .tag(index)
+ }
+ }
+ }
+ }
+ .talerFont(.title3)
+// .pickerStyle(.menu)
+ .onAppear() {
+ withAnimation { selected = value }
+ }
+ .onChange(of: selected) { newValue in
+ action(newValue)
+ }
+ }
+}
diff --git a/TalerWallet1/Views/HelperViews/SegmentControl.swift b/TalerWallet1/Views/HelperViews/SegmentControl.swift
@@ -0,0 +1,83 @@
+/*
+ * This file is part of GNU Taler, ©2022-25 Taler Systems S.A.
+ * See LICENSE.md
+ */
+/**
+ * @author Marc Stibane
+ */
+import SwiftUI
+
+struct SegmentControl: View {
+ @Binding var value: Int
+ let accountDetails: [ExchangeAccountDetails]
+ let action: (Int) -> Void
+
+ @Environment(\.colorScheme) private var colorScheme
+ @Environment(\.colorSchemeContrast) private var colorSchemeContrast
+
+ @State private var selectedAccount = 0
+ @ScaledMetric var frameHeight = 80 // relative to fontSize
+
+ public var body: some View {
+ let count = accountDetails.count
+ ZStack(alignment: .center) {
+ GeometryReader { geo in
+ RoundedRectangle(cornerRadius: 6.0)
+ .foregroundColor(WalletColors().pickerSelected(colorScheme, colorSchemeContrast))
+ .cornerRadius(6.0)
+ .padding(4)
+ .frame(width: geo.size.width / CGFloat(count))
+ .offset(x: geo.size.width / CGFloat(count) * CGFloat(selectedAccount), y: 0)
+ }
+ .frame(height: frameHeight)
+
+ HStack(spacing: 0) {
+ ForEach((0..<count), id: \.self) { index in
+ let detail = accountDetails[index]
+ let specs = detail.currencySpecification
+ let scope = detail.scope
+ let amount = detail.transferAmount
+ let formatted = amount?.formatted(specs: specs,
+ isNegative: false,
+ scope: scope,
+ useISO: false)
+ ?? (EMPTYSTRING, EMPTYSTRING)
+ let bankName = detail.bankLabel
+ let a11yLabel = bankName != nil ? (bankName! + SPACE + formatted.1)
+ : formatted.1
+// let _ = print(amountStr)
+ VStack(spacing: 6) {
+ Text(formatted.0)
+ .talerFont(.title3)
+ if let bankName {
+ Text(bankName)
+ .talerFont(.subheadline)
+ }
+ }
+ .accessibilityElement(children: .combine)
+ .accessibilityLabel(a11yLabel)
+ .accessibilityAddTraits(.isButton)
+ .accessibilityAddTraits(index == selectedAccount ? .isSelected : [])
+ .frame(maxWidth: .infinity)
+ .onTapGesture {
+ withAnimation(.easeInOut(duration: 0.150)) {
+ selectedAccount = index
+ }
+ }
+ }
+ }
+ }
+ .onAppear() {
+ if selectedAccount != value {
+ withAnimation { selectedAccount = value }
+ }
+ }
+ .onChange(of: selectedAccount) { selected in
+ action(selected)
+ }
+ .background(
+ RoundedRectangle(cornerRadius: 6.0)
+ .fill(WalletColors().sideBackground)
+ )
+ }
+}
diff --git a/TalerWallet1/Views/Transactions/ManualDetailsV.swift b/TalerWallet1/Views/Transactions/ManualDetailsV.swift
@@ -9,121 +9,6 @@ import SwiftUI
import OrderedCollections
import taler_swift
-struct SegmentControl: View {
- @Binding var value: Int
- let accountDetails: [ExchangeAccountDetails]
- let action: (Int) -> Void
-
- @Environment(\.colorScheme) private var colorScheme
- @Environment(\.colorSchemeContrast) private var colorSchemeContrast
-
- @State private var selectedAccount = 0
- @ScaledMetric var frameHeight = 80 // relative to fontSize
-
- public var body: some View {
- let count = accountDetails.count
- ZStack(alignment: .center) {
- GeometryReader { geo in
- RoundedRectangle(cornerRadius: 6.0)
- .foregroundColor(WalletColors().pickerSelected(colorScheme, colorSchemeContrast))
- .cornerRadius(6.0)
- .padding(4)
- .frame(width: geo.size.width / CGFloat(count))
- .offset(x: geo.size.width / CGFloat(count) * CGFloat(selectedAccount), y: 0)
- }
- .frame(height: frameHeight)
-
- HStack(spacing: 0) {
- ForEach((0..<count), id: \.self) { index in
- let detail = accountDetails[index]
- let specs = detail.currencySpecification
- let scope = detail.scope
- let amount = detail.transferAmount
- let formatted = amount?.formatted(specs: specs,
- isNegative: false,
- scope: scope,
- useISO: false)
- ?? (EMPTYSTRING, EMPTYSTRING)
- let bankName = detail.bankLabel
- let a11yLabel = bankName != nil ? (bankName! + SPACE + formatted.1)
- : formatted.1
-// let _ = print(amountStr)
- VStack(spacing: 6) {
- Text(formatted.0)
- .talerFont(.title3)
- if let bankName {
- Text(bankName)
- .talerFont(.subheadline)
- }
- }
- .accessibilityElement(children: .combine)
- .accessibilityLabel(a11yLabel)
- .accessibilityAddTraits(.isButton)
- .accessibilityAddTraits(index == selectedAccount ? .isSelected : [])
- .frame(maxWidth: .infinity)
- .onTapGesture {
- withAnimation(.easeInOut(duration: 0.150)) {
- selectedAccount = index
- }
- }
- }
- }
- }
- .onAppear() {
- if selectedAccount != value {
- withAnimation { selectedAccount = value }
- }
- }
- .onChange(of: selectedAccount) { selected in
- action(selected)
- }
- .background(
- RoundedRectangle(cornerRadius: 6.0)
- .fill(WalletColors().sideBackground)
- )
- }
-}
-struct AccountPicker: View {
- let title: String
- @Binding var value: Int
- let accountDetails: [ExchangeAccountDetails]
- let action: (Int) -> Void
-
- @State private var selected = 0
-
- var body: some View {
- Picker(title, selection: $selected) {
- ForEach(0..<accountDetails.count, id: \.self) { index in
- let detail = accountDetails[index]
- if let amount = detail.transferAmount {
- let amountStr = amount.formatted(specs: detail.currencySpecification,
- isNegative: false,
- scope: detail.scope,
- useISO: false)
-// let _ = print(amountStr)
- if let bankName = detail.bankLabel {
- Text(bankName + ": " + amountStr.0)
- .accessibilityLabel(bankName + ": " + amountStr.1)
- .tag(index)
- } else {
- Text(amountStr.0)
- .accessibilityLabel(amountStr.1)
- .tag(index)
- }
- }
- }
- }
- .talerFont(.title3)
-// .pickerStyle(.menu)
- .onAppear() {
- withAnimation { selected = value }
- }
- .onChange(of: selected) { newValue in
- action(newValue)
- }
- }
-}
-// MARK: -
struct ManualDetailsV: View {
let stack: CallStack
let common: TransactionCommon