Callback

abstract class Callback(source)

This class is the contract between ItemTouchHelper and your application. It lets you control which touch behaviors are enabled per each ViewHolder and also receive callbacks when user performs these actions.

To control which actions user can take on each view, you should override getMovementFlags and return appropriate set of direction flags. (LEFT, RIGHT, START, END, UP, DOWN). You can use makeMovementFlags to easily construct it. Alternatively, you can use SimpleCallback.

If user drags an item, ItemTouchHelper will call onMove(recyclerView, dragged, target). Upon receiving this callback, you should move the item from the old position (dragged.getAdapterPosition()) to new position (target.getAdapterPosition()) in your adapter and also call notifyItemMoved. To control where a View can be dropped, you can override canDropOver. When a dragging View overlaps multiple other views, Callback chooses the closest View with which dragged View might have changed positions. Although this approach works for many use cases, if you have a custom LayoutManager, you can override chooseDropTarget to select a custom drop target.

When a View is swiped, ItemTouchHelper animates it until it goes out of bounds, then calls onSwiped. At this point, you should update your adapter (e.g. remove the item) and call related Adapter#notify event.

Inheritors

Constructors

Link copied to clipboard
constructor()

Properties

Functions

Link copied to clipboard
Return true if the current ViewHolder can be dropped over the the target ViewHolder.
Link copied to clipboard
Called by ItemTouchHelper to select a drop target from the list of ViewHolders that are under the dragged View.
Link copied to clipboard
open fun clearView(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder)
Called by the ItemTouchHelper when the user interaction with an element is over and it also completed its animation.
Link copied to clipboard
open fun convertToAbsoluteDirection(flags: Int, layoutDirection: Int): Int
Converts a given set of flags to absolution direction which means START and END are replaced with LEFT and RIGHT depending on the layout direction.
Link copied to clipboard
open fun convertToRelativeDirection(flags: Int, layoutDirection: Int): Int
Replaces a movement direction with its relative version by taking layout direction into account.
Link copied to clipboard
open fun getAnimationDuration(@NonNull recyclerView: RecyclerView, animationType: Int, animateDx: Float, animateDy: Float): Long
Called by the ItemTouchHelper when user action finished on a ViewHolder and now the View will be animated to its final position.
Link copied to clipboard
When finding views under a dragged view, by default, ItemTouchHelper searches for views that overlap with the dragged View.
Link copied to clipboard
Returns the ItemTouchUIUtil that is used by the Callback class for visual changes on Views in response to user interactions.
Link copied to clipboard
abstract fun getMovementFlags(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder): Int
Should return a composite flag which defines the enabled move directions in each state (idle, swiping, dragging).
Link copied to clipboard
Returns the fraction that the user should move the View to be considered as it is dragged.
Link copied to clipboard
open fun getSwipeEscapeVelocity(defaultValue: Float): Float
Defines the minimum velocity which will be considered as a swipe action by the user.
Link copied to clipboard
Returns the fraction that the user should move the View to be considered as swiped.
Link copied to clipboard
open fun getSwipeVelocityThreshold(defaultValue: Float): Float
Defines the maximum velocity ItemTouchHelper will ever calculate for pointer movements.
Link copied to clipboard
open fun interpolateOutOfBoundsScroll(@NonNull recyclerView: RecyclerView, viewSize: Int, viewSizeOutOfBounds: Int, totalSize: Int, msSinceStartScroll: Long): Int
Called by the ItemTouchHelper when user is dragging a view out of bounds.
Link copied to clipboard
Returns whether ItemTouchHelper should start a swipe operation if a pointer is swiped over the View.
Link copied to clipboard
Returns whether ItemTouchHelper should start a drag and drop operation if an item is long pressed.
Link copied to clipboard
open fun makeFlag(actionState: Int, directions: Int): Int
Shifts the given direction flags to the offset of the given action state.
Link copied to clipboard
open fun makeMovementFlags(dragFlags: Int, swipeFlags: Int): Int
Convenience method to create movement flags.
Link copied to clipboard
open fun onChildDraw(@NonNull c: Canvas, @NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean)
Called by ItemTouchHelper on RecyclerView's onDraw callback.
Link copied to clipboard
open fun onChildDrawOver(@NonNull c: Canvas, @NonNull recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, dX: Float, dY: Float, actionState: Int, isCurrentlyActive: Boolean)
Called by ItemTouchHelper on RecyclerView's onDraw callback.
Link copied to clipboard
abstract fun onMove(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder, @NonNull target: RecyclerView.ViewHolder): Boolean
Called when ItemTouchHelper wants to move the dragged item from its old position to the new position.
Link copied to clipboard
open fun onMoved(@NonNull recyclerView: RecyclerView, @NonNull viewHolder: RecyclerView.ViewHolder, fromPos: Int, @NonNull target: RecyclerView.ViewHolder, toPos: Int, x: Int, y: Int)
Called when onMove returns true.
Link copied to clipboard
open fun onSelectedChanged(@Nullable viewHolder: RecyclerView.ViewHolder, actionState: Int)
Called when the ViewHolder swiped or dragged by the ItemTouchHelper is changed.
Link copied to clipboard
abstract fun onSwiped(@NonNull viewHolder: RecyclerView.ViewHolder, direction: Int)
Called when a ViewHolder is swiped by the user.
Link copied to clipboard
open fun seslOnSwipeFailed(@NonNull viewHolder: RecyclerView.ViewHolder, direction: Int)