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.
		
		
		
		
		
			
		
			
				
	
	
		
			99 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Swift
		
	
			
		
		
	
	
			99 lines
		
	
	
		
			3.0 KiB
		
	
	
	
		
			Swift
		
	
// Copyright © 2024 Rangeproof Pty Ltd. All rights reserved.
 | 
						|
 | 
						|
import SwiftUI
 | 
						|
import SessionUIKit
 | 
						|
import SignalUtilitiesKit
 | 
						|
import SessionUtilitiesKit
 | 
						|
import AVFoundation
 | 
						|
 | 
						|
struct QRCodeScreen: View {
 | 
						|
    @EnvironmentObject var host: HostWrapper
 | 
						|
    
 | 
						|
    @State var tabIndex = 0
 | 
						|
    @State private var accountId: String = ""
 | 
						|
    @State private var errorString: String? = nil
 | 
						|
    
 | 
						|
    var body: some View {
 | 
						|
        ZStack(alignment: .topLeading) {
 | 
						|
            VStack(
 | 
						|
                spacing: 0
 | 
						|
            ){
 | 
						|
                CustomTopTabBar(
 | 
						|
                    tabIndex: $tabIndex,
 | 
						|
                    tabTitles: [
 | 
						|
                        "view".localized(),
 | 
						|
                        "settings_scan_qr_code_tab_title".localized()
 | 
						|
                    ]
 | 
						|
                ).frame(maxWidth: .infinity)
 | 
						|
                    
 | 
						|
                if tabIndex == 0 {
 | 
						|
                    MyQRCodeScreen()
 | 
						|
                }
 | 
						|
                else {
 | 
						|
                    ScanQRCodeScreen(
 | 
						|
                        $accountId,
 | 
						|
                        error: $errorString,
 | 
						|
                        continueAction: continueWithAccountId
 | 
						|
                    )
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        .backgroundColor(themeColor: .backgroundPrimary)
 | 
						|
    }
 | 
						|
    
 | 
						|
    fileprivate func startNewPrivateChatIfPossible(with hexEncodedPublicKey: String, onError: (() -> ())?) {
 | 
						|
        if !KeyPair.isValidHexEncodedPublicKey(candidate: hexEncodedPublicKey) {
 | 
						|
            errorString = "qrNotAccountId".localized()
 | 
						|
        }
 | 
						|
        else {
 | 
						|
            SessionApp.presentConversationCreatingIfNeeded(
 | 
						|
                for: hexEncodedPublicKey,
 | 
						|
                variant: .contact,
 | 
						|
                action: .compose,
 | 
						|
                dismissing: self.host.controller,
 | 
						|
                animated: false
 | 
						|
            )
 | 
						|
        }
 | 
						|
    }
 | 
						|
    
 | 
						|
    func continueWithAccountId(onSuccess: (() -> ())?, onError: (() -> ())?) {
 | 
						|
        let hexEncodedPublicKey = accountId
 | 
						|
        startNewPrivateChatIfPossible(with: hexEncodedPublicKey, onError: onError)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
struct MyQRCodeScreen: View {
 | 
						|
    var body: some View{
 | 
						|
        VStack(
 | 
						|
            spacing: Values.mediumSpacing
 | 
						|
        ) {
 | 
						|
            QRCodeView(
 | 
						|
                string: getUserHexEncodedPublicKey(),
 | 
						|
                hasBackground: false,
 | 
						|
                logo: "SessionWhite40",
 | 
						|
                themeStyle: ThemeManager.currentTheme.interfaceStyle
 | 
						|
            )
 | 
						|
            .accessibility(
 | 
						|
                Accessibility(
 | 
						|
                    identifier: "QR code",
 | 
						|
                    label: "QR code"
 | 
						|
                )
 | 
						|
            )
 | 
						|
            .aspectRatio(1, contentMode: .fit)
 | 
						|
            
 | 
						|
            Text("settings_view_my_qr_code_explanation".localized())
 | 
						|
                .font(.system(size: Values.verySmallFontSize))
 | 
						|
                .foregroundColor(themeColor: .textSecondary)
 | 
						|
                .multilineTextAlignment(.center)
 | 
						|
            
 | 
						|
            Spacer()
 | 
						|
        }
 | 
						|
        .padding(.horizontal, Values.mediumSpacing)
 | 
						|
        .padding(.all, Values.veryLargeSpacing)
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
#Preview {
 | 
						|
    QRCodeScreen()
 | 
						|
}
 |