ChatMEssageTextBubbleContentNode: large emojis

This commit is contained in:
Peter 2019-03-22 15:20:37 +04:00
parent 727623e1a9
commit e93b3ebe42
2 changed files with 61 additions and 13 deletions

View File

@ -194,14 +194,33 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
let bubbleTheme = item.presentationData.theme.theme.chat.bubble 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 { 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 { } 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? var cutout: TextNodeCutout?
if let statusSize = statusSize { if let statusSize = statusSize, !forceStatusNewline {
cutout = TextNodeCutout(bottomRight: statusSize) cutout = TextNodeCutout(bottomRight: statusSize)
} }
@ -214,26 +233,45 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
var statusFrame: CGRect? var statusFrame: CGRect?
if let statusSize = statusSize { if let statusSize = statusSize {
statusFrame = CGRect(origin: CGPoint(x: textFrameWithoutInsets.maxX - statusSize.width, y: textFrameWithoutInsets.maxY - statusSize.height), size: 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) 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) 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) statusFrame = statusFrame?.offsetBy(dx: layoutConstants.text.bubbleInsets.left, dy: layoutConstants.text.bubbleInsets.top)
var boundingSize: CGSize var suggestedBoundingWidth: CGFloat
if let statusFrame = statusFrame { if let statusFrame = statusFrame {
boundingSize = textFrameWithoutInsets.union(statusFrame).size suggestedBoundingWidth = textFrameWithoutInsets.union(statusFrame).width
} else { } else {
boundingSize = textFrameWithoutInsets.size suggestedBoundingWidth = textFrameWithoutInsets.width
} }
boundingSize.width += layoutConstants.text.bubbleInsets.left + layoutConstants.text.bubbleInsets.right suggestedBoundingWidth += layoutConstants.text.bubbleInsets.left + layoutConstants.text.bubbleInsets.right
boundingSize.height += layoutConstants.text.bubbleInsets.top + layoutConstants.text.bubbleInsets.bottom
return (boundingSize.width, { boundingWidth in return (suggestedBoundingWidth, { boundingWidth in
var boundingSize: CGSize
var adjustedStatusFrame: CGRect? var adjustedStatusFrame: CGRect?
if let statusFrame = statusFrame { if let statusFrame = statusFrame {
adjustedStatusFrame = CGRect(origin: CGPoint(x: boundingWidth - statusFrame.size.width - layoutConstants.text.bubbleInsets.right, y: statusFrame.origin.y), size: statusFrame.size) 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
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 return (boundingSize, { [weak self] animation, _ in
@ -247,7 +285,7 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
if case .System = animation { if case .System = animation {
if let cachedLayout = cachedLayout { if let cachedLayout = cachedLayout {
if cachedLayout != textLayout { if !cachedLayout.areLinesEqual(to: textLayout) {
if let textContents = strongSelf.textNode.contents { if let textContents = strongSelf.textNode.contents {
let fadeNode = ASDisplayNode() let fadeNode = ASDisplayNode()
fadeNode.displaysAsynchronously = false fadeNode.displaysAsynchronously = false
@ -288,7 +326,11 @@ class ChatMessageTextBubbleContentNode: ChatMessageBubbleContentNode {
strongSelf.statusNode.removeFromSupernode() 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.frame = textFrame
strongSelf.textAccessibilityOverlayNode.cachedLayout = textLayout strongSelf.textAccessibilityOverlayNode.cachedLayout = textLayout
} }

View File

@ -71,6 +71,9 @@ public final class ChatPresentationData {
let disableAnimations: Bool let disableAnimations: Bool
let messageFont: UIFont let messageFont: UIFont
let messageEmojiFont1: UIFont
let messageEmojiFont2: UIFont
let messageEmojiFont3: UIFont
let messageBoldFont: UIFont let messageBoldFont: UIFont
let messageItalicFont: UIFont let messageItalicFont: UIFont
let messageFixedFont: UIFont let messageFixedFont: UIFont
@ -85,6 +88,9 @@ public final class ChatPresentationData {
let baseFontSize = fontSize.baseDisplaySize let baseFontSize = fontSize.baseDisplaySize
self.messageFont = UIFont.systemFont(ofSize: baseFontSize) 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.messageBoldFont = UIFont.boldSystemFont(ofSize: baseFontSize)
self.messageItalicFont = UIFont.italicSystemFont(ofSize: baseFontSize) self.messageItalicFont = UIFont.italicSystemFont(ofSize: baseFontSize)
self.messageFixedFont = UIFont(name: "Menlo-Regular", size: baseFontSize - 1.0) ?? UIFont.systemFont(ofSize: baseFontSize) self.messageFixedFont = UIFont(name: "Menlo-Regular", size: baseFontSize - 1.0) ?? UIFont.systemFont(ofSize: baseFontSize)