smarteist / Android-Image-Slider

Android Auto Image Slider
Apache License 2.0
948 stars 299 forks source link

Issues when using the slider in a RecyclerView #87

Open gnuyork opened 5 years ago

gnuyork commented 5 years ago

I've got two issues by using the slider nested in a recycler view:

  1. There are a lot of IllegalStateExceptions when I scroll vertically through the RecyclerView, coming from the unRegisterSetObserver() method in PageIndicatorView, complaining that the app tries to remove an observer that has not been added before. (Seems to be a problem caused by the RecyclerView that removes and recreates the slider views while scrolling).
  2. In some (not all) of the slider views in my recycler view I got a strange bug: When I swipe to the second image in the slider the first time, it automatically snaps back to the first one. (This "back-swipe" is then not connected to an onTouch event.)

Has anyone an idea how to fix this (esp. the second problem)?

gnuyork commented 5 years ago

I fixed the second problem myself by adding the following code to the setSliderAdapter() method in the SliderView:

if (mSliderPager!=null && mCircularSliderHandle!=null){ mSliderPager.removeOnPageChangeListener(mCircularSliderHandle); } mCircularSliderHandle = new CircularSliderHandle(mSliderPager); mSliderPager.addOnPageChangeListener(mCircularSliderHandle);

The reason for the bug is that the RecyclerView doesn't create a new Slider for every entry but reuses the existing ones while scrolling to new elements and just updates their views. So the mCircularSliderHandle object isn't recreated every time, but used for multiple entries which makes the onPageScrollStateChanged() method in the CircularSliderHandle class executing mSliderPager.setCurrentItem(0); sometimes, which produces the behavior mentioned above.

Maybe you could add the lines above to the next release to fix it for other people that also use multiple Sliders in a RecyclerView.

panagiac commented 4 years ago

@gnuyork could you please commit your fix? This is still an open bug

Hatzen commented 4 years ago

It seems that Version 1.3.5 fixed this issues. At least for me it did, but updating from 1.3.2 it was a breaking change to me as adapter handling seems to be changed