mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 00:52:43 +02:00
67df1a3e95
Merge commit 'af0b6d4be985d9f26e5111d3fa01389c7321949f' into feature/7276_FOSS_Merge_1_27_11 # Conflicts: # Config/AppVersion.xcconfig # Gemfile.lock # IDETemplateMacros.plist # Podfile # Podfile.lock # README.md # Riot/Modules/Authentication/AuthenticationCoordinator.swift # Riot/Modules/Room/CellData/RoomBubbleCellData.m # Riot/target.yml # RiotNSE/NotificationService.swift # RiotSwiftUI/Modules/Authentication/ServerSelection/AuthenticationServerSelectionModels.swift # RiotSwiftUI/Modules/Authentication/ServerSelection/AuthenticationServerSelectionViewModel.swift # RiotSwiftUI/Modules/Authentication/ServerSelection/Coordinator/AuthenticationServerSelectionCoordinator.swift # RiotSwiftUI/Modules/Authentication/ServerSelection/View/AuthenticationServerSelectionScreen.swift # RiotSwiftUI/Modules/Room/CompletionSuggestion/Service/CompletionSuggestionService.swift # fastlane/Fastfile
137 lines
5.5 KiB
Swift
137 lines
5.5 KiB
Swift
//
|
|
// Copyright 2021-2024 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
// Please see LICENSE files in the repository root for full details.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ChangePasswordScreen: View {
|
|
// MARK: - Properties
|
|
|
|
// MARK: Private
|
|
|
|
@Environment(\.theme) private var theme
|
|
|
|
enum Field { case oldPassword, newPassword1, newPassword2 }
|
|
@State private var focusedField: Field?
|
|
|
|
// MARK: Public
|
|
|
|
@ObservedObject var viewModel: ChangePasswordViewModel.Context
|
|
|
|
// MARK: Views
|
|
|
|
var body: some View {
|
|
ScrollView {
|
|
VStack(spacing: 0) {
|
|
header
|
|
.padding(.top, 16)
|
|
.padding(.bottom, 36)
|
|
form
|
|
}
|
|
.readableFrame()
|
|
.padding(.horizontal, 16)
|
|
}
|
|
.background(theme.colors.background.ignoresSafeArea())
|
|
.alert(item: $viewModel.alertInfo) { $0.alert }
|
|
.accentColor(theme.colors.accent)
|
|
}
|
|
|
|
/// The title and icon at the top of the screen.
|
|
var header: some View {
|
|
VStack(spacing: 8) {
|
|
OnboardingIconImage(image: Asset.Images.authenticationPasswordIcon)
|
|
.padding(.bottom, 16)
|
|
|
|
Text(VectorL10n.settingsChangePassword)
|
|
.font(theme.fonts.title2B)
|
|
.multilineTextAlignment(.center)
|
|
.foregroundColor(theme.colors.primaryContent)
|
|
.accessibilityIdentifier("titleLabel")
|
|
}
|
|
}
|
|
|
|
/// The text fields and submit button.
|
|
var form: some View {
|
|
VStack(alignment: .leading, spacing: 12) {
|
|
RoundedBorderTextField(placeHolder: BWIL10n.settingsOldPassword,
|
|
text: $viewModel.oldPassword,
|
|
isFirstResponder: focusedField == .oldPassword,
|
|
configuration: UIKitTextInputConfiguration(returnKeyType: .next,
|
|
isSecureTextEntry: true),
|
|
onCommit: { focusedField = .newPassword1 })
|
|
.accessibilityIdentifier("oldPasswordTextField")
|
|
|
|
RoundedBorderTextField(placeHolder: BWIL10n.settingsNewPassword,
|
|
text: $viewModel.newPassword1,
|
|
isFirstResponder: focusedField == .newPassword1,
|
|
configuration: UIKitTextInputConfiguration(returnKeyType: .next,
|
|
isSecureTextEntry: true),
|
|
onCommit: { focusedField = .newPassword2 })
|
|
.accessibilityIdentifier("newPasswordTextField1")
|
|
|
|
RoundedBorderTextField(placeHolder: BWIL10n.settingsConfirmPassword,
|
|
text: $viewModel.newPassword2,
|
|
isFirstResponder: focusedField == .newPassword2,
|
|
configuration: UIKitTextInputConfiguration(returnKeyType: .done,
|
|
isSecureTextEntry: true),
|
|
onCommit: submit)
|
|
.accessibilityIdentifier("newPasswordTextField2")
|
|
|
|
HStack(alignment: .center, spacing: 8) {
|
|
Toggle(VectorL10n.authenticationChoosePasswordSignoutAllDevices, isOn: $viewModel.signoutAllDevices)
|
|
.toggleStyle(AuthenticationTermsToggleStyle())
|
|
.accessibilityIdentifier("signoutAllDevicesToggle")
|
|
Text(VectorL10n.authenticationChoosePasswordSignoutAllDevices)
|
|
.foregroundColor(theme.colors.secondaryContent)
|
|
}
|
|
.onTapGesture(perform: toggleSignoutAllDevices)
|
|
.padding(.vertical, 8)
|
|
|
|
if BWIBuildSettings.shared.showPasswordRequirements {
|
|
Text(viewModel.viewState.passwordRequirements)
|
|
.font(theme.fonts.body)
|
|
.multilineTextAlignment(.leading)
|
|
.foregroundColor(theme.colors.secondaryContent)
|
|
.accessibilityIdentifier("passwordRequirementsLabel")
|
|
.padding(.top, 8)
|
|
.padding(.bottom, 16)
|
|
}
|
|
Button(action: submit) {
|
|
Text(VectorL10n.save)
|
|
// bwi: use buttonStyle font color
|
|
// .foregroundColor(Color(ThemeService.shared().theme.tintColor))
|
|
}
|
|
.buttonStyle(PrimaryActionButtonStyle())
|
|
.disabled(!viewModel.viewState.canSubmit)
|
|
.accessibilityIdentifier("submitButton")
|
|
}
|
|
}
|
|
|
|
/// Sends the `submit` view action if viewModel.viewState.canSubmit.
|
|
func submit() {
|
|
guard viewModel.viewState.canSubmit else { return }
|
|
viewModel.send(viewAction: .submit)
|
|
}
|
|
|
|
/// Sends the `toggleSignoutAllDevices` view action.
|
|
func toggleSignoutAllDevices() {
|
|
viewModel.send(viewAction: .toggleSignoutAllDevices)
|
|
}
|
|
}
|
|
|
|
// MARK: - Previews
|
|
|
|
struct ChangePasswordScreen_Previews: PreviewProvider {
|
|
static let stateRenderer = MockChangePasswordScreenState.stateRenderer
|
|
static var previews: some View {
|
|
stateRenderer.screenGroup(addNavigation: true)
|
|
.navigationViewStyle(.stack)
|
|
stateRenderer.screenGroup(addNavigation: true)
|
|
.navigationViewStyle(.stack)
|
|
.theme(.dark).preferredColorScheme(.dark)
|
|
}
|
|
}
|