mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Reset Recovery Key Screen (#2648)
Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
// periphery:ignore:all - this is just a resetKey remove this comment once generating the final file
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
enum ResetRecoveryKeyScreenCoordinatorAction {
|
||||
case cancel
|
||||
}
|
||||
|
||||
final class ResetRecoveryKeyScreenCoordinator: CoordinatorProtocol {
|
||||
private let viewModel: ResetRecoveryKeyScreenViewModelProtocol
|
||||
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
private let actionsSubject: PassthroughSubject<ResetRecoveryKeyScreenCoordinatorAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<ResetRecoveryKeyScreenCoordinatorAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init() {
|
||||
viewModel = ResetRecoveryKeyScreenViewModel()
|
||||
}
|
||||
|
||||
func start() {
|
||||
viewModel.actionsPublisher.sink { [weak self] action in
|
||||
MXLog.info("Coordinator: received view model action: \(action)")
|
||||
|
||||
guard let self else { return }
|
||||
switch action {
|
||||
case .cancel:
|
||||
self.actionsSubject.send(.cancel)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func toPresentable() -> AnyView {
|
||||
AnyView(ResetRecoveryKeyScreen(context: viewModel.context))
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum ResetRecoveryKeyScreenViewModelAction {
|
||||
case cancel
|
||||
}
|
||||
|
||||
struct ResetRecoveryKeyScreenViewState: BindableState {
|
||||
let listItem3AttributedText = {
|
||||
let boldPlaceholder = "{bold}"
|
||||
var finalString = AttributedString(L10n.screenCreateNewRecoveryKeyListItem3(boldPlaceholder))
|
||||
var boldString = AttributedString(L10n.screenCreateNewRecoveryKeyListItem3ResetAll)
|
||||
boldString.bold()
|
||||
finalString.replace(boldPlaceholder, with: boldString)
|
||||
return finalString
|
||||
}()
|
||||
}
|
||||
|
||||
enum ResetRecoveryKeyScreenViewAction {
|
||||
case cancel
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
import SwiftUI
|
||||
|
||||
typealias ResetRecoveryKeyScreenViewModelType = StateStoreViewModel<ResetRecoveryKeyScreenViewState, ResetRecoveryKeyScreenViewAction>
|
||||
|
||||
class ResetRecoveryKeyScreenViewModel: ResetRecoveryKeyScreenViewModelType, ResetRecoveryKeyScreenViewModelProtocol {
|
||||
private let actionsSubject: PassthroughSubject<ResetRecoveryKeyScreenViewModelAction, Never> = .init()
|
||||
var actionsPublisher: AnyPublisher<ResetRecoveryKeyScreenViewModelAction, Never> {
|
||||
actionsSubject.eraseToAnyPublisher()
|
||||
}
|
||||
|
||||
init() {
|
||||
super.init(initialViewState: ResetRecoveryKeyScreenViewState())
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: ResetRecoveryKeyScreenViewAction) {
|
||||
switch viewAction {
|
||||
case .cancel:
|
||||
actionsSubject.send(.cancel)
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Combine
|
||||
|
||||
@MainActor
|
||||
protocol ResetRecoveryKeyScreenViewModelProtocol {
|
||||
var actionsPublisher: AnyPublisher<ResetRecoveryKeyScreenViewModelAction, Never> { get }
|
||||
var context: ResetRecoveryKeyScreenViewModelType.Context { get }
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Compound
|
||||
import SwiftUI
|
||||
|
||||
struct ResetRecoveryKeyScreen: View {
|
||||
@ObservedObject var context: ResetRecoveryKeyScreenViewModel.Context
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
FullscreenDialog {
|
||||
mainContent
|
||||
} bottomContent: {
|
||||
EmptyView()
|
||||
}
|
||||
.toolbar { toolbar }
|
||||
.toolbar(.visible, for: .navigationBar)
|
||||
.background()
|
||||
.environment(\.backgroundStyle, AnyShapeStyle(Color.compound.bgSubtleSecondary))
|
||||
.interactiveDismissDisabled()
|
||||
}
|
||||
}
|
||||
|
||||
private var mainContent: some View {
|
||||
VStack(spacing: 40) {
|
||||
header
|
||||
list
|
||||
}
|
||||
}
|
||||
|
||||
private var header: some View {
|
||||
VStack(spacing: 16) {
|
||||
HeroImage(icon: \.computer, style: .subtle)
|
||||
|
||||
Text(L10n.screenCreateNewRecoveryKeyTitle)
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.font(.compound.headingMDBold)
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
}
|
||||
|
||||
private var list: some View {
|
||||
VStack(alignment: .leading, spacing: 24) {
|
||||
Label {
|
||||
Text(L10n.screenCreateNewRecoveryKeyListItem1)
|
||||
} icon: {
|
||||
Image(systemSymbol: ._1Circle)
|
||||
.imageScale(.large)
|
||||
.fontWeight(.light)
|
||||
.foregroundColor(.compound.textPlaceholder)
|
||||
}
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.font(.compound.bodyMD)
|
||||
|
||||
Label {
|
||||
Text(L10n.screenCreateNewRecoveryKeyListItem2)
|
||||
} icon: {
|
||||
Image(systemSymbol: ._2Circle)
|
||||
.imageScale(.large)
|
||||
.fontWeight(.light)
|
||||
.foregroundColor(.compound.textPlaceholder)
|
||||
}
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.font(.compound.bodyMD)
|
||||
|
||||
Label {
|
||||
Text(context.viewState.listItem3AttributedText)
|
||||
} icon: {
|
||||
Image(systemSymbol: ._3Circle)
|
||||
.imageScale(.large)
|
||||
.fontWeight(.light)
|
||||
.foregroundColor(.compound.textPlaceholder)
|
||||
}
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.font(.compound.bodyMD)
|
||||
|
||||
Label {
|
||||
Text(L10n.screenCreateNewRecoveryKeyListItem4)
|
||||
} icon: {
|
||||
Image(systemSymbol: ._4Circle)
|
||||
.imageScale(.large)
|
||||
.fontWeight(.light)
|
||||
.foregroundColor(.compound.textPlaceholder)
|
||||
}
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.font(.compound.bodyMD)
|
||||
|
||||
Label {
|
||||
Text(L10n.screenCreateNewRecoveryKeyListItem5)
|
||||
} icon: {
|
||||
Image(systemSymbol: ._5Circle)
|
||||
.imageScale(.large)
|
||||
.fontWeight(.light)
|
||||
.foregroundColor(.compound.textPlaceholder)
|
||||
}
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.font(.compound.bodyMD)
|
||||
}
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
private var toolbar: some ToolbarContent {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(L10n.actionCancel) {
|
||||
context.send(viewAction: .cancel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct ResetRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview {
|
||||
static let viewModel = ResetRecoveryKeyScreenViewModel()
|
||||
static var previews: some View {
|
||||
NavigationStack {
|
||||
ResetRecoveryKeyScreen(context: viewModel.context)
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -28,6 +28,7 @@ enum SecureBackupRecoveryKeyScreenCoordinatorAction {
|
||||
case recoverySetUp
|
||||
case recoveryChanged
|
||||
case recoveryFixed
|
||||
case showResetKeyInfo
|
||||
}
|
||||
|
||||
final class SecureBackupRecoveryKeyScreenCoordinator: CoordinatorProtocol {
|
||||
@@ -62,6 +63,8 @@ final class SecureBackupRecoveryKeyScreenCoordinator: CoordinatorProtocol {
|
||||
case .fixRecovery:
|
||||
self.actionsSubject.send(.recoveryFixed)
|
||||
}
|
||||
case .showResetKeyInfo:
|
||||
self.actionsSubject.send(.showResetKeyInfo)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
||||
+2
@@ -19,6 +19,7 @@ import Foundation
|
||||
enum SecureBackupRecoveryKeyScreenViewModelAction {
|
||||
case done(mode: SecureBackupRecoveryKeyScreenViewMode)
|
||||
case cancel
|
||||
case showResetKeyInfo
|
||||
}
|
||||
|
||||
enum SecureBackupRecoveryKeyScreenViewMode {
|
||||
@@ -82,6 +83,7 @@ enum SecureBackupRecoveryKeyScreenViewAction {
|
||||
case copyKey
|
||||
case keySaved
|
||||
case confirmKey
|
||||
case resetKey
|
||||
case done
|
||||
case cancel
|
||||
}
|
||||
|
||||
+2
@@ -100,6 +100,8 @@ class SecureBackupRecoveryKeyScreenViewModel: SecureBackupRecoveryKeyScreenViewM
|
||||
guard let self else { return }
|
||||
actionsSubject.send(.done(mode: context.viewState.mode))
|
||||
}))
|
||||
case .resetKey:
|
||||
actionsSubject.send(.showResetKeyInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
-2
@@ -64,6 +64,12 @@ struct SecureBackupRecoveryKeyScreen: View {
|
||||
case .setupRecovery, .changeRecovery:
|
||||
recoveryCreatedActionButtons
|
||||
case .fixRecovery:
|
||||
incompleteVerificationActionButtons
|
||||
}
|
||||
}
|
||||
|
||||
private var incompleteVerificationActionButtons: some View {
|
||||
VStack(spacing: 16) {
|
||||
Button {
|
||||
context.send(viewAction: .confirmKey)
|
||||
} label: {
|
||||
@@ -71,6 +77,14 @@ struct SecureBackupRecoveryKeyScreen: View {
|
||||
}
|
||||
.buttonStyle(.compound(.primary))
|
||||
.disabled(context.confirmationRecoveryKey.isEmpty)
|
||||
|
||||
Button {
|
||||
context.send(viewAction: .resetKey)
|
||||
} label: {
|
||||
Text(L10n.screenIdentityConfirmationCreateNewRecoveryKey)
|
||||
.padding(.vertical, 14)
|
||||
}
|
||||
.buttonStyle(.compound(.plain))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +141,7 @@ struct SecureBackupRecoveryKeyScreen: View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text(L10n.commonRecoveryKey)
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.font(.compound.bodySM)
|
||||
.font(.compound.bodySMSemibold)
|
||||
|
||||
Group {
|
||||
if context.viewState.recoveryKey == nil {
|
||||
@@ -180,7 +194,7 @@ struct SecureBackupRecoveryKeyScreen: View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text(L10n.commonRecoveryKey)
|
||||
.foregroundColor(.compound.textPrimary)
|
||||
.font(.compound.bodySM)
|
||||
.font(.compound.bodySMSemibold)
|
||||
|
||||
SecureField(L10n.screenRecoveryKeyConfirmKeyPlaceholder, text: $context.confirmationRecoveryKey)
|
||||
.textContentType(.password) // Not ideal but stops random suggestions
|
||||
|
||||
+17
-3
@@ -51,18 +51,20 @@ final class SecureBackupScreenCoordinator: CoordinatorProtocol {
|
||||
|
||||
recoveryKeyCoordinator.actions.sink { [weak self] action in
|
||||
guard let self else { return }
|
||||
|
||||
parameters.navigationStackCoordinator?.setSheetCoordinator(nil)
|
||||
|
||||
switch action {
|
||||
case .cancel:
|
||||
break
|
||||
case .recoverySetUp:
|
||||
showSuccessIndicator(title: L10n.screenRecoveryKeySetupSuccess)
|
||||
parameters.navigationStackCoordinator?.setSheetCoordinator(nil)
|
||||
case .recoveryChanged:
|
||||
showSuccessIndicator(title: L10n.screenRecoveryKeyChangeSuccess)
|
||||
parameters.navigationStackCoordinator?.setSheetCoordinator(nil)
|
||||
case .recoveryFixed:
|
||||
showSuccessIndicator(title: L10n.screenRecoveryKeyConfirmSuccess)
|
||||
parameters.navigationStackCoordinator?.setSheetCoordinator(nil)
|
||||
case .showResetKeyInfo:
|
||||
showResetRecoveryKeyScreen(navigationStackCoordinator: navigationStackCoordinator)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
@@ -105,4 +107,16 @@ final class SecureBackupScreenCoordinator: CoordinatorProtocol {
|
||||
iconName: "checkmark",
|
||||
persistent: false))
|
||||
}
|
||||
|
||||
private func showResetRecoveryKeyScreen(navigationStackCoordinator: NavigationStackCoordinator) {
|
||||
let coordinator = ResetRecoveryKeyScreenCoordinator()
|
||||
coordinator.actionsPublisher.sink { action in
|
||||
switch action {
|
||||
case .cancel:
|
||||
navigationStackCoordinator.setSheetCoordinator(nil)
|
||||
}
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
navigationStackCoordinator.setSheetCoordinator(coordinator)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user