Run SwiftFormat.

This commit is contained in:
Doug
2026-05-27 14:38:50 +01:00
committed by Doug
parent 5138e05e47
commit fa67713726
573 changed files with 2426 additions and 2426 deletions
@@ -30,11 +30,11 @@ enum LoginScreenCoordinatorAction {
final class LoginScreenCoordinator: CoordinatorProtocol {
private let parameters: LoginScreenCoordinatorParameters
private var viewModel: LoginScreenViewModelProtocol
private var authenticationService: AuthenticationServiceProtocol {
parameters.authenticationService
}
private let actionsSubject: PassthroughSubject<LoginScreenCoordinatorAction, Never> = .init()
private var cancellables = Set<AnyCancellable>()
@@ -55,7 +55,7 @@ final class LoginScreenCoordinator: CoordinatorProtocol {
}
// MARK: - Public
func start() {
viewModel.actions
.sink { [weak self] action in
@@ -70,7 +70,7 @@ final class LoginScreenCoordinator: CoordinatorProtocol {
}
.store(in: &cancellables)
}
func stop() {
viewModel.stopLoading()
}
@@ -21,7 +21,7 @@ class LoginScreenViewModel: LoginScreenViewModelType, LoginScreenViewModelProtoc
var actions: AnyPublisher<LoginScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(authenticationService: AuthenticationServiceProtocol,
loginHint: String?,
userIndicatorController: UserIndicatorControllerProtocol,
@@ -48,7 +48,7 @@ class LoginScreenViewModel: LoginScreenViewModelType, LoginScreenViewModelProtoc
.weakAssign(to: \.state.homeserver, on: self)
.store(in: &cancellables)
}
override func process(viewAction: LoginScreenViewAction) {
switch viewAction {
case .parseUsername:
@@ -92,7 +92,7 @@ struct LoginScreen: View {
.onSubmit(submit)
Spacer().frame(height: 32)
Button(action: submit) {
Text(L10n.actionContinue)
}
@@ -139,7 +139,7 @@ class OAuthAuthenticationPresenter: NSObject {
private var loadingIndicatorID: String {
"\(Self.self)-Loading"
}
private var failureIndicatorID: String {
"\(Self.self)-Failure"
}
@@ -60,7 +60,7 @@ final class ServerConfirmationScreenCoordinator: CoordinatorProtocol {
}
.store(in: &cancellables)
}
func toPresentable() -> AnyView {
AnyView(ServerConfirmationScreen(context: viewModel.context))
}
@@ -52,7 +52,7 @@ struct ServerConfirmationScreenViewState: BindableState {
/// The message shown beneath the title.
var message: String? {
guard case let .confirmation(homeserverAddress) = mode else { return nil }
return switch authenticationFlow {
case .login:
if homeserverAddress == "matrix.org" {
@@ -22,7 +22,7 @@ class ServerConfirmationScreenViewModel: ServerConfirmationScreenViewModelType,
var actions: AnyPublisher<ServerConfirmationScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(authenticationService: AuthenticationServiceProtocol,
mode: ServerConfirmationScreenMode,
authenticationFlow: AuthenticationFlow,
@@ -30,7 +30,7 @@ final class ServerSelectionScreenCoordinator: CoordinatorProtocol {
private var authenticationService: AuthenticationServiceProtocol {
parameters.authenticationService
}
private let actionsSubject: PassthroughSubject<ServerSelectionScreenCoordinatorAction, Never> = .init()
private var cancellables = Set<AnyCancellable>()
@@ -22,7 +22,7 @@ class ServerSelectionScreenViewModel: ServerSelectionScreenViewModelType, Server
var actions: AnyPublisher<ServerSelectionScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(authenticationService: AuthenticationServiceProtocol,
authenticationFlow: AuthenticationFlow,
appSettings: AppSettings,
@@ -20,7 +20,7 @@ enum MockSoftLogoutScreenState: String, CaseIterable {
case oAuth
case unsupported
case keyBackupNeeded
/// Generate the view struct for the screen state.
@MainActor var viewModel: SoftLogoutScreenViewModel {
let credentials = SoftLogoutScreenCredentials(userID: "@mock:matrix.org",
@@ -46,7 +46,7 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
private var authenticationService: AuthenticationServiceProtocol {
parameters.authenticationService
}
private var oAuthPresenter: OAuthAuthenticationPresenter?
var actions: AnyPublisher<SoftLogoutScreenCoordinatorResult, Never> {
@@ -69,7 +69,7 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
.sink { [weak self] action in
guard let self else { return }
MXLog.info("Did complete with result: \(action).")
switch action {
case .login(let password):
login(withPassword: password)
@@ -117,18 +117,18 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
@MainActor private func stopLoading() {
parameters.userIndicatorController.retractIndicatorWithId(Self.loadingIndicatorIdentifier)
}
/// Shows the forgot password screen.
@MainActor private func showForgotPasswordScreen() {
viewModel.displayError(.alert("Not implemented."))
}
/// Login with the supplied username and password.
@MainActor private func login(withPassword password: String) {
let username = parameters.credentials.userID
startLoading()
Task {
switch await authenticationService.login(username: username,
password: password,
@@ -143,7 +143,7 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
}
}
}
private func continueWithOAuth(presentationAnchor: UIWindow?) {
guard let presentationAnchor else { return }
@@ -174,7 +174,7 @@ final class SoftLogoutScreenCoordinator: CoordinatorProtocol {
}
}
}
/// Processes an error to either update the flow or display it to the user.
private func handleError(_ error: AuthenticationServiceError) {
switch error {
@@ -43,16 +43,16 @@ enum SoftLogoutScreenViewModelAction: CustomStringConvertible {
struct SoftLogoutScreenViewState: BindableState {
/// Soft logout credentials
var credentials: SoftLogoutScreenCredentials
/// Data about the selected homeserver.
var homeserver: LoginHomeserver
/// Flag indicating soft logged out user needs backup for some keys
var keyBackupNeeded: Bool
/// View state that can be bound to from SwiftUI.
var bindings: SoftLogoutScreenBindings
/// The types of login supported by the homeserver.
var loginMode: LoginMode {
homeserver.loginMode
@@ -60,12 +60,12 @@ struct SoftLogoutScreenViewState: BindableState {
/// The presentation anchor used for OAuth authentication.
var window: UIWindow?
/// Whether to show recover encryption keys message
var showRecoverEncryptionKeysMessage: Bool {
keyBackupNeeded
}
/// `true` when valid credentials have been entered and a homeserver has been loaded.
var canSubmit: Bool {
!bindings.password.isEmpty
@@ -17,7 +17,7 @@ class SoftLogoutScreenViewModel: SoftLogoutScreenViewModelType, SoftLogoutScreen
var actions: AnyPublisher<SoftLogoutScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(credentials: SoftLogoutScreenCredentials,
homeserver: LoginHomeserver,
keyBackupNeeded: Bool,
@@ -45,7 +45,7 @@ class SoftLogoutScreenViewModel: SoftLogoutScreenViewModelType, SoftLogoutScreen
Task { state.window = window }
}
}
@MainActor func displayError(_ type: SoftLogoutScreenErrorType) {
switch type {
case .alert(let message):
@@ -10,10 +10,10 @@ import SwiftUI
struct SoftLogoutScreen: View {
@State private var showingClearDataConfirmation = false
/// The focus state of the password text field.
@FocusState private var isPasswordFocused: Bool
@Bindable var context: SoftLogoutScreenViewModel.Context
var body: some View {
@@ -22,7 +22,7 @@ struct SoftLogoutScreen: View {
header
.padding(.top, UIConstants.titleTopPaddingToNavigationBar)
.padding(.bottom, 36)
switch context.viewState.loginMode {
case .password:
loginForm
@@ -31,7 +31,7 @@ struct SoftLogoutScreen: View {
default:
loginUnavailableText
}
clearDataForm
.padding(.top, 16)
}
@@ -45,7 +45,7 @@ struct SoftLogoutScreen: View {
context.send(viewAction: .updateWindow(window))
}
}
/// The title, message and icon at the top of the screen.
var header: some View {
VStack(alignment: .leading, spacing: 16) {
@@ -54,13 +54,13 @@ struct SoftLogoutScreen: View {
.multilineTextAlignment(.leading)
.foregroundColor(.compound.textPrimary)
.accessibilityIdentifier(A11yIdentifiers.softLogoutScreen.title)
Text(UntranslatedL10n.softLogoutSigninNotice(context.viewState.credentials.homeserverName, context.viewState.credentials.userDisplayName, context.viewState.credentials.userID))
.font(.compound.bodyLG)
.multilineTextAlignment(.leading)
.foregroundColor(.compound.textPrimary)
.accessibilityIdentifier(A11yIdentifiers.softLogoutScreen.message)
if context.viewState.showRecoverEncryptionKeysMessage {
Text(UntranslatedL10n.softLogoutSigninE2eWarningNotice)
.font(.compound.bodyLG)
@@ -69,7 +69,7 @@ struct SoftLogoutScreen: View {
}
}
}
/// The form with text fields for username and password, along with a submit button.
var loginForm: some View {
VStack(spacing: 14) {
@@ -80,7 +80,7 @@ struct SoftLogoutScreen: View {
.submitLabel(.done)
.onSubmit(submit)
.accessibilityIdentifier(A11yIdentifiers.softLogoutScreen.password)
Button { context.send(viewAction: .forgotPassword) } label: {
Text(L10n.actionForgotPassword)
.font(.compound.bodyLG)
@@ -88,7 +88,7 @@ struct SoftLogoutScreen: View {
.frame(maxWidth: .infinity, alignment: .trailing)
.padding(.bottom, 8)
.accessibilityIdentifier(A11yIdentifiers.softLogoutScreen.forgotPassword)
Button(action: submit) {
Text(L10n.actionNext)
}
@@ -97,7 +97,7 @@ struct SoftLogoutScreen: View {
.accessibilityIdentifier(A11yIdentifiers.softLogoutScreen.next)
}
}
/// The OAuth button that can be used for login.
var oAuthButton: some View {
Button { context.send(viewAction: .continueWithOAuth) } label: {
@@ -105,7 +105,7 @@ struct SoftLogoutScreen: View {
}
.buttonStyle(.compound(.primary))
}
/// Text shown if neither password or OAuth login is supported.
var loginUnavailableText: some View {
Text(L10n.screenLoginErrorUnsupportedAuthentication)
@@ -114,7 +114,7 @@ struct SoftLogoutScreen: View {
.foregroundColor(.compound.textPrimary)
.frame(maxWidth: .infinity)
}
/// The text field and submit button where the user enters an email address.
var clearDataForm: some View {
VStack(alignment: .leading, spacing: 12) {
@@ -123,14 +123,14 @@ struct SoftLogoutScreen: View {
.multilineTextAlignment(.leading)
.foregroundColor(.compound.textPrimary)
.accessibilityIdentifier(A11yIdentifiers.softLogoutScreen.clearDataTitle)
Text(UntranslatedL10n.softLogoutClearDataNotice)
.font(.compound.bodyLG)
.multilineTextAlignment(.leading)
.foregroundColor(.compound.textPrimary)
.accessibilityIdentifier(A11yIdentifiers.softLogoutScreen.clearDataMessage)
.padding(.bottom, 12)
Button(role: .destructive, action: clearData) {
Text(UntranslatedL10n.softLogoutClearDataSubmit)
}
@@ -146,13 +146,13 @@ struct SoftLogoutScreen: View {
}
}
}
/// Sends the `login` view action so long as a valid email address has been input.
func submit() {
guard context.viewState.canSubmit else { return }
context.send(viewAction: .login)
}
/// Sends the `clearAllData` view action.
func clearData() {
context.send(viewAction: .clearAllData)
@@ -167,7 +167,7 @@ struct SoftLogoutScreen_Previews: PreviewProvider, TestablePreview {
screen(for: state.viewModel)
}
}
static func screen(for viewModel: SoftLogoutScreenViewModel) -> some View {
ElementNavigationStack {
SoftLogoutScreen(context: viewModel.context)
@@ -64,12 +64,12 @@ final class AuthenticationStartScreenCoordinator: CoordinatorProtocol {
actionsSubject.send(.login)
case .register:
actionsSubject.send(.register)
case .loginDirectlyWithOAuth(let data, let window):
actionsSubject.send(.loginDirectlyWithOAuth(data: data, window: window))
case .loginDirectlyWithPassword(let loginHint):
actionsSubject.send(.loginDirectlyWithPassword(loginHint: loginHint))
case .reportProblem:
actionsSubject.send(.reportProblem)
case .developerOptions:
@@ -89,14 +89,14 @@ class AuthenticationStartScreenViewModel: AuthenticationStartScreenViewModelType
}
case .developerOptions:
actionsSubject.send(.developerOptions)
case .loginWithQR:
actionsSubject.send(.loginWithQR)
case .login:
Task { await login() }
case .register:
actionsSubject.send(.register)
case .continueWithClassic(let account):
Task { await login(classicAppAccount: account) }
case .otherOptions(let account):
@@ -65,12 +65,12 @@ private struct AuthenticationBrandLogoModifier: ViewModifier {
private var isLight: Bool {
colorScheme == .light
}
/// Extra padding needed to avoid cropping the shadows.
private var extra: CGFloat {
64 * scale
}
/// The shape that the logo is composed on top of.
private var outerShape: RoundedRectangle {
RoundedRectangle(cornerRadius: 44 * scale)
@@ -21,7 +21,7 @@ enum UIConstants {
/// The padding used to the top of the view for breaker screens that don't have a navigation bar.
static let startScreenBreakerScreenTopPadding: CGFloat = 80
/// The height to use for top/bottom spacers to pad the views to fit the `maxContentHeight`.
static func spacerHeight(in geometry: GeometryProxy) -> CGFloat {
max(0, (geometry.size.height - maxContentHeight) / 2)