BeksOmega / looping-layout

A looping LayoutManager for the Android RecyclerView.
Apache License 2.0
274 stars 16 forks source link

feat: Added scrollToPosition. #16

Closed BeksOmega closed 4 years ago

BeksOmega commented 4 years ago

:clap: Resolves

Closes #5

:star2: Description

Adds support for the scrollToPosition function.

This mostly follows the original proposal in the issue. There are only two main differences:

  1. There is no strategy for picking which view to scroll to, because the default behavior is that if there is already a view visible, no scrolling occures.
  2. Instead of an enum-esc value for determining the movement direction I decided to allow passing a function. This has to do with the following:

The default direction-determining strategy estimates which direction would be shortest. This assumes that all of the views in the recycler are the same size. If they are not the same size this function could be incorrect.

With a function-based system, if a developer has views with varying sizes, they can pass their own function that takes these differences into account.

By default I decided to provide three DirectionDecider functions:

:bug: Testing

Lots of tests! 84 in total.

:thought_balloon: Other info

N/A

BeksOmega commented 4 years ago

Here is a picture documenting how I set up the estimateShortestRoute tests: EstimateShortestRoutTests

The tests set up the views in the given configurations, and then they attempt to scroll to the underlined index. After scrolling the view associated with the index should be visible on the side where it is underlined. For example, in the top diagram, after scrolling, the "0" view should be aligned with the left edge of the recycler/screen.