Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mdrafiwynk opened this issue Jul 10, 2024 · 9 comments · Fixed by #237
Closed
Labels
help wanted Extra attention is needed

Comments

@mdrafiwynk
Copy link

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
Copy link
Owner

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

@rubensousa rubensousa added the help wanted Extra attention is needed label Jul 10, 2024
@mdrafiwynk
Copy link
Author

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
Copy link
Owner

@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
Copy link
Owner

@mdrafiwynk have a look here: #237

@mdrafiwynk
Copy link
Author

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

Thank you soo much.

@rubensousa
Copy link
Owner

Closing since the sample now contains examples for canceling the animations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
2 participants