Fixes #641 - Prevent large ranges before the view renders the room list

This commit is contained in:
Stefan Ceriu
2023-04-24 17:42:51 +03:00
committed by Stefan Ceriu
parent 07f5827786
commit 003dfd5996

View File

@@ -216,12 +216,16 @@ struct HomeScreen: View {
private func updateVisibleRange() {
guard let scrollView = scrollViewAdapter.scrollView,
context.viewState.rooms.count > 0 else {
context.viewState.visibleRooms.count > 0 else {
return
}
guard scrollView.contentSize.height > scrollView.bounds.height else {
return
}
let adjustedContentSize = max(scrollView.contentSize.height - scrollView.contentInset.top - scrollView.contentInset.bottom, scrollView.bounds.height)
let cellHeight = adjustedContentSize / Double(context.viewState.rooms.count)
let cellHeight = adjustedContentSize / Double(context.viewState.visibleRooms.count)
let firstIndex = Int(max(0.0, scrollView.contentOffset.y + scrollView.contentInset.top) / cellHeight)
let lastIndex = Int(max(0.0, scrollView.contentOffset.y + scrollView.bounds.height) / cellHeight)