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.

Carousel - Detecting current item

See original GitHub issue

Hi, how would you go about detecting the current position that the carousel has snapped to, given that setNumViewsToShowOnScreen is set to 1?

`void buildModels() {

List<PhotoViewModel_> photoModels = new ArrayList(); for (photo in photos) { photoModels.add(new PhotoViewModel_() .id(photo.id()) .url(photo.url)) }

new CarouselModel_() .id(“carousel”) .models(photoModels) .addTo(this); }`

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
idrisadetunmbicommented, Feb 24, 2020

Thanks, @denison-chua. I did something simpler by just overriding onScrollStateChanged and calling a callback prop in it when the Recycler view state is idle.

0reactions
denison-chuacommented, Feb 21, 2020

Hi @idrisadetunmbi , what I did was create a subclass of Carousel and then override addOnScrollListener and set a RecyclerView.OnScrollListener on your EpoxyController.

Here is my code for my Carousel subclass: ` @ModelView(saveViewState = true, autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT) public class CustomEpoxyCarousel extends Carousel {

private static SnapHelperFactory defaultGlobalSnapHelperFactory =
        new SnapHelperFactory() {

            @Override
            @NonNull
            public SnapHelper buildSnapHelper(Context context) {
                return new LinearSnapHelper();
            }
        };

@ModelProp(options = ModelProp.Option.DoNotHash)
@Override
public void addOnScrollListener(@NotNull OnScrollListener onScrollListener) {
    super.addOnScrollListener(onScrollListener);
}

@Nullable
@Override
public LayoutManager getLayoutManager() {
    return super.getLayoutManager();
}

@Nullable
@Override
protected SnapHelperFactory getSnapHelperFactory() {
    return defaultGlobalSnapHelperFactory;
}

public CustomEpoxyCarousel(Context context) {
    super(context);
}

} `

And here is the code snippet inside my EpoxyController: CustomEpoxyCarouselModel_ walletCarouselModel; walletCarouselModel = new CustomEpoxyCarouselModel_() .id("carouselWallet") .models(walletEpoxyModel_list) .padding(Carousel.Padding.dp( 10, //left 0, //top 10, //right 0, //bottom 0 //itemspacing )) .addOnScrollListener(getWalletScrollListener()) .numViewsToShowOnScreen(numViewsToShow); walletCarouselModel.addTo(this);

Read more comments on GitHub >

github_iconTop Results From Across the Web

React-Bootstrap carousel slider: how to detect current slide in ...
1. You have to make the carousel a controlled component, and track the active index in state. · I saw the documentation, but...
Read more >
Configure CarouselView interaction - .NET MAUI
The currently displayed item in a .NET MAUI CarouselView can be accessed through the CurrentItem and Position properties.
Read more >
Carousel — Kivy 2.1.0 documentation
It will detect a swipe gesture according to the Carousel.scroll_timeout and ... It is None if the current slide is the last slide...
Read more >
accessible-slick - the last (accessible) carousel you'll ever need
You still need to call $(element).slick() to initialize slick on the element. ... this current slide of this carousel will change the current...
Read more >
Options - Splide
Determines whether to pause autoplay while the carousel contains the active element (focused element). This should be true for accessibility. resetProgress.
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