rubensousa / DpadRecyclerView

A RecyclerView built for Android TV with Compose in mind and as a replacement for Leanback's BaseGridView.
https://rubensousa.github.io/DpadRecyclerView/
Apache License 2.0
136 stars 17 forks source link

Scroll a nested recyclerview to a specific item (without focussing it) #208

Closed fankloano closed 6 months ago

fankloano commented 6 months ago

Another question I have come across in the meantime: Is it possible to scroll a nested recyclerview to a specific point (without giving it the focus)? I have attached a picture to clarify what I mean. The respective date is displayed on the left in the yellow recyclerview. If a date receives the focus, the corresponding EPG data of this day for the channel is displayed on the right. If today's date is selected, the recyclerview on the right should display the currently running program in the middle (i.e. theoretically scroll to it), if the user then clicks to the right to go to the epg-data-recyclerview, the current program receives the focus (as far as I know, this can be implemented with setSelection(currentProgramPosition)). If the focused date is not today's date, the first visible item should simply be the first program for the date, i.e. the normal behavior. I played around with setSelection or scrollToPosition because I thought that was one of the things it was made for, but I couldn't achieve my desired scenario. Is there any way to do this?

date_epg_rv

rubensousa commented 6 months ago

Hi @fankloano

You can use setSelectedPosition to achieve this. DpadRecyclerView will only dispatch focus after you invoke that if it already has focus.

fankloano commented 6 months ago

Oooh, using recyclerview.post solved the problem and setSelectedPosition works as you said: binding.rvFullepg.post { binding.rvFullepg.setSelectedPosition(currentProgramPosition) }

rubensousa commented 6 months ago

@fankloano I'm glad you managed to get it working :)