Emoji improvements

This commit is contained in:
Ali
2022-07-24 21:38:41 +02:00
parent c95c59661a
commit c1595c9de9
5 changed files with 112 additions and 82 deletions

View File

@@ -849,7 +849,7 @@ public func makeDefaultDayPresentationTheme(extendingThemeReference: Presentatio
inputStrokeColor: UIColor(rgb: 0x000000, alpha: 0.1), inputStrokeColor: UIColor(rgb: 0x000000, alpha: 0.1),
inputPlaceholderColor: UIColor(rgb: 0xbebec0), inputPlaceholderColor: UIColor(rgb: 0xbebec0),
inputTextColor: UIColor(rgb: 0x000000), inputTextColor: UIColor(rgb: 0x000000),
inputControlColor: UIColor(rgb: 0xa0a7b0), inputControlColor: UIColor(rgb: 0x868D98),
actionControlFillColor: defaultDayAccentColor, actionControlFillColor: defaultDayAccentColor,
actionControlForegroundColor: UIColor(rgb: 0xffffff), actionControlForegroundColor: UIColor(rgb: 0xffffff),
primaryTextColor: UIColor(rgb: 0x000000), primaryTextColor: UIColor(rgb: 0x000000),

View File

@@ -60,7 +60,7 @@ func accessoryPanelForChatPresentationIntefaceState(_ chatPresentationInterfaceS
forwardPanelNode.updateThemeAndStrings(theme: chatPresentationInterfaceState.theme, strings: chatPresentationInterfaceState.strings, forwardOptionsState: chatPresentationInterfaceState.interfaceState.forwardOptionsState) forwardPanelNode.updateThemeAndStrings(theme: chatPresentationInterfaceState.theme, strings: chatPresentationInterfaceState.strings, forwardOptionsState: chatPresentationInterfaceState.interfaceState.forwardOptionsState)
return forwardPanelNode return forwardPanelNode
} else { } else {
let panelNode = ForwardAccessoryPanelNode(context: context, messageIds: forwardMessageIds, theme: chatPresentationInterfaceState.theme, strings: chatPresentationInterfaceState.strings, fontSize: chatPresentationInterfaceState.fontSize, nameDisplayOrder: chatPresentationInterfaceState.nameDisplayOrder, forwardOptionsState: chatPresentationInterfaceState.interfaceState.forwardOptionsState) let panelNode = ForwardAccessoryPanelNode(context: context, messageIds: forwardMessageIds, theme: chatPresentationInterfaceState.theme, strings: chatPresentationInterfaceState.strings, fontSize: chatPresentationInterfaceState.fontSize, nameDisplayOrder: chatPresentationInterfaceState.nameDisplayOrder, forwardOptionsState: chatPresentationInterfaceState.interfaceState.forwardOptionsState, animationCache: chatControllerInteraction?.presentationContext.animationCache, animationRenderer: chatControllerInteraction?.presentationContext.animationRenderer)
panelNode.interfaceInteraction = interfaceInteraction panelNode.interfaceInteraction = interfaceInteraction
return panelNode return panelNode
} }

View File

