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 136ecb125c
commit d8845303fd
2 changed files with 8 additions and 6 deletions
@@ -193,8 +193,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
case .focusLive: case .focusLive:
focusLive() focusLive()
case .scrolledToFocussedItem: case .scrolledToFocussedItem:
// Use a Task to mutate view state after the current view update. didScrollToFocussedItem()
Task { didScrollToFocussedItem() }
case .hasSwitchedTimeline: case .hasSwitchedTimeline:
Task { state.timelineViewState.isSwitchingTimelines = false } Task { state.timelineViewState.isSwitchingTimelines = false }
} }
@@ -340,12 +340,15 @@ class TimelineTableViewController: UIViewController {
/// Scrolls to the item with the corresponding event ID if loaded in the timeline. /// Scrolls to the item with the corresponding event ID if loaded in the timeline.
private func scrollToItem(eventID: String, animated: Bool) { private func scrollToItem(eventID: String, animated: Bool) {
DispatchQueue.main.async { [weak self] in // Fixes #2805
guard let self else { return }
if let kvPair = timelineItemsDictionary.first(where: { $0.value.identifier.eventID == eventID }), if let kvPair = timelineItemsDictionary.first(where: { $0.value.identifier.eventID == eventID }),
let indexPath = dataSource?.indexPath(for: kvPair.key) { let indexPath = dataSource?.indexPath(for: kvPair.key) {
tableView.scrollToRow(at: indexPath, at: .middle, animated: animated) tableView.scrollToRow(at: indexPath, at: .middle, animated: animated)
coordinator.send(viewAction: .scrolledToFocussedItem) coordinator.send(viewAction: .scrolledToFocussedItem)
} }
} }
}
/// Checks whether or not pagination is needed in either direction and requests one if so. /// Checks whether or not pagination is needed in either direction and requests one if so.
/// ///