mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-18 07:28:28 +02:00
Add AnalyticsPrompt to SwiftUI target and replace old UIAlertController.
This commit is contained in:
139
RiotSwiftUI/Modules/AnalyticsPrompt/View/AnalyticsPrompt.swift
Normal file
139
RiotSwiftUI/Modules/AnalyticsPrompt/View/AnalyticsPrompt.swift
Normal file
@@ -0,0 +1,139 @@
|
||||
// File created from SimpleUserProfileExample
|
||||
// $ createScreen.sh AnalyticsPrompt AnalyticsPrompt
|
||||
//
|
||||
// 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
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
/// A prompt that asks the user whether they would like to enable Analytics or not.
|
||||
struct AnalyticsPrompt: View {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@Environment(\.theme) private var theme
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@ObservedObject var viewModel: AnalyticsPromptViewModel.Context
|
||||
|
||||
// MARK: Views
|
||||
|
||||
/// The text that explains what analytics will do.
|
||||
private var descriptionText: some View {
|
||||
VStack {
|
||||
Text("\(viewModel.viewState.promptType.description)\n")
|
||||
|
||||
AnalyticsPromptTermsText(promptType: viewModel.viewState.promptType)
|
||||
.onTapGesture {
|
||||
viewModel.send(viewAction: .openTermsURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The list of re-assurances about analytics.
|
||||
private var checkmarkList: some View {
|
||||
VStack(alignment: .leading) {
|
||||
Label {
|
||||
Text(VectorL10n.analyticsPromptPoint1Start)
|
||||
+ Text(VectorL10n.analyticsPromptPoint1BoldedDont).font(theme.fonts.bodySB)
|
||||
+ Text(VectorL10n.analyticsPromptPoint1End)
|
||||
} icon: {
|
||||
Image(uiImage: Asset.Images.analyticsCheckmark.image)
|
||||
}
|
||||
|
||||
Label {
|
||||
Text(VectorL10n.analyticsPromptPoint2Start)
|
||||
+ Text(VectorL10n.analyticsPromptPoint2BoldedDont).font(theme.fonts.bodySB)
|
||||
+ Text(VectorL10n.analyticsPromptPoint2End)
|
||||
} icon: {
|
||||
Image(uiImage: Asset.Images.analyticsCheckmark.image)
|
||||
}
|
||||
|
||||
Label {
|
||||
Text(VectorL10n.analyticsPromptPoint3)
|
||||
} icon: {
|
||||
Image(uiImage: Asset.Images.analyticsCheckmark.image)
|
||||
}
|
||||
}
|
||||
.font(theme.fonts.body)
|
||||
}
|
||||
|
||||
/// The stack of enable/disable buttons.
|
||||
private var buttons: some View {
|
||||
VStack {
|
||||
Button { viewModel.send(viewAction: .enable) } label: {
|
||||
Text(viewModel.viewState.promptType.enableButtonTitle)
|
||||
.font(theme.fonts.bodySB)
|
||||
}
|
||||
.buttonStyle(PrimaryActionButtonStyle())
|
||||
.accessibilityIdentifier("enableButton")
|
||||
|
||||
Button { viewModel.send(viewAction: .disable) } label: {
|
||||
Text(viewModel.viewState.promptType.disableButtonTitle)
|
||||
.font(theme.fonts.bodySB)
|
||||
.foregroundColor(theme.colors.accent)
|
||||
}
|
||||
.buttonStyle(PrimaryActionButtonStyle(customColor: .clear))
|
||||
.accessibilityIdentifier("disableButton")
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
ScrollView(showsIndicators: false) {
|
||||
VStack {
|
||||
Image(uiImage: Asset.Images.analyticsLogo.image)
|
||||
.padding(.bottom, 25)
|
||||
|
||||
Text(VectorL10n.analyticsPromptTitle(viewModel.viewState.appDisplayName))
|
||||
.font(theme.fonts.title2B)
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
.padding(.bottom, 2)
|
||||
|
||||
descriptionText
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
.multilineTextAlignment(.center)
|
||||
|
||||
Divider()
|
||||
.background(theme.colors.quinaryContent)
|
||||
.padding(.vertical, 28)
|
||||
|
||||
checkmarkList
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
}
|
||||
.padding(.top, 50)
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
|
||||
buttons
|
||||
.padding(.horizontal, 16)
|
||||
}
|
||||
.background(theme.colors.background.ignoresSafeArea())
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct AnalyticsPrompt_Previews: PreviewProvider {
|
||||
static let stateRenderer = MockAnalyticsPromptScreenState.stateRenderer
|
||||
static var previews: some View {
|
||||
stateRenderer.screenGroup()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user