daimajia / AndroidSwipeLayout

The Most Powerful Swipe Layout!
MIT License
12.38k stars 2.67k forks source link

SwipeListener calls onOpen callback multiple times #469

Open Dropppan opened 7 years ago

Dropppan commented 7 years ago

I have two ConstraintLayouts inside Swipelayout. If I keep dragging SurfaceView after the whole BottomView is revealed, the swipelisteners onOpen callback is triggered multiple times.

itaispector commented 6 years ago

@Dropppan Happens to me as well

Hbworld commented 6 years ago

@Dropppan @itaispector any fixes? Happens to me as well

alex-bo commented 6 years ago

Hey Guys, I have just faced the same problem and found a solution that may work for you too. If you are using swipeLayout in RecyclerView and doing swipeLayout.addSwipeListener in onBindViewHolder(), move it to constructor of your RecyclerView.ViewHolder implementation.

The causes of the problem: swipeLayout.addSwipeListener does not set new listener but instead adds one to the internal collection. onBindViewHolder() method is invoked every time you scroll the list. So every time the list is scrolled, onBindViewHolder() is executed and adds a new instance of SwipeListener. To prevent this, simply add listener once when new holder is created and never change it.

It looks like it's not actually a bug, but misleading example of usage. Hope this helps.