From d5948c014242ec5378b3deced26b3769e739933b Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 31 Aug 2022 17:42:37 +1000 Subject: [PATCH] fix a crash when remove reaction and there are exactly 6 reactors --- .../Views & Modals/ReactionListSheet.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Session/Conversations/Views & Modals/ReactionListSheet.swift b/Session/Conversations/Views & Modals/ReactionListSheet.swift index 3aab2bf3e..2de3cca58 100644 --- a/Session/Conversations/Views & Modals/ReactionListSheet.swift +++ b/Session/Conversations/Views & Modals/ReactionListSheet.swift @@ -326,7 +326,10 @@ final class ReactionListSheet: BaseVC { deleteRowsAnimation: .none, insertRowsAnimation: .none, reloadRowsAnimation: .none, - interrupt: { $0.changeCount > 100 } + interrupt: { + $0.elementInserted.count == 1 && self.selectedReactionUserList.count == 4 || + $0.changeCount > 100 + } ) { [weak self] updatedData in self?.selectedReactionUserList = updatedData } @@ -387,18 +390,19 @@ extension ReactionListSheet: UICollectionViewDataSource, UICollectionViewDelegat extension ReactionListSheet: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - let moreReactorCount = self.reactionSummaries[lastSelectedReactionIndex].number - self.selectedReactionUserList.count - return moreReactorCount > 0 ? self.selectedReactionUserList.count + 1 : self.selectedReactionUserList.count + return self.selectedReactionUserList.count + 1 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { guard indexPath.row < self.selectedReactionUserList.count else { + let moreReactorCount = self.reactionSummaries[lastSelectedReactionIndex].number - self.selectedReactionUserList.count let footerCell: FooterCell = tableView.dequeue(type: FooterCell.self, for: indexPath) footerCell.update( - moreReactorCount: self.reactionSummaries[lastSelectedReactionIndex].number - self.selectedReactionUserList.count, + moreReactorCount: moreReactorCount, emoji: self.reactionSummaries[lastSelectedReactionIndex].emoji.rawValue ) footerCell.selectionStyle = .none + footerCell.isHidden = (moreReactorCount <= 0) return footerCell }