Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ItemTouchHelper and SwipeRefreshLayout (RecyclerView)

I want to use the new ItemTouchHelper from the v7 design library. I use it inside of a SwipeRefreshLayout.

The problem is that with the SwipeRefreshLayout the animation for the swipe to dismiss is wrong and buggy.

Anyone knows how to fix this?

like image 382
Elias Avatar asked Aug 07 '15 14:08

Elias


1 Answers

You could disable your SwipeRefreshLayout as long as you are swiping.

final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {
    @Override
    public int getMovementFlags(RecyclerView recyclerView, ViewHolder viewHolder) {
        return makeMovementFlags(0, ItemTouchHelper.START | ItemTouchHelper.END);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, ViewHolder viewHolder, ViewHolder target) {
        return false;
    }

    @Override
    public void onSwiped(ViewHolder viewHolder, int direction) {
        // do something
    }

    @Override
    public void onSelectedChanged(ViewHolder viewHolder, int actionState) {
        super.onSelectedChanged(viewHolder, actionState);
        final boolean swiping = actionState == ItemTouchHelper.ACTION_STATE_SWIPE;
        swipeRefreshLayout.setEnabled(!swiping);
    }
});
itemTouchHelper.attachToRecyclerView(recyclerView);
like image 96
segoh Avatar answered Oct 29 '22 11:10

segoh