element-ios/RiotSwiftUI/Modules/Authentication/ReCaptcha/View/AuthenticationReCaptchaScreen.swift
Doug b9b4d18124 Add Email/Terms/ReCaptcha into the Authentication flow
Replace ReCaptcha navigation delegate with a WKUserContentController.
Move callback property closures onto the MainActor.
Show a loading indicator whilst waiting for the authentication service to start.
Move nextUncompletedStage into FlowResult.
Handle text field actions during authentication.
Remove scroll view tweaks in server selection screen following EMS banner removal.
2022-05-19 11:43:38 +01:00

107 lines
3.6 KiB
Swift

//
// Copyright 2021 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 SwiftUI
struct AuthenticationReCaptchaScreen: View {
// MARK: - Properties
// MARK: Private
@Environment(\.theme) private var theme
@State private var isLoading = false
// MARK: Public
@ObservedObject var viewModel: AuthenticationReCaptchaViewModel.Context
// MARK: Views
var body: some View {
GeometryReader { geometry in
ScrollView {
VStack(spacing: 40) {
header
.padding(.top, OnboardingMetrics.topPaddingToNavigationBar)
.padding(.horizontal, 16)
.fixedSize(horizontal: false, vertical: true)
recaptcha
.frame(minHeight: 500)
}
.readableFrame()
.frame(minHeight: geometry.size.height)
.ignoresSafeArea(.all, edges: .bottom)
}
}
.navigationBarTitleDisplayMode(.inline)
.background(theme.colors.background.ignoresSafeArea())
.toolbar { toolbar }
.alert(item: $viewModel.alertInfo) { $0.alert }
.accentColor(theme.colors.accent)
}
/// The header containing the icon, title and message.
var header: some View {
VStack(spacing: 8) {
OnboardingIconImage(image: Asset.Images.onboardingCongratulationsIcon)
.padding(.bottom, 8)
Text(VectorL10n.authenticationRegistrationTitle)
.font(theme.fonts.title2B)
.multilineTextAlignment(.center)
.foregroundColor(theme.colors.primaryContent)
Text(VectorL10n.authenticationRecaptchaMessage)
.font(theme.fonts.body)
.multilineTextAlignment(.center)
.foregroundColor(theme.colors.secondaryContent)
}
}
/// The web view that shows the ReCaptcha to the user.
var recaptcha: some View {
AuthenticationRecaptchaWebView(siteKey: viewModel.viewState.siteKey,
homeserverURL: viewModel.viewState.homeserverURL,
isLoading: $isLoading) { response in
viewModel.send(viewAction: .validate(response))
}
}
/// A simple toolbar with a cancel button.
var toolbar: some ToolbarContent {
ToolbarItem(placement: .cancellationAction) {
Button(VectorL10n.cancel) {
viewModel.send(viewAction: .cancel)
}
}
}
}
// MARK: - Previews
struct AuthenticationReCaptcha_Previews: PreviewProvider {
static let stateRenderer = MockAuthenticationReCaptchaScreenState.stateRenderer
static var previews: some View {
stateRenderer.screenGroup(addNavigation: true)
.navigationViewStyle(.stack)
stateRenderer.screenGroup(addNavigation: true)
.navigationViewStyle(.stack)
.theme(.dark).preferredColorScheme(.dark)
}
}