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

Focus item take more time #152

Closed minhvietattt closed 1 year ago

minhvietattt commented 1 year ago

Hi, I'm trying to implement delete list item. I try to delete item then after that need focus to next item in list. But it seem slow. I have parent Dpad recyler view and 4 child dpad recycler view. I want to delete item in one of childs dpadrecycler view then restore focus. Can you help me give suggestion for my case when using dpad recyclerview ?

rubensousa commented 1 year ago

How are you deleting the items and requesting focus? If you're using the default RecyclerView item animator, it might make sense to enable this: https://github.com/rubensousa/DpadRecyclerView/blob/master/dpadrecyclerview/src/main/java/com/rubensousa/dpadrecyclerview/DpadRecyclerView.kt#L658

recyclerView.setFocusSearchEnabledDuringAnimations(true)

I intentionally disabled this because by default because it's a weird behavior to switch focus during animations

minhvietattt commented 1 year ago

Thank you. Let me try it first

minhvietattt commented 1 year ago

Hmm, can i ask another question. How can we setFocus and select to an item in one child-dpadrecycler view fastest. At this time i try to using recyclerView.setSelectedPosition(). At this time when delete item in list (delete data and submitList() ), i save the "next_focus_position" after the deletion done. I tried to use recyclerView.setSelectedPosition() ... Unlucky it take more time than i expected.

rubensousa commented 1 year ago

You should reconsider using submitList for mutable adapters and instead just remove the item from the adapter and then call notifyItemRemoved.

submitList will trigger diffing which you don't need if you're removing a single item. You could try requesting focus before the deletion is completed, instead of doing it afterwards

minhvietattt commented 1 year ago

Let me try it first. It seem take more time to request focus in parent dpad recycle view. "You could try requesting focus before the deletion is completed" i will try this suggestion

rubensousa commented 1 year ago

@minhvietattt Any update here? If you still have problems with this, please share a sample project where I can see this issue

minhvietattt commented 1 year ago

Thank you... I will try to make the sample soon. You help us a lot

rubensousa commented 1 year ago

@minhvietattt any update on this issue?

rubensousa commented 1 year ago

@minhvietattt closing due to inactivity. Please let me know if there's anything missing