mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-18 15:38:28 +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:
@@ -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