Hi Koders!
I’m excited to share a new extension based on the RecyclerView extension by Zain Ul Hassan. I’ve added some new features, including:
-
Drag-and-Drop: Move items within the list by dragging.
- By long-pressing on an item.
- By dragging the drag handle (a dedicated element within the list item).
- Swipe Actions: Swipe list items to trigger custom actions (e.g., delete or edit).
- Scrollbar: Smooth scrolling with a visible scrollbar.
New blocks
■
New Events
Triggered when the user starts moving an item.
Parameters
position: initial position of the dragged item
Triggered when the user ends moving an item.
Parameters
startPos: initial position of the dragged item
endPos: the position of the item when the drag was completed
Triggered when an item in the list is moved.
Parameters
fromPosition: Specifies the current position of the item that the user is dragging, before the list position change occurs.
toPosition: Specifies the new position of the item that is being dragged, after the next list position change occurs.
Triggered when item is swiped.
Parameters
position: position of the swiped item
direction: “left” or “right” swiping
■
New Functions
InitializeRecyclerList
inside a layout with some new parametersImportant notes:
- the Drag&Drop mechanism works well with LinearLayoutManager as layoutManager and Vertical orientation.
- there are three dragMode options: HandlerDragMode, LongPressDragMode and NoDragMode
Get component using its id.
■
New Properties
Change element opacity while dragging
Important note! Use this block before the block “Initialize”
Set dragMode in the block “Initialize”
Special tag for drag&drop handler. It is necessary when you use DragHandlerMode
Sample
This is a simple project that renders buttons, labels and drag handlers inside cards. When a button is pressed, the label above the list shows the text of the corresponding label inside the card.
The basic description of working with the extension is given here. But it should be noted that the property DragHandleTag is used to create a component, that will be used as a drag handle. Example of using inside OnCreateView
:
Example of using inside OnBindView
:
Important note: If you use the drag&drop mechanism, be sure to create unique identifiers for each list element. It is strongly recommended not to use identifiers based on the element’s position.
Project Files
DragRecyclerView.aia (159.5 KB)
DragRecyclerView.apk (4.5 MB)
Download Extension
2.0.0
- com.dreamers.recyclerlist.aix (104.5 KB)