92 lines
2.9 KiB
Swift
92 lines
2.9 KiB
Swift
//
|
|
// Copyright 2022-2024 New Vector Ltd.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
// Please see LICENSE in the repository root for full details.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
/// The form shown to enter an email address.
|
|
struct AuthenticationVerifyMsisdnForm: View {
|
|
// MARK: - Properties
|
|
|
|
// MARK: Private
|
|
|
|
@Environment(\.theme) private var theme
|
|
|
|
@State private var isEditingTextField = false
|
|
|
|
// MARK: Public
|
|
|
|
@ObservedObject var viewModel: AuthenticationVerifyMsisdnViewModel.Context
|
|
|
|
// MARK: Views
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
header
|
|
.padding(.top, OnboardingMetrics.topPaddingToNavigationBar)
|
|
.padding(.bottom, 36)
|
|
|
|
mainContent
|
|
}
|
|
}
|
|
|
|
/// The title, message and icon at the top of the screen.
|
|
var header: some View {
|
|
VStack(spacing: 8) {
|
|
OnboardingIconImage(image: Asset.Images.authenticationMsisdnIcon)
|
|
.padding(.bottom, 8)
|
|
|
|
Text(VectorL10n.authenticationVerifyMsisdnInputTitle)
|
|
.font(theme.fonts.title2B)
|
|
.multilineTextAlignment(.center)
|
|
.foregroundColor(theme.colors.primaryContent)
|
|
.accessibilityIdentifier("titleLabel")
|
|
|
|
Text(viewModel.viewState.formHeaderMessage)
|
|
.font(theme.fonts.body)
|
|
.multilineTextAlignment(.center)
|
|
.foregroundColor(theme.colors.secondaryContent)
|
|
.accessibilityIdentifier("messageLabel")
|
|
}
|
|
}
|
|
|
|
/// The text field and submit button where the user enters a phone number.
|
|
var mainContent: some View {
|
|
VStack(alignment: .leading, spacing: 12) {
|
|
if #available(iOS 15.0, *) {
|
|
textField
|
|
.onSubmit(sendSMS)
|
|
} else {
|
|
textField
|
|
}
|
|
|
|
Button(action: sendSMS) {
|
|
Text(VectorL10n.next)
|
|
}
|
|
.buttonStyle(PrimaryActionButtonStyle())
|
|
.disabled(viewModel.viewState.hasInvalidPhoneNumber)
|
|
.accessibilityIdentifier("nextButton")
|
|
}
|
|
}
|
|
|
|
/// The text field, extracted for iOS 15 modifiers to be applied.
|
|
var textField: some View {
|
|
TextField(VectorL10n.authenticationVerifyMsisdnTextFieldPlaceholder, text: $viewModel.phoneNumber) {
|
|
isEditingTextField = $0
|
|
}
|
|
.textFieldStyle(BorderedInputFieldStyle(isEditing: isEditingTextField, isError: false))
|
|
.keyboardType(.phonePad)
|
|
.disableAutocorrection(true)
|
|
.accessibilityIdentifier("phoneNumberTextField")
|
|
}
|
|
|
|
/// Sends the `send` view action so long as a valid phone number has been input.
|
|
func sendSMS() {
|
|
guard !viewModel.viewState.hasInvalidPhoneNumber else { return }
|
|
viewModel.send(viewAction: .send)
|
|
}
|
|
}
|