2021-12-06 12:52:33 +00:00
|
|
|
// 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")
|
|
|
|
|
2021-12-07 12:09:26 +00:00
|
|
|
AnalyticsPromptTermsText(attributedString: viewModel.viewState.promptType.termsStrings)
|
2021-12-08 12:00:23 +00:00
|
|
|
.accessibilityLabel(Text(viewModel.viewState.promptType.termsStrings.string))
|
|
|
|
.accessibilityValue(Text(VectorL10n.accessibilityButtonLabel))
|
2021-12-06 12:52:33 +00:00
|
|
|
.onTapGesture {
|
|
|
|
viewModel.send(viewAction: .openTermsURL)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The list of re-assurances about analytics.
|
|
|
|
private var checkmarkList: some View {
|
|
|
|
VStack(alignment: .leading) {
|
2021-12-07 12:09:26 +00:00
|
|
|
AnalyticsPromptCheckmarkItem(attributedString: viewModel.viewState.strings.point1)
|
2021-12-08 12:00:23 +00:00
|
|
|
.accessibilityLabel(Text(viewModel.viewState.strings.point1.string))
|
|
|
|
|
2021-12-07 12:09:26 +00:00
|
|
|
AnalyticsPromptCheckmarkItem(attributedString: viewModel.viewState.strings.point2)
|
2021-12-08 12:00:23 +00:00
|
|
|
.accessibilityLabel(Text(viewModel.viewState.strings.point2.string))
|
|
|
|
|
2021-12-07 12:09:26 +00:00
|
|
|
AnalyticsPromptCheckmarkItem(string: VectorL10n.analyticsPromptPoint3)
|
2021-12-06 12:52:33 +00:00
|
|
|
}
|
|
|
|
.font(theme.fonts.body)
|
2021-12-08 12:00:23 +00:00
|
|
|
.frame(maxWidth: .infinity)
|
2021-12-06 12:52:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// 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)
|
|
|
|
|
2021-12-07 12:09:26 +00:00
|
|
|
Text(VectorL10n.analyticsPromptTitle(viewModel.viewState.strings.appDisplayName))
|
2021-12-06 12:52:33 +00:00
|
|
|
.font(theme.fonts.title2B)
|
|
|
|
.foregroundColor(theme.colors.primaryContent)
|
|
|
|
.padding(.bottom, 2)
|
|
|
|
|
|
|
|
descriptionText
|
2021-12-08 12:00:23 +00:00
|
|
|
.font(theme.fonts.body)
|
2021-12-06 12:52:33 +00:00
|
|
|
.foregroundColor(theme.colors.secondaryContent)
|
|
|
|
.multilineTextAlignment(.center)
|
|
|
|
|
|
|
|
Divider()
|
|
|
|
.background(theme.colors.quinaryContent)
|
|
|
|
.padding(.vertical, 28)
|
|
|
|
|
|
|
|
checkmarkList
|
|
|
|
.foregroundColor(theme.colors.secondaryContent)
|
2021-12-07 12:09:26 +00:00
|
|
|
.padding(.bottom, 16)
|
2021-12-06 12:52:33 +00:00
|
|
|
}
|
|
|
|
.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()
|
|
|
|
}
|
|
|
|
}
|