Skip to content

Touch Support

Eli Hart edited this page Aug 10, 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 sample app demonstrates a bit of what is possible:

Sample touch support gif

The easiest way to do this is through the EpoxyTouchHelper class.

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