Reset carousel scrolling position
See original GitHub issueHello! Thanks for the great library!
I have a nested custom Carousel and I need to reset it to the initial position after refreshing the content. I’m using the version 2.19.0
and I load the models in the buildModels()
like this
new OfferCarouselModel_()
.id("offer")
.padding(carouselPadding)
.numViewsToShowOnScreen(1.1F)
.models(generatePopularOfferModels())
.addIf(!offersList.isEmpty(), this);
and when I need to refresh the content I clear the list in the controller, set the new data and then requestModelBuild()
.
Everything works fine, but if I scrolled through the carousel before refreshing its content it’ll be at the old position, not at the first one. The Carousel class it’s really simple
@ModelView(saveViewState = true, autoLayout = Size.MATCH_WIDTH_WRAP_HEIGHT)
public class OfferCarousel extends Carousel {
private static final int SPAN_COUNT = 1;
private static SnapHelperFactory offerCarouselSnapHelper =
new SnapHelperFactory() {
@Override
@NonNull
public SnapHelper buildSnapHelper(Context context) {
return new PagerSnapHelper();
}
};
public OfferCarousel(Context context) {
super(context);
}
@NonNull
@Override
protected LayoutManager createLayoutManager() {
return new GridLayoutManager(getContext(), SPAN_COUNT, LinearLayoutManager.HORIZONTAL, false);
}
@Override
protected SnapHelperFactory getSnapHelperFactory() {
return offerCarouselSnapHelper;
}
}
Am I missing something? Thank you!
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
jCarousel resetting scroll position - Stack Overflow
You can either reset the carousel as the new data is loaded: success:function(data){ carousel.reset(); $('#thumbs').html(data); }.
Read more >Restore RecyclerView scroll position | by Florina Muntenescu
There are several ways to ensure a correct scroll position that you might have adopted. The best one is making sure that you...
Read more >Solved: How to reset vertical position of a canvas compone...
How to reset vertical position of a canvas component · 1)set the scroll screen's OnVisible: UpdateContext({resetCan:false}) · 2)set the scroll ...
Read more >Bug - Scroll position resets when using slider dragger in 2022.1
To reproduce: 1. Place any input such as a slider, an input field or a button inside a scroll view. 2. Run the...
Read more >Carousel - Bootstrap
The .active class needs to be added to one of the slides otherwise the carousel will not be visible. Also be sure to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
try posting the call to
view.scrollToPosition(0);
- when you update a carousel’s contents the model building is posted to the next frame, just like a normal EpoxyControllerrequestModelBuild
callI tried different things, but the only one that seems to work in all my use cases is the following
at the end of the
buildModels()
. Is there a better solution?