mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
FF for QR code login + Login with qr code button (#2643)
This commit is contained in:
@@ -54,6 +54,7 @@ final class AppSettings {
|
||||
case markAsFavouriteEnabled
|
||||
case roomModerationEnabled
|
||||
case publicSearchEnabled
|
||||
case qrCodeLoginEnabled
|
||||
}
|
||||
|
||||
private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
|
||||
@@ -287,6 +288,9 @@ final class AppSettings {
|
||||
@UserPreference(key: UserDefaultsKeys.publicSearchEnabled, defaultValue: false, storageType: .volatile)
|
||||
var publicSearchEnabled
|
||||
|
||||
@UserPreference(key: UserDefaultsKeys.qrCodeLoginEnabled, defaultValue: false, storageType: .userDefaults(store))
|
||||
var qrCodeLoginEnabled
|
||||
|
||||
#endif
|
||||
|
||||
// MARK: - Shared
|
||||
|
||||
@@ -80,15 +80,18 @@ class AuthenticationFlowCoordinator: FlowCoordinatorProtocol {
|
||||
// MARK: - Private
|
||||
|
||||
private func showStartScreen() {
|
||||
let coordinator = AuthenticationStartScreenCoordinator()
|
||||
let coordinator = AuthenticationStartScreenCoordinator(parameters: .init(appSettings: appSettings))
|
||||
|
||||
coordinator.actions
|
||||
.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
switch action {
|
||||
case .login:
|
||||
case .loginManually:
|
||||
Task { await self.startAuthentication() }
|
||||
case .loginWithQR:
|
||||
// TODO: Implement QR code login navigation
|
||||
break
|
||||
case .reportProblem:
|
||||
showReportProblemScreen()
|
||||
}
|
||||
|
||||
@@ -125,6 +125,7 @@ enum A11yIdentifiers {
|
||||
|
||||
struct AuthenticationStartScreen {
|
||||
let signIn = "authentication_start-sign_in"
|
||||
let signInWithQr = "authentication_start-sign_in_with_qr"
|
||||
let hidden = "authentication_start-hidden"
|
||||
}
|
||||
|
||||
|
||||
+10
-4
@@ -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)
|
||||
}
|
||||
|
||||
+9
-4
@@ -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
|
||||
}
|
||||
|
||||
+10
-3
@@ -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)
|
||||
}
|
||||
|
||||
+15
-4
@@ -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)
|
||||
|
||||
+1
@@ -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 { }
|
||||
|
||||
+6
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user