taler-ios

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

OIMactionButtons.swift (2198B)


      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 
     10 fileprivate let chestOpen = "ChestOpen"
     11 fileprivate let chestClosed = "ChestClosed"
     12 
     13 enum OIMactions {
     14     case withdrawal
     15     case deposit
     16     case sendP2P
     17     case requestP2P
     18 //    case goal
     19 //    case scanQR
     20 }
     21 
     22 struct OIMactionButton: View {
     23     let type: OIMactions
     24     let isFinal: Bool
     25     let action: (() -> Void)?
     26 
     27     var body: some View {
     28         let imageName = switch type {
     29             case .sendP2P :     "SendMoney"
     30             case .withdrawal:   "Withdraw"
     31             case .deposit:      "Deposit"
     32             case .requestP2P:   "Request"
     33         }
     34         let disabled = action == nil
     35         Button(action: action ?? { } ) {
     36             Image(imageName)
     37                 .resizable()
     38                 .scaledToFit()
     39                 .foregroundStyle(Color.accentColor)
     40         }
     41             .tagStyle(isFinal ? .bordered : .borderless)
     42             .opacity(disabled ? INVISIBLE : 1)
     43             .disabled(disabled)
     44     }
     45 }
     46 
     47 struct OIMbalanceButton: View {
     48     let isOpen: Bool
     49     let chest: String
     50     let isFinal: Bool
     51     let action: () -> Void
     52 
     53     var body: some View {
     54         let chestName = isOpen ? chestOpen : chestClosed
     55         let imageName = chestName + chest
     56         Button(action: action) {
     57             Image(imageName)
     58                 .resizable()
     59                 .scaledToFit()
     60         }
     61         .tagStyle(isFinal ? .prominent : .borderless)
     62     }
     63 }
     64 
     65 enum TagButtonStyle {
     66     case prominent
     67     case bordered
     68     case `default`
     69     case borderless
     70     // .. extend with any custom here
     71 }
     72 
     73 extension Button {
     74 
     75     @ViewBuilder
     76     func tagStyle(_ style: TagButtonStyle) -> some View {
     77         switch style {
     78             case .prominent:
     79                 self.buttonStyle(BorderedProminentButtonStyle())
     80             case .bordered:
     81                 self.buttonStyle(BorderedButtonStyle())
     82             case .borderless:
     83                 self.buttonStyle(BorderlessButtonStyle())
     84             case .default:
     85                 self.buttonStyle(DefaultButtonStyle())
     86                 // .. extend with any custom here
     87         }
     88     }
     89 }
     90