For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt, and this page is available as Markdown at /next/ui/components/draggable.md.
lynx-ui logo
lynx-ui
  • English
  • Draggable

    A headless Draggable component for ReactLynx. It provides drag-and-drop primitives via main-thread execution.
    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

    Draggable supports two gesture modes: immediate (drag starts instantly on touch) and longpress (drag starts after a long press gesture). You can also control whether the position resets when the drag ends or preserves its transform position.

    Examples

    With bounds

    The draggable area allowed can be limited with min(max)TranslateX/Y props.

    Structure

    Use <Draggable> when the whole component should respond to dragging.

    <Draggable>
      {/* Your content */}
    </Draggable>

    Use <DraggableRoot> and <DraggableArea> when only a specific area should respond to dragging.

    <DraggableRoot>
      <DraggableArea />
    </DraggableRoot>

    Component API

    Draggable

    allowedDirectioniOSAndroidHarmony
    TypeDirections·Default'all'
    The direction of the drag.
    childreniOSAndroidHarmony
    TypeReactNode
    children
    classNameiOSAndroidHarmony
    Typestring
    className
    debugLogiOSAndroidHarmony
    Typeboolean·Defaultfalse
    Display debug logs. Open it when you find a bug.
    draggablePropsiOSAndroidHarmony
    TypeViewProps
    Extra props for draggable. It accepts all the props of the normal view.
    enableDraggingiOSAndroidHarmony
    Typeboolean·Defaulttrue
    Whether the component is draggable.
    idiOSAndroidHarmony
    Typestring
    Id
    maxTranslateXiOSAndroidHarmony
    Typenumber
    The maximum value of the X-axis translation.
    maxTranslateYiOSAndroidHarmony
    Typenumber
    The maximum value of the Y-axis translation.
    minTranslateXiOSAndroidHarmony
    Typenumber
    The minimum value of the X-axis translation.
    minTranslateYiOSAndroidHarmony
    Typenumber
    The minimum value of the Y-axis translation.
    MTSRefiOSAndroidHarmony
    TypeRefObject<DraggableRef>
    main-thread:ref
    onDragEndiOSAndroidHarmony
    Type(translate: Point) => void
    Triggers when the drag is over
    onDraggingiOSAndroidHarmony
    Type(translate: Point) => void
    Triggers when the item is dragging
    onDragStartiOSAndroidHarmony
    Type(pagePoint: Point) => void
    Triggers when the item starts to be dragged
    onMTSDragEndiOSAndroidHarmony
    Type(translate: Point, event: MouseEvent | TouchEvent) => void
    Triggered when the dragging ends. It runs on the main thread, allowing for more timely UI operations. Please ensure that the passed handler is a main thread function, i.e., a function marked with 'main thread'.
    onMTSDraggingiOSAndroidHarmony
    Type(translate: Point, event: MouseEvent | TouchEvent) => void
    Triggered when the dragging ends. It runs on the main thread, allowing for more timely UI operations. Please ensure that the passed handler is a main thread function, i.e., a function marked with 'main thread'.
    onMTSDragStartiOSAndroidHarmony
    Type(pagePoint: Point, event: MouseEvent | TouchEvent) => void
    Triggered during the dragging process. It runs on the main thread, allowing for more timely UI operations. Please ensure that the passed handler is a main thread function, i.e., a function marked with 'main thread'.
    resetOnEndiOSAndroidHarmony
    Typeboolean
    Reset the transform to 0 when the dragging process ends.
    styleiOSAndroidHarmony
    TypeCSSProperties
    style
    triggeriOSAndroidHarmony
    Typelongpress | immediate·Default'longpress'
    The way to trigger the drag.

    DraggableArea

    childreniOSAndroidHarmony
    TypeReactNode
    children
    classNameiOSAndroidHarmony
    Typestring
    className
    idiOSAndroidHarmony
    Typestring
    Id
    styleiOSAndroidHarmony
    TypeCSSProperties
    style

    DraggableRef

    MTSResetInternalTranslateValues
    Type() => void
    Resets the internal state of the draggable component, such as the starting touch point and current translation. This is useful for programmatically resetting the component's state if you control the transform outside this component.
    MTSSetOtherStyles
    Type(styles: Record<string, string>) => void
    Programmatically sets a map of CSS styles on the draggable element. This is useful for setting styles that are not directly related to the draggable behavior.
    MTSSetTransform
    Type(x: number, y: number) => void
    Programmatically sets the transform style of the draggable element. 'transform' should always be set this way from the outside or it will break the logic.
    Except as otherwise noted, this work is licensed under a Creative Commons Attribution 4.0 International License, and code samples are licensed under the Apache License 2.0.