Skip to content

Commit 6b15af1

Browse files
fix: various UI issues in Backup/Restore - WPB-16078 (#2550)
Co-authored-by: Christoph Aldrian <[email protected]>
1 parent 2db834d commit 6b15af1

File tree

90 files changed

+299
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+299
-243
lines changed

WireFoundation/Sources/WireFoundation/Design/WireAccentColor/WireAccentColor+Environment.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,3 @@ public extension EnvironmentValues {
2828
set { self[WireAccentColorKey.self] = newValue }
2929
}
3030
}
31-
32-
public extension View {
33-
func wireAccentColor(_ accentColor: WireAccentColor) -> some View {
34-
environment(\.wireAccentColor, accentColor)
35-
}
36-
}

WireUI/Sources/WireDesign/Buttons/UIButton.Configuration+ButtonStyles.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ public extension UIButton.Configuration {
2323

2424
static var primary: Self {
2525

26-
var configuration = shared
27-
configuration.baseBackgroundColor = ColorTheme.Buttons.Primary.enabled
28-
return configuration
29-
30-
}
31-
32-
private static var shared: Self {
33-
3426
var configuration = UIButton.Configuration.filled()
3527
configuration.buttonSize = .large
3628
configuration.titleTextAttributesTransformer = .init { attributeContainer in

WireUI/Sources/WireDesign/Colors/WireAccentColorMapping.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func WireAccentColorMappingPreview() -> some View {
6262
VStack {
6363
ForEach(WireAccentColor.allCases, id: \.self) { accentColor in
6464
MappingTestView()
65-
.wireAccentColor(accentColor)
65+
.environment(\.wireAccentColor, accentColor)
6666
if accentColor != WireAccentColor.allCases.last {
6767
Divider()
6868
}

WireUI/Sources/WireSettingsUI/Account/BackupImportExport/BackupImportExportBuilder.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
//
1818

1919
import SwiftUI
20+
import WireDesign
2021
import WireDomainPkg
22+
import WireFoundation
2123
import WireLogging
2224

2325
public struct BackupImportExportBuilder {
@@ -28,21 +30,27 @@ public struct BackupImportExportBuilder {
2830
let cleanUpBackupsUseCase: any CleanUpBackupsUseCaseProtocol
2931
let exportBackupLogger: any LoggerProtocol
3032
let importBackupLogger: any LoggerProtocol
33+
let wireAccentColor: WireAccentColor
34+
let wireAccentColorMapping: WireAccentColorMapping
3135

3236
public init(
3337
backupPasswordValidator: any BackupPasswordValidatorProtocol,
3438
createBackupUseCase: any CreateBackupUseCaseProtocol,
3539
importBackupUseCase: any ImportBackupUseCaseProtocol,
3640
cleanUpBackupsUseCase: any CleanUpBackupsUseCaseProtocol,
3741
exportBackupLogger: any LoggerProtocol,
38-
importBackupLogger: any LoggerProtocol
42+
importBackupLogger: any LoggerProtocol,
43+
wireAccentColorMapping: WireAccentColorMapping,
44+
wireAccentColor: WireAccentColor
3945
) {
4046
self.backupPasswordValidator = backupPasswordValidator
4147
self.createBackupUseCase = createBackupUseCase
4248
self.importBackupUseCase = importBackupUseCase
4349
self.cleanUpBackupsUseCase = cleanUpBackupsUseCase
4450
self.exportBackupLogger = exportBackupLogger
4551
self.importBackupLogger = importBackupLogger
52+
self.wireAccentColorMapping = wireAccentColorMapping
53+
self.wireAccentColor = wireAccentColor
4654
}
4755

4856
@MainActor
@@ -56,6 +64,8 @@ public struct BackupImportExportBuilder {
5664
buildExportBackupView()
5765
buildImportBackupView()
5866
}
67+
.environment(\.wireAccentColorMapping, wireAccentColorMapping)
68+
.environment(\.wireAccentColor, wireAccentColor)
5969
}
6070

6171
@MainActor @ViewBuilder
@@ -124,7 +134,9 @@ extension BackupImportExportBuilder {
124134
importBackupUseCase: PreviewImportBackupUseCase(),
125135
cleanUpBackupsUseCase: PreviewCleanUpBackupsUseCase(),
126136
exportBackupLogger: PreviewLogger(),
127-
importBackupLogger: PreviewLogger()
137+
importBackupLogger: PreviewLogger(),
138+
wireAccentColorMapping: WireAccentColorMapping(),
139+
wireAccentColor: .purple
128140
)
129141
}
130142
}

WireUI/Sources/WireSettingsUI/Account/BackupImportExport/Export/CreatingBackupProgressView/CreatingBackupProgressView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ struct CreatingBackupProgressView: View {
3636
.toolbar {
3737
ToolbarItem(placement: .topBarLeading) {
3838
Button(Strings.Cancel.title, action: cancelAction)
39-
.foregroundStyle(ColorTheme.Base.primary.color)
4039
.accessibilityLabel(Labels.Cancel.label)
4140
.accessibilityIdentifier("cancel")
4241
}
@@ -74,8 +73,10 @@ struct CreatingBackupProgressView: View {
7473

7574
#Preview("in progress") {
7675
CreatingBackupProgressPreview(.ongoing(0.25))
76+
.tint(Color.purple)
7777
}
7878

7979
#Preview("ready") {
8080
CreatingBackupProgressPreview(.finished(.init(fileURLWithPath: "/")))
81+
.tint(Color.purple)
8182
}

WireUI/Sources/WireSettingsUI/Account/BackupImportExport/Export/CreatingBackupProgressView/CreatingBackupProgressViewController.swift

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ final class CreatingBackupProgressViewController: UIViewController {
8484

8585
private lazy var progressView = {
8686
let progressView = UIProgressView()
87-
progressView.progressTintColor = ColorTheme.Base.primary
8887
progressView.accessibilityIdentifier = "progressView"
8988
return progressView
9089
}()
@@ -97,6 +96,10 @@ final class CreatingBackupProgressViewController: UIViewController {
9796
return exportButton
9897
}()
9998

99+
/// A view which is placed with the optimal bottom spacing.
100+
/// It's used for calculations of the optimal sheet presentation detent.
101+
private lazy var bottomSpacer = UIView()
102+
100103
// MARK: - Methods
101104

102105
override func viewDidLoad() {
@@ -123,7 +126,9 @@ final class CreatingBackupProgressViewController: UIViewController {
123126
stackView.translatesAutoresizingMaskIntoConstraints = false
124127
scrollView.addSubview(stackView)
125128

126-
// constraints
129+
bottomSpacer.translatesAutoresizingMaskIntoConstraints = false
130+
view.insertSubview(bottomSpacer, at: 0)
131+
127132
let svLayoutGuide = scrollView.contentLayoutGuide
128133
NSLayoutConstraint.activate([
129134

@@ -137,18 +142,30 @@ final class CreatingBackupProgressViewController: UIViewController {
137142
stackView.leadingAnchor.constraint(equalToSystemSpacingAfter: svLayoutGuide.leadingAnchor, multiplier: 3),
138143
stackView.topAnchor.constraint(equalToSystemSpacingBelow: svLayoutGuide.topAnchor, multiplier: 1),
139144
svLayoutGuide.trailingAnchor.constraint(equalToSystemSpacingAfter: stackView.trailingAnchor, multiplier: 3),
140-
svLayoutGuide.bottomAnchor.constraint(equalTo: stackView.bottomAnchor)
145+
svLayoutGuide.bottomAnchor.constraint(equalTo: stackView.bottomAnchor),
146+
147+
bottomSpacer.heightAnchor.constraint(equalToConstant: 0),
148+
bottomSpacer.widthAnchor.constraint(equalToConstant: 0),
149+
bottomSpacer.centerXAnchor.constraint(equalTo: view.centerXAnchor),
150+
view.bottomAnchor.constraint(equalToSystemSpacingBelow: bottomSpacer.bottomAnchor, multiplier: 3)
141151

142152
])
143153

154+
bottomSpacer.backgroundColor = .red
155+
144156
}
145157

146158
override func viewDidLayoutSubviews() {
147159
super.viewDidLayoutSubviews()
148160

149-
let stackViewHeight = stackView.frame.maxY + (navigationController?.navigationBar.frame.height ?? 0)
150-
if let sheetPresentationController = navigationController?.sheetPresentationController {
151-
sheetPresentationController.detents = [.custom { _ in stackViewHeight }]
161+
guard let navigationController else { return }
162+
163+
let topSpace = navigationController.view.convert(stackView.bounds, from: stackView).minY
164+
let stackViewHeight = stackView.frame.height
165+
let bottomSpace = view.bounds.maxY - bottomSpacer.frame.maxY
166+
let detent = topSpace + stackViewHeight + bottomSpace
167+
if let sheetPresentationController = navigationController.sheetPresentationController {
168+
sheetPresentationController.detents = [.custom { _ in detent }]
152169
}
153170
}
154171

WireUI/Sources/WireSettingsUI/Account/BackupImportExport/Export/SetBackupBasswordView/SetBackupPasswordView.swift

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@
1818

1919
import SwiftUI
2020
import WireDesign
21+
import WireFoundation
2122

2223
struct SetBackupPasswordView: View {
2324

2425
@StateObject var viewModel: SetBackupPasswordViewModel
2526

27+
@Environment(\.wireAccentColor) private var wireAccentColor
28+
@Environment(\.wireAccentColorMapping) private var wireAccentColorMapping
29+
2630
private typealias Strings = L10n.Localizable
2731
private typealias Labels = L10n.Accessibility.ExportBackup
2832

@@ -36,7 +40,6 @@ struct SetBackupPasswordView: View {
3640
.toolbar {
3741
ToolbarItem(placement: .topBarLeading) {
3842
Button(Strings.ExportBackup.Cancel.title, action: viewModel.cancel)
39-
.foregroundStyle(ColorTheme.Base.primary.color)
4043
.accessibilityLabel(Labels.Cancel.label)
4144
.accessibilityIdentifier("cancel")
4245
}
@@ -68,36 +71,37 @@ struct SetBackupPasswordView: View {
6871
@ViewBuilder
6972
private func scrollViewContent() -> some View {
7073
VStack(alignment: .leading, spacing: 0) {
71-
Spacer()
7274

7375
Text(Strings.ExportBackup.description)
7476
.font(.body)
7577
.padding(.bottom, 28)
7678

77-
Text(Strings.ExportBackup.SetBackupPassword.title)
78-
.foregroundStyle(passwordFieldTitleColor)
79-
.font(.subheadline)
80-
.padding(.bottom, 2)
81-
82-
ToggleablePasswordField(
83-
password: $viewModel.password,
84-
placeholder: Strings.ExportBackup.SetBackupPassword.placeholder,
85-
placeholderColor: passwordFieldPlaceholderColor,
86-
borderColor: passwordFieldBorderColor,
87-
focusOnAppear: true
88-
)
89-
.padding(.bottom, 8)
79+
passwordField
80+
.padding(.bottom, 8)
9081

91-
Text(viewModel.localizedPasswordRules)
92-
.foregroundStyle(passwordFooterColor)
93-
.font(.caption)
82+
footer
9483

95-
Spacer()
9684
}
9785
.padding()
9886
}
9987

100-
// TODO: [WPB-16061] the following code is almost identical to the one in EnterPasswordView.swift, try to reuse
88+
// TODO: [WPB-16061] the following code is similar to the one in EnterPasswordView.swift, try to reuse
89+
90+
@ViewBuilder private var passwordField: some View {
91+
92+
Text(Strings.ExportBackup.SetBackupPassword.title)
93+
.foregroundStyle(passwordFieldTitleColor)
94+
.font(.subheadline)
95+
.padding(.bottom, 2)
96+
97+
ToggleablePasswordField(
98+
password: $viewModel.password,
99+
placeholder: Strings.ExportBackup.SetBackupPassword.placeholder,
100+
placeholderColor: passwordFieldPlaceholderColor,
101+
focusOnAppear: true
102+
)
103+
.tint(passwordFieldBorderColor)
104+
}
101105

102106
private var passwordFieldTitleColor: Color {
103107
if !viewModel.isPasswordValid {
@@ -108,7 +112,7 @@ struct SetBackupPasswordView: View {
108112
: BaseColorPalette.Grays.gray40
109113
}.color
110114
} else {
111-
ColorTheme.Base.primary.color
115+
wireAccentColorMapping?.color(for: wireAccentColor) ?? ColorTheme.Base.primary.color
112116
}
113117
}
114118

@@ -121,7 +125,7 @@ struct SetBackupPasswordView: View {
121125
: BaseColorPalette.Grays.gray60
122126
}.color
123127
} else {
124-
ColorTheme.Base.primary.color
128+
wireAccentColorMapping?.color(for: wireAccentColor) ?? ColorTheme.Base.primary.color
125129
}
126130
}
127131

@@ -134,23 +138,35 @@ struct SetBackupPasswordView: View {
134138
: BaseColorPalette.Grays.gray80
135139
}.color
136140
} else {
137-
ColorTheme.Base.primary.color
141+
wireAccentColorMapping?.color(for: wireAccentColor) ?? ColorTheme.Base.primary.color
138142
}
139143
}
140144

141-
private var passwordFooterColor: Color {
145+
@ViewBuilder private var footer: some View {
146+
147+
let footer = Text(viewModel.localizedPasswordRules)
148+
.font(.caption)
149+
142150
if !viewModel.isPasswordValid {
143-
ColorTheme.Base.error.color
151+
152+
footer
153+
.foregroundStyle(ColorTheme.Base.error.color)
154+
144155
} else {
145-
UIColor { $0.userInterfaceStyle != .dark
156+
157+
let footerColor = UIColor { $0.userInterfaceStyle != .dark
146158
? BaseColorPalette.Grays.gray70
147159
: BaseColorPalette.Grays.gray40
148-
}.color
160+
}
161+
footer
162+
.foregroundStyle(footerColor.color)
163+
149164
}
150165
}
151166

152167
}
153168

154169
#Preview {
155170
SetBackupPasswordPreview()
171+
.tint(.purple)
156172
}

WireUI/Sources/WireSettingsUI/Account/BackupImportExport/Import/EnterPasswordView/EnterPasswordView.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ struct EnterPasswordView: View {
2727
let continueAction: (_ password: String) -> Void
2828
let cancelAction: () -> Void
2929

30+
@Environment(\.wireAccentColor) private var wireAccentColor
31+
@Environment(\.wireAccentColorMapping) private var wireAccentColorMapping
32+
3033
private typealias Strings = L10n.Localizable.ImportBackup
3134
private typealias Labels = L10n.Accessibility.ImportBackup
3235

@@ -39,7 +42,6 @@ struct EnterPasswordView: View {
3942
.toolbar {
4043
ToolbarItem(placement: .topBarLeading) {
4144
Button(Strings.Cancel.title, action: cancelAction)
42-
.foregroundStyle(ColorTheme.Base.primary.color)
4345
.accessibilityLabel(Labels.Cancel.label)
4446
.accessibilityIdentifier("cancel")
4547
}
@@ -87,14 +89,14 @@ struct EnterPasswordView: View {
8789
password: $password,
8890
placeholder: Strings.EnterPassword.TextField.placeholder,
8991
placeholderColor: passwordFieldPlaceholderColor,
90-
borderColor: passwordFieldBorderColor,
9192
focusOnAppear: true
9293
)
94+
.tint(passwordFieldBorderColor)
9395
.padding(.bottom, 8)
9496

9597
if passwordIsWrong {
9698
Text(Strings.EnterPassword.wrongPassword)
97-
.foregroundStyle(passwordFieldTitleColor)
99+
.foregroundStyle(passwordFooterColor)
98100
.font(.caption)
99101
}
100102

@@ -112,7 +114,7 @@ struct EnterPasswordView: View {
112114
: BaseColorPalette.Grays.gray40
113115
}.color
114116
} else {
115-
ColorTheme.Base.primary.color
117+
wireAccentColorMapping?.color(for: wireAccentColor) ?? ColorTheme.Base.primary.color
116118
}
117119
}
118120

@@ -125,7 +127,7 @@ struct EnterPasswordView: View {
125127
: BaseColorPalette.Grays.gray60
126128
}.color
127129
} else {
128-
ColorTheme.Base.primary.color
130+
wireAccentColorMapping?.color(for: wireAccentColor) ?? ColorTheme.Base.primary.color
129131
}
130132
}
131133

@@ -138,7 +140,7 @@ struct EnterPasswordView: View {
138140
: BaseColorPalette.Grays.gray80
139141
}.color
140142
} else {
141-
ColorTheme.Base.primary.color
143+
wireAccentColorMapping?.color(for: wireAccentColor) ?? ColorTheme.Base.primary.color
142144
}
143145
}
144146

WireUI/Sources/WireSettingsUI/Account/BackupImportExport/Import/ImportBackupViewModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ final class ImportBackupViewModel: ObservableObject {
119119
importTask?.cancel()
120120
importTask = Task {
121121
do {
122+
backupPassword = password
122123
state = .importingBackup(progress: 0)
123124
for try await update in importBackupUseCase.invoke(url: url, password: password) {
124125
switch update {

WireUI/Sources/WireSettingsUI/Account/BackupImportExport/Import/ImportProgressView/ImportProgressView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ struct ImportProgressView: View {
3838
Button(action: cancelAction) {
3939
Text(Strings.Cancel.title)
4040
}
41-
.foregroundStyle(ColorTheme.Base.primary.color)
4241
.accessibilityLabel(Labels.Cancel.label)
4342
.accessibilityIdentifier("cancel")
4443
}

0 commit comments

Comments
 (0)