From 446aab58de40e2d15fdfe777426f10ab97efa743 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 8 Apr 2024 16:19:06 +0300 Subject: [PATCH] Fixes ELEMENT-97277 - Be less aggressive on recovery key states --- ...reBackupRecoveryKeyScreenCoordinator.swift | 2 + .../SecureBackupRecoveryKeyScreenModels.swift | 11 ++- ...cureBackupRecoveryKeyScreenViewModel.swift | 2 +- .../View/SecureBackupRecoveryKeyScreen.swift | 70 ++++++++++++------- ...upRecoveryKeyScreen-iPad-en-GB.Unknown.png | 3 + ...pRecoveryKeyScreen-iPad-pseudo.Unknown.png | 3 + ...overyKeyScreen-iPhone-15-en-GB.Unknown.png | 3 + ...veryKeyScreen-iPhone-15-pseudo.Unknown.png | 3 + 8 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPad-en-GB.Unknown.png create mode 100644 PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPad-pseudo.Unknown.png create mode 100644 PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPhone-15-en-GB.Unknown.png create mode 100644 PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPhone-15-pseudo.Unknown.png diff --git a/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenCoordinator.swift b/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenCoordinator.swift index d7ea324c7..19de61de4 100644 --- a/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenCoordinator.swift +++ b/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenCoordinator.swift @@ -62,6 +62,8 @@ final class SecureBackupRecoveryKeyScreenCoordinator: CoordinatorProtocol { self.actionsSubject.send(.recoveryChanged) case .fixRecovery: self.actionsSubject.send(.recoveryFixed) + case .unknown: + fatalError() } case .showResetKeyInfo: self.actionsSubject.send(.showResetKeyInfo) diff --git a/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenModels.swift b/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenModels.swift index cb5655fd4..3bccf26ce 100644 --- a/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenModels.swift +++ b/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenModels.swift @@ -26,6 +26,7 @@ enum SecureBackupRecoveryKeyScreenViewMode { case setupRecovery case changeRecovery case fixRecovery + case unknown } struct SecureBackupRecoveryKeyScreenViewState: BindableState { @@ -47,10 +48,12 @@ struct SecureBackupRecoveryKeyScreenViewState: BindableState { return recoveryKey == nil ? L10n.screenRecoveryKeyChangeTitle : L10n.screenRecoveryKeySaveTitle case .fixRecovery: return L10n.screenRecoveryKeyConfirmTitle + default: + return L10n.errorUnknown } } - var subtitle: String { + var subtitle: String? { switch mode { case .setupRecovery: return recoveryKey == nil ? L10n.screenRecoveryKeySetupDescription : L10n.screenRecoveryKeySaveDescription @@ -58,10 +61,12 @@ struct SecureBackupRecoveryKeyScreenViewState: BindableState { return recoveryKey == nil ? L10n.screenRecoveryKeyChangeDescription : L10n.screenRecoveryKeySaveDescription case .fixRecovery: return L10n.screenRecoveryKeyConfirmDescription + default: + return nil } } - var recoveryKeySubtitle: String { + var recoveryKeySubtitle: String? { switch mode { case .setupRecovery: return recoveryKey == nil ? L10n.screenRecoveryKeySetupGenerateKeyDescription : L10n.screenRecoveryKeySaveKeyDescription @@ -69,6 +74,8 @@ struct SecureBackupRecoveryKeyScreenViewState: BindableState { return recoveryKey == nil ? L10n.screenRecoveryKeyChangeGenerateKeyDescription : L10n.screenRecoveryKeySaveKeyDescription case .fixRecovery: return L10n.screenRecoveryKeyConfirmKeyDescription + default: + return nil } } } diff --git a/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenViewModel.swift b/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenViewModel.swift index 112a6a3fe..c8aa406e4 100644 --- a/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenViewModel.swift +++ b/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/SecureBackupRecoveryKeyScreenViewModel.swift @@ -116,7 +116,7 @@ extension SecureBackupRecoveryState { case .incomplete: return .fixRecovery default: - fatalError("Invalid recovery state") + return .unknown } } } diff --git a/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/View/SecureBackupRecoveryKeyScreen.swift b/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/View/SecureBackupRecoveryKeyScreen.swift index 06fffee2f..370d8196c 100644 --- a/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/View/SecureBackupRecoveryKeyScreen.swift +++ b/ElementX/Sources/Screens/SecureBackup/SecureBackupRecoveryKeyScreen/View/SecureBackupRecoveryKeyScreen.swift @@ -54,6 +54,26 @@ struct SecureBackupRecoveryKeyScreen: View { case .fixRecovery: header confirmRecoveryKeySection + case .unknown: + header + } + } + } + + private var header: some View { + VStack(spacing: 16) { + HeroImage(icon: \.keySolid) + + Text(context.viewState.title) + .foregroundColor(.compound.textPrimary) + .font(.compound.headingMDBold) + .multilineTextAlignment(.center) + + if let subtitle = context.viewState.subtitle { + Text(subtitle) + .foregroundColor(.compound.textSecondary) + .font(.compound.bodyMD) + .multilineTextAlignment(.center) } } } @@ -65,6 +85,8 @@ struct SecureBackupRecoveryKeyScreen: View { recoveryCreatedActionButtons case .fixRecovery: incompleteVerificationActionButtons + case .unknown: + EmptyView() } } @@ -121,22 +143,6 @@ struct SecureBackupRecoveryKeyScreen: View { } } - private var header: some View { - VStack(spacing: 16) { - HeroImage(icon: \.keySolid) - - Text(context.viewState.title) - .foregroundColor(.compound.textPrimary) - .font(.compound.headingMDBold) - .multilineTextAlignment(.center) - - Text(context.viewState.subtitle) - .foregroundColor(.compound.textSecondary) - .font(.compound.bodyMD) - .multilineTextAlignment(.center) - } - } - private var generateRecoveryKeySection: some View { VStack(alignment: .leading, spacing: 8) { Text(L10n.commonRecoveryKey) @@ -172,16 +178,18 @@ struct SecureBackupRecoveryKeyScreen: View { .background(Color.compound.bgSubtleSecondaryLevel0) .clipShape(RoundedRectangle(cornerRadius: 8)) - Label { - Text(context.viewState.recoveryKeySubtitle) - .foregroundColor(.compound.textSecondary) - .font(.compound.bodySM) - } icon: { - if context.viewState.recoveryKey == nil { - CompoundIcon(\.infoSolid, size: .small, relativeTo: .compound.bodySM) + if let subtitle = context.viewState.recoveryKeySubtitle { + Label { + Text(subtitle) + .foregroundColor(.compound.textSecondary) + .font(.compound.bodySM) + } icon: { + if context.viewState.recoveryKey == nil { + CompoundIcon(\.infoSolid, size: .small, relativeTo: .compound.bodySM) + } } + .labelStyle(.custom(spacing: 8, alignment: .top)) } - .labelStyle(.custom(spacing: 8, alignment: .top)) } } @@ -211,9 +219,11 @@ struct SecureBackupRecoveryKeyScreen: View { context.send(viewAction: .confirmKey) } - Text(context.viewState.recoveryKeySubtitle) - .foregroundColor(.compound.textSecondary) - .font(.compound.bodySM) + if let subtitle = context.viewState.recoveryKeySubtitle { + Text(subtitle) + .foregroundColor(.compound.textSecondary) + .font(.compound.bodySM) + } } } } @@ -224,6 +234,7 @@ struct SecureBackupRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview static let setupViewModel = viewModel(recoveryState: .enabled) static let notSetUpViewModel = viewModel(recoveryState: .disabled) static let incompleteViewModel = viewModel(recoveryState: .incomplete) + static let unknownViewModel = viewModel(recoveryState: .unknown) static var previews: some View { NavigationStack { @@ -240,6 +251,11 @@ struct SecureBackupRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview SecureBackupRecoveryKeyScreen(context: incompleteViewModel.context) } .previewDisplayName("Incomplete") + + NavigationStack { + SecureBackupRecoveryKeyScreen(context: unknownViewModel.context) + } + .previewDisplayName("Unknown") } static func viewModel(recoveryState: SecureBackupRecoveryState) -> SecureBackupRecoveryKeyScreenViewModelType { diff --git a/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPad-en-GB.Unknown.png b/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPad-en-GB.Unknown.png new file mode 100644 index 000000000..7e74d59f3 --- /dev/null +++ b/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPad-en-GB.Unknown.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:edb78e9330dad85dbea6b78e5251de463d5256467d156b5c115412f70ffb6e40 +size 89995 diff --git a/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPad-pseudo.Unknown.png b/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPad-pseudo.Unknown.png new file mode 100644 index 000000000..fe71fbb2b --- /dev/null +++ b/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPad-pseudo.Unknown.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:db402366ea030a33cee42151bb53fe0246552e5c62007db21973e1b2dd65d46b +size 111948 diff --git a/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPhone-15-en-GB.Unknown.png b/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPhone-15-en-GB.Unknown.png new file mode 100644 index 000000000..79f8efee9 --- /dev/null +++ b/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPhone-15-en-GB.Unknown.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4887b2039b61cb4983f2b21c8188196363ac15d731ce7d6d5da8587ee9ab7202 +size 48061 diff --git a/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPhone-15-pseudo.Unknown.png b/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPhone-15-pseudo.Unknown.png new file mode 100644 index 000000000..91b7838f0 --- /dev/null +++ b/PreviewTests/__Snapshots__/PreviewTests/test_secureBackupRecoveryKeyScreen-iPhone-15-pseudo.Unknown.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66d22d7edf9db13c6dd7e9a40333ee03efd7dc1815abf8c9c7cc31c0f8737f3b +size 68216