-
Notifications
You must be signed in to change notification settings - Fork 732
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:
The easiest way to do this is through the EpoxyTouchHelper class.
Initialize dragging with an EpoxyController like this:
EpoxyTouchHelper.initDragging(epoxyController)
.withRecyclerView(recyclerView)
.forVerticalList()
.withTarget(MyModel.class)
.andCallbacks(new DragCallback<MyModel>() {
@Override
public void onModelMoved(int fromPosition, int toPosition,
MyModel modelBeingMoved, View itemView) {
// You MUST use this callback to update your data to reflect the move
// Epoxy will automatically update the models in the controller and notify
// the RecyclerView of the move
}
});
Initialize swiping like this:
EpoxyTouchHelper.initSwiping(recyclerView)
.leftAndRight()
.withTarget(MyModel.class)
.andCallbacks(new SwipeCallbacks<MyModel>() {
@Override
public void onSwipeCompleted(MyModel model, View itemView, int position,
int direction) {
// Use must use this callback to update data to remove the item at the given position
// You must also request a model build on the EpoxyController once the data is updated
}
});