mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Web app improvements
This commit is contained in:
@@ -25,9 +25,11 @@ private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureReco
|
||||
private let strings: PresentationStrings
|
||||
private let title: String
|
||||
private let text: String
|
||||
private let additionalText: String?
|
||||
|
||||
private let titleNode: ImmediateTextNode
|
||||
private let textNode: ImmediateTextNode
|
||||
private let additionalTextNode: ImmediateTextNode
|
||||
|
||||
private let acceptTermsCheckNode: InteractiveCheckNode
|
||||
private let acceptTermsLabelNode: ImmediateTextNode
|
||||
@@ -53,10 +55,11 @@ private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureReco
|
||||
|
||||
var openTerms: () -> Void = {}
|
||||
|
||||
init(context: AccountContext, theme: AlertControllerTheme, ptheme: PresentationTheme, strings: PresentationStrings, title: String, text: String, actions: [TextAlertAction]) {
|
||||
init(context: AccountContext, theme: AlertControllerTheme, ptheme: PresentationTheme, strings: PresentationStrings, title: String, text: String, additionalText: String?, actions: [TextAlertAction]) {
|
||||
self.strings = strings
|
||||
self.title = title
|
||||
self.text = text
|
||||
self.additionalText = additionalText
|
||||
|
||||
self.titleNode = ImmediateTextNode()
|
||||
self.titleNode.displaysAsynchronously = false
|
||||
@@ -69,6 +72,12 @@ private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureReco
|
||||
self.textNode.lineSpacing = 0.1
|
||||
self.textNode.textAlignment = .center
|
||||
|
||||
self.additionalTextNode = ImmediateTextNode()
|
||||
self.additionalTextNode.maximumNumberOfLines = 0
|
||||
self.additionalTextNode.displaysAsynchronously = false
|
||||
self.additionalTextNode.lineSpacing = 0.1
|
||||
self.additionalTextNode.textAlignment = .center
|
||||
|
||||
self.acceptTermsCheckNode = InteractiveCheckNode(theme: CheckNodeTheme(backgroundColor: theme.accentColor, strokeColor: theme.contrastColor, borderColor: theme.controlBorderColor, overlayBorder: false, hasInset: false, hasShadow: false))
|
||||
self.acceptTermsLabelNode = ImmediateTextNode()
|
||||
self.acceptTermsLabelNode.maximumNumberOfLines = 4
|
||||
@@ -94,6 +103,7 @@ private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureReco
|
||||
|
||||
self.addSubnode(self.titleNode)
|
||||
self.addSubnode(self.textNode)
|
||||
self.addSubnode(self.additionalTextNode)
|
||||
|
||||
self.addSubnode(self.acceptTermsCheckNode)
|
||||
self.addSubnode(self.acceptTermsLabelNode)
|
||||
@@ -179,6 +189,11 @@ private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureReco
|
||||
override func updateTheme(_ theme: AlertControllerTheme) {
|
||||
self.titleNode.attributedText = NSAttributedString(string: self.title, font: Font.semibold(17.0), textColor: theme.primaryColor, paragraphAlignment: .center)
|
||||
self.textNode.attributedText = formattedText(self.text, fontSize: 13.0, color: theme.primaryColor, linkColor: theme.accentColor, textAlignment: .center)
|
||||
if let additionalText = self.additionalText {
|
||||
self.additionalTextNode.attributedText = formattedText(additionalText, fontSize: 13.0, color: theme.primaryColor, linkColor: theme.accentColor, textAlignment: .center)
|
||||
} else {
|
||||
self.additionalTextNode.attributedText = nil
|
||||
}
|
||||
|
||||
let attributedAgreeText = parseMarkdownIntoAttributedString(
|
||||
self.strings.WebApp_DisclaimerAgree,
|
||||
@@ -242,6 +257,14 @@ private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureReco
|
||||
transition.updateFrame(node: self.acceptTermsLabelNode, frame: CGRect(origin: CGPoint(x: acceptTermsOriginX + checkSize.width + spacing, y: origin.y), size: acceptTermsSize))
|
||||
origin.y += acceptTermsSize.height
|
||||
entriesHeight += acceptTermsSize.height
|
||||
origin.y += 21.0
|
||||
}
|
||||
|
||||
let additionalTextSize = self.additionalTextNode.updateLayout(CGSize(width: size.width - 48.0, height: size.height))
|
||||
transition.updateFrame(node: self.additionalTextNode, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - additionalTextSize.width) / 2.0), y: origin.y), size: additionalTextSize))
|
||||
origin.y += additionalTextSize.height
|
||||
if additionalTextSize.height > 0.0 {
|
||||
entriesHeight += 20.0
|
||||
}
|
||||
|
||||
let actionButtonHeight: CGFloat = 44.0
|
||||
@@ -275,7 +298,7 @@ private final class WebAppTermsAlertContentNode: AlertContentNode, UIGestureReco
|
||||
actionsHeight = actionButtonHeight * CGFloat(self.actionNodes.count)
|
||||
}
|
||||
|
||||
let resultSize = CGSize(width: contentWidth, height: titleSize.height + textSize.height + entriesHeight + actionsHeight + 3.0 + insets.top + insets.bottom)
|
||||
let resultSize = CGSize(width: contentWidth, height: titleSize.height + textSize.height + additionalTextSize.height + entriesHeight + actionsHeight + 3.0 + insets.top + insets.bottom)
|
||||
|
||||
transition.updateFrame(node: self.actionNodesSeparator, frame: CGRect(origin: CGPoint(x: 0.0, y: resultSize.height - actionsHeight - UIScreenPixel), size: CGSize(width: resultSize.width, height: UIScreenPixel)))
|
||||
|
||||
@@ -350,9 +373,17 @@ public func webAppTermsAlertController(
|
||||
})]
|
||||
|
||||
let title = presentationData.strings.WebApp_DisclaimerTitle
|
||||
let text = presentationData.strings.WebApp_DisclaimerText(bot.peer.compactDisplayTitle).string
|
||||
let text = presentationData.strings.WebApp_DisclaimerText
|
||||
let additionalText: String?
|
||||
if bot.flags.contains(.showInSettings) {
|
||||
additionalText = presentationData.strings.WebApp_DisclaimerShortcutsSettingsText(bot.peer.compactDisplayTitle).string
|
||||
} else if bot.flags.contains(.showInAttachMenu) {
|
||||
additionalText = presentationData.strings.WebApp_DisclaimerShortcutsText(bot.peer.compactDisplayTitle).string
|
||||
} else {
|
||||
additionalText = nil
|
||||
}
|
||||
|
||||
let contentNode = WebAppTermsAlertContentNode(context: context, theme: AlertControllerTheme(presentationData: presentationData), ptheme: theme, strings: strings, title: title, text: text, actions: actions)
|
||||
let contentNode = WebAppTermsAlertContentNode(context: context, theme: AlertControllerTheme(presentationData: presentationData), ptheme: theme, strings: strings, title: title, text: text, additionalText: additionalText, actions: actions)
|
||||
contentNode.openTerms = {
|
||||
context.sharedContext.openExternalUrl(context: context, urlContext: .generic, url: presentationData.strings.WebApp_Disclaimer_URL, forceExternal: true, presentationData: context.sharedContext.currentPresentationData.with { $0 }, navigationController: nil, dismissInput: {
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user