Skip to content

Commit

Permalink
Update the recovery key field to match the designs.
Browse files Browse the repository at this point in the history
  • Loading branch information
pixlwave committed Dec 20, 2024
1 parent bdc8994 commit ceda817
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,15 @@ struct SecureBackupRecoveryKeyScreen: View {
.font(.compound.bodySMSemibold)
.padding(.leading, 16)

Group {
ZStack {
RecoveryKeyView(recoveryKey: "", isInvisibleForLayout: true) { }

if context.viewState.recoveryKey == nil {
if !context.viewState.isGeneratingKey {
Button(generateButtonTitle) {
context.send(viewAction: .generateKey)
}
.font(.compound.bodyLGSemibold)
.padding(.vertical, 11)
.accessibilityIdentifier(A11yIdentifiers.secureBackupRecoveryKeyScreen.generateRecoveryKey)
} else {
HStack(spacing: 8) {
Expand All @@ -150,23 +151,10 @@ struct SecureBackupRecoveryKeyScreen: View {
}
.font(.compound.bodyLGSemibold)
.foregroundStyle(.compound.textPrimary)
.padding(.vertical, 11)
}
} else {
HStack(spacing: 8) {
Text(context.viewState.recoveryKey ?? "")
.foregroundColor(.compound.textPrimary)
.font(.compound.bodyLG)
.frame(maxWidth: .infinity, alignment: .leading)

Button {
context.send(viewAction: .copyKey)
} label: {
CompoundIcon(\.copy)
}
.tint(.compound.iconSecondary)
.accessibilityLabel(L10n.actionCopy)
.accessibilityIdentifier(A11yIdentifiers.secureBackupRecoveryKeyScreen.copyRecoveryKey)
RecoveryKeyView(recoveryKey: context.viewState.recoveryKey ?? "") {
context.send(viewAction: .copyKey)
}
}
}
Expand Down Expand Up @@ -219,6 +207,35 @@ struct SecureBackupRecoveryKeyScreen: View {
}
}

private struct RecoveryKeyView: View {
/// The recovery key to show. This can be blank if `isInvisibleForLayout` is `true.`
let recoveryKey: String
/// Hides the view, laying it out with the expected key size so that the superview can have a consistent size.
var isInvisibleForLayout = false
/// The action performed when tapping the copy button.
let copyAction: () -> Void

private let placeholderRecoveryKey = "Text Text Text Text Text Text Text Text Text Text Text Text"

var body: some View {
HStack(spacing: 8) {
Text(isInvisibleForLayout ? placeholderRecoveryKey : recoveryKey)
.foregroundColor(.compound.textSecondary)
.font(.compound.bodyLG.monospaced())
.frame(maxWidth: .infinity, alignment: .leading)

Button(action: copyAction) {
CompoundIcon(\.copy)
}
.tint(.compound.iconSecondary)
.accessibilityLabel(L10n.actionCopy)
.accessibilityIdentifier(A11yIdentifiers.secureBackupRecoveryKeyScreen.copyRecoveryKey)
}
.opacity(isInvisibleForLayout ? 0 : 1)
.accessibilityHidden(isInvisibleForLayout)
}
}

// MARK: - Previews

struct SecureBackupRecoveryKeyScreen_Previews: PreviewProvider, TestablePreview {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ceda817

Please sign in to comment.