Add more safety to scroll to
This commit is contained in:
parent
7e88339dc5
commit
b0630ae9c3
|
@ -62,10 +62,13 @@ public struct TimelineView: View {
|
|||
}
|
||||
}
|
||||
.onChange(of: viewModel.scrollToIndex) { index in
|
||||
if let index {
|
||||
collectionView?.scrollToItem(at: .init(row: index, section: 0),
|
||||
at: .top,
|
||||
animated: viewModel.scrollToIndexAnimated)
|
||||
if let collectionView,
|
||||
let index,
|
||||
let rows = collectionView.dataSource?.collectionView(collectionView, numberOfItemsInSection: 0),
|
||||
rows > index {
|
||||
collectionView.scrollToItem(at: .init(row: index, section: 0),
|
||||
at: .top,
|
||||
animated: viewModel.scrollToIndexAnimated)
|
||||
viewModel.scrollToIndexAnimated = false
|
||||
viewModel.scrollToIndex = nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue