mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Fix visible room sliding sync view ranges changing while inside rooms
This commit is contained in:
committed by
Stefan Ceriu
parent
bd61793798
commit
455a7105ef
@@ -17,13 +17,21 @@
|
||||
import SwiftUI
|
||||
|
||||
struct HomeScreen: View {
|
||||
enum Constants {
|
||||
static let slidingWindowBoundsPadding = 5
|
||||
}
|
||||
|
||||
@ObservedObject var context: HomeScreenViewModel.Context
|
||||
|
||||
@State private var isViewVisible = false
|
||||
|
||||
@State private var scrollViewAdapter = ScrollViewAdapter()
|
||||
@State private var showingLogoutConfirmation = false
|
||||
@State private var visibleItemIdentifiers = Set<String>() {
|
||||
didSet {
|
||||
updateVisibleRange()
|
||||
if isViewVisible {
|
||||
updateVisibleRange()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +77,12 @@ struct HomeScreen: View {
|
||||
.disableAutocorrection(true)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
isViewVisible = true
|
||||
}
|
||||
.onDisappear {
|
||||
isViewVisible = false
|
||||
}
|
||||
.introspectScrollView { scrollView in
|
||||
guard scrollView != scrollViewAdapter.scrollView else { return }
|
||||
scrollViewAdapter.scrollView = scrollView
|
||||
@@ -198,7 +212,10 @@ struct HomeScreen: View {
|
||||
return
|
||||
}
|
||||
|
||||
context.send(viewAction: .updateVisibleItemRange(range: firstIndex..<lastIndex, isScrolling: scrollViewAdapter.isScrolling.value))
|
||||
let lowerBound = max(0, firstIndex - Constants.slidingWindowBoundsPadding)
|
||||
let upperBound = min(Int(context.viewState.rooms.count), lastIndex + Constants.slidingWindowBoundsPadding)
|
||||
|
||||
context.send(viewAction: .updateVisibleItemRange(range: lowerBound..<upperBound, isScrolling: scrollViewAdapter.isScrolling.value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user