@@ -119,7 +119,7 @@ private final class AccessoryItemIconButtonNode: HighlightTrackingButtonNode {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
static func imageAndInsets(item: ChatTextInputAccessoryItem, theme: PresentationTheme, strings: PresentationStrings) -> (UIImage?, String?, String, CGFloat, UIEdgeInsets) { private static func imageAndInsets(item: ChatTextInputAccessoryItem, theme: PresentationTheme, strings: PresentationStrings) -> (UIImage?, String?, String, CGFloat, UIEdgeInsets) {
switch item { switch item {
case let .input(isEnabled, inputMode), let .botInput(isEnabled, inputMode): case let .input(isEnabled, inputMode), let .botInput(isEnabled, inputMode):
switch inputMode { switch inputMode {
@@ -149,7 +149,7 @@ private final class AccessoryItemIconButtonNode: HighlightTrackingButtonNode {
} }
} }
static func calculateWidth(item: ChatTextInputAccessoryItem, image: UIImage?, text: String?, strings: PresentationStrings) -> CGFloat { private static func calculateWidth(item: ChatTextInputAccessoryItem, image: UIImage?, text: String?, strings: PresentationStrings) -> CGFloat {
switch item { switch item {
case .input, .botInput, .silentPost, .commands, .scheduledMessages: case .input, .botInput, .silentPost, .commands, .scheduledMessages:
return 32.0 return 32.0
@@ -175,7 +175,9 @@ private final class AccessoryItemIconButtonNode: HighlightTrackingButtonNode {
self.iconImageNode.frame = imageFrame self.iconImageNode.frame = imageFrame
if let animationView = self.animationView { if let animationView = self.animationView {
let animationFrame = imageFrame.insetBy(dx: -4.0, dy: -4.0) let iconSize: CGSize = CGSize(width: 32.0, height: 32.0)
let iconFrame = CGRect(origin: CGPoint(x: floor((size.width - iconSize.width) / 2.0), y: floor((size.height - iconSize.height) / 2.0) - bottomInset), size: iconSize)
let animationFrame = iconFrame.insetBy(dx: -4.0, dy: -4.0)
var previousInputMode: ChatTextInputAccessoryItem.InputMode? var previousInputMode: ChatTextInputAccessoryItem.InputMode?
var inputMode: ChatTextInputAccessoryItem.InputMode? var inputMode: ChatTextInputAccessoryItem.InputMode?
@@ -274,7 +276,7 @@ private final class AccessoryItemIconButtonNode: HighlightTrackingButtonNode {
colors[colorKey] = self.theme.chat.inputPanel.inputControlColor.blitOver(self.theme.chat.inputPanel.inputBackgroundColor, alpha: 1.0) colors[colorKey] = self.theme.chat.inputPanel.inputControlColor.blitOver(self.theme.chat.inputPanel.inputBackgroundColor, alpha: 1.0)
} }
let _ = animationView.update( let animationSize = animationView.update(
transition: .immediate, transition: .immediate,
component: AnyComponent(LottieAnimationComponent( component: AnyComponent(LottieAnimationComponent(
animation: LottieAnimationComponent.AnimationItem( animation: LottieAnimationComponent.AnimationItem(
@@ -282,7 +284,7 @@ private final class AccessoryItemIconButtonNode: HighlightTrackingButtonNode {
mode: animationMode mode: animationMode
), ),
colors: colors, colors: colors,
size: animationFrame.size size: CGSize(width: 32.0, height: 32.0)
)), )),
environment: {}, environment: {},
containerSize: animationFrame.size containerSize: animationFrame.size
@@ -292,7 +294,7 @@ private final class AccessoryItemIconButtonNode: HighlightTrackingButtonNode {
if view.superview == nil { if view.superview == nil {
self.view.addSubview(view) self.view.addSubview(view)
} }
view.frame = animationFrame view.frame = CGRect(origin: CGPoint(x: animationFrame.minX + floor((animationFrame.width - animationSize.width) / 2.0), y: animationFrame.minY + floor((animationFrame.height - animationSize.height) / 2.0)), size: animationSize)
} }
} }
} }

View File

@@ -15,67 +15,70 @@ import TextFormat
import Markdown import Markdown
import TelegramNotices import TelegramNotices
import ChatPresentationInterfaceState import ChatPresentationInterfaceState
import TextNodeWithEntities
import AnimationCache
import MultiAnimationRenderer
func textStringForForwardedMessage(_ message: Message, strings: PresentationStrings) -> (String, Bool) { func textStringForForwardedMessage(_ message: Message, strings: PresentationStrings) -> (text: String, entities: [MessageTextEntity], isMedia: Bool) {
for media in message.media { for media in message.media {
switch media { switch media {
case _ as TelegramMediaImage: case _ as TelegramMediaImage:
return (strings.Message_Photo, true) return (strings.Message_Photo, [], true)
case let file as TelegramMediaFile: case let file as TelegramMediaFile:
if file.isVideoSticker || file.isAnimatedSticker { if file.isVideoSticker || file.isAnimatedSticker {
return (strings.Message_Sticker, true) return (strings.Message_Sticker, [], true)
} }
var fileName: String = strings.Message_File var fileName: String = strings.Message_File
for attribute in file.attributes { for attribute in file.attributes {
switch attribute { switch attribute {
case .Sticker: case .Sticker:
return (strings.Message_Sticker, true) return (strings.Message_Sticker, [], true)
case let .FileName(name): case let .FileName(name):
fileName = name fileName = name
case let .Audio(isVoice, _, title, performer, _): case let .Audio(isVoice, _, title, performer, _):
if isVoice { if isVoice {
return (strings.Message_Audio, true) return (strings.Message_Audio, [], true)
} else { } else {
if let title = title, let performer = performer, !title.isEmpty, !performer.isEmpty { if let title = title, let performer = performer, !title.isEmpty, !performer.isEmpty {
return (title + "" + performer, true) return (title + "" + performer, [], true)
} else if let title = title, !title.isEmpty { } else if let title = title, !title.isEmpty {
return (title, true) return (title, [], true)
} else if let performer = performer, !performer.isEmpty { } else if let performer = performer, !performer.isEmpty {
return (performer, true) return (performer, [], true)
} else { } else {
return (strings.Message_Audio, true) return (strings.Message_Audio, [], true)
} }
} }
case .Video: case .Video:
if file.isAnimated { if file.isAnimated {
return (strings.Message_Animation, true) return (strings.Message_Animation, [], true)
} else { } else {
return (strings.Message_Video, true) return (strings.Message_Video, [], true)
} }
default: default:
break break
} }
} }
return (fileName, true) return (fileName, [], true)
case _ as TelegramMediaContact: case _ as TelegramMediaContact:
return (strings.Message_Contact, true) return (strings.Message_Contact, [], true)
case let game as TelegramMediaGame: case let game as TelegramMediaGame:
return (game.title, true) return (game.title, [], true)
case _ as TelegramMediaMap: case _ as TelegramMediaMap:
return (strings.Message_Location, true) return (strings.Message_Location, [], true)
case _ as TelegramMediaAction: case _ as TelegramMediaAction:
return ("", true) return ("", [], true)
case _ as TelegramMediaPoll: case _ as TelegramMediaPoll:
return (strings.ForwardedPolls(1), true) return (strings.ForwardedPolls(1), [], true)
case let dice as TelegramMediaDice: case let dice as TelegramMediaDice:
return (dice.emoji, true) return (dice.emoji, [], true)
case let invoice as TelegramMediaInvoice: case let invoice as TelegramMediaInvoice:
return (invoice.title, true) return (invoice.title, [], true)
default: default:
break break
} }
} }
return (message.text, false) return (message.text, message.textEntitiesAttribute?.entities ?? [], false)
} }
final class ForwardAccessoryPanelNode: AccessoryPanelNode { final class ForwardAccessoryPanelNode: AccessoryPanelNode {
@@ -89,7 +92,8 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
let lineNode: ASImageNode let lineNode: ASImageNode
let iconNode: ASImageNode let iconNode: ASImageNode
let titleNode: ImmediateTextNode let titleNode: ImmediateTextNode
let textNode: ImmediateTextNode let textNode: ImmediateTextNodeWithEntities
private var originalText: NSAttributedString?
private let actionArea: AccessibilityAreaNode private let actionArea: AccessibilityAreaNode
@@ -102,7 +106,7 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
private var validLayout: (size: CGSize, inset: CGFloat, interfaceState: ChatPresentationInterfaceState)? private var validLayout: (size: CGSize, inset: CGFloat, interfaceState: ChatPresentationInterfaceState)?
init(context: AccountContext, messageIds: [MessageId], theme: PresentationTheme, strings: PresentationStrings, fontSize: PresentationFontSize, nameDisplayOrder: PresentationPersonNameOrder, forwardOptionsState: ChatInterfaceForwardOptionsState?) { init(context: AccountContext, messageIds: [MessageId], theme: PresentationTheme, strings: PresentationStrings, fontSize: PresentationFontSize, nameDisplayOrder: PresentationPersonNameOrder, forwardOptionsState: ChatInterfaceForwardOptionsState?, animationCache: AnimationCache?, animationRenderer: MultiAnimationRenderer?) {
self.context = context self.context = context
self.messageIds = messageIds self.messageIds = messageIds
self.theme = theme self.theme = theme
@@ -131,7 +135,7 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
self.titleNode.maximumNumberOfLines = 1 self.titleNode.maximumNumberOfLines = 1
self.titleNode.displaysAsynchronously = false self.titleNode.displaysAsynchronously = false
self.textNode = ImmediateTextNode() self.textNode = ImmediateTextNodeWithEntities()
self.textNode.maximumNumberOfLines = 1 self.textNode.maximumNumberOfLines = 1
self.textNode.displaysAsynchronously = false self.textNode.displaysAsynchronously = false
@@ -148,6 +152,16 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
self.addSubnode(self.textNode) self.addSubnode(self.textNode)
self.addSubnode(self.actionArea) self.addSubnode(self.actionArea)
if let animationCache = animationCache, let animationRenderer = animationRenderer {
self.textNode.arguments = TextNodeWithEntities.Arguments(
context: context,
cache: animationCache,
renderer: animationRenderer,
placeholderColor: theme.list.mediaPlaceholderColor,
attemptSynchronous: false
)
}
self.messageDisposable.set((context.account.postbox.messagesAtIds(messageIds) self.messageDisposable.set((context.account.postbox.messagesAtIds(messageIds)
|> deliverOnMainQueue).start(next: { [weak self] messages in |> deliverOnMainQueue).start(next: { [weak self] messages in
if let strongSelf = self { if let strongSelf = self {
@@ -157,7 +171,7 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
var authors = "" var authors = ""
var uniquePeerIds = Set<PeerId>() var uniquePeerIds = Set<PeerId>()
var title = "" var title = ""
var text = "" var text = NSMutableAttributedString(string: "")
var sourcePeer: (Bool, String)? var sourcePeer: (Bool, String)?
for message in messages { for message in messages {
if let author = message.forwardInfo?.author ?? message.effectiveAuthor, !uniquePeerIds.contains(author.id) { if let author = message.forwardInfo?.author ?? message.effectiveAuthor, !uniquePeerIds.contains(author.id) {
@@ -178,11 +192,27 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
if messages.count == 1 { if messages.count == 1 {
title = strongSelf.strings.Conversation_ForwardOptions_ForwardTitleSingle title = strongSelf.strings.Conversation_ForwardOptions_ForwardTitleSingle
let (string, _) = textStringForForwardedMessage(messages[0], strings: strings) let (string, entities, _) = textStringForForwardedMessage(messages[0], strings: strings)
text = "\(authors): \(string)"
text = NSMutableAttributedString(attributedString: NSAttributedString(string: "\(authors): ", font: Font.regular(15.0), textColor: strongSelf.theme.chat.inputPanel.secondaryTextColor))
let additionalText = NSMutableAttributedString(attributedString: NSAttributedString(string: string, font: Font.regular(15.0), textColor: strongSelf.theme.chat.inputPanel.secondaryTextColor))
for entity in entities {
switch entity.type {
case let .CustomEmoji(_, fileId):
let range = NSRange(location: entity.range.lowerBound, length: entity.range.upperBound - entity.range.lowerBound)
if range.lowerBound >= 0 && range.upperBound <= additionalText.length {
additionalText.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(stickerPack: nil, fileId: fileId, file: messages[0].associatedMedia[MediaId(namespace: Namespaces.Media.CloudFile, id: fileId)] as? TelegramMediaFile), range: range)
}
default:
break
}
}
text.append(additionalText)
} else { } else {
title = strongSelf.strings.Conversation_ForwardOptions_ForwardTitle(Int32(messages.count)) title = strongSelf.strings.Conversation_ForwardOptions_ForwardTitle(Int32(messages.count))
text = strongSelf.strings.Conversation_ForwardFrom(authors).string text = NSMutableAttributedString(attributedString: NSAttributedString(string: strongSelf.strings.Conversation_ForwardFrom(authors).string, font: Font.regular(15.0), textColor: strongSelf.theme.chat.inputPanel.secondaryTextColor))
} }
strongSelf.messages = messages strongSelf.messages = messages
@@ -190,7 +220,9 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
strongSelf.authors = authors strongSelf.authors = authors
strongSelf.titleNode.attributedText = NSAttributedString(string: title, font: Font.medium(15.0), textColor: strongSelf.theme.chat.inputPanel.panelControlAccentColor) strongSelf.titleNode.attributedText = NSAttributedString(string: title, font: Font.medium(15.0), textColor: strongSelf.theme.chat.inputPanel.panelControlAccentColor)
strongSelf.textNode.attributedText = NSAttributedString(string: text, font: Font.regular(15.0), textColor: strongSelf.theme.chat.inputPanel.secondaryTextColor) strongSelf.textNode.attributedText = text
strongSelf.originalText = text
strongSelf.textNode.visibility = true
let headerString: String let headerString: String
if messages.count == 1 { if messages.count == 1 {
@@ -273,25 +305,21 @@ final class ForwardAccessoryPanelNode: AccessoryPanelNode {
let filteredMessages = self.messages let filteredMessages = self.messages
var authors = self.authors ?? ""
if forwardOptionsState?.hideNames == true {
authors = self.strings.DialogList_You
}
var title = "" var title = ""
var text = "" if filteredMessages.count == 1 {
if filteredMessages.count == 1, let message = filteredMessages.first {
title = self.strings.Conversation_ForwardOptions_ForwardTitleSingle title = self.strings.Conversation_ForwardOptions_ForwardTitleSingle
let (string, _) = textStringForForwardedMessage(message, strings: strings)
text = "\(authors): \(string)"
} else { } else {
title = self.strings.Conversation_ForwardOptions_ForwardTitle(Int32(filteredMessages.count)) title = self.strings.Conversation_ForwardOptions_ForwardTitle(Int32(filteredMessages.count))
text = self.strings.Conversation_ForwardFrom(authors).string
} }
self.titleNode.attributedText = NSAttributedString(string: title, font: Font.medium(15.0), textColor: self.theme.chat.inputPanel.panelControlAccentColor) self.titleNode.attributedText = NSAttributedString(string: title, font: Font.medium(15.0), textColor: self.theme.chat.inputPanel.panelControlAccentColor)
self.textNode.attributedText = NSAttributedString(string: text, font: Font.regular(15.0), textColor: self.theme.chat.inputPanel.secondaryTextColor) if let attributedText = self.textNode.attributedText {
let updatedText = NSMutableAttributedString(attributedString: attributedText)
updatedText.addAttribute(.foregroundColor, value: self.theme.chat.inputPanel.secondaryTextColor, range: NSRange(location: 0, length: updatedText.length))
self.textNode.attributedText = updatedText
self.originalText = updatedText
}
if let (size, inset, interfaceState) = self.validLayout { if let (size, inset, interfaceState) = self.validLayout {
self.updateState(size: size, inset: inset, interfaceState: interfaceState) self.updateState(size: size, inset: inset, interfaceState: interfaceState)

View File

@@ -386,7 +386,7 @@ final class PeerSelectionControllerNode: ASDisplayNode {
func beginSelection() { func beginSelection() {
if let _ = self.textInputPanelNode { if let _ = self.textInputPanelNode {
} else { } else {
let forwardAccessoryPanelNode = ForwardAccessoryPanelNode(context: self.context, messageIds: self.forwardedMessageIds, theme: self.presentationData.theme, strings: self.presentationData.strings, fontSize: self.presentationData.chatFontSize, nameDisplayOrder: self.presentationData.nameDisplayOrder, forwardOptionsState: self.presentationInterfaceState.interfaceState.forwardOptionsState) let forwardAccessoryPanelNode = ForwardAccessoryPanelNode(context: self.context, messageIds: self.forwardedMessageIds, theme: self.presentationData.theme, strings: self.presentationData.strings, fontSize: self.presentationData.chatFontSize, nameDisplayOrder: self.presentationData.nameDisplayOrder, forwardOptionsState: self.presentationInterfaceState.interfaceState.forwardOptionsState, animationCache: nil, animationRenderer: nil)
forwardAccessoryPanelNode.interfaceInteraction = self.interfaceInteraction forwardAccessoryPanelNode.interfaceInteraction = self.interfaceInteraction
self.addSubnode(forwardAccessoryPanelNode) self.addSubnode(forwardAccessoryPanelNode)
self.forwardAccessoryPanelNode = forwardAccessoryPanelNode self.forwardAccessoryPanelNode = forwardAccessoryPanelNode