Allow registration on matrix.org using a custom helper URL. (#3282)

This commit is contained in:
Doug
2024-09-16 13:05:22 +01:00
committed by GitHub
parent 6cfe09b96d
commit 6efbf6117f
15 changed files with 129 additions and 42 deletions
@@ -8,6 +8,10 @@
import Combine
import SwiftUI
struct AuthenticationStartScreenParameters {
let webRegistrationEnabled: Bool
}
final class AuthenticationStartScreenCoordinator: CoordinatorProtocol {
private var viewModel: AuthenticationStartScreenViewModelProtocol
private let actionsSubject: PassthroughSubject<AuthenticationStartScreenCoordinatorAction, Never> = .init()
@@ -17,8 +21,8 @@ final class AuthenticationStartScreenCoordinator: CoordinatorProtocol {
actionsSubject.eraseToAnyPublisher()
}
init() {
viewModel = AuthenticationStartScreenViewModel()
init(parameters: AuthenticationStartScreenParameters) {
viewModel = AuthenticationStartScreenViewModel(webRegistrationEnabled: parameters.webRegistrationEnabled)
}
// MARK: - Public
@@ -33,6 +37,8 @@ final class AuthenticationStartScreenCoordinator: CoordinatorProtocol {
actionsSubject.send(.loginManually)
case .loginWithQR:
actionsSubject.send(.loginWithQR)
case .register:
actionsSubject.send(.register)
case .reportProblem:
actionsSubject.send(.reportProblem)
}
@@ -12,21 +12,25 @@ import SwiftUI
enum AuthenticationStartScreenCoordinatorAction {
case loginManually
case loginWithQR
case register
case reportProblem
}
enum AuthenticationStartScreenViewModelAction {
case loginManually
case loginWithQR
case register
case reportProblem
}
struct AuthenticationStartScreenViewState: BindableState {
var isQRCodeLoginEnabled = false
let isWebRegistrationEnabled: Bool
let isQRCodeLoginEnabled: Bool
}
enum AuthenticationStartScreenViewAction {
case loginManually
case loginWithQR
case register
case reportProblem
}
@@ -17,9 +17,9 @@ class AuthenticationStartScreenViewModel: AuthenticationStartScreenViewModelType
actionsSubject.eraseToAnyPublisher()
}
init() {
super.init(initialViewState: AuthenticationStartScreenViewState())
state.isQRCodeLoginEnabled = !ProcessInfo.processInfo.isiOSAppOnMac && AppSettings.isDevelopmentBuild
init(webRegistrationEnabled: Bool) {
super.init(initialViewState: AuthenticationStartScreenViewState(isWebRegistrationEnabled: webRegistrationEnabled,
isQRCodeLoginEnabled: !ProcessInfo.processInfo.isiOSAppOnMac && AppSettings.isDevelopmentBuild))
}
override func process(viewAction: AuthenticationStartScreenViewAction) {
@@ -28,6 +28,8 @@ class AuthenticationStartScreenViewModel: AuthenticationStartScreenViewModelType
actionsSubject.send(.loginManually)
case .loginWithQR:
actionsSubject.send(.loginWithQR)
case .register:
actionsSubject.send(.register)
case .reportProblem:
actionsSubject.send(.reportProblem)
}
@@ -99,6 +99,14 @@ struct AuthenticationStartScreen: View {
}
.buttonStyle(.compound(.primary))
.accessibilityIdentifier(A11yIdentifiers.authenticationStartScreen.signIn)
if context.viewState.isWebRegistrationEnabled {
Button { context.send(viewAction: .register) } label: {
Text(L10n.screenCreateAccountTitle)
.padding(14)
}
.buttonStyle(.compound(.plain))
}
}
.padding(.horizontal, verticalSizeClass == .compact ? 128 : 24)
.readableFrame()
@@ -108,7 +116,7 @@ struct AuthenticationStartScreen: View {
// MARK: - Previews
struct AuthenticationStartScreen_Previews: PreviewProvider, TestablePreview {
static let viewModel = AuthenticationStartScreenViewModel()
static let viewModel = AuthenticationStartScreenViewModel(webRegistrationEnabled: true)
static var previews: some View {
AuthenticationStartScreen(context: viewModel.context)