A Kotlin DSL for RecyclerView drag-and-drop actions.
recyclerView.dragDropWith {
onDropped { oldPos, newPos ->
val moved: String = itemsList.removeAt(oldPos)
itemsList.add(newPos, moved)
}
constrainDrag { vh ->
val pos = vh.adapterPosition
return@constrainDrag (pos - 3)..(pos + 3)
}
canDrag = { vh ->
vh.itemView.listText.text != "Banana"
}
elevateBy = 4.dp //default is 8
}
- The library handles updating the adapter, but the underlying data does need to be updated at the end for the changes to stay in effect.
- This is a pre-release, so the API is subject to change
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.andb3:dragdropper:0.3.0'
}