Skip to content

Touch Support

Eli Hart edited this page Aug 9, 2017 · 12 revisions

(Since 2.3.0)

Epoxy helps you easily integrate RecyclerView's ItemTouchHelper with your Epoxy controllers and models. There is support for both dragging and swiping views.

The easiest way to set up touch support is with EpoxyTouchHelper.

Dragging

Initialize dragging with an EpoxyController like this:

EpoxyTouchHelper.initDragging(epoxyController)
        .withRecyclerView(recyclerView)
        .forVerticalList()
        .withTarget(MyModel.class)
        .andCallbacks(new DragCallback<CarouselModelGroup>() {

          @Override
          public void onModelMoved(int fromPosition, int toPosition,
              MyModel modelBeingMoved, View itemView) {

          }
});

Swiping

Initialize swiping like this:

EpoxyTouchHelper.initSwiping(recyclerView)
        .leftAndRight()
        .withTarget(MyModel.class)
        .andCallbacks(new SwipeCallbacks<CarouselModelGroup>() {

          @Override
          public void onSwipeCompleted(MyModel model, View itemView, int position,
              int direction) {
            carousels.remove(model.data);
            updateController();
          }
        });

Clone this wiki locally