ui: fix reaction views automatically collapse
This commit is contained in:
parent
b6b99fac69
commit
ee9d856e3c
|
@ -39,6 +39,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
|||
var baselineKeyboardHeight: CGFloat = 0
|
||||
// Reaction
|
||||
var showingReactionListForMessageId: String?
|
||||
var reactionExpandedMessageIds: Set<String> = []
|
||||
|
||||
var audioSession: OWSAudioSession { Environment.shared.audioSession }
|
||||
var dbConnection: YapDatabaseConnection { OWSPrimaryStorage.shared().uiDatabaseConnection }
|
||||
|
@ -454,6 +455,7 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
|||
|
||||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||
let viewItem = viewItems[indexPath.row]
|
||||
viewItem.reactionShouldExpanded = reactionExpandedMessageIds.contains(viewItem.interaction.uniqueId ?? "")
|
||||
let cell = tableView.dequeueReusableCell(withIdentifier: MessageCell.getCellType(for: viewItem).identifier) as! MessageCell
|
||||
cell.delegate = self
|
||||
cell.thread = thread
|
||||
|
@ -767,11 +769,18 @@ final class ConversationVC : BaseVC, ConversationViewModelDelegate, OWSConversat
|
|||
return UITableView.automaticDimension
|
||||
}
|
||||
|
||||
func needsLayout() {
|
||||
func needsLayout(for viewItem: ConversationViewItem, expandingReactions: Bool) {
|
||||
UIView.setAnimationsEnabled(false)
|
||||
messagesTableView.beginUpdates()
|
||||
messagesTableView.endUpdates()
|
||||
UIView.setAnimationsEnabled(true)
|
||||
if let messageId = viewItem.interaction.uniqueId {
|
||||
if expandingReactions {
|
||||
reactionExpandedMessageIds.insert(messageId)
|
||||
} else {
|
||||
reactionExpandedMessageIds.remove(messageId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func getMediaCache() -> NSCache<NSString, AnyObject> {
|
||||
|
|
|
@ -121,6 +121,8 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType);
|
|||
|
||||
@property (nonatomic, readonly, nullable) NSString *systemMessageText;
|
||||
|
||||
@property (nonatomic) BOOL reactionShouldExpanded;
|
||||
|
||||
// NOTE: This property is only set for incoming messages.
|
||||
@property (nonatomic, readonly, nullable) NSString *authorConversationColorName;
|
||||
|
||||
|
|
|
@ -121,6 +121,7 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|||
@synthesize lastAudioMessageView = _lastAudioMessageView;
|
||||
@synthesize senderName = _senderName;
|
||||
@synthesize shouldHideFooter = _shouldHideFooter;
|
||||
@synthesize reactionShouldExpanded = _reactionShouldExpanded;
|
||||
|
||||
- (instancetype)initWithInteraction:(TSInteraction *)interaction
|
||||
isGroupThread:(BOOL)isGroupThread
|
||||
|
@ -295,6 +296,13 @@ NSString *NSStringForOWSMessageCellType(OWSMessageCellType cellType)
|
|||
[self clearCachedLayoutState];
|
||||
}
|
||||
|
||||
- (void)setReactionShouldExpanded:(BOOL)reactionShouldExpanded
|
||||
{
|
||||
_reactionShouldExpanded = reactionShouldExpanded;
|
||||
|
||||
[self clearCachedLayoutState];
|
||||
}
|
||||
|
||||
- (void)clearCachedLayoutState
|
||||
{
|
||||
self.cachedCellSize = nil;
|
||||
|
|
|
@ -16,7 +16,7 @@ final class ReactionContainerView : UIView {
|
|||
return result
|
||||
}()
|
||||
|
||||
private var showingAllReactions = false
|
||||
var showingAllReactions = false
|
||||
private var isOutgoingMessage = false
|
||||
private var showNumbers = true
|
||||
private var maxEmojisPerLine = isIPhone6OrSmaller ? 5 : 6
|
||||
|
|
|
@ -81,5 +81,5 @@ protocol MessageCellDelegate : ReactionDelegate {
|
|||
func handleReplyButtonTapped(for viewItem: ConversationViewItem)
|
||||
func showUserDetails(for sessionID: String)
|
||||
func showReactionList(_ viewItem: ConversationViewItem, selectedReaction: EmojiWithSkinTones?)
|
||||
func needsLayout()
|
||||
func needsLayout(for viewItem: ConversationViewItem, expandingReactions: Bool)
|
||||
}
|
||||
|
|
|
@ -468,6 +468,7 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
|
|||
}
|
||||
}
|
||||
}
|
||||
reactionContainerView.showingAllReactions = viewItem.reactionShouldExpanded
|
||||
reactionContainerView.update(reactions.orderedItems.map { ReactionViewModel(emoji: $0.0, value: $0.1.0, showBorder:$0.1.1 )}, isOutgoingMessage: direction == .outgoing, showNumbers: thread!.isGroupThread())
|
||||
}
|
||||
|
||||
|
@ -579,11 +580,11 @@ final class VisibleMessageCell : MessageCell, LinkPreviewViewDelegate {
|
|||
}
|
||||
if let expandButton = reactionContainerView.expandButton, expandButton.frame.contains(convertedLocation) {
|
||||
reactionContainerView.showAllEmojis()
|
||||
delegate?.needsLayout()
|
||||
delegate?.needsLayout(for: viewItem, expandingReactions: true)
|
||||
}
|
||||
if reactionContainerView.collapseButton.frame.contains(convertedLocation) {
|
||||
reactionContainerView.showLessEmojis()
|
||||
delegate?.needsLayout()
|
||||
delegate?.needsLayout(for: viewItem, expandingReactions: false)
|
||||
}
|
||||
} else {
|
||||
delegate?.handleViewItemTapped(viewItem, gestureRecognizer: gestureRecognizer)
|
||||
|
|
Loading…
Reference in New Issue