-
Notifications
You must be signed in to change notification settings - Fork 3k
/
RemoveCardButton.swift
81 lines (74 loc) · 2.88 KB
/
RemoveCardButton.swift
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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/
import Common
import Foundation
import SwiftUI
import Shared
struct RemoveCardButton: View {
// Theming
@Environment(\.themeType)
var themeVal
@State private var showAlert = false
struct AlertDetails {
let alertTitle: Text
let alertBody: Text?
let primaryButtonStyleAndText: Alert.Button
let secondaryButtonStyleAndText: Alert.Button
let primaryButtonAction: () -> Void
let secondaryButtonAction: (() -> Void)?
}
@State var removeButtonColor: Color = .clear
@State var borderColor: Color = .clear
@State var backgroundColor: Color = .clear
let alertDetails: AlertDetails
var body: some View {
ZStack {
VStack {
Rectangle()
.fill(borderColor)
.frame(maxWidth: .infinity)
.frame(height: 0.7)
VStack {
Button(String.CreditCard.EditCard.RemoveCardButtonTitle) {
showAlert.toggle()
}
.alert(isPresented: $showAlert) {
Alert(
title: alertDetails.alertTitle,
message: alertDetails.alertBody,
primaryButton: alertDetails.primaryButtonStyleAndText,
secondaryButton: alertDetails.secondaryButtonStyleAndText
)
}
.font(.body)
.foregroundColor(removeButtonColor)
.padding(.leading, 16)
.padding(.trailing, 16)
}
Rectangle()
.fill(borderColor)
.frame(maxWidth: .infinity)
.frame(height: 0.7)
}.background(backgroundColor.edgesIgnoringSafeArea(.bottom))
}.onAppear {
applyTheme(theme: themeVal.theme)
}
.onChange(of: themeVal) { newThemeValue in
applyTheme(theme: newThemeValue.theme)
}
.onReceive(
NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)) { _ in
// part of FXIOS-6797, if the app goes to the background and
// then the user fails the biometric authentication this alert
// prevents the screen dismissal, hiding it is the simplest way to solve the issue.
showAlert = false
}
}
func applyTheme(theme: Theme) {
let color = theme.colors
backgroundColor = Color(color.layer2)
removeButtonColor = Color(color.textWarning)
borderColor = Color(color.borderPrimary)
}
}