-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChannelSelectionView.swift
More file actions
96 lines (84 loc) · 2.96 KB
/
Copy pathChannelSelectionView.swift
File metadata and controls
96 lines (84 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// ChannelSelectionView.swift
// PaystackUI
//
// Created by Peter-John Welcome on 2023/12/01.
//
import SwiftUI
import PaystackCore
@available(iOS 14.0, *)
struct ChannelSelectionView: View {
@EnvironmentObject
var visibilityContainer: ViewVisibilityContainer
@StateObject
var viewModel: ChannelSelectionViewModel
let supportedChannels: [SupportedChannel]
let columns = [GridItem(.flexible()), GridItem(.flexible())]
init(state: Binding<ChargeState>,
supportedChannels: [SupportedChannel],
information: VerifyAccessCode) {
self._viewModel = StateObject(wrappedValue: ChannelSelectionViewModel(state: state, information: information))
self.supportedChannels = supportedChannels
}
var body: some View {
ScrollView {
VStack(spacing: .triplePadding) {
Text("Choose a payment method to continue")
.font(.body16M)
.foregroundColor(.stackBlue)
.multilineTextAlignment(.center)
GeometryReader { geo in
LazyVGrid(columns: columns) {
ForEach(supportedChannels) { channel in
ChannelView(channelTitle: channel.displayTitle, image: channel.image)
.padding(.singlePadding)
.onTapGesture {
viewModel.choose(channel)
}
.frame(width: (geo.size.width / CGFloat(supportedChannels.count)).rounded())
}
}
}
}
}
}
}
class ChannelSelectionViewModel: ObservableObject {
@Binding
var state: ChargeState
private let information: VerifyAccessCode
init(state: Binding<ChargeState>, information: VerifyAccessCode) {
self._state = state
self.information = information
}
func choose(_ channel: SupportedChannel) {
switch channel {
case .card:
state = .payment(type: .card(transactionInformation: self.information))
case .mobileMoney(let provider):
state = .payment(type: .mobileMoney(transactionInformation: self.information,
provider: provider))
}
}
}
struct ChannelView: View {
let channelTitle: String
let image: Image
var body: some View {
HStack(spacing: .singlePadding) {
VStack(alignment: .leading, spacing: .singlePadding) {
image.frame(width: 20, height: 20)
Text(channelTitle)
.font(.body14M)
.foregroundColor(.navy02)
}
Spacer()
}
.padding(.doublePadding)
.cornerRadius(.cornerRadius)
.overlay(
RoundedRectangle(cornerRadius: .cornerRadius)
.stroke(Color.navy05, lineWidth: 1)
)
}
}