question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Losing nested scroll position when scrolling parent

See original GitHub issue

Hello!

I have a vertical list composed of multiple nested horizontal lists. If I scroll my horizontal list and then scroll vertically my list, I sometime lost the scroll position of my nested horizontal list.

device-2019-05-22-161930 2019-05-22 16_44_45 Losing nested position demo: 1- scrolling “A voir aussi” to Calls as first fully displayed item 2- scrolling “Sous couverture” to Strike Back as first fully displayed item 3- scroll down 4- scroll up: “A voir aussi” scrolling position is ok but “Sous couverture” isn’t, it display as first item “Killing Eve”

Here is my code: https://github.com/loutry/EpoxySample/commits/lost-nesting-position-on-rebind

I’m using EpoxyRecyclerView everywhere and I enable saveViewState.

I also followed the discussions https://github.com/airbnb/epoxy/issues/561 but I didn’t successfully fix my problem.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
eboudrantcommented, May 22, 2019

Your RowGroupView is a LinearLayout and Epoxy is saving its state only (with saveViewState = true) . To restore scroll position you need to manually save/restore the state of the inner EpoxyRecyclerView from your RowGroupView.

As a quick fix try something like :

class RowGroupView : LinearLayout {
    ...
    override fun onSaveInstanceState(): Parcelable? {
        return recycler.onSaveInstanceState()
    }

    override fun onRestoreInstanceState(state: Parcelable?) {
        recycler.onRestoreInstanceState(state)
    }
}
0reactions
loutrycommented, Jun 17, 2019

Hi again! I end up fixing my problem by relying on ViewGroup and ViewStub as state in the documentation: https://github.com/airbnb/epoxy/wiki/Grouping-Models.

Here is the updated branch on the sample: https://github.com/loutry/EpoxySample/tree/viewstub

Our custom layout manager was indeed not compliant regarding state restoration but nothing that we can’t manage on or own 😃

Thanks a lot for your guidance and time!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Recycler view inside NestedScrollView causes scroll to start in ...
I was using NestedScrollView followed by LinearLayout which contains RecyclerView and EditText. The scrolling behavior was fixed by using android: ...
Read more >
Saving Scroll Positions of Nested RecyclerViews - Medium
Create a SparseIntArray or map to hold the scroll position of each carousel. Now override the onViewRecycled to store the position of the...
Read more >
Saving scroll state of nested RecyclerViews - Part 2
After scrolling the first nested list to position 5, if you scroll down the parent and that list is recycled, the scroll state...
Read more >
Support nested scrolling views-compose-views cases
when nested scrolling in compose is done, we need to consider supporting cases for view interop when compose is either a parent or...
Read more >
NestedScrollView - Android Developers
Handles scrolling in response to a "home/end" shortcut press. Returns true if this view has a nested scrolling parent for the given input...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found