mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 09:02:44 +02:00
Support link/html in analytics prompt strings.
Show the new prompt to everyone, even if they previously opted out. Add docs to Analytics.
This commit is contained in:
@@ -39,7 +39,7 @@ struct AnalyticsPrompt: View {
|
||||
VStack {
|
||||
Text("\(viewModel.viewState.promptType.description)\n")
|
||||
|
||||
AnalyticsPromptTermsText(promptType: viewModel.viewState.promptType)
|
||||
AnalyticsPromptTermsText(attributedString: viewModel.viewState.promptType.termsStrings)
|
||||
.onTapGesture {
|
||||
viewModel.send(viewAction: .openTermsURL)
|
||||
}
|
||||
@@ -49,27 +49,9 @@ struct AnalyticsPrompt: View {
|
||||
/// 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)
|
||||
}
|
||||
AnalyticsPromptCheckmarkItem(attributedString: viewModel.viewState.strings.point1)
|
||||
AnalyticsPromptCheckmarkItem(attributedString: viewModel.viewState.strings.point2)
|
||||
AnalyticsPromptCheckmarkItem(string: VectorL10n.analyticsPromptPoint3)
|
||||
}
|
||||
.font(theme.fonts.body)
|
||||
}
|
||||
@@ -101,7 +83,7 @@ struct AnalyticsPrompt: View {
|
||||
Image(uiImage: Asset.Images.analyticsLogo.image)
|
||||
.padding(.bottom, 25)
|
||||
|
||||
Text(VectorL10n.analyticsPromptTitle(viewModel.viewState.appDisplayName))
|
||||
Text(VectorL10n.analyticsPromptTitle(viewModel.viewState.strings.appDisplayName))
|
||||
.font(theme.fonts.title2B)
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
.padding(.bottom, 2)
|
||||
@@ -116,6 +98,7 @@ struct AnalyticsPrompt: View {
|
||||
|
||||
checkmarkList
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
.padding(.bottom, 16)
|
||||
}
|
||||
.padding(.top, 50)
|
||||
.padding(.horizontal, 16)
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// 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, *)
|
||||
struct AnalyticsPromptCheckmarkItem: View {
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@Environment(\.theme) private var theme
|
||||
|
||||
/// A string with a bold property.
|
||||
private struct StringComponent {
|
||||
let string: String
|
||||
let isBold: Bool
|
||||
}
|
||||
|
||||
/// Internal representation of the string as composable parts.
|
||||
private let components: [StringComponent]
|
||||
|
||||
// MARK: - Setup
|
||||
|
||||
init(attributedString: NSAttributedString) {
|
||||
var components = [StringComponent]()
|
||||
let range = NSRange(location: 0, length: attributedString.length)
|
||||
let string = attributedString.string as NSString
|
||||
|
||||
attributedString.enumerateAttributes(in: range, options: []) { attributes, range, stop in
|
||||
var isBold = false
|
||||
|
||||
if let font = attributes[.font] as? UIFont {
|
||||
isBold = font.fontDescriptor.symbolicTraits.contains(.traitBold)
|
||||
}
|
||||
|
||||
components.append(StringComponent(string: string.substring(with: range), isBold: isBold))
|
||||
}
|
||||
|
||||
self.components = components
|
||||
}
|
||||
|
||||
init(string: String) {
|
||||
self.components = [StringComponent(string: string, isBold: false)]
|
||||
}
|
||||
|
||||
// MARK: - Views
|
||||
|
||||
var label: Text {
|
||||
components.reduce(Text("")) {
|
||||
$0 + Text($1.string).font($1.isBold ? theme.fonts.bodySB : theme.fonts.body)
|
||||
}
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Label { label } icon: {
|
||||
Image(uiImage: Asset.Images.analyticsCheckmark.image)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
@available(iOS 14.0, *)
|
||||
struct AnalyticsPromptCheckmarkItem_Previews: PreviewProvider {
|
||||
|
||||
static let strings = MockAnalyticsPromptStrings()
|
||||
|
||||
static var previews: some View {
|
||||
VStack(alignment:.leading) {
|
||||
AnalyticsPromptCheckmarkItem(attributedString: strings.point1)
|
||||
AnalyticsPromptCheckmarkItem(attributedString: strings.point2)
|
||||
AnalyticsPromptCheckmarkItem(attributedString: strings.longString)
|
||||
AnalyticsPromptCheckmarkItem(attributedString: strings.shortString)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
@@ -26,17 +26,49 @@ struct AnalyticsPromptTermsText: View {
|
||||
|
||||
@Environment(\.theme) private var theme
|
||||
|
||||
// MARK: Public
|
||||
/// A string with a link attribute.
|
||||
private struct StringComponent {
|
||||
let string: String
|
||||
let isLink: Bool
|
||||
}
|
||||
|
||||
let promptType: AnalyticsPromptType
|
||||
/// Internal representation of the string as composable parts.
|
||||
private let components: [StringComponent]
|
||||
|
||||
// MARK: Views
|
||||
// MARK: - Setup
|
||||
|
||||
init(attributedString: NSAttributedString) {
|
||||
var components = [StringComponent]()
|
||||
let range = NSRange(location: 0, length: attributedString.length)
|
||||
let string = attributedString.string as NSString
|
||||
|
||||
attributedString.enumerateAttributes(in: range, options: []) { attributes, range, stop in
|
||||
let isLink = attributes.keys.contains(.analyticsPromptTermsTextLink)
|
||||
components.append(StringComponent(string: string.substring(with: range), isLink: isLink))
|
||||
}
|
||||
|
||||
self.components = components
|
||||
}
|
||||
|
||||
// MARK: - Views
|
||||
|
||||
var body: some View {
|
||||
let (start, link, end) = promptType.termsStrings
|
||||
|
||||
Text(start)
|
||||
+ Text(link).foregroundColor(theme.colors.accent)
|
||||
+ Text(end)
|
||||
components.reduce(Text("")) {
|
||||
$0 + Text($1.string).foregroundColor($1.isLink ? theme.colors.accent : nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
@available(iOS 14.0, *)
|
||||
struct AnalyticsPromptTermsText_Previews: PreviewProvider {
|
||||
|
||||
static let strings = MockAnalyticsPromptStrings()
|
||||
|
||||
static var previews: some View {
|
||||
VStack(spacing: 8) {
|
||||
AnalyticsPromptTermsText(attributedString: strings.termsNewUser)
|
||||
AnalyticsPromptTermsText(attributedString: strings.termsUpgrade)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user