ScrollToNextItem function
:key: Use case
Hi, just wondering if the looper can implement scrollToNextItem() function
:hammer: Proposal
- a function that be able to scroll to next item; input should be delay time until next item can be scrolled.
- a function to stop next item scroll
:wrench: Alternative
:memo: Other info
:bee: Request for assignment
I'm just requesting this feature. I don't want to implement it.
Hello, thank you for submitting this issue :D
Currently the LoopingLayoutManger supports scrolling via the smoothScrollToPosition function of the RecyclerView. If you use this in combination with the new adapter index accessors, and DirectionalDeciders I think you should be able to get the LoopingLayoutManager to do what you want.
Do you think this will work for your use case? =)
Best wishes --Beka
Has anyone managed to solve this problem?
Has anyone managed to solve this problem?
Have you tried the recommendation in my above comment?
@BeksOmega I tried parsing, but I get a failure, most likely I'm doing something wrong(
@BeksOmega I tried parsing, but I get a failure, most likely I'm doing something wrong(
Could you post the code you tried? If I see what you're doing I may be able to give advice =)
I solved my problem by adding this extension.
fun LoopingLayoutManager.smoothSnapToPosition(
context: Context,
itemCount: Int,
millisecondPerInch: Float = MILLISECONDS_PER_INCH,
snapMode: Int = LinearSmoothScroller.SNAP_TO_START
) {
val smoothScroller = object : LinearSmoothScroller(context) {
override fun getVerticalSnapPreference(): Int = snapMode
override fun getHorizontalSnapPreference(): Int = snapMode
override fun calculateSpeedPerPixel(displayMetrics: DisplayMetrics): Float =
millisecondPerInch / displayMetrics.densityDpi
}
val nextPosition = this.topLeftIndex + 1
Handler(Looper.getMainLooper()).postDelayed({
smoothScroller.targetPosition = if (nextPosition == itemCount) 0 else nextPosition % itemCount
startSmoothScroll(smoothScroller)
}, DELAY_MILLIS)
}
Also thanks for such a cool library)