mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			78 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Swift
		
	
			
		
		
	
	
			78 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			Swift
		
	
| // Copyright © 2024 Rangeproof Pty Ltd. All rights reserved.
 | |
| 
 | |
| import SwiftUI
 | |
| import SessionUIKit
 | |
| import AVFoundation
 | |
| import SessionUtilitiesKit
 | |
| 
 | |
| struct ScanQRCodeScreen: View {
 | |
|     @Binding var result: String
 | |
|     @Binding var error: String?
 | |
|     @State var hasCameraAccess: Bool = (AVCaptureDevice.authorizationStatus(for: .video) == .authorized)
 | |
|     
 | |
|     var continueAction: (((() -> ())?, (() -> ())?) -> Void)?
 | |
|     
 | |
|     init(
 | |
|         _ result: Binding<String>,
 | |
|         error: Binding<String?>,
 | |
|         continueAction: (((() -> ())?, (() -> ())?) -> Void)?
 | |
|     ) {
 | |
|         self._result = result
 | |
|         self._error = error
 | |
|         self.continueAction = continueAction
 | |
|     }
 | |
|     
 | |
|     var body: some View{
 | |
|         ZStack{
 | |
|             if hasCameraAccess {
 | |
|                 VStack {
 | |
|                     QRCodeScanningVC_SwiftUI { result, onSuccess, onError in
 | |
|                         self.result = result
 | |
|                         continueAction?(onSuccess, onError)
 | |
|                     }
 | |
|                 }
 | |
|                 .frame(
 | |
|                     maxWidth: .infinity,
 | |
|                     maxHeight: .infinity
 | |
|                 )
 | |
|             } else {
 | |
|                 VStack(
 | |
|                     alignment: .center,
 | |
|                     spacing: Values.mediumSpacing
 | |
|                 ) {
 | |
|                     Spacer()
 | |
|                     
 | |
|                     Text(
 | |
|                         "cameraGrantAccessQr"
 | |
|                             .put(key: "app_name", value: Constants.app_name)
 | |
|                             .localized()
 | |
|                     )
 | |
|                     .font(.system(size: Values.smallFontSize))
 | |
|                     .foregroundColor(themeColor: .textPrimary)
 | |
|                     .multilineTextAlignment(.center)
 | |
|                     
 | |
|                     Button {
 | |
|                         requestCameraAccess()
 | |
|                     } label: {
 | |
|                         Text("theContinue".localized())
 | |
|                             .bold()
 | |
|                             .font(.system(size: Values.mediumFontSize))
 | |
|                             .foregroundColor(themeColor: .primary)
 | |
|                     }
 | |
|                     
 | |
|                     Spacer()
 | |
|                 }
 | |
|                 .padding(.horizontal, Values.massiveSpacing)
 | |
|                 .padding(.bottom, Values.massiveSpacing)
 | |
|             }
 | |
|         }
 | |
|         .toastView(message: $error)
 | |
|     }
 | |
|     
 | |
|     private func requestCameraAccess() {
 | |
|         Permissions.requestCameraPermissionIfNeeded {
 | |
|             hasCameraAccess.toggle()
 | |
|         }
 | |
|     }
 | |
| }
 |