taler-ios

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

OIMSubjectView.swift (4705B)


      1 /*
      2  * This file is part of GNU Taler, ©2022-25 Taler Systems S.A.
      3  * See LICENSE.md
      4  */
      5 /**
      6  * @author Marc Stibane
      7  */
      8 import SwiftUI
      9 import taler_swift
     10 
     11 struct GoalsHStack: View {
     12     let goals: [String]
     13     @Binding var selectedGoal: String?
     14 
     15     @EnvironmentObject private var wrapper: NamespaceWrapper
     16 
     17     var body: some View {
     18         HStack {
     19             ForEach(goals, id: \.self) { goal in
     20                 if let selectedGoal {
     21                     if goal == selectedGoal {
     22                         Image(goal)
     23                             .resizable()
     24                             .background(Color.white)
     25                             .scaledToFit()
     26                             .matchedGeometryEffect(id: goal, in: wrapper.namespace)
     27                             .onTapGesture {
     28                                 withAnimation(.basic1) {
     29                                     self.selectedGoal = nil
     30                                 }
     31                             }
     32                     }
     33                 } else {
     34                     Image(goal)
     35                         .resizable()
     36                         .background(Color.white)
     37                         .scaledToFit()
     38                         .matchedGeometryEffect(id: goal, in: wrapper.namespace)
     39                         .onTapGesture {
     40                             withAnimation(.basic1) {
     41                                 selectedGoal = goal
     42                             }
     43                         }
     44                 }
     45             }
     46         }
     47     }
     48 }
     49 // MARK: -
     50 @available(iOS 16.4, *)
     51 struct OIMSubjectView: View {
     52     let stack: CallStack
     53     let cash: OIMcash
     54     let available: Amount
     55     @Binding var amountToTransfer: Amount
     56     @Binding var selectedGoal: String?
     57 //    let decimal: Int            // 0 for ¥,HUF;   2 for $,€,£;   3 for ﷼,₯ (arabic)
     58     @Binding var fwdButtonTapped: Bool
     59 
     60     @Environment(\.dismiss) var dismiss     // pop back once
     61     @EnvironmentObject private var wrapper: NamespaceWrapper
     62 
     63     @State private var amount2: Amount? = nil
     64     @State private var amountVal: UInt64 = 0
     65     @State private var sending = false              // user tapped on Send
     66     @State private var appeared = false
     67 
     68     func sendAction() {
     69         withAnimation(.basic1) {
     70             sending = true                              //
     71         }
     72         var transaction = Transaction()
     73         transaction.disablesAnimations = true
     74         withTransaction(transaction) {
     75             fwdButtonTapped = true          // ==> Send the money
     76         }
     77     }
     78 
     79     func dismissNoTransaction() {
     80         var transaction = Transaction()
     81         transaction.disablesAnimations = true
     82         withTransaction(transaction) {
     83             dismiss()
     84         }
     85     }
     86 
     87     var body: some View {
     88 //        let _ = Self._printChanges()
     89         let currency = cash.currency
     90         let goals1 = ["blank", "Phone", "Electricity", "gasPump", "Hammer", "Water", "Kitchenware", "Cloth", "Medication"].shuffled()
     91         let goals2 = ["shopping", "Rent", "Schooling", "RepayLoan", "Medical", "Farming", "Bottle", "Paint", "GasCooker"].shuffled()
     92 
     93         let gotAction = (selectedGoal != nil) ? sendAction : nil
     94         OIMnavBack(stack: stack.push(),
     95                    chest: currency.chest,
     96                     type: .sendP2P,
     97                  isFinal: false,
     98                isSending: sending,
     99                   action: gotAction,
    100              actDisabled: amount2?.isZero ?? true
    101         ) {
    102             VStack {
    103                 OIMtitleView(cash: cash,
    104                            amount: available,
    105                           history: false,
    106                      secondAmount: amountToTransfer)
    107                 Spacer()
    108                 GoalsHStack(goals: goals1, selectedGoal: $selectedGoal)
    109                     .opacity(appeared ? 1 : INVISIBLE)
    110                     .scaleEffect(appeared ? 1 : 0.3)
    111                 GoalsHStack(goals: goals2, selectedGoal: $selectedGoal)
    112                     .opacity(appeared ? 1 : INVISIBLE)
    113                     .scaleEffect(appeared ? 1 : 0.3)
    114                 Spacer()
    115                 OIMlineView(stack: stack.push(),
    116                              cash: cash,
    117                         amountVal: $amountVal,
    118                           canEdit: false)
    119                     .scaleEffect(selectedGoal == nil ? 0.6 : 1)
    120                     .onTapGesture {
    121                         dismissNoTransaction()
    122                     }
    123             }
    124 //              .border(.red)
    125         }.task {
    126             amount2 = amountToTransfer
    127             amountVal = amountToTransfer.centValue                              // TODO: centValue factor
    128             withAnimation(.basic1) {
    129                 appeared = true
    130             }
    131         }
    132     }
    133 }