Skip to content

Commit

Permalink
Fixes #641 - Prevent large ranges before the view renders the room list
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanceriu committed Apr 24, 2023
1 parent 5a14c70 commit 178e1a6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ElementX/Sources/Screens/HomeScreen/View/HomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 178e1a6

Please sign in to comment.