From b17b7b7a24463145c464c90d16514c679e1cef8e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Mon, 2 Jan 2023 17:18:30 -0500 Subject: [PATCH] Fix crash when inserting present items when there are no existing items --- Tusker/Screens/Timeline/TimelineViewController.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index 48160fd4..9a4b208c 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -621,9 +621,12 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro snapshot.insertItems(presentItems.map { .status(id: $0, collapseState: .unknown, filterState: .unknown) }, beforeItem: .gap) if applySnapshotBeforeScrolling { - let firstVisibleIndexPath = collectionView.indexPathsForVisibleItems.min()! - let firstVisibleItem = dataSource.itemIdentifier(for: firstVisibleIndexPath)! - applySnapshot(snapshot, maintainingBottomRelativeScrollPositionOf: firstVisibleItem) + if let firstVisibleIndexPath = collectionView.indexPathsForVisibleItems.min() { + let firstVisibleItem = dataSource.itemIdentifier(for: firstVisibleIndexPath)! + applySnapshot(snapshot, maintainingBottomRelativeScrollPositionOf: firstVisibleItem) + } else { + dataSource.apply(snapshot, animatingDifferences: false) + } } var config = ToastConfiguration(title: "Jump to Present")