mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Don't crash when scrolling to the oldest item before the data is applied
scrollToOldestItem targeted (timelineItemsIDs.count - 1, section: 1) even when the table's data source hadn't applied that section yet, raising an out-of-bounds NSRangeException. Scroll against the table's actual section and row counts instead.
This commit is contained in:
@@ -420,10 +420,13 @@ class TimelineTableViewController: UIViewController {
|
||||
|
||||
/// Scrolls to the oldest item in the timeline.
|
||||
private func scrollToOldestItem(animated: Bool) {
|
||||
guard !timelineItemsIDs.isEmpty else {
|
||||
// The data source can lag behind timelineItemsIDs, so scroll against the table's actual
|
||||
// contents to avoid targeting a section or row that doesn't exist yet.
|
||||
guard tableView.numberOfSections > 1,
|
||||
tableView.numberOfRows(inSection: 1) > 0 else {
|
||||
return
|
||||
}
|
||||
tableView.scrollToRow(at: IndexPath(item: timelineItemsIDs.count - 1, section: 1), at: .bottom, animated: animated)
|
||||
tableView.scrollToRow(at: IndexPath(item: tableView.numberOfRows(inSection: 1) - 1, section: 1), at: .bottom, animated: animated)
|
||||
scrollDirectionPublisher.send(.top)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user