Scrolling crash content offset (IOS-254) (#1281)

* Remove unused code (IOS-254)

* Don't hide pill immediately every single time (IOS-254)

* Check if there's something to scroll to (IOS-254)

As the cause for the crash seems to be clear (scrolling to an indexPath that doesn't exist -> crash) we could check for the indexPath to exist.

* Remove unused code

* Only cache my timeline (IOS-254)
This commit is contained in:
Nathan Mattes 2024-05-02 16:47:37 +02:00 committed by GitHub
parent b759c207f6
commit 906b13c03d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 6 additions and 33 deletions

View File

@ -27,22 +27,4 @@ extension UITableView {
}
})
}
func blinkRow(at indexPath: IndexPath) {
DispatchQueue.main.asyncAfter(wallDeadline: .now() + 1) { [weak self] in
guard let self = self else { return }
guard let cell = self.cellForRow(at: indexPath) else { return }
let backgroundColor = cell.backgroundColor
UIView.animate(withDuration: 0.3) {
cell.backgroundColor = Asset.Colors.Brand.blurple.color.withAlphaComponent(0.5)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
UIView.animate(withDuration: 0.3) {
cell.backgroundColor = backgroundColor
}
}
}
}
}
}

View File

@ -81,9 +81,6 @@ final class HomeTimelineViewController: UIViewController, NeedsDependency, Media
let tableView: UITableView = {
let tableView = ControlContainableTableView()
tableView.register(StatusTableViewCell.self, forCellReuseIdentifier: String(describing: StatusTableViewCell.self))
tableView.register(TimelineMiddleLoaderTableViewCell.self, forCellReuseIdentifier: String(describing: TimelineMiddleLoaderTableViewCell.self))
tableView.register(TimelineBottomLoaderTableViewCell.self, forCellReuseIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self))
tableView.rowHeight = UITableView.automaticDimension
tableView.separatorStyle = .none
tableView.backgroundColor = .clear
@ -341,8 +338,6 @@ extension HomeTimelineViewController {
if isOffline {
self.timelinePill.update(with: .offline)
self.showTimelinePill()
} else {
self.hideTimelinePill()
}
})
.store(in: &disposeBag)

View File

@ -85,7 +85,9 @@ extension HomeTimelineViewModel {
}
await self.updateDataSource(snapshot: newSnapshot, animatingDifferences: false)
tableView.scrollToRow(at: difference.targetIndexPath, at: .top, animated: false)
if tableView.numberOfSections >= difference.targetIndexPath.section && tableView.numberOfRows(inSection: difference.targetIndexPath.section) >= difference.targetIndexPath.row {
tableView.scrollToRow(at: difference.targetIndexPath, at: .top, animated: false)
}
var contentOffset = tableView.contentOffset
contentOffset.y = tableView.contentOffset.y - difference.sourceDistanceToTableViewTopEdge
tableView.setContentOffset(contentOffset, animated: false)

View File

@ -99,7 +99,9 @@ final class HomeTimelineViewModel: NSObject {
self.dataController.$records
.removeDuplicates()
.receive(on: DispatchQueue.main)
.sink(receiveValue: { feeds in
.sink(receiveValue: { [weak self] feeds in
guard let self, self.timelineContext == .home else { return }
let items: [MastodonStatus] = feeds.compactMap { feed -> MastodonStatus? in
guard let status = feed.status else { return nil }
return status

View File

@ -77,14 +77,6 @@ extension NotificationTimelineViewModel {
}
extension NotificationTimelineViewModel {
@MainActor func updateDataSource(
snapshot: NSDiffableDataSourceSnapshot<NotificationSection, NotificationItem>,
animatingDifferences: Bool
) async {
await diffableDataSource?.apply(snapshot, animatingDifferences: animatingDifferences)
}
@MainActor func updateSnapshotUsingReloadData(
snapshot: NSDiffableDataSourceSnapshot<NotificationSection, NotificationItem>
) async {