damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

QRScanNSECView.swift (2402B)


      1 //
      2 //  QRScanNSECView.swift
      3 //  damus
      4 //
      5 //  Created by Jericho Hasselbush on 9/29/23.
      6 //
      7 
      8 import CodeScanner
      9 import SwiftUI
     10 import VisionKit
     11 
     12 struct QRScanNSECView: View {
     13     @Binding var showQR: Bool
     14     @Binding var privKeyFound: Bool
     15     var codeScannerCompletion: (Result<ScanResult, ScanError>) -> Void
     16     var body: some View {
     17         ZStack {
     18             ZStack {
     19                 DamusGradient()
     20             }
     21             VStack {
     22                 Text("Scan Your Private Key QR",
     23                      comment: "Text to prompt scanning a QR code of a user's privkey to login to their profile.")
     24                     .padding(.top, 50)
     25                     .font(.system(size: 24, weight: .heavy))
     26 
     27                 Spacer()
     28                 CodeScannerView(codeTypes: [.qr],
     29                                 scanMode: .continuous,
     30                                 scanInterval: 2.0,
     31                                 showViewfinder: false,
     32                                 simulatedData: "",
     33                                 shouldVibrateOnSuccess: false,
     34                                 isTorchOn: false,
     35                                 isGalleryPresented: .constant(false),
     36                                 videoCaptureDevice: .default(for: .video),
     37                                 completion: codeScannerCompletion)
     38                     .scaledToFit()
     39                     .frame(width: 300, height: 300)
     40                     .cornerRadius(10)
     41                     .overlay(RoundedRectangle(cornerRadius: 10).stroke(DamusColors.white, lineWidth: 5.0))
     42                     .shadow(radius: 10)
     43 
     44                 Button(action: { showQR = false  }) {
     45                     VStack {
     46                         Image(systemName: privKeyFound ? "sparkle.magnifyingglass" : "magnifyingglass")
     47                             .font(privKeyFound ? .title : .title3)
     48                     }}
     49                 .padding(.top)
     50                 .buttonStyle(GradientButtonStyle())
     51 
     52                 Spacer()
     53 
     54                 Spacer()
     55             }
     56         }
     57     }
     58 }
     59 
     60 struct QRScanNSECView_Previews: PreviewProvider {
     61     @State static var showQR  = true
     62     @State static var privKeyFound = false
     63     @State static var shouldSaveKey = true
     64 
     65     static var previews: some View {
     66         QRScanNSECView(showQR: $showQR,
     67                        privKeyFound: $privKeyFound,
     68                        codeScannerCompletion: { _ in })
     69     }
     70 }