Add CFV2 Scroll-to-position wiring.

This commit is contained in:
Alex Hart
2023-04-19 09:45:19 -03:00
committed by Cody Henthorne
parent e32b81dc2a
commit 65e0fae3f4
9 changed files with 248 additions and 108 deletions

View File

@@ -52,9 +52,36 @@ class ScrollToPositionDelegate private constructor(
recyclerView.doAfterNextLayout {
handleScrollPositionRequest(position, recyclerView)
}
if (!(recyclerView.isLayoutRequested || recyclerView.isInLayout)) {
recyclerView.requestLayout()
}
})
}
/**
* Entry point for requesting a specific scroll position.
*/
fun requestScrollPosition(position: Int, smooth: Boolean = true) {
scrollPositionRequested.onNext(ScrollToPositionRequest(position, smooth))
}
/**
* Reset the scroll position to 0
*/
fun resetScrollPosition() {
requestScrollPosition(0, true)
}
/**
* This should be called every time a list is submitted to the RecyclerView's adapter.
*/
fun notifyListCommitted() {
listCommitted.onNext(Unit)
}
fun isListCommitted(): Boolean = listCommitted.value != null
private fun handleScrollPositionRequest(
request: ScrollToPositionRequest,
recyclerView: RecyclerView
@@ -87,28 +114,6 @@ class ScrollToPositionDelegate private constructor(
}
}
/**
* Entry point for requesting a specific scroll position.
*/
fun requestScrollPosition(position: Int, smooth: Boolean = true) {
scrollPositionRequested.onNext(ScrollToPositionRequest(position, smooth))
}
/**
* Reset the scroll position to 0
*/
fun resetScrollPosition() {
requestScrollPosition(0, true)
recyclerView.requestLayout()
}
/**
* This should be called every time a list is submitted to the RecyclerView's adapter.
*/
fun notifyListCommitted() {
listCommitted.onNext(Unit)
}
private data class ScrollToPositionRequest(
val position: Int,
val smooth: Boolean