-
Notifications
You must be signed in to change notification settings - Fork 17
Challenges of creating a looping LayoutManager
This page is meant to document some challenges that should be kept in mind when contributing to the Looping Layout Manager project.
Views in a layout manager have two kinds of indices. One (the child index) is associated with the position of the view on screen, and the other (the adapter index) tells us which piece of adapter data the view is assoicated with.
Sadly LayoutManagers can only loop through views based on their child index, so you need to make sure you properly convert between the two.
For more information about child indices vs adapter indices, see the directional conversion page.
Because the LoopingLayoutManager loops, we can sometimes have more than one view on screen associated with the same adapter index. Specifically if the total size of all the views is less than the size of the recycler.
And because of this, if we're trying to find a view associated with a given index we need a way to decide between two (or more) views. This logic is encapsulated in a ViewPicker.
If you want to make a certain view visible on screen, you can scroll in either direction to find it. This is convenient for users, but makes it harder to implement things like programmatic smooth scrolling, because you have to decide programmatically which direction you want to go in. The logic for deciding is encapsulated in a DirectionDecider.