mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-08 08:31:13 +00:00
ChatMEssageTextBubbleContentNode: large emojis
This commit is contained in:
parent
727623e1a9
commit
e93b3ebe42
@ -194,14 +194,33 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
|
||||
|
||||
let bubbleTheme = item.presentationData.theme.theme.chat.bubble
|
||||
|
||||
var textFont = item.presentationData.messageFont
|
||||
var forceStatusNewline = false
|
||||
if rawText.containsOnlyEmoji {
|
||||
let emojis = rawText.emojis
|
||||
switch emojis.count {
|
||||
case 1:
|
||||
textFont = item.presentationData.messageEmojiFont1
|
||||
forceStatusNewline = true
|
||||
case 2:
|
||||
textFont = item.presentationData.messageEmojiFont2
|
||||
forceStatusNewline = true
|
||||
case 3:
|
||||
textFont = item.presentationData.messageEmojiFont3
|
||||
forceStatusNewline = true
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if let entities = entities {
|
||||
attributedText = stringWithAppliedEntities(rawText, entities: entities, baseColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor, linkColor: incoming ? bubbleTheme.incomingLinkTextColor : bubbleTheme.outgoingLinkTextColor, baseFont: item.presentationData.messageFont, linkFont: item.presentationData.messageFont, boldFont: item.presentationData.messageBoldFont, italicFont: item.presentationData.messageItalicFont, fixedFont: item.presentationData.messageFixedFont)
|
||||
attributedText = stringWithAppliedEntities(rawText, entities: entities, baseColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor, linkColor: incoming ? bubbleTheme.incomingLinkTextColor : bubbleTheme.outgoingLinkTextColor, baseFont: textFont, linkFont: textFont, boldFont: item.presentationData.messageBoldFont, italicFont: item.presentationData.messageItalicFont, fixedFont: item.presentationData.messageFixedFont)
|
||||
} else {
|
||||
attributedText = NSAttributedString(string: rawText, font: item.presentationData.messageFont, textColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor)
|
||||
attributedText = NSAttributedString(string: rawText, font: textFont, textColor: incoming ? bubbleTheme.incomingPrimaryTextColor : bubbleTheme.outgoingPrimaryTextColor)
|
||||
}
|
||||
|
||||
var cutout: TextNodeCutout?
|
||||
if let statusSize = statusSize {
|
||||
if let statusSize = statusSize, !forceStatusNewline {
|
||||
cutout = TextNodeCutout(bottomRight: statusSize)
|
||||
}
|
||||
|
||||
@ -214,26 +233,45 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
|
||||
|
||||
var statusFrame: CGRect?
|
||||
if let statusSize = statusSize {
|
||||
if forceStatusNewline {
|
||||
statusFrame = CGRect(origin: CGPoint(x: textFrameWithoutInsets.maxX - statusSize.width, y: textFrameWithoutInsets.maxY), size: statusSize)
|
||||
} else {
|
||||
statusFrame = CGRect(origin: CGPoint(x: textFrameWithoutInsets.maxX - statusSize.width, y: textFrameWithoutInsets.maxY - statusSize.height), size: statusSize)
|
||||
}
|
||||
}
|
||||
|
||||
textFrame = textFrame.offsetBy(dx: layoutConstants.text.bubbleInsets.left, dy: layoutConstants.text.bubbleInsets.top)
|
||||
textFrameWithoutInsets = textFrameWithoutInsets.offsetBy(dx: layoutConstants.text.bubbleInsets.left, dy: layoutConstants.text.bubbleInsets.top)
|
||||
statusFrame = statusFrame?.offsetBy(dx: layoutConstants.text.bubbleInsets.left, dy: layoutConstants.text.bubbleInsets.top)
|
||||
|
||||
var boundingSize: CGSize
|
||||
var suggestedBoundingWidth: CGFloat
|
||||
if let statusFrame = statusFrame {
|
||||
boundingSize = textFrameWithoutInsets.union(statusFrame).size
|
||||
suggestedBoundingWidth = textFrameWithoutInsets.union(statusFrame).width
|
||||
} else {
|
||||
boundingSize = textFrameWithoutInsets.size
|
||||
suggestedBoundingWidth = textFrameWithoutInsets.width
|
||||
}
|
||||
suggestedBoundingWidth += layoutConstants.text.bubbleInsets.left + layoutConstants.text.bubbleInsets.right
|
||||
|
||||
return (suggestedBoundingWidth, { boundingWidth in
|
||||
var boundingSize: CGSize
|
||||
var adjustedStatusFrame: CGRect?
|
||||
|
||||
if let statusFrame = statusFrame {
|
||||
if !forceStatusNewline || boundingWidth < statusFrame.width + textFrame.width {
|
||||
boundingSize = textFrameWithoutInsets.union(statusFrame).size
|
||||
boundingSize.width += layoutConstants.text.bubbleInsets.left + layoutConstants.text.bubbleInsets.right
|
||||
boundingSize.height += layoutConstants.text.bubbleInsets.top + layoutConstants.text.bubbleInsets.bottom
|
||||
|
||||
return (boundingSize.width, { boundingWidth in
|
||||
var adjustedStatusFrame: CGRect?
|
||||
if let statusFrame = statusFrame {
|
||||
adjustedStatusFrame = CGRect(origin: CGPoint(x: boundingWidth - statusFrame.size.width - layoutConstants.text.bubbleInsets.right, y: statusFrame.origin.y), size: statusFrame.size)
|
||||
} else {
|
||||
boundingSize = textFrameWithoutInsets.size
|
||||
boundingSize.width += layoutConstants.text.bubbleInsets.left + layoutConstants.text.bubbleInsets.right
|
||||
boundingSize.height += layoutConstants.text.bubbleInsets.top + layoutConstants.text.bubbleInsets.bottom
|
||||
adjustedStatusFrame = CGRect(origin: CGPoint(x: boundingWidth - statusFrame.size.width - layoutConstants.text.bubbleInsets.right, y: boundingSize.height - statusFrame.height - layoutConstants.text.bubbleInsets.bottom), size: statusFrame.size)
|
||||
}
|
||||
} else {
|
||||
boundingSize = textFrameWithoutInsets.size
|
||||
boundingSize.width += layoutConstants.text.bubbleInsets.left + layoutConstants.text.bubbleInsets.right
|
||||
boundingSize.height += layoutConstants.text.bubbleInsets.top + layoutConstants.text.bubbleInsets.bottom
|
||||
}
|
||||
|
||||
return (boundingSize, { [weak self] animation, _ in
|
||||
@ -247,7 +285,7 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
|
||||
|
||||
if case .System = animation {
|
||||
if let cachedLayout = cachedLayout {
|
||||
if cachedLayout != textLayout {
|
||||
if !cachedLayout.areLinesEqual(to: textLayout) {
|
||||
if let textContents = strongSelf.textNode.contents {
|
||||
let fadeNode = ASDisplayNode()
|
||||
fadeNode.displaysAsynchronously = false
|
||||
@ -288,7 +326,11 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
|
||||
strongSelf.statusNode.removeFromSupernode()
|
||||
}
|
||||
|
||||
strongSelf.textNode.frame = textFrame
|
||||
var adjustedTextFrame = textFrame
|
||||
if forceStatusNewline {
|
||||
adjustedTextFrame.origin.x = floor((boundingWidth - adjustedTextFrame.width) / 2.0)
|
||||
}
|
||||
strongSelf.textNode.frame = adjustedTextFrame
|
||||
strongSelf.textAccessibilityOverlayNode.frame = textFrame
|
||||
strongSelf.textAccessibilityOverlayNode.cachedLayout = textLayout
|
||||
}
|
||||
|
@ -71,6 +71,9 @@ public final class ChatPresentationData {
|
||||
let disableAnimations: Bool
|
||||
|
||||
let messageFont: UIFont
|
||||
let messageEmojiFont1: UIFont
|
||||
let messageEmojiFont2: UIFont
|
||||
let messageEmojiFont3: UIFont
|
||||
let messageBoldFont: UIFont
|
||||
let messageItalicFont: UIFont
|
||||
let messageFixedFont: UIFont
|
||||
@ -85,6 +88,9 @@ public final class ChatPresentationData {
|
||||
|
||||
let baseFontSize = fontSize.baseDisplaySize
|
||||
self.messageFont = UIFont.systemFont(ofSize: baseFontSize)
|
||||
self.messageEmojiFont1 = UIFont.systemFont(ofSize: ceil(baseFontSize * 2.94))
|
||||
self.messageEmojiFont2 = UIFont.systemFont(ofSize: ceil(baseFontSize * 2.29))
|
||||
self.messageEmojiFont3 = UIFont.systemFont(ofSize: ceil(baseFontSize * 1.64))
|
||||
self.messageBoldFont = UIFont.boldSystemFont(ofSize: baseFontSize)
|
||||
self.messageItalicFont = UIFont.italicSystemFont(ofSize: baseFontSize)
|
||||
self.messageFixedFont = UIFont(name: "Menlo-Regular", size: baseFontSize - 1.0) ?? UIFont.systemFont(ofSize: baseFontSize)
|
||||
|
Loading…
x
Reference in New Issue
Block a user