Fixes #2805 - Fixes animation artifacts when focusing on in-reply-to messages

This commit is contained in:
Stefan Ceriu
2024-05-10 15:36:37 +03:00
committed by Stefan Ceriu
parent 434a6428ee
commit cc4bc179af
2 changed files with 8 additions and 6 deletions

View File

@@ -193,8 +193,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
case .focusLive:
focusLive()
case .scrolledToFocussedItem:
// Use a Task to mutate view state after the current view update.
Task { didScrollToFocussedItem() }
didScrollToFocussedItem()
case .hasSwitchedTimeline:
Task { state.timelineViewState.isSwitchingTimelines = false }
}

View File

@@ -340,10 +340,13 @@ class TimelineTableViewController: UIViewController {
/// Scrolls to the item with the corresponding event ID if loaded in the timeline.
private func scrollToItem(eventID: String, animated: Bool) {
if let kvPair = timelineItemsDictionary.first(where: { $0.value.identifier.eventID == eventID }),
let indexPath = dataSource?.indexPath(for: kvPair.key) {
tableView.scrollToRow(at: indexPath, at: .middle, animated: animated)
coordinator.send(viewAction: .scrolledToFocussedItem)
DispatchQueue.main.async { [weak self] in // Fixes #2805
guard let self else { return }
if let kvPair = timelineItemsDictionary.first(where: { $0.value.identifier.eventID == eventID }),
let indexPath = dataSource?.indexPath(for: kvPair.key) {
tableView.scrollToRow(at: indexPath, at: .middle, animated: animated)
coordinator.send(viewAction: .scrolledToFocussedItem)
}
}
}