Last active
May 13, 2021 16:37
-
-
Save rahulsainani/d8833c36b375afe215371b8bc9f613d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private tailrec suspend fun autoScrollFeaturesList() { | |
if (recyclerFeatures.canScrollHorizontally(DIRECTION_RIGHT)) { | |
recyclerFeatures.smoothScrollBy(SCROLL_DX, 0) | |
} else { | |
val firstPosition = | |
(recyclerFeatures.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() | |
if (firstPosition != RecyclerView.NO_POSITION) { | |
val currentList = featuresAdapter.currentList | |
val secondPart = currentList.subList(0, firstPosition) | |
val firstPart = currentList.subList(firstPosition, currentList.size) | |
featuresAdapter.submitList(firstPart + secondPart) | |
} | |
} | |
delay(DELAY_BETWEEN_SCROLL_MS) | |
autoScrollFeaturesList() | |
} | |
private const val DELAY_BETWEEN_SCROLL_MS = 25L | |
private const val SCROLL_DX = 5 | |
private const val DIRECTION_RIGHT = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment