do not show number when there is only 1 react per emoji in 1-1 convos
This commit is contained in:
parent
a572c4274b
commit
c33680fe70
|
@ -18,6 +18,7 @@ final class ReactionContainerView : UIView {
|
|||
|
||||
private var showingAllReactions = false
|
||||
private var isOutgoingMessage = false
|
||||
private var showNumbers = true
|
||||
private var maxEmojisPerLine = isIPhone6OrSmaller ? 5 : 6
|
||||
|
||||
var reactions: [(String, (Int, Bool))] = []
|
||||
|
@ -57,9 +58,10 @@ final class ReactionContainerView : UIView {
|
|||
mainStackView.pin(to: self)
|
||||
}
|
||||
|
||||
public func update(_ reactions: [(String, (Int, Bool))], isOutgoingMessage: Bool) {
|
||||
public func update(_ reactions: [(String, (Int, Bool))], isOutgoingMessage: Bool, showNumbers: Bool) {
|
||||
self.reactions = reactions
|
||||
self.isOutgoingMessage = isOutgoingMessage
|
||||
self.showNumbers = showNumbers
|
||||
prepareForUpdate()
|
||||
if showingAllReactions {
|
||||
updateAllReactions()
|
||||
|
@ -93,7 +95,7 @@ final class ReactionContainerView : UIView {
|
|||
}
|
||||
|
||||
for reaction in displayedReactions {
|
||||
let reactionView = ReactionButton(emoji: reaction.0, value: reaction.1.0, showBorder: reaction.1.1)
|
||||
let reactionView = ReactionButton(emoji: reaction.0, value: reaction.1.0, showBorder: reaction.1.1, showNumber: showNumbers)
|
||||
stackView.addArrangedSubview(reactionView)
|
||||
reactionViews.append(reactionView)
|
||||
}
|
||||
|
@ -131,13 +133,13 @@ final class ReactionContainerView : UIView {
|
|||
public func showAllEmojis() {
|
||||
guard !showingAllReactions else { return }
|
||||
showingAllReactions = true
|
||||
update(reactions, isOutgoingMessage: isOutgoingMessage)
|
||||
update(reactions, isOutgoingMessage: isOutgoingMessage, showNumbers: showNumbers)
|
||||
}
|
||||
|
||||
public func showLessEmojis() {
|
||||
guard showingAllReactions else { return }
|
||||
showingAllReactions = false
|
||||
update(reactions, isOutgoingMessage: isOutgoingMessage)
|
||||
update(reactions, isOutgoingMessage: isOutgoingMessage, showNumbers: showNumbers)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ final class ReactionButton : UIView {
|
|||
let emoji: String
|
||||
let number: Int
|
||||
let showBorder: Bool
|
||||
let showNumber: Bool
|
||||
|
||||
// MARK: Settings
|
||||
private var height: CGFloat = 22
|
||||
|
@ -12,10 +13,11 @@ final class ReactionButton : UIView {
|
|||
private var spacing: CGFloat = Values.verySmallSpacing
|
||||
|
||||
// MARK: Lifecycle
|
||||
init(emoji: String, value: Int, showBorder: Bool = false) {
|
||||
init(emoji: String, value: Int, showBorder: Bool = false, showNumber: Bool = true) {
|
||||
self.emoji = emoji
|
||||
self.number = value
|
||||
self.showBorder = showBorder
|
||||
self.showNumber = showNumber
|
||||
super.init(frame: CGRect.zero)
|
||||
setUpViewHierarchy()
|
||||
}
|
||||
|
@ -33,12 +35,7 @@ final class ReactionButton : UIView {
|
|||
emojiLabel.text = emoji
|
||||
emojiLabel.font = .systemFont(ofSize: fontSize)
|
||||
|
||||
let numberLabel = UILabel()
|
||||
numberLabel.text = self.number < 1000 ? "\(number)" : String(format: "%.1f", Float(number) / 1000) + "k"
|
||||
numberLabel.font = .systemFont(ofSize: fontSize)
|
||||
numberLabel.textColor = Colors.text
|
||||
|
||||
let stackView = UIStackView(arrangedSubviews: [ emojiLabel, numberLabel ])
|
||||
let stackView = UIStackView(arrangedSubviews: [ emojiLabel ])
|
||||
stackView.axis = .horizontal
|
||||
stackView.spacing = spacing
|
||||
stackView.alignment = .center
|
||||
|
@ -54,6 +51,14 @@ final class ReactionButton : UIView {
|
|||
if showBorder {
|
||||
self.addBorder(with: Colors.accent)
|
||||
}
|
||||
|
||||
if showNumber || self.number > 1 {
|
||||
let numberLabel = UILabel()
|
||||
numberLabel.text = self.number < 1000 ? "\(number)" : String(format: "%.1f", Float(number) / 1000) + "k"
|
||||
numberLabel.font = .systemFont(ofSize: fontSize)
|
||||
numberLabel.textColor = Colors.text
|
||||
stackView.addArrangedSubview(numberLabel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -467,7 +467,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
|
|||
}
|
||||
}
|
||||
}
|
||||
reactionContainerView.update(reactions.orderedItems, isOutgoingMessage: direction == .outgoing)
|
||||
reactionContainerView.update(reactions.orderedItems, isOutgoingMessage: direction == .outgoing, showNumbers: thread!.isGroupThread())
|
||||
}
|
||||
|
||||
override func layoutSubviews() {
|
||||
|
|
Loading…
Reference in New Issue