|
| 1 | +import SwiftUI |
| 2 | + |
| 3 | +struct DeleteView<Content: View, Info: View>: View { |
| 4 | + private let deleteAction: () -> Void |
| 5 | + private let showInfoView: Bool |
| 6 | + private var loading: Bool |
| 7 | + |
| 8 | + @ViewBuilder private var content: () -> Content |
| 9 | + @ViewBuilder private var info: () -> Info |
| 10 | + |
| 11 | + @Environment(\.presentationMode) var presentationMode |
| 12 | + |
| 13 | + init( |
| 14 | + showInfoView: Bool = true, |
| 15 | + loading: Bool = false, |
| 16 | + deleteAction: @escaping () -> Void, |
| 17 | + @ViewBuilder content: @escaping () -> Content, |
| 18 | + @ViewBuilder info: @escaping () -> Info |
| 19 | + ) { |
| 20 | + self.deleteAction = deleteAction |
| 21 | + self.content = content |
| 22 | + self.info = info |
| 23 | + self.showInfoView = showInfoView |
| 24 | + self.loading = loading |
| 25 | + } |
| 26 | + |
| 27 | + var body: some View { |
| 28 | + VStack(spacing: 15) { |
| 29 | + VStack(spacing: 9) { |
| 30 | + Image("icon_delete") |
| 31 | + VStack(spacing: 4) { |
| 32 | + Text("contacts_delete_confrimation_title".localize()) |
| 33 | + .font(.body) |
| 34 | + .fontWeight(.heavy) |
| 35 | + .bold() |
| 36 | + .foregroundColor(Color(.red)) |
| 37 | + Text("contacts_delete_confrimation_message".localize()) |
| 38 | + .font(.body) |
| 39 | + .foregroundColor(.gray) |
| 40 | + } |
| 41 | + } |
| 42 | + Divider() |
| 43 | + content() |
| 44 | + Divider() |
| 45 | + if showInfoView { |
| 46 | + info() |
| 47 | + Divider() |
| 48 | + } |
| 49 | + HStack { |
| 50 | + Button(action: { |
| 51 | + self.presentationMode.wrappedValue.dismiss() |
| 52 | + }, label: { |
| 53 | + Text("cancel".localize()) |
| 54 | + .frame(maxWidth: .infinity) |
| 55 | + .secondaryButtonModifier() |
| 56 | + }) |
| 57 | + |
| 58 | + AtalaButton(loading: self.loading) { |
| 59 | + self.deleteAction() |
| 60 | + } label: { |
| 61 | + Text("delete".localize()) |
| 62 | + .frame(maxWidth: .infinity) |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | + .padding(24) |
| 67 | + .background(Color.white) |
| 68 | + .clipShape(RoundedRectangle(cornerRadius: 10)) |
| 69 | + .padding() |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +struct DeleteView_Previews: PreviewProvider { |
| 74 | + static var previews: some View { |
| 75 | + DeleteView(showInfoView: true) {} content: { |
| 76 | + HStack(spacing: 16) { |
| 77 | + Image("ico_placeholder_credential") |
| 78 | + .resizable() |
| 79 | + .frame(width: 40, height: 40) |
| 80 | + .clipShape(RoundedRectangle(cornerRadius: 10)) |
| 81 | + Text("Atala KYC") |
| 82 | + .font(.title3) |
| 83 | + .fontWeight(.heavy) |
| 84 | + .bold() |
| 85 | + .foregroundColor(.black) |
| 86 | + Spacer() |
| 87 | + } |
| 88 | + } info: { |
| 89 | + VStack(alignment: .leading, spacing: 9) { |
| 90 | + Text("contacts_delete_description".localize()) |
| 91 | + .font(.body) |
| 92 | + .foregroundColor(.gray) |
| 93 | + VStack(alignment: .leading, spacing: 6) { |
| 94 | + Text(". ID Credential") |
| 95 | + .bold() |
| 96 | + .font(.body) |
| 97 | + .foregroundColor(.black) |
| 98 | + Text(". University Credential") |
| 99 | + .bold() |
| 100 | + .font(.body) |
| 101 | + .foregroundColor(.black) |
| 102 | + } |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments