Skip to content

Commit f960a0e

Browse files
authored
Merge pull request #706 from Adamant-im/trello.com/c/NOMM1JYt
[trello.com/c/NOMM1JYt] fix Lags on Chats screen
2 parents f5276b9 + 5b33325 commit f960a0e

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Adamant/Modules/ChatsList/ChatListViewController.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ final class ChatListViewController: KeyboardObservingViewController {
130130

131131
private var loadNewChatTask: Task<(), Never>?
132132
private var subscriptions = Set<AnyCancellable>()
133-
133+
private var swipedIndex: IndexPath?
134134
// MARK: Init
135135

136136
init(
@@ -360,12 +360,13 @@ final class ChatListViewController: KeyboardObservingViewController {
360360
/// update specific rows in the tableView to refresh the dates.
361361
private func refreshDatesIfNeeded() {
362362
guard !isBusy,
363-
let indexPaths = tableView.indexPathsForVisibleRows
363+
var indexPaths = tableView.indexPathsForVisibleRows
364364
else {
365365
return
366366
}
367367

368368
lastDatesUpdate = Date()
369+
indexPaths.removeAll { $0 == swipedIndex }
369370
tableView.reloadRowsAndPreserveSelection(at: indexPaths)
370371
}
371372

@@ -1074,6 +1075,7 @@ extension ChatListViewController {
10741075
_ tableView: UITableView,
10751076
trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath
10761077
) -> UISwipeActionsConfiguration? {
1078+
swipedIndex = indexPath
10771079
guard let chatroom = chatsController?.fetchedObjects?[safe: indexPath.row] else {
10781080
return nil
10791081
}
@@ -1095,6 +1097,7 @@ extension ChatListViewController {
10951097
_ tableView: UITableView,
10961098
leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath
10971099
) -> UISwipeActionsConfiguration? {
1100+
swipedIndex = indexPath
10981101
guard let chatroom = chatsController?.fetchedObjects?[safe: indexPath.row] else {
10991102
return nil
11001103
}
@@ -1106,7 +1109,12 @@ extension ChatListViewController {
11061109

11071110
return UISwipeActionsConfiguration(actions: actions)
11081111
}
1109-
1112+
func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
1113+
swipedIndex = nil
1114+
if let indexPath {
1115+
tableView.reloadRowsAndPreserveSelection(at: [indexPath])
1116+
}
1117+
}
11101118
private func blockChat(with address: String, for chatroom: Chatroom?) {
11111119
Task {
11121120
chatroom?.isHidden = true

0 commit comments

Comments
 (0)