Renaming for clarity

This commit is contained in:
shannon 2024-12-17 12:55:28 -05:00
parent a5ca642a7f
commit 99fad6fb23

View File

@ -127,34 +127,34 @@ extension HomeTimelineViewModel {
oldSnapshot: NSDiffableDataSourceSnapshot<S, T>, oldSnapshot: NSDiffableDataSourceSnapshot<S, T>,
newSnapshot: NSDiffableDataSourceSnapshot<S, T> newSnapshot: NSDiffableDataSourceSnapshot<S, T>
) -> Difference<T>? { ) -> Difference<T>? {
guard let sourceIndexPath = (tableView.indexPathsForVisibleRows ?? []).sorted().first else { return nil } guard let currentFirstVisibleIndexPath = (tableView.indexPathsForVisibleRows ?? []).sorted().first else { return nil }
let rectForSourceItemCell = tableView.rectForRow(at: sourceIndexPath) let rectForCurrentFirstVisibleCell = tableView.rectForRow(at: currentFirstVisibleIndexPath)
let sourceDistanceToTableViewTopEdge: CGFloat = { let currentDistanceFromFirstVisibleCellToTableViewTopEdge: CGFloat = {
if tableView.window != nil { if tableView.window != nil {
return tableView.convert(rectForSourceItemCell, to: nil).origin.y - tableView.safeAreaInsets.top return tableView.convert(rectForCurrentFirstVisibleCell, to: nil).origin.y - tableView.safeAreaInsets.top
} else { } else {
return rectForSourceItemCell.origin.y - tableView.contentOffset.y - tableView.safeAreaInsets.top return rectForCurrentFirstVisibleCell.origin.y - tableView.contentOffset.y - tableView.safeAreaInsets.top
} }
}() }()
guard sourceIndexPath.section < oldSnapshot.numberOfSections, guard currentFirstVisibleIndexPath.section < oldSnapshot.numberOfSections,
sourceIndexPath.row < oldSnapshot.numberOfItems(inSection: oldSnapshot.sectionIdentifiers[sourceIndexPath.section]) currentFirstVisibleIndexPath.row < oldSnapshot.numberOfItems(inSection: oldSnapshot.sectionIdentifiers[currentFirstVisibleIndexPath.section])
else { return nil } else { assertionFailure("tableview not in sync with oldSnapshot"); return nil }
let sectionIdentifier = oldSnapshot.sectionIdentifiers[sourceIndexPath.section] let currentFirstVisibleSectionIdentifier = oldSnapshot.sectionIdentifiers[currentFirstVisibleIndexPath.section]
let item = oldSnapshot.itemIdentifiers(inSection: sectionIdentifier)[sourceIndexPath.row] let currentFirstVisibleItem = oldSnapshot.itemIdentifiers(inSection: currentFirstVisibleSectionIdentifier)[currentFirstVisibleIndexPath.row]
guard let targetIndexPathRow = newSnapshot.indexOfItem(item), guard let targetIndexPathRow = newSnapshot.indexOfItem(currentFirstVisibleItem),
let newSectionIdentifier = newSnapshot.sectionIdentifier(containingItem: item), let newSectionIdentifier = newSnapshot.sectionIdentifier(containingItem: currentFirstVisibleItem),
let targetIndexPathSection = newSnapshot.indexOfSection(newSectionIdentifier) let targetIndexPathSection = newSnapshot.indexOfSection(newSectionIdentifier)
else { return nil } else { return nil }
let targetIndexPath = IndexPath(row: targetIndexPathRow, section: targetIndexPathSection) let targetIndexPath = IndexPath(row: targetIndexPathRow, section: targetIndexPathSection)
return Difference( return Difference(
item: item, item: currentFirstVisibleItem,
sourceIndexPath: sourceIndexPath, sourceIndexPath: currentFirstVisibleIndexPath,
sourceDistanceToTableViewTopEdge: sourceDistanceToTableViewTopEdge, sourceDistanceToTableViewTopEdge: currentDistanceFromFirstVisibleCellToTableViewTopEdge,
targetIndexPath: targetIndexPath targetIndexPath: targetIndexPath
) )
} }