mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Fix ad layout
This commit is contained in:
parent
26f765c269
commit
a4df0ea488
@ -332,13 +332,13 @@ final class ChatAdPanelNode: ASDisplayNode {
|
|||||||
let textConstrainedSize = CGSize(width: width - contentLeftInset - contentRightInset - textRightInset, height: CGFloat.greatestFiniteMagnitude)
|
let textConstrainedSize = CGSize(width: width - contentLeftInset - contentRightInset - textRightInset, height: CGFloat.greatestFiniteMagnitude)
|
||||||
|
|
||||||
//TODO:localize
|
//TODO:localize
|
||||||
let (adLayout, adApply) = makeAdLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: "Ad", font: Font.semibold(14.0), textColor: theme.chat.inputPanel.panelControlAccentColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: textConstrainedSize, alignment: .natural, cutout: nil, insets: UIEdgeInsets(top: 2.0, left: 0.0, bottom: 2.0, right: 0.0)))
|
let (adLayout, adApply) = makeAdLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: "Ad", font: Font.semibold(14.0), textColor: theme.chat.inputPanel.panelControlAccentColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: textConstrainedSize, alignment: .natural, cutout: nil, insets: .zero))
|
||||||
|
|
||||||
var titleText: String = ""
|
var titleText: String = ""
|
||||||
if let author = message.author {
|
if let author = message.author {
|
||||||
titleText = EnginePeer(author).compactDisplayTitle
|
titleText = EnginePeer(author).compactDisplayTitle
|
||||||
}
|
}
|
||||||
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: titleText, font: Font.semibold(14.0), textColor: theme.chat.inputPanel.primaryTextColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: textConstrainedSize, alignment: .natural, cutout: nil, insets: UIEdgeInsets(top: 2.0, left: 0.0, bottom: 2.0, right: 0.0)))
|
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: titleText, font: Font.semibold(14.0), textColor: theme.chat.inputPanel.primaryTextColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: textConstrainedSize, alignment: .natural, cutout: nil, insets: .zero))
|
||||||
|
|
||||||
let (textString, _, isText) = descriptionStringForMessage(contentSettings: context.currentContentSettings.with { $0 }, message: EngineMessage(message), strings: strings, nameDisplayOrder: nameDisplayOrder, dateTimeFormat: dateTimeFormat, accountPeerId: accountPeerId)
|
let (textString, _, isText) = descriptionStringForMessage(contentSettings: context.currentContentSettings.with { $0 }, message: EngineMessage(message), strings: strings, nameDisplayOrder: nameDisplayOrder, dateTimeFormat: dateTimeFormat, accountPeerId: accountPeerId)
|
||||||
|
|
||||||
@ -376,13 +376,23 @@ final class ChatAdPanelNode: ASDisplayNode {
|
|||||||
messageText = NSAttributedString(string: foldLineBreaks(textString.string), font: textFont, textColor: message.media.isEmpty || message.media.first is TelegramMediaWebpage ? theme.chat.inputPanel.primaryTextColor : theme.chat.inputPanel.secondaryTextColor)
|
messageText = NSAttributedString(string: foldLineBreaks(textString.string), font: textFont, textColor: message.media.isEmpty || message.media.first is TelegramMediaWebpage ? theme.chat.inputPanel.primaryTextColor : theme.chat.inputPanel.secondaryTextColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
let (textLayout, textApply) = makeTextLayout(TextNodeLayoutArguments(attributedString: messageText, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: textConstrainedSize, alignment: .natural, cutout: nil, insets: UIEdgeInsets(top: 2.0, left: 0.0, bottom: 2.0, right: 0.0)))
|
let (textLayout, textApply) = makeTextLayout(TextNodeLayoutArguments(attributedString: messageText, backgroundColor: nil, maximumNumberOfLines: 0, truncationType: .end, constrainedSize: textConstrainedSize, alignment: .natural, cutout: nil, insets: .zero))
|
||||||
|
|
||||||
var panelHeight: CGFloat = 0.0
|
var panelHeight: CGFloat = 0.0
|
||||||
if let _ = imageDimensions {
|
if let _ = imageDimensions {
|
||||||
panelHeight = 9.0 + imageBoundingSize.height + 9.0
|
panelHeight = 9.0 + imageBoundingSize.height + 9.0
|
||||||
}
|
}
|
||||||
panelHeight = max(panelHeight, 9.0 + titleLayout.size.height + textLayout.size.height + 9.0)
|
|
||||||
|
var textHeight: CGFloat
|
||||||
|
var titleOnSeparateLine = false
|
||||||
|
if textLayout.numberOfLines == 1 || contentLeftInset + adLayout.size.width + 2.0 + titleLayout.size.width > width - contentRightInset - textRightInset {
|
||||||
|
textHeight = adLayout.size.height + titleLayout.size.height + textLayout.size.height + 15.0
|
||||||
|
titleOnSeparateLine = true
|
||||||
|
} else {
|
||||||
|
textHeight = titleLayout.size.height + textLayout.size.height + 15.0
|
||||||
|
}
|
||||||
|
|
||||||
|
panelHeight = max(panelHeight, textHeight)
|
||||||
|
|
||||||
Queue.mainQueue().async {
|
Queue.mainQueue().async {
|
||||||
let _ = adApply()
|
let _ = adApply()
|
||||||
@ -407,18 +417,18 @@ final class ChatAdPanelNode: ASDisplayNode {
|
|||||||
|
|
||||||
let removeTextSize = self.removeTextNode.updateLayout(CGSize(width: width, height: .greatestFiniteMagnitude))
|
let removeTextSize = self.removeTextNode.updateLayout(CGSize(width: width, height: .greatestFiniteMagnitude))
|
||||||
|
|
||||||
if textLayout.numberOfLines == 1 {
|
if titleOnSeparateLine {
|
||||||
self.adNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 7.0), size: adLayout.size)
|
self.adNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 9.0), size: adLayout.size)
|
||||||
self.titleNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 24.0), size: titleLayout.size)
|
self.titleNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 26.0), size: titleLayout.size)
|
||||||
self.textNode.textNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 41.0), size: textLayout.size)
|
self.textNode.textNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 43.0), size: textLayout.size)
|
||||||
|
|
||||||
self.removeTextNode.frame = CGRect(origin: CGPoint(x: contentLeftInset + adLayout.size.width + 8.0, y: 11.0 - UIScreenPixel), size: removeTextSize)
|
self.removeTextNode.frame = CGRect(origin: CGPoint(x: contentLeftInset + adLayout.size.width + 8.0, y: 11.0 - UIScreenPixel), size: removeTextSize)
|
||||||
self.removeBackgroundNode.frame = self.removeTextNode.frame.insetBy(dx: -5.0, dy: -1.0)
|
self.removeBackgroundNode.frame = self.removeTextNode.frame.insetBy(dx: -5.0, dy: -1.0)
|
||||||
self.removeButtonNode.frame = self.removeBackgroundNode.frame
|
self.removeButtonNode.frame = self.removeBackgroundNode.frame
|
||||||
} else {
|
} else {
|
||||||
self.adNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 7.0), size: adLayout.size)
|
self.adNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 9.0), size: adLayout.size)
|
||||||
self.titleNode.frame = CGRect(origin: CGPoint(x: adLayout.size.width + 2.0, y: 7.0), size: titleLayout.size)
|
self.titleNode.frame = CGRect(origin: CGPoint(x: adLayout.size.width + 2.0, y: 9.0), size: titleLayout.size)
|
||||||
self.textNode.textNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 24.0), size: textLayout.size)
|
self.textNode.textNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 26.0), size: textLayout.size)
|
||||||
|
|
||||||
self.removeTextNode.frame = CGRect(origin: CGPoint(x: contentLeftInset + adLayout.size.width + 2.0 + titleLayout.size.width + 8.0, y: 11.0 - UIScreenPixel), size: removeTextSize)
|
self.removeTextNode.frame = CGRect(origin: CGPoint(x: contentLeftInset + adLayout.size.width + 2.0 + titleLayout.size.width + 8.0, y: 11.0 - UIScreenPixel), size: removeTextSize)
|
||||||
self.removeBackgroundNode.frame = self.removeTextNode.frame.insetBy(dx: -5.0, dy: -1.0)
|
self.removeBackgroundNode.frame = self.removeTextNode.frame.insetBy(dx: -5.0, dy: -1.0)
|
||||||
|
@ -5810,6 +5810,12 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
|||||||
boostsToUnrestrict = cachedChannelData.boostsToUnrestrict
|
boostsToUnrestrict = cachedChannelData.boostsToUnrestrict
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var adMessage = adMessage
|
||||||
|
if let peer = strongSelf.presentationInterfaceState.renderedPeer?.peer as? TelegramUser, peer.botInfo != nil {
|
||||||
|
} else {
|
||||||
|
adMessage = nil
|
||||||
|
}
|
||||||
|
|
||||||
strongSelf.updateChatPresentationInterfaceState(animated: animated, interactive: false, {
|
strongSelf.updateChatPresentationInterfaceState(animated: animated, interactive: false, {
|
||||||
return $0.updatedPeer { _ in
|
return $0.updatedPeer { _ in
|
||||||
return renderedPeer
|
return renderedPeer
|
||||||
|
Loading…
x
Reference in New Issue
Block a user