For AI agents: the complete documentation index is available at /next/zh/llms.txt, the full documentation bundle is available at /next/zh/llms-full.txt, and this page is available as Markdown at /next/zh/ui/components/sortable.md.
lynx-ui logo
lynx-ui
  • 简体中文
  • Sortable

    一个适用于 ReactLynx 的无样式可排序列表组件,通过主线程动画提供列表重排基础能力。
    Info

    你可以查看源码来了解它的运行原理,也欢迎大家提 PR 来丰富其能力。

    基本用法

    示例

    无边界拖拽

    如果未提供 boundaryId,则 SortableItem 可以不受限制地自由拖拽。

    禁用所有拖拽和排序行为

    结构

    默认情况下,整个 SortableItem 都会响应拖拽。

    <SortableRoot>
      {(item) => (
        <SortableItem sortingKey={item.getSortingKey()} />
      )}
    </SortableRoot>

    当只有特定区域需要响应拖拽时,使用 SortableItemArea。

    <SortableRoot>
      {(item) => (
        <SortableItem as="DraggableRoot" sortingKey={item.getSortingKey()}>
          <SortableItemArea />
        </SortableItem>
      )}
    </SortableRoot>

    组件 API

    SortableRoot

    asiOSAndroidHarmony
    类型'ScrollView'
    指定 SortableRoot 渲染并持有的滚动容器类型。 - 'ScrollView':渲染一个内部的纵向 scroll-view。 - 不传(默认):渲染普通 view,不带滚动能力。
    boundaryIdiOSAndroidHarmony
    类型string
    作为边界限制的项的唯一键。如果项被拖出边界,排序将被取消。
    childreniOSAndroidHarmony
    类型(item: {dataItem: T, getSortingKey: () => string}) => ReactNode
    子节点,是一个接收 item 并返回 ReactNode 的函数。
    dataiOSAndroidHarmony
    类型SortableData<T>[]
    拖拽列表的数据。
    debugLogiOSAndroidHarmony
    类型boolean·默认值false
    显示调试日志,发现问题时开启。
    enableSortingiOSAndroidHarmony
    类型boolean·默认值true
    是否启用排序。
    onSortEndiOSAndroidHarmony
    类型(sortedData: SortableData<T>[]) => void
    排序结束时触发的回调函数。参数为排序后的data。
    onSortStartiOSAndroidHarmony
    类型() => void
    拖拽排序开始时触发的回调函数。
    scrollableBoundaryIdiOSAndroidHarmony
    类型string
    可滚动边界容器的唯一 id。当拖拽项触达该容器边缘时,Sortable 会对其调用 scrollBy,使列表随拖拽方向继续滚动。
    scrollableClassNameiOSAndroidHarmony
    类型string
    as 为 'ScrollView' 时应用到内部 scroll-view 的类名。
    scrollableContentClassNameiOSAndroidHarmony
    类型string
    as 为 'ScrollView' 时应用到内部内容边界 view 的类名。
    scrollableEnableScrolliOSAndroidHarmony
    类型boolean·默认值true
    内部 scroll-view 是否允许用户手势滚动。
    scrollableStickyLowerOffsetiOSAndroidHarmony
    类型number·默认值0
    向下自动滚动时,拖拽项与可滚动边界下边缘之间保持的距离。
    scrollableStickyUpperOffsetiOSAndroidHarmony
    类型number·默认值0
    向上自动滚动时,拖拽项与可滚动边界上边缘之间保持的距离。

    SortableItem

    The item inside Sortable.

    asiOSAndroidHarmony
    类型Draggable | DraggableRoot·默认值'Draggable'
    指定底层组件。若整个子节点区域均可拖动,使用默认值 'Draggable';否则使用 'DraggableRoot','DraggableRoot' 需与子节点 'DraggableArea' 一起使用。仅触摸其子节点 'DraggableArea' 时可拖动。
    childreniOSAndroidHarmony
    类型ReactNode
    子节点。
    classNameiOSAndroidHarmony
    类型string
    类名
    disablediOSAndroidHarmony
    类型boolean·默认值false
    是否禁用该项的拖拽排序。 被禁用的项: - 自身无法被拖动。其上不会绑定 touch / longpress 等手势,触摸该项不会触发任何排序操作。 - 不会因为其他项的拖动而发生位移,始终保持在原位置。 - 在最终排序结果中始终保持其绝对位置不变;其他项仍可自由地越过它进行排序, 仅未被禁用项之间的相对顺序会发生变化。 该属性只影响被禁用的项自身;其它(未被禁用的)项的交互能力不受影响。
    sortingKeyiOSAndroidHarmony
    类型string
    用于排序的唯一键。

    辅助类型

    SortableData

    The data structure for each item in the Sortable component.

    dataItemiOSAndroidHarmony
    类型T
    原始数据项。
    getSortingKeyiOSAndroidHarmony
    类型() => string
    返回子节点用于排序的唯一键的函数。
    除非另有说明,本项目采用知识共享署名 4.0 国际许可协议进行许可,代码示例采用 Apache License 2.0 许可协议进行许可。