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 numViewsToShowOnScreen and config changes

See original GitHub issue

Hey @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.

carousel_small

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:closed
  • Created 5 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
andybdahlcommented, Feb 12, 2021

@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:

Thanks for the investigation @andybdahl https://github.com/andybdahl , that seems to make sense. It does seem a little difficult to detect when the measured width/height is not accurate though. Some possibilities:

  • figure out how to properly detect a configuration change
  • add an option to the carousel to not use measured dimensions

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/airbnb/epoxy/issues/682#issuecomment-777607472, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHDZZORFK2YCREPZLTEQL2TS6P6NRANCNFSM4GW42Z5A .

1reaction
andybdahlcommented, Feb 5, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

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