From e6bf1d857a2e3493699b29cc58840105f1d5c722 Mon Sep 17 00:00:00 2001 From: Isaac <> Date: Sun, 21 Jan 2024 21:43:38 +0100 Subject: [PATCH] Fix alert formatting --- .../AuthorizationSequenceController.swift | 6 ++++ ...uthorizationSequenceSignUpController.swift | 29 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/submodules/AuthorizationUI/Sources/AuthorizationSequenceController.swift b/submodules/AuthorizationUI/Sources/AuthorizationSequenceController.swift index 9b2377772c..2d5e02d6d5 100644 --- a/submodules/AuthorizationUI/Sources/AuthorizationSequenceController.swift +++ b/submodules/AuthorizationUI/Sources/AuthorizationSequenceController.swift @@ -1031,6 +1031,12 @@ public final class AuthorizationSequenceController: NavigationController, ASAuth let _ = TelegramEngineUnauthorized(account: strongSelf.account).auth.setState(state: UnauthorizedAccountState(isTestingEnvironment: strongSelf.account.testingEnvironment, masterDatacenterId: strongSelf.account.masterDatacenterId, contents: .phoneEntry(countryCode: countryCode, number: ""))).startStandalone() }, displayCancel: displayCancel) + controller.openUrl = { [weak self] url in + guard let self else { + return + } + self.openUrl(url) + } controller.signUpWithName = { [weak self, weak controller] firstName, lastName, avatarData, avatarAsset, avatarAdjustments in if let strongSelf = self { controller?.inProgress = true diff --git a/submodules/AuthorizationUI/Sources/AuthorizationSequenceSignUpController.swift b/submodules/AuthorizationUI/Sources/AuthorizationSequenceSignUpController.swift index 1bb8bf0521..02154b68c2 100644 --- a/submodules/AuthorizationUI/Sources/AuthorizationSequenceSignUpController.swift +++ b/submodules/AuthorizationUI/Sources/AuthorizationSequenceSignUpController.swift @@ -10,6 +10,7 @@ import ProgressNavigationButtonNode import ImageCompression import LegacyMediaPickerUI import Postbox +import TextFormat final class AuthorizationSequenceSignUpController: ViewController { private var controllerNode: AuthorizationSequenceSignUpControllerNode { @@ -25,6 +26,7 @@ final class AuthorizationSequenceSignUpController: ViewController { private var termsOfService: UnauthorizedAccountTermsOfService? var signUpWithName: ((String, String, Data?, Any?, TGVideoEditAdjustments?) -> Void)? + var openUrl: ((String) -> Void)? var avatarAsset: Any? var avatarAdjustments: TGVideoEditAdjustments? @@ -122,7 +124,32 @@ final class AuthorizationSequenceSignUpController: ViewController { return } strongSelf.view.endEditing(true) - strongSelf.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: strongSelf.presentationData), title: strongSelf.presentationData.strings.Login_TermsOfServiceHeader, text: termsOfService.text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root)) + + let presentAlertImpl: () -> Void = { + guard let strongSelf = self else { + return + } + var dismissImpl: (() -> Void)? + let alertTheme = AlertControllerTheme(presentationData: strongSelf.presentationData) + let attributedText = stringWithAppliedEntities(termsOfService.text, entities: termsOfService.entities, baseColor: alertTheme.primaryColor, linkColor: alertTheme.accentColor, baseFont: Font.regular(13.0), linkFont: Font.regular(13.0), boldFont: Font.semibold(13.0), italicFont: Font.italic(13.0), boldItalicFont: Font.semiboldItalic(13.0), fixedFont: Font.regular(13.0), blockQuoteFont: Font.regular(13.0), message: nil) + let contentNode = TextAlertContentNode(theme: alertTheme, title: NSAttributedString(string: strongSelf.presentationData.strings.Login_TermsOfServiceHeader, font: Font.medium(17.0), textColor: alertTheme.primaryColor, paragraphAlignment: .center), text: attributedText, actions: [ + TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: { + dismissImpl?() + }) + ], actionLayout: .vertical, dismissOnOutsideTap: true) + contentNode.textAttributeAction = (NSAttributedString.Key(rawValue: TelegramTextAttributes.URL), { value in + if let value = value as? String { + strongSelf.openUrl?(value) + } + }) + let controller = AlertController(theme: alertTheme, contentNode: contentNode) + dismissImpl = { [weak controller] in + controller?.dismissAnimated() + } + strongSelf.view.endEditing(true) + strongSelf.present(controller, in: .window(.root)) + } + presentAlertImpl() } self.controllerNode.updateData(firstName: self.initialName.0, lastName: self.initialName.1, hasTermsOfService: self.termsOfService != nil)