Carousel numViewsToShowOnScreen and config changes
See original GitHub issueHey @elihart, I’ve been trying to set numViewsToShowOnScreen
on a Carousel to a percentage of the display width (which gets updated upon config changes). To achieve this, what I’m doing is quite simple:
numViewsToShowOnScreen((17 * screenWidthPx / 100) / 100) // Where 17 is the percentage visible
This works well upon rendering the first time, but it breaks as soon as I rotate the device… and if I scroll through the carousel it seems to fix itself (probably due to recycling of the modes). I’m attaching a short GIF of what’s happening.
Any idea of what might be happening? I’ve tried invalidating the RecyclerView and the Carousel itself (during onBind), also assigning Random
id’s to force Epoxy to rebuild the models, but none of this seem to solve the issue.
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Snapping behaviour in Epoxy Carousel and its pitfalls
Setup. We decided to use Airbnb's Epoxy for the Carousel . ... list of items and in a Carousel and redraw the view...
Read more >Carousel - javadoc.io
This is intended as a plug and play "Carousel" view - a Recyclerview with horizontal scrolling. It comes with common defaults and performance...
Read more >Epoxy CarouselModel_ spanSizeOverride didn't work
I need 2 span count carousel. So I used spanSizeOverride and it did'nt work. it's sitll show only 1 spancount. CarouselModel_() .
Read more >Carousel.setInitialPrefetchItemCount - airbnb/epoxy - Tabnine
numViewsToShowOnScreen = viewCount; setInitialPrefetchItemCount((int) Math.ceil(viewCount));
Read more >@androidx.annotation.Dimension(unit = Dimension.DP ...
Update the drawable's * bounds, color, etc as {@code offset} changes to show the ... private float numViewsToShowOnScreen; public Carousel(Context context) ...
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
@EliHart We fixed it locally in our app already, I’ll be putting up a merge request when I get the time for it soon.
I fixed it by checking whether or not the carousel has been rendered dirty after a configuration change, so it’s rather simple.
On Thu, 11 Feb 2021, 17.10 Eli Hart, notifications@github.com wrote:
I deep dived into this a bit as I have experienced problem multiple times before. The culprit is the Carousel.getTotalWidthPx function, as this returns the wrong value after a configuration change. At first the totalWidthPx returns the measured width of the carousel as it hasn’t been laid out yet, which is the correct totalWidth for the carousel. After a configuration change, the carousel is already laid out before the change, and so the getTotalWidthPx returns the carousels actual width, which is “wrong” as it was the width before the configuration change, so this could be fixed by checking if the screen was rotated since the view was laid out, and thus returning a measured value instead, as the view hasn’t been laid out in the current configuration yet.