FF for QR code login + Login with qr code button (#2643)

This commit is contained in:
Mauro
2024-04-04 10:37:42 +02:00
committed by GitHub
parent 3fea635d67
commit df242e3f1c
14 changed files with 70 additions and 25 deletions
@@ -17,6 +17,10 @@
import Combine
import SwiftUI
struct AuthenticationStartScreenCoordinatorParameters {
let appSettings: AppSettings
}
final class AuthenticationStartScreenCoordinator: CoordinatorProtocol {
private var viewModel: AuthenticationStartScreenViewModelProtocol
private let actionsSubject: PassthroughSubject<AuthenticationStartScreenCoordinatorAction, Never> = .init()
@@ -26,8 +30,8 @@ final class AuthenticationStartScreenCoordinator: CoordinatorProtocol {
actionsSubject.eraseToAnyPublisher()
}
init() {
viewModel = AuthenticationStartScreenViewModel()
init(parameters: AuthenticationStartScreenCoordinatorParameters) {
viewModel = AuthenticationStartScreenViewModel(appSettings: parameters.appSettings)
}
// MARK: - Public
@@ -38,8 +42,10 @@ final class AuthenticationStartScreenCoordinator: CoordinatorProtocol {
guard let self else { return }
switch action {
case .login:
actionsSubject.send(.login)
case .loginManually:
actionsSubject.send(.loginManually)
case .loginWithQR:
actionsSubject.send(.loginWithQR)
case .reportProblem:
actionsSubject.send(.reportProblem)
}
@@ -19,18 +19,23 @@ import SwiftUI
// MARK: - Coordinator
enum AuthenticationStartScreenCoordinatorAction {
case login
case loginManually
case loginWithQR
case reportProblem
}
enum AuthenticationStartScreenViewModelAction {
case login
case loginManually
case loginWithQR
case reportProblem
}
struct AuthenticationStartScreenViewState: BindableState { }
struct AuthenticationStartScreenViewState: BindableState {
var isQRCodeLoginEnabled = false
}
enum AuthenticationStartScreenViewAction {
case login
case loginManually
case loginWithQR
case reportProblem
}
@@ -20,20 +20,27 @@ import SwiftUI
typealias AuthenticationStartScreenViewModelType = StateStoreViewModel<AuthenticationStartScreenViewState, AuthenticationStartScreenViewAction>
class AuthenticationStartScreenViewModel: AuthenticationStartScreenViewModelType, AuthenticationStartScreenViewModelProtocol {
private let appSettings: AppSettings
private var actionsSubject: PassthroughSubject<AuthenticationStartScreenViewModelAction, Never> = .init()
var actions: AnyPublisher<AuthenticationStartScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init() {
init(appSettings: AppSettings) {
self.appSettings = appSettings
super.init(initialViewState: AuthenticationStartScreenViewState())
appSettings.$qrCodeLoginEnabled
.weakAssign(to: \.state.isQRCodeLoginEnabled, on: self)
.store(in: &cancellables)
}
override func process(viewAction: AuthenticationStartScreenViewAction) {
switch viewAction {
case .login:
actionsSubject.send(.login)
case .loginManually:
actionsSubject.send(.loginManually)
case .loginWithQR:
actionsSubject.send(.loginWithQR)
case .reportProblem:
actionsSubject.send(.reportProblem)
}
@@ -94,9 +94,17 @@ struct AuthenticationStartScreen: View {
/// The main action buttons.
var buttons: some View {
VStack(spacing: 12) {
Button { context.send(viewAction: .login) } label: {
Text(L10n.actionContinue)
VStack(spacing: 16) {
if context.viewState.isQRCodeLoginEnabled {
Button { context.send(viewAction: .loginManually) } label: {
Label(L10n.screenOnboardingSignInWithQrCode, icon: \.qrCode)
}
.buttonStyle(.compound(.primary))
.accessibilityIdentifier(A11yIdentifiers.authenticationStartScreen.signInWithQr)
}
Button { context.send(viewAction: .loginManually) } label: {
Text(context.viewState.isQRCodeLoginEnabled ? L10n.screenOnboardingSignInManually : L10n.actionContinue)
}
.buttonStyle(.compound(.primary))
.accessibilityIdentifier(A11yIdentifiers.authenticationStartScreen.signIn)
@@ -109,7 +117,10 @@ struct AuthenticationStartScreen: View {
// MARK: - Previews
struct AuthenticationStartScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = AuthenticationStartScreenViewModel()
static let viewModel = {
ServiceLocator.shared.settings.qrCodeLoginEnabled = true
return AuthenticationStartScreenViewModel(appSettings: ServiceLocator.shared.settings)
}()
static var previews: some View {
AuthenticationStartScreen(context: viewModel.context)
@@ -51,6 +51,7 @@ protocol DeveloperOptionsProtocol: AnyObject {
var roomModerationEnabled: Bool { get set }
var elementCallBaseURL: URL { get set }
var publicSearchEnabled: Bool { get set }
var qrCodeLoginEnabled: Bool { get set }
}
extension AppSettings: DeveloperOptionsProtocol { }
@@ -53,6 +53,12 @@ struct DeveloperOptionsScreen: View {
}
}
Section("QR Code") {
Toggle(isOn: $context.qrCodeLoginEnabled) {
Text("QR code login")
}
}
Section("Element Call") {
TextField(context.elementCallBaseURL.absoluteString, text: $elementCallBaseURLString)
.submitLabel(.done)