Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Apr 10, 2024
1 parent 3052a64 commit 8486020
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 49 deletions.
2 changes: 1 addition & 1 deletion ElementX/Sources/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
appSettings: appSettings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
windowManager: windowManager)
orientationManager: windowManager)
authenticationFlowCoordinator?.delegate = self

authenticationFlowCoordinator?.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
private let appSettings: AppSettings
private let analytics: AnalyticsService
private let userIndicatorController: UserIndicatorControllerProtocol
private let windowManager: WindowManagerProtocol
private let orientationManager: OrientationManagerProtocol

private var cancellables = Set<AnyCancellable>()

Expand All @@ -47,14 +47,14 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
appSettings: AppSettings,
analytics: AnalyticsService,
userIndicatorController: UserIndicatorControllerProtocol,
windowManager: WindowManagerProtocol) {
orientationManager: WindowManagerProtocol) {
self.authenticationService = authenticationService
self.bugReportService = bugReportService
self.navigationRootCoordinator = navigationRootCoordinator
self.appSettings = appSettings
self.analytics = analytics
self.userIndicatorController = userIndicatorController
self.windowManager = windowManager
self.orientationManager = orientationManager

navigationStackCoordinator = NavigationStackCoordinator()
}
Expand Down Expand Up @@ -107,7 +107,7 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {

private func startQRCodeLogin() {
let coordinator = QRCodeLoginScreenCoordinator(parameters: .init(qrCodeLoginService: QRCodeLoginService(),
orientationManager: windowManager))
orientationManager: orientationManager))
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ class AuthenticationStartScreenViewModel: AuthenticationStartScreenViewModelType
init(appSettings: AppSettings) {
self.appSettings = appSettings
super.init(initialViewState: AuthenticationStartScreenViewState())
appSettings.$qrCodeLoginEnabled
.weakAssign(to: \.state.isQRCodeLoginEnabled, on: self)
.store(in: &cancellables)
if !ProcessInfo.processInfo.isiOSAppOnMac {
appSettings.$qrCodeLoginEnabled
.weakAssign(to: \.state.isQRCodeLoginEnabled, on: self)
.store(in: &cancellables)
}
}

override func process(viewAction: AuthenticationStartScreenViewAction) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,24 @@ enum QRCodeLoginScreenViewAction {
case startScan
}

enum QRCodeLoginState {
enum QRCodeLoginState: Equatable {
/// Initial state where the user is informed how to perform the scan
case initial
/// The camera is scanning
case scan(QRCodeLoginScanningState)
/// Any full screen error state
case error(QRCodeLoginErrorState)

enum QRCodeLoginErrorState {
enum QRCodeLoginErrorState: Equatable {
case noCameraPermission
}

enum QRCodeLoginScanningState {
enum QRCodeLoginScanningState: Equatable {
/// the qr code is scanning
case scanning
/// the qr code has been detected and is being processed
case connecting
/// the qr code has been processed and is invalid
case invalid
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,7 @@ import SwiftUI

struct QRCodeLoginScreen: View {
@ObservedObject var context: QRCodeLoginScreenViewModel.Context

@State private var qrFrame = CGRect.zero
private let dashRatio: CGFloat = 80.0 / 312.0
private let emptyRatio: CGFloat = 232.0 / 312.0
private let dashPhaseRatio: CGFloat = 40.0 / 312.0

private var dashLenght: CGFloat {
qrFrame.height * dashRatio
}

private var emptyLenght: CGFloat {
qrFrame.height * emptyRatio
}

private var dashPhase: CGFloat {
qrFrame.height * dashPhaseRatio
}

var body: some View {
NavigationStack {
Expand All @@ -56,7 +40,7 @@ struct QRCodeLoginScreen: View {
case .scan:
qrScanContent
case .error:
// TODO: Handle states
// TODO: Handle error states
EmptyView()
}
}
Expand Down Expand Up @@ -112,9 +96,11 @@ struct QRCodeLoginScreen: View {
VStack(spacing: 4) {
ProgressView()
Text(L10n.screenQrCodeLoginConnectingSubtitle)
.foregroundColor(.compound.textSecondary)
.font(.compound.bodySM)
}
case .scanning:
// Just here to keep the spacing consistent between states
// To keep the spacing consistent between states
Button("") { }
.buttonStyle(.compound(.primary))
.hidden()
Expand All @@ -126,14 +112,10 @@ struct QRCodeLoginScreen: View {
.buttonStyle(.compound(.primary))

VStack(spacing: 0) {
HStack(spacing: 10) {
CompoundIcon(\.error, size: .medium, relativeTo: .compound.bodyMDSemibold)
.accessibilityLabel(L10n.commonSendingFailed)

Text(L10n.screenQrCodeLoginInvalidScanStateSubtitle)
}
.font(.compound.bodyMDSemibold)
.foregroundColor(.compound.textCriticalPrimary)
Label(L10n.screenQrCodeLoginInvalidScanStateSubtitle, icon: \.error, iconSize: .medium, relativeTo: .compound.bodyMDSemibold)
.labelStyle(.custom(spacing: 10))
.font(.compound.bodyMDSemibold)
.foregroundColor(.compound.textCriticalPrimary)

Text(L10n.screenQrCodeLoginInvalidScanStateDescription)
.foregroundColor(.compound.textSecondary)
Expand All @@ -151,8 +133,7 @@ struct QRCodeLoginScreen: View {
.readFrame($qrFrame)
.background(.compound.bgCanvasDefault)
.overlay(
Rectangle()
.stroke(.compound.textPrimary, style: StrokeStyle(lineWidth: 4.0, lineCap: .square, dash: [dashLenght, emptyLenght], dashPhase: dashPhase))
QRScannerViewOverlay(length: qrFrame.height)
)
}

Expand All @@ -166,6 +147,31 @@ struct QRCodeLoginScreen: View {
}
}

private struct QRScannerViewOverlay: View {
let length: CGFloat

private let dashRatio: CGFloat = 80.0 / 312.0
private let emptyRatio: CGFloat = 232.0 / 312.0
private let dashPhaseRatio: CGFloat = 40.0 / 312.0

private var dashLength: CGFloat {
length * dashRatio
}

private var emptyLength: CGFloat {
length * emptyRatio
}

private var dashPhase: CGFloat {
length * dashPhaseRatio
}

var body: some View {
Rectangle()
.stroke(.compound.textPrimary, style: StrokeStyle(lineWidth: 4.0, lineCap: .square, dash: [dashLength, emptyLength], dashPhase: dashPhase))
}
}

// MARK: - Previews

struct QRCodeLoginScreen_Previews: PreviewProvider, TestablePreview {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ final class QRScannerController: UIViewController {
view.layer.addSublayer(previewLayer)

// Start video capture.
DispatchQueue.global(qos: .background).async {
DispatchQueue.global(qos: .userInitiated).async {
self.captureSession.startRunning()
}
}
Expand Down
2 changes: 1 addition & 1 deletion ElementX/Sources/UITests/UITestsAppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class MockScreen: Identifiable {
appSettings: ServiceLocator.shared.settings,
analytics: ServiceLocator.shared.analytics,
userIndicatorController: ServiceLocator.shared.userIndicatorController,
windowManager: windowManager)
orientationManager: windowManager)
flowCoordinator.start()
retainedState.append(flowCoordinator)
return nil
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8486020

Please sign in to comment.