Advertisement
vmeansdev

Scroll example

Jun 2nd, 2020
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.89 KB | None | 0 0
  1. private fun onSubSharesScrolled() {
  2.     val subSharesLm = subSharesRecyclerView.layoutManager as LinearLayoutManager
  3.     val variantsLm = variantsRecyclerView.layoutManager as LinearLayoutManager
  4.     val first = subSharesLm.findFirstVisibleItemPosition()
  5.     val last = subSharesLm.findLastVisibleItemPosition()
  6.     if (first < 0 || last < 0) {
  7.         // When the list is empty, we get -1 for the positions.
  8.         return
  9.     }
  10.  
  11.     val firstId = verticalVariantIndexes[first]
  12.     val lastId = verticalVariantIndexes[last]
  13.     val range = verticalVariantIndexes.values.indexOf(firstId)..verticalVariantIndexes.values.indexOf(lastId)
  14.     if (range != cachedRange) {
  15.         cachedRange = highlightRange
  16.         val selectedPosition = horizontalVariantIndexes[firstId]
  17.         smoothScroller.targetPosition = selectedPosition ?: return
  18.         variantsLm.startSmoothScroll(smoothScroller)
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement