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
127 stars 17 forks source link

Nested Child recycler view onCreate called every time during parent recycler view scroll. #236

Closed mdrafiwynk closed 1 month ago

mdrafiwynk commented 1 month ago

I am working on tv app and using dpad recycler view. But I am getting huge performance issue in nested recycler view when scrolling vertically horizontal recycler view each item is created and its UI is inflated again. I have check in library sample under nested option but facing same lagging and jank while vertical scrolling. Please check and fix it asap.

Feel free to contact any time.

rubensousa commented 1 month ago

@mdrafiwynk can you please share a sample that reproduces that issue? In the sample app, the views are being recycled correctly

mdrafiwynk commented 1 month ago

I have checked in profiler. In sample app, there is only one text view in item view but it will take lot of time to inflate. Also showing lot of janks whenever scrolling vertical in nested one

rubensousa commented 1 month ago

@mdrafiwynk I just checked and found the problem in the sample app. I'm running some animations which are not cancelled in onViewDetachedFromWindow, which prevents ViewHolders from being recycled since there is transient state: https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter#onFailedToRecycleView(VH)

Will file a MR that fixes that, but if you're affected by this, it means you're also running animations you're not cancelling.

Will link the fix MR here once it is open

rubensousa commented 1 month ago

@mdrafiwynk have a look here: https://github.com/rubensousa/DpadRecyclerView/pull/237

mdrafiwynk commented 1 month ago

Yes i am using nested horizontal RV item animation to scale In current focused item and scale out last focused item. Is I need to cancel it OnViewHolderDetachFromWindow?

mdrafiwynk commented 1 month ago

Is there any method in you library which called during scroll is idle. Like I am scale in currently focused and scale out last focused on focus listener of itemView. But if I scroll horizontal faster then it will show little scale in and out animation for micro second. I want to scale item only if scroll state is idle. How can i achieve this with your library?

rubensousa commented 1 month ago

do I need to cancel it OnViewHolderDetachFromWindow?

Yes, you do.

How can i achieve this with your library?

You can observe scroll state of RecyclerView via https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView#addOnScrollListener(androidx.recyclerview.widget.RecyclerView.OnScrollListener)

or you can use the selection callback that has the aligned event:

recyclerView.addOnViewHolderSelectedListener(object : OnViewHolderSelectedListener {
    override fun onViewHolderSelectedAndAligned(
        parent: RecyclerView,
        child: RecyclerView.ViewHolder?,
        position: Int,
        subPosition: Int
    ) {
        super.onViewHolderSelectedAndAligned(parent, child, position, subPosition)
        // ViewHolder is in its final position
    }
})
mdrafiwynk commented 1 month ago

Thank you soo much.

rubensousa commented 1 month ago

Closing since the sample now contains examples for canceling the animations