Sortable
A headless Sortable list component for ReactLynx. It provides list reordering primitives via main-thread animations.Info
You can check the source code to understand how it works, and you're welcome to submit PRs to enhance its capabilities.
Basic Usage
Examples
Drag Without a boundary
If no boundaryId is provided, the SortableItem can be dragged freely without restrictions.
Disable all dragging and sorting behavior
Structure
By default, the whole SortableItem responds to dragging.
Use SortableItemArea when only a specific area should respond to dragging.
Component API
SortableRoot
asiOSAndroidHarmony
Specifies which container element SortableRoot should render and own as the scrollable boundary.
-
'ScrollView': render an internal vertical scroll-view.
- Omit (default): render a plain view without scrolling capability.boundaryIdiOSAndroidHarmony
The unique key of the item that acts as the boundary. If the item is dragged out of the boundary, the sorting will be canceled.
childreniOSAndroidHarmony
Children, which is a function that receives an item and returns a ReactNode.
dataiOSAndroidHarmony
The data for the sortable list.
debugLogiOSAndroidHarmony
Display debug logs. Open it when you find a bug.
enableSortingiOSAndroidHarmony
Whether to enable sorting.
onSortEndiOSAndroidHarmony
Callback function that is triggered when sorting ends. The parameter is the sorted data.
onSortStartiOSAndroidHarmony
Callback function that is triggered when sorting starts.
scrollableBoundaryIdiOSAndroidHarmony
The unique id of a scrollable boundary container. When the dragged item reaches the edge of this container, Sortable will call
scrollBy on it so the list can continue moving with the drag direction.scrollableClassNameiOSAndroidHarmony
Class name applied to the owned
scroll-view when as is 'ScrollView'.scrollableContentClassNameiOSAndroidHarmony
Class name applied to the owned content boundary view when
as is 'ScrollView'.scrollableEnableScrolliOSAndroidHarmony
Whether the owned
scroll-view can be scrolled by user gestures.scrollableStickyLowerOffsetiOSAndroidHarmony
Distance between the dragged item and the lower edge of the owned or configured scrollable boundary while auto-scrolling downward.
scrollableStickyUpperOffsetiOSAndroidHarmony
Distance between the dragged item and the upper edge of the owned or configured scrollable boundary while auto-scrolling upward.
SortableItem
The item inside Sortable.
asiOSAndroidHarmony
Specifies the underlying component to be used.
childreniOSAndroidHarmony
Children.
classNameiOSAndroidHarmony
className
disablediOSAndroidHarmony
Whether this item is locked from sorting.
A disabled item:
- Cannot be dragged itself. Touch / long-press gestures are not bound on
it, so interacting with it never starts a sort operation.
- Cannot be displaced by other items being dragged. It always stays at
its current position.
- Always keeps its absolute position in the final sorted order. Other
items can still freely cross over it; only the relative order of
non-disabled items can change.
Note that this only affects the disabled item itself. Other (non-disabled)
items keep their full interactivity.
sortingKeyiOSAndroidHarmony
The unique key for sorting.
Supporting Types
SortableData
The data structure for each item in the Sortable component.
dataItemiOSAndroidHarmony
The original data item.
getSortingKeyiOSAndroidHarmony
A function that returns the unique key for sorting.