Skip to content

Commit

Permalink
[Catalog][Carousel] Update slider position when carousel is scrolled …
Browse files Browse the repository at this point in the history
…in uncontained carousel demo

Resolves #3539

GIT_ORIGIN_REV_ID=c520f2f5fa88a9c08e65e9d3e34db075fdb938dd
PiperOrigin-RevId: 560815648
  • Loading branch information
manabu-nakamura authored and leticiarossi committed Aug 29, 2023
1 parent aa5b5bc commit 480bbc6
Showing 1 changed file with 24 additions and 1 deletion.
Expand Up @@ -103,8 +103,31 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle bundle) {

CarouselAdapter adapter =
new CarouselAdapter(
(item, position) -> uncontainedRecyclerView.scrollToPosition(position),
(item, position) -> {
uncontainedRecyclerView.scrollToPosition(position);
positionSlider.setValue(position + 1);
},
R.layout.cat_carousel_item_narrow);
uncontainedRecyclerView.addOnScrollListener(
new RecyclerView.OnScrollListener() {
private boolean dragged = false;

@Override
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
dragged = true;
} else if (dragged && newState == RecyclerView.SCROLL_STATE_IDLE) {
if (recyclerView.computeHorizontalScrollRange() != 0) {
positionSlider.setValue(
(adapter.getItemCount() - 1)
* recyclerView.computeHorizontalScrollOffset()
/ recyclerView.computeHorizontalScrollRange()
+ 1);
}
dragged = false;
}
}
});

itemCountDropdown.setOnItemClickListener(
(parent, view1, position, id) ->
Expand Down

0 comments on commit 480bbc6

Please sign in to comment.