From c33680fe700f8676674757abf88ad090f1379298 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Mon, 6 Jun 2022 16:42:35 +1000 Subject: [PATCH] do not show number when there is only 1 react per emoji in 1-1 convos --- .../Content Views/ReactionContainerView.swift | 10 ++++++---- .../Content Views/ReactionView.swift | 19 ++++++++++++------- .../Message Cells/VisibleMessageCell.swift | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Session/Conversations/Message Cells/Content Views/ReactionContainerView.swift b/Session/Conversations/Message Cells/Content Views/ReactionContainerView.swift index d99aca43a..5a71d539d 100644 --- a/Session/Conversations/Message Cells/Content Views/ReactionContainerView.swift +++ b/Session/Conversations/Message Cells/Content Views/ReactionContainerView.swift @@ -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) } } diff --git a/Session/Conversations/Message Cells/Content Views/ReactionView.swift b/Session/Conversations/Message Cells/Content Views/ReactionView.swift index 627195692..3c1c6cd8d 100644 --- a/Session/Conversations/Message Cells/Content Views/ReactionView.swift +++ b/Session/Conversations/Message Cells/Content Views/ReactionView.swift @@ -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) + } } } diff --git a/Session/Conversations/Message Cells/VisibleMessageCell.swift b/Session/Conversations/Message Cells/VisibleMessageCell.swift index c189354fd..35b03b8c6 100644 --- a/Session/Conversations/Message Cells/VisibleMessageCell.swift +++ b/Session/Conversations/Message Cells/VisibleMessageCell.swift @@ -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() {