forked from shadowfacts/Tusker
Fix crash when TimelineViewController tries to apply snapshot while not visible
This commit is contained in:
parent
eac2a9b19f
commit
fc8fcb76fd
|
@ -522,10 +522,12 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
|
|
||||||
private func applySnapshot(_ snapshot: NSDiffableDataSourceSnapshot<Section, Item>, maintainingScreenPosition offsetFromTop: CGFloat, ofItem itemToMaintain: Item) {
|
private func applySnapshot(_ snapshot: NSDiffableDataSourceSnapshot<Section, Item>, maintainingScreenPosition offsetFromTop: CGFloat, ofItem itemToMaintain: Item) {
|
||||||
// use a snapshot of the collection view to hide the flicker as the content offset changes and then changes back
|
// use a snapshot of the collection view to hide the flicker as the content offset changes and then changes back
|
||||||
let snapshotView = collectionView.snapshotView(afterScreenUpdates: false)!
|
let snapshotView = collectionView.snapshotView(afterScreenUpdates: false)
|
||||||
|
if let snapshotView {
|
||||||
snapshotView.layer.zPosition = 1000
|
snapshotView.layer.zPosition = 1000
|
||||||
snapshotView.frame = view.bounds
|
snapshotView.frame = view.bounds
|
||||||
view.addSubview(snapshotView)
|
view.addSubview(snapshotView)
|
||||||
|
}
|
||||||
|
|
||||||
dataSource.apply(snapshot, animatingDifferences: false) {
|
dataSource.apply(snapshot, animatingDifferences: false) {
|
||||||
if let indexPathOfItemToMaintain = self.dataSource.indexPath(for: itemToMaintain) {
|
if let indexPathOfItemToMaintain = self.dataSource.indexPath(for: itemToMaintain) {
|
||||||
|
@ -558,7 +560,7 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
||||||
self.collectionView.contentOffset.y -= offsetFromTop
|
self.collectionView.contentOffset.y -= offsetFromTop
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshotView.removeFromSuperview()
|
snapshotView?.removeFromSuperview()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue