Replace timeline animation delay with a check on the item count. (#1777)

This commit is contained in:
Doug
2023-09-21 11:57:11 +01:00
committed by GitHub
parent 8b69308e05
commit 057c33e680
@@ -83,8 +83,6 @@ class TimelineTableViewController: UIViewController {
private let paginateBackwardsPublisher = PassthroughSubject<Void, Never>() private let paginateBackwardsPublisher = PassthroughSubject<Void, Never>()
/// Whether or not the view has been shown on screen yet. /// Whether or not the view has been shown on screen yet.
private var hasAppearedOnce = false private var hasAppearedOnce = false
/// Whether the scroll and the animations should happen
private var shouldAnimate = false
init(coordinator: UITimelineView.Coordinator, init(coordinator: UITimelineView.Coordinator,
timelineStyle: TimelineStyle, timelineStyle: TimelineStyle,
@@ -134,10 +132,6 @@ class TimelineTableViewController: UIViewController {
tableView.contentOffset.y = -1 tableView.contentOffset.y = -1
hasAppearedOnce = true hasAppearedOnce = true
paginateBackwardsPublisher.send() paginateBackwardsPublisher.send()
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
self.shouldAnimate = true
}
} }
override func viewWillLayoutSubviews() { override func viewWillLayoutSubviews() {
@@ -207,8 +201,8 @@ class TimelineTableViewController: UIViewController {
let currentSnapshot = dataSource.snapshot() let currentSnapshot = dataSource.snapshot()
MXLog.verbose("DIFF: \(snapshot.itemIdentifiers.difference(from: currentSnapshot.itemIdentifiers))") MXLog.verbose("DIFF: \(snapshot.itemIdentifiers.difference(from: currentSnapshot.itemIdentifiers))")
// We only animate when new items come at the end of the timeline // We only animate when new items come at the end of the timeline, ignoring transitions through empty.
let animated = shouldAnimate && let animated = currentSnapshot.numberOfItems > 0 && snapshot.numberOfItems > 0 &&
snapshot.itemIdentifiers.first != currentSnapshot.itemIdentifiers.first snapshot.itemIdentifiers.first != currentSnapshot.itemIdentifiers.first
dataSource.apply(snapshot, animatingDifferences: animated) dataSource.apply(snapshot, animatingDifferences: animated)
} }