sparrow007 / CarouselRecyclerview

Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.
Apache License 2.0
634 stars 78 forks source link

Divide by zero crash when calling notifydatasetchanged during scroll animation #31

Open alexwyattdev opened 1 year ago

alexwyattdev commented 1 year ago

java.lang.ArithmeticException: divide by zero at com.jackandphantom.carouselrecyclerview.CarouselLayoutManager.onSelectedCallback(CarouselLayoutManager.kt:559)

selectedPosition = abs(selectedPosition % itemCount)

Example for reproducing the issue:

  1. Have a carousel recyclerview in a layout under SwipeRefreshLayout
  2. Use the SwipeRefreshLayout to load the list items using notifydatasetchanged on the adapter while the carousel is inbetween 2 items

Tried invalidation, canceling animations, removing all views - to no avail.

alexwyattdev commented 1 year ago

Workaround solution I found is to manually inflate the CarouselRecyclerView into the layout when data is ready, then before refreshing, remove it.