mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 14:45:21 +00:00
Emoji improvements
This commit is contained in:
@@ -15,6 +15,9 @@ import PhotoResources
|
||||
import TelegramStringFormatting
|
||||
import TextFormat
|
||||
import InvisibleInkDustNode
|
||||
import TextNodeWithEntities
|
||||
import AnimationCache
|
||||
import MultiAnimationRenderer
|
||||
|
||||
public final class ChatMessageNotificationItem: NotificationItem {
|
||||
let context: AccountContext
|
||||
@@ -69,7 +72,7 @@ final class ChatMessageNotificationItemNode: NotificationItemNode {
|
||||
private let avatarNode: AvatarNode
|
||||
private let titleIconNode: ASImageNode
|
||||
private let titleNode: TextNode
|
||||
private let textNode: TextNode
|
||||
private let textNode: TextNodeWithEntities
|
||||
private var dustNode: InvisibleInkDustNode?
|
||||
private let imageNode: TransformImageNode
|
||||
|
||||
@@ -79,6 +82,9 @@ final class ChatMessageNotificationItemNode: NotificationItemNode {
|
||||
private var compact: Bool?
|
||||
private var validLayout: CGFloat?
|
||||
|
||||
private var animationCache: AnimationCache?
|
||||
private var multiAnimationRenderer: MultiAnimationRenderer?
|
||||
|
||||
override init() {
|
||||
self.avatarNode = AvatarNode(font: avatarFont)
|
||||
|
||||
@@ -90,8 +96,8 @@ final class ChatMessageNotificationItemNode: NotificationItemNode {
|
||||
self.titleIconNode.displayWithoutProcessing = true
|
||||
self.titleIconNode.displaysAsynchronously = false
|
||||
|
||||
self.textNode = TextNode()
|
||||
self.textNode.isUserInteractionEnabled = false
|
||||
self.textNode = TextNodeWithEntities()
|
||||
self.textNode.textNode.isUserInteractionEnabled = false
|
||||
|
||||
self.imageNode = TransformImageNode()
|
||||
|
||||
@@ -100,12 +106,20 @@ final class ChatMessageNotificationItemNode: NotificationItemNode {
|
||||
self.addSubnode(self.avatarNode)
|
||||
self.addSubnode(self.titleIconNode)
|
||||
self.addSubnode(self.titleNode)
|
||||
self.addSubnode(self.textNode)
|
||||
self.addSubnode(self.textNode.textNode)
|
||||
self.addSubnode(self.imageNode)
|
||||
}
|
||||
|
||||
func setupItem(_ item: ChatMessageNotificationItem, compact: Bool) {
|
||||
self.item = item
|
||||
|
||||
if self.animationCache == nil {
|
||||
self.animationCache = AnimationCacheImpl(basePath: item.context.account.postbox.mediaBox.basePath + "/animation-cache", allocateTempFile: {
|
||||
return TempBox.shared.tempFile(fileName: "file").path
|
||||
})
|
||||
self.multiAnimationRenderer = MultiAnimationRendererImpl()
|
||||
}
|
||||
|
||||
self.compact = compact
|
||||
if compact {
|
||||
self.avatarNode.font = compactAvatarFont
|
||||
@@ -190,6 +204,8 @@ final class ChatMessageNotificationItemNode: NotificationItemNode {
|
||||
messageEntities = message.textEntitiesAttribute?.entities.filter { entity in
|
||||
if case .Spoiler = entity.type {
|
||||
return true
|
||||
} else if case .CustomEmoji = entity.type {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
@@ -384,10 +400,24 @@ final class ChatMessageNotificationItemNode: NotificationItemNode {
|
||||
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: self.titleAttributedText, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: width - leftInset - rightInset - titleInset, height: CGFloat.greatestFiniteMagnitude), alignment: .left, lineSpacing: 0.0, cutout: nil, insets: UIEdgeInsets()))
|
||||
let _ = titleApply()
|
||||
|
||||
let makeTextLayout = TextNode.asyncLayout(self.textNode)
|
||||
let makeTextLayout = TextNodeWithEntities.asyncLayout(self.textNode)
|
||||
let (textLayout, textApply) = makeTextLayout(TextNodeLayoutArguments(attributedString: self.textAttributedText, backgroundColor: nil, maximumNumberOfLines: 2, truncationType: .end, constrainedSize: CGSize(width: width - leftInset - rightInset, height: CGFloat.greatestFiniteMagnitude), alignment: .left, lineSpacing: 0.0, cutout: nil, insets: UIEdgeInsets()))
|
||||
let _ = titleApply()
|
||||
let _ = textApply()
|
||||
|
||||
if let item = self.item, let cache = self.animationCache, let renderer = self.multiAnimationRenderer {
|
||||
let theme = item.context.sharedContext.currentPresentationData.with({ $0 }).theme
|
||||
let _ = textApply(TextNodeWithEntities.Arguments(
|
||||
context: item.context,
|
||||
cache: cache,
|
||||
renderer: renderer,
|
||||
placeholderColor: theme.list.mediaPlaceholderColor,
|
||||
attemptSynchronous: false
|
||||
))
|
||||
} else {
|
||||
let _ = textApply(nil)
|
||||
}
|
||||
|
||||
self.textNode.visibilityRect = CGRect.infinite
|
||||
|
||||
let textSpacing: CGFloat = 1.0
|
||||
|
||||
@@ -399,7 +429,7 @@ final class ChatMessageNotificationItemNode: NotificationItemNode {
|
||||
}
|
||||
|
||||
let textFrame = CGRect(origin: CGPoint(x: leftInset, y: titleFrame.maxY + textSpacing), size: textLayout.size)
|
||||
transition.updateFrame(node: self.textNode, frame: textFrame)
|
||||
transition.updateFrame(node: self.textNode.textNode, frame: textFrame)
|
||||
|
||||
transition.updateFrame(node: self.imageNode, frame: CGRect(origin: CGPoint(x: width - 10.0 - imageSize.width, y: (panelHeight - imageSize.height) / 2.0), size: imageSize))
|
||||
|
||||
@@ -411,7 +441,7 @@ final class ChatMessageNotificationItemNode: NotificationItemNode {
|
||||
dustNode = InvisibleInkDustNode(textNode: nil)
|
||||
dustNode.isUserInteractionEnabled = false
|
||||
self.dustNode = dustNode
|
||||
self.insertSubnode(dustNode, aboveSubnode: self.textNode)
|
||||
self.insertSubnode(dustNode, aboveSubnode: self.textNode.textNode)
|
||||
}
|
||||
dustNode.frame = textFrame.insetBy(dx: -3.0, dy: -3.0).offsetBy(dx: 0.0, dy: 3.0)
|
||||
dustNode.update(size: dustNode.frame.size, color: presentationData.theme.inAppNotification.primaryTextColor, textColor: presentationData.theme.inAppNotification.primaryTextColor, rects: textLayout.spoilers.map { $0.1.offsetBy(dx: 3.0, dy: 3.0).insetBy(dx: 1.0, dy: 1.0) }, wordRects: textLayout.spoilerWords.map { $0.1.offsetBy(dx: 3.0, dy: 3.0).insetBy(dx: 1.0, dy: 1.0) })
|
||||
|
||||
Reference in New Issue
Block a user