mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Reaction improvements
This commit is contained in:
parent
73b49b6039
commit
f830972d32
4 changed files with 57 additions and 22 deletions
|
|
@ -153,7 +153,7 @@ public final class ReactionButtonAsyncNode: ContextControllerSourceNode {
|
|||
}
|
||||
|
||||
var counterComponents: [String] = []
|
||||
for character in "\(spec.component.count)" {
|
||||
for character in countString(Int64(spec.component.count)) {
|
||||
counterComponents.append(String(character))
|
||||
}
|
||||
|
||||
|
|
@ -164,12 +164,12 @@ public final class ReactionButtonAsyncNode: ContextControllerSourceNode {
|
|||
var previousDisplayCounter: String?
|
||||
if let currentLayout = currentLayout {
|
||||
if currentLayout.spec.component.avatarPeers.isEmpty {
|
||||
previousDisplayCounter = "\(spec.component.count)"
|
||||
previousDisplayCounter = countString(Int64(spec.component.count))
|
||||
}
|
||||
}
|
||||
var currentDisplayCounter: String?
|
||||
if spec.component.avatarPeers.isEmpty {
|
||||
currentDisplayCounter = "\(spec.component.count)"
|
||||
currentDisplayCounter = countString(Int64(spec.component.count))
|
||||
}
|
||||
|
||||
let backgroundImage: UIImage
|
||||
|
|
@ -669,7 +669,7 @@ public final class ReactionButtonComponent: Component {
|
|||
|
||||
self.iconView.frame = CGRect(origin: CGPoint(x: sideInsets, y: floorToScreenPixels((height - imageSize.height) / 2.0)), size: imageSize)
|
||||
|
||||
let text = "\(component.count)"
|
||||
let text = countString(Int64(component.count))
|
||||
var measureText = ""
|
||||
for _ in 0 ..< text.count {
|
||||
measureText.append("0")
|
||||
|
|
|
|||
|
|
@ -95,3 +95,31 @@ public func dataSizeString(_ size: Int64, forceDecimal: Bool = false, formatting
|
|||
return formatting.byte("\(size)").string
|
||||
}
|
||||
}
|
||||
|
||||
public func countString(_ count: Int64, forceDecimal: Bool = false) -> String {
|
||||
let decimalSeparator = "."
|
||||
if count >= 1000 * 1000 * 1000 {
|
||||
let remainder = Int64((Double(count % (1000 * 1000 * 1000)) / (1000 * 1000 * 100.0)).rounded(.down))
|
||||
if remainder != 0 || forceDecimal {
|
||||
return "\(count / (1000 * 1000 * 1000))\(decimalSeparator)\(remainder)T"
|
||||
} else {
|
||||
return "\(count / (1000 * 1000 * 1000))T"
|
||||
}
|
||||
} else if count >= 1000 * 1000 {
|
||||
let remainder = Int64((Double(count % (1000 * 1000)) / (1000.0 * 100.0)).rounded(.down))
|
||||
if remainder != 0 || forceDecimal {
|
||||
return "\(count / (1000 * 1000))\(decimalSeparator)\(remainder)M"
|
||||
} else {
|
||||
return "\(count / (1000 * 1000))M"
|
||||
}
|
||||
} else if count >= 1000 {
|
||||
let remainder = (count % (1000)) / (102)
|
||||
if remainder != 0 || forceDecimal {
|
||||
return "\(count / 1000)\(decimalSeparator)\(remainder)K"
|
||||
} else {
|
||||
return "\(count / 1000)K"
|
||||
}
|
||||
} else {
|
||||
return "\(count)"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1265,23 +1265,27 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
|||
}
|
||||
}
|
||||
})
|
||||
} else if let removedReaction = removedReaction, let targetView = itemNode.targetReactionView(value: removedReaction), shouldDisplayInlineDateReactions(message: message) {
|
||||
var hideRemovedReaction: Bool = false
|
||||
if let reactions = mergedMessageReactions(attributes: message.attributes) {
|
||||
for reaction in reactions.reactions {
|
||||
if reaction.value == removedReaction {
|
||||
hideRemovedReaction = reaction.count == 1
|
||||
break
|
||||
} else {
|
||||
strongSelf.chatDisplayNode.messageTransitionNode.dismissMessageReactionContexts(itemNode: itemNode)
|
||||
|
||||
if let removedReaction = removedReaction, let targetView = itemNode.targetReactionView(value: removedReaction), shouldDisplayInlineDateReactions(message: message) {
|
||||
var hideRemovedReaction: Bool = false
|
||||
if let reactions = mergedMessageReactions(attributes: message.attributes) {
|
||||
for reaction in reactions.reactions {
|
||||
if reaction.value == removedReaction {
|
||||
hideRemovedReaction = reaction.count == 1
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let standaloneDismissAnimation = StandaloneDismissReactionAnimation()
|
||||
standaloneDismissAnimation.frame = strongSelf.chatDisplayNode.bounds
|
||||
strongSelf.chatDisplayNode.addSubnode(standaloneDismissAnimation)
|
||||
standaloneDismissAnimation.animateReactionDismiss(sourceView: targetView, hideNode: hideRemovedReaction, completion: { [weak standaloneDismissAnimation] in
|
||||
standaloneDismissAnimation?.removeFromSupernode()
|
||||
})
|
||||
}
|
||||
|
||||
let standaloneDismissAnimation = StandaloneDismissReactionAnimation()
|
||||
standaloneDismissAnimation.frame = strongSelf.chatDisplayNode.bounds
|
||||
strongSelf.chatDisplayNode.addSubnode(standaloneDismissAnimation)
|
||||
standaloneDismissAnimation.animateReactionDismiss(sourceView: targetView, hideNode: hideRemovedReaction, completion: { [weak standaloneDismissAnimation] in
|
||||
standaloneDismissAnimation?.removeFromSupernode()
|
||||
})
|
||||
}
|
||||
|
||||
let _ = updateMessageReactionsInteractively(account: strongSelf.context.account, messageId: message.id, reaction: updatedReaction).start()
|
||||
|
|
|
|||
|
|
@ -775,11 +775,14 @@ public final class ChatMessageTransitionNode: ASDisplayNode {
|
|||
}
|
||||
}
|
||||
|
||||
func dismissMessageReactionContexts() {
|
||||
for messageReactionContext in self.messageReactionContexts {
|
||||
messageReactionContext.dismiss()
|
||||
func dismissMessageReactionContexts(itemNode: ListViewItemNode? = nil) {
|
||||
for i in (0 ..< self.messageReactionContexts.count).reversed() {
|
||||
let messageReactionContext = self.messageReactionContexts[i]
|
||||
if itemNode == nil || messageReactionContext.itemNode === itemNode {
|
||||
self.messageReactionContexts.remove(at: i)
|
||||
messageReactionContext.dismiss()
|
||||
}
|
||||
}
|
||||
self.messageReactionContexts.removeAll()
|
||||
}
|
||||
|
||||
func addMessageContextController(messageId: MessageId, contextController: ContextController) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue