From c9d97c10d04d623875452b2279faf13a7bf6f5e4 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 16 Aug 2023 13:43:33 +1000 Subject: [PATCH] WIP: landing screen (attributed text) --- Session.xcodeproj/project.pbxproj | 4 ++ .../Translations/de.lproj/Localizable.strings | 3 ++ .../Translations/en.lproj/Localizable.strings | 3 ++ .../Translations/es.lproj/Localizable.strings | 3 ++ .../Translations/fa.lproj/Localizable.strings | 3 ++ .../Translations/fi.lproj/Localizable.strings | 3 ++ .../Translations/fr.lproj/Localizable.strings | 3 ++ .../Translations/hi.lproj/Localizable.strings | 3 ++ .../Translations/hr.lproj/Localizable.strings | 3 ++ .../id-ID.lproj/Localizable.strings | 3 ++ .../Translations/it.lproj/Localizable.strings | 3 ++ .../Translations/ja.lproj/Localizable.strings | 3 ++ .../Translations/nl.lproj/Localizable.strings | 3 ++ .../Translations/pl.lproj/Localizable.strings | 3 ++ .../pt_BR.lproj/Localizable.strings | 3 ++ .../Translations/ru.lproj/Localizable.strings | 3 ++ .../Translations/si.lproj/Localizable.strings | 3 ++ .../Translations/sk.lproj/Localizable.strings | 3 ++ .../Translations/sv.lproj/Localizable.strings | 3 ++ .../Translations/th.lproj/Localizable.strings | 3 ++ .../vi-VN.lproj/Localizable.strings | 3 ++ .../zh-Hant.lproj/Localizable.strings | 3 ++ .../zh_CN.lproj/Localizable.strings | 3 ++ Session/Onboarding/LandingView.swift | 19 ++++++-- .../Shared/SessionHostingViewController.swift | 23 ++++++++++ SessionUIKit/Components/AttributedText.swift | 46 +++++++++++++++++++ .../Style Guide/Themes/SwiftUI+Theme.swift | 12 +++++ 27 files changed, 167 insertions(+), 3 deletions(-) create mode 100644 SessionUIKit/Components/AttributedText.swift diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 6e5a8f895..3a43923a5 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -159,6 +159,7 @@ 7BDCFC08242186E700641C39 /* NotificationServiceExtensionContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDCFC07242186E700641C39 /* NotificationServiceExtensionContext.swift */; }; 7BDCFC0B2421EB7600641C39 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = B6F509951AA53F760068F56A /* Localizable.strings */; }; 7BDE2A982A8B122900AE4393 /* LandingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDE2A972A8B122900AE4393 /* LandingView.swift */; }; + 7BDE2A9A2A8C59CF00AE4393 /* AttributedText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BDE2A992A8C59CF00AE4393 /* AttributedText.swift */; }; 7BF8D1FB2A70AF57005F1D6E /* SwiftUI+Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BF8D1FA2A70AF57005F1D6E /* SwiftUI+Theme.swift */; }; 7BFA8AE32831D0D4001876F3 /* ContextMenuVC+EmojiReactsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BFA8AE22831D0D4001876F3 /* ContextMenuVC+EmojiReactsView.swift */; }; 7BFD1A8A2745C4F000FB91B9 /* Permissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BFD1A892745C4F000FB91B9 /* Permissions.swift */; }; @@ -1274,6 +1275,7 @@ 7BDCFC0424206E7300641C39 /* SessionNotificationServiceExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SessionNotificationServiceExtension.entitlements; sourceTree = ""; }; 7BDCFC07242186E700641C39 /* NotificationServiceExtensionContext.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationServiceExtensionContext.swift; sourceTree = ""; }; 7BDE2A972A8B122900AE4393 /* LandingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LandingView.swift; sourceTree = ""; }; + 7BDE2A992A8C59CF00AE4393 /* AttributedText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributedText.swift; sourceTree = ""; }; 7BE2701D2A64C11500CEB71A /* SessionCarouselView+SwiftUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SessionCarouselView+SwiftUI.swift"; sourceTree = ""; }; 7BF8D1FA2A70AF57005F1D6E /* SwiftUI+Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SwiftUI+Theme.swift"; sourceTree = ""; }; 7BFA8AE22831D0D4001876F3 /* ContextMenuVC+EmojiReactsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ContextMenuVC+EmojiReactsView.swift"; sourceTree = ""; }; @@ -2946,6 +2948,7 @@ C38EF2A4255B6D93007E1867 /* ProfilePictureView.swift */, FD71165A28E6DDBC00B47552 /* StyledNavigationController.swift */, FD0B77AF29B69A65009169BA /* TopBannerController.swift */, + 7BDE2A992A8C59CF00AE4393 /* AttributedText.swift */, ); path = Components; sourceTree = ""; @@ -5491,6 +5494,7 @@ FD37EA0128A60473003AE748 /* UIKit+Theme.swift in Sources */, FD37E9CF28A1EB1B003AE748 /* Theme.swift in Sources */, C331FFB92558FA8D00070591 /* UIView+Constraints.swift in Sources */, + 7BDE2A9A2A8C59CF00AE4393 /* AttributedText.swift in Sources */, FD0B77B029B69A65009169BA /* TopBannerController.swift in Sources */, FD37E9F628A5F106003AE748 /* Configuration.swift in Sources */, 7BF8D1FB2A70AF57005F1D6E /* SwiftUI+Theme.swift in Sources */, diff --git a/Session/Meta/Translations/de.lproj/Localizable.strings b/Session/Meta/Translations/de.lproj/Localizable.strings index d302b4f14..67d906f4d 100644 --- a/Session/Meta/Translations/de.lproj/Localizable.strings +++ b/Session/Meta/Translations/de.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index 5da6cb25e..a5fadd666 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/es.lproj/Localizable.strings b/Session/Meta/Translations/es.lproj/Localizable.strings index 7c99f276a..024e2bb0f 100644 --- a/Session/Meta/Translations/es.lproj/Localizable.strings +++ b/Session/Meta/Translations/es.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/fa.lproj/Localizable.strings b/Session/Meta/Translations/fa.lproj/Localizable.strings index 13e988207..c1b458aa9 100644 --- a/Session/Meta/Translations/fa.lproj/Localizable.strings +++ b/Session/Meta/Translations/fa.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/fi.lproj/Localizable.strings b/Session/Meta/Translations/fi.lproj/Localizable.strings index 90029c8ee..bc712f34e 100644 --- a/Session/Meta/Translations/fi.lproj/Localizable.strings +++ b/Session/Meta/Translations/fi.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/fr.lproj/Localizable.strings b/Session/Meta/Translations/fr.lproj/Localizable.strings index 2bcad1d08..2a5a00f1b 100644 --- a/Session/Meta/Translations/fr.lproj/Localizable.strings +++ b/Session/Meta/Translations/fr.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/hi.lproj/Localizable.strings b/Session/Meta/Translations/hi.lproj/Localizable.strings index f133434de..2605a045f 100644 --- a/Session/Meta/Translations/hi.lproj/Localizable.strings +++ b/Session/Meta/Translations/hi.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/hr.lproj/Localizable.strings b/Session/Meta/Translations/hr.lproj/Localizable.strings index 9e584ec6c..e2bd15c9c 100644 --- a/Session/Meta/Translations/hr.lproj/Localizable.strings +++ b/Session/Meta/Translations/hr.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/id-ID.lproj/Localizable.strings b/Session/Meta/Translations/id-ID.lproj/Localizable.strings index 81f4b80f3..919365412 100644 --- a/Session/Meta/Translations/id-ID.lproj/Localizable.strings +++ b/Session/Meta/Translations/id-ID.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/it.lproj/Localizable.strings b/Session/Meta/Translations/it.lproj/Localizable.strings index ce9d39d78..e77b1ed97 100644 --- a/Session/Meta/Translations/it.lproj/Localizable.strings +++ b/Session/Meta/Translations/it.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/ja.lproj/Localizable.strings b/Session/Meta/Translations/ja.lproj/Localizable.strings index c9b0b6d2b..c927b609c 100644 --- a/Session/Meta/Translations/ja.lproj/Localizable.strings +++ b/Session/Meta/Translations/ja.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/nl.lproj/Localizable.strings b/Session/Meta/Translations/nl.lproj/Localizable.strings index 89c4e2362..167e06f8c 100644 --- a/Session/Meta/Translations/nl.lproj/Localizable.strings +++ b/Session/Meta/Translations/nl.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/pl.lproj/Localizable.strings b/Session/Meta/Translations/pl.lproj/Localizable.strings index 2b153dba3..8b43ff475 100644 --- a/Session/Meta/Translations/pl.lproj/Localizable.strings +++ b/Session/Meta/Translations/pl.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/pt_BR.lproj/Localizable.strings b/Session/Meta/Translations/pt_BR.lproj/Localizable.strings index 752b50617..278344991 100644 --- a/Session/Meta/Translations/pt_BR.lproj/Localizable.strings +++ b/Session/Meta/Translations/pt_BR.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/ru.lproj/Localizable.strings b/Session/Meta/Translations/ru.lproj/Localizable.strings index b704414db..c63944321 100644 --- a/Session/Meta/Translations/ru.lproj/Localizable.strings +++ b/Session/Meta/Translations/ru.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/si.lproj/Localizable.strings b/Session/Meta/Translations/si.lproj/Localizable.strings index cd6b3de5d..965014681 100644 --- a/Session/Meta/Translations/si.lproj/Localizable.strings +++ b/Session/Meta/Translations/si.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/sk.lproj/Localizable.strings b/Session/Meta/Translations/sk.lproj/Localizable.strings index 46a966347..22d3972a5 100644 --- a/Session/Meta/Translations/sk.lproj/Localizable.strings +++ b/Session/Meta/Translations/sk.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/sv.lproj/Localizable.strings b/Session/Meta/Translations/sv.lproj/Localizable.strings index ec101d557..8e37b756e 100644 --- a/Session/Meta/Translations/sv.lproj/Localizable.strings +++ b/Session/Meta/Translations/sv.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/th.lproj/Localizable.strings b/Session/Meta/Translations/th.lproj/Localizable.strings index c53fe6c0b..4a3c4da37 100644 --- a/Session/Meta/Translations/th.lproj/Localizable.strings +++ b/Session/Meta/Translations/th.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/vi-VN.lproj/Localizable.strings b/Session/Meta/Translations/vi-VN.lproj/Localizable.strings index 7622a4079..7474fac4c 100644 --- a/Session/Meta/Translations/vi-VN.lproj/Localizable.strings +++ b/Session/Meta/Translations/vi-VN.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings b/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings index 40084bdbc..1d73613f0 100644 --- a/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings +++ b/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Meta/Translations/zh_CN.lproj/Localizable.strings b/Session/Meta/Translations/zh_CN.lproj/Localizable.strings index 3c56ee8a8..4b5aac0b2 100644 --- a/Session/Meta/Translations/zh_CN.lproj/Localizable.strings +++ b/Session/Meta/Translations/zh_CN.lproj/Localizable.strings @@ -661,3 +661,6 @@ "onboarding_landing_title" = "Privacy in your pocket."; "onboarding_landing_register_button_title" = "Create account"; "onboarding_landing_restore_button_title" = "I have an account"; +"onboarding_T&C" = "By using this service, you agree to our %@ and %@"; +"terms_of_service" = "Terms of Service"; +"privacy_policy" = "Privacy Policy"; diff --git a/Session/Onboarding/LandingView.swift b/Session/Onboarding/LandingView.swift index 80c952ab1..891d1f4ee 100644 --- a/Session/Onboarding/LandingView.swift +++ b/Session/Onboarding/LandingView.swift @@ -40,7 +40,7 @@ struct LandingView: View { height: 40, alignment: .center ) - .background(ThemeManager.currentTheme.colorSwiftUI(for: .sessionButton_filledBackground)) + .backgroundColor(themeColor: .sessionButton_filledBackground) .cornerRadius(20) } @@ -58,14 +58,27 @@ struct LandingView: View { ) .overlay( Capsule() - .stroke(ThemeManager.currentTheme.colorSwiftUI(for: .sessionButton_border)!) + .stroke(themeColor: .sessionButton_border) ) } Button { } label: { - Text("") + let attributedText: NSAttributedString = { + let text = String(format: "onboarding_T&C".localized(), "terms_of_service".localized(), "privacy_policy".localized()) + let result = NSMutableAttributedString( + string: text, + attributes: [ .font : UIFont.systemFont(ofSize: Values.verySmallFontSize)] + ) + result.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: Values.verySmallFontSize), range: (text as NSString).range(of: "terms_of_service".localized())) + result.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: Values.verySmallFontSize), range: (text as NSString).range(of: "privacy_policy".localized())) + + return result + }() + AttributedText(attributedText) + .foregroundColor(themeColor: .textPrimary) + .frame(width: 262) } } } diff --git a/Session/Shared/SessionHostingViewController.swift b/Session/Shared/SessionHostingViewController.swift index 8c04d6a8e..f3971e56e 100644 --- a/Session/Shared/SessionHostingViewController.swift +++ b/Session/Shared/SessionHostingViewController.swift @@ -56,4 +56,27 @@ public class SessionHostingViewController: UIHostingController navigationItem.titleView = container } + + internal func setUpNavBarSessionHeading() { + let headingImageView = UIImageView( + image: UIImage(named: "SessionHeading")? + .withRenderingMode(.alwaysTemplate) + ) + headingImageView.themeTintColor = .textPrimary + headingImageView.contentMode = .scaleAspectFit + headingImageView.set(.width, to: 150) + headingImageView.set(.height, to: Values.mediumFontSize) + + navigationItem.titleView = headingImageView + } + + internal func setUpNavBarSessionIcon() { + let logoImageView = UIImageView() + logoImageView.image = #imageLiteral(resourceName: "SessionGreen32") + logoImageView.contentMode = .scaleAspectFit + logoImageView.set(.width, to: 32) + logoImageView.set(.height, to: 32) + + navigationItem.titleView = logoImageView + } } diff --git a/SessionUIKit/Components/AttributedText.swift b/SessionUIKit/Components/AttributedText.swift new file mode 100644 index 000000000..f5f14816c --- /dev/null +++ b/SessionUIKit/Components/AttributedText.swift @@ -0,0 +1,46 @@ +// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved. + +import SwiftUI + +struct AttributedTextBlock { + let content: String + let font: Font? + let color: Color? +} + +public struct AttributedText: View { + var attributedText: NSAttributedString? + + private var descriptions: [AttributedTextBlock] = [] + + public init(_ attributedText: NSAttributedString?) { + self.attributedText = attributedText + + self.extractDescriptions() + } + + private mutating func extractDescriptions() { + if let text = attributedText { + text.enumerateAttributes(in: NSMakeRange(0, text.length), options: [], using: { (attribute, range, stop) in + let substring = (text.string as NSString).substring(with: range) + let font = (attribute[.font] as? UIFont).map { Font($0) } + let color = (attribute[.foregroundColor] as? UIColor).map { Color($0) } + descriptions.append(AttributedTextBlock(content: substring, + font: font, + color: color)) + }) + } + } + + public var body: some View { + let _ = print(descriptions) + descriptions.map { description in + var text: Text = Text(description.content) + if let font: Font = description.font { text = text.font(font) } + if let color: Color = description.color { text = text.foregroundColor(color) } + return text + }.reduce(Text("")) { (result, text) in + result + text + } + } +} diff --git a/SessionUIKit/Style Guide/Themes/SwiftUI+Theme.swift b/SessionUIKit/Style Guide/Themes/SwiftUI+Theme.swift index f92b3ec39..e9362bf81 100644 --- a/SessionUIKit/Style Guide/Themes/SwiftUI+Theme.swift +++ b/SessionUIKit/Style Guide/Themes/SwiftUI+Theme.swift @@ -8,6 +8,12 @@ public extension View { ThemeManager.currentTheme.colorSwiftUI(for: themeColor) ) } + + func backgroundColor(themeColor: ThemeValue) -> some View { + return self.background( + ThemeManager.currentTheme.colorSwiftUI(for: themeColor) + ) + } } public extension Shape { @@ -16,4 +22,10 @@ public extension Shape { ThemeManager.currentTheme.colorSwiftUI(for: themeColor) ?? Color.primary ) } + + func stroke(themeColor: ThemeValue) -> some View { + return self.stroke( + ThemeManager.currentTheme.colorSwiftUI(for: themeColor) ?? Color.primary + ) + } }