react-native-tree-multi-select
Version:
Super-fast, customizable tree view component for React Native with drag-and-drop reordering, multi-selection, and search filtering.
74 lines • 4.09 kB
TypeScript
import { MutableRefObject, RefObject } from "react";
import { Animated, type NativeScrollEvent, type NativeSyntheticEvent, type PanResponderInstance } from "react-native";
import type { FlashList } from "@shopify/flash-list";
import type { __FlattenedTreeNode__, TreeNode, DropAutoScrollOptions } from "../types/treeView.types";
import type { ScrollToNodeHandlerRef } from "./useScrollToNode";
import type { DragCancelEvent, DragEndEvent, DragStartEvent, DropPosition } from "../types/dragDrop.types";
interface UseDragDropParams<ID> {
storeId: string;
flattenedNodes: __FlattenedTreeNode__<ID>[];
flashListRef: RefObject<FlashList<__FlattenedTreeNode__<ID>> | null>;
containerRef: RefObject<{
measureInWindow: (cb: (x: number, y: number, w: number, h: number) => void) => void;
} | null>;
dragEnabled: boolean;
onDragStart?: (event: DragStartEvent<ID>) => void;
onDragEnd?: (event: DragEndEvent<ID>) => void;
onDragCancel?: (event: DragCancelEvent<ID>) => void;
longPressDuration: number;
autoScrollThreshold: number;
autoScrollSpeed: number;
measuredItemHeightRef: MutableRefObject<number>;
/** Live total content height of the list (from FlashList onContentSizeChange),
* used to clamp auto-scroll so the offset never runs past the end of the list. */
contentHeightRef: MutableRefObject<number>;
/** Measured row heights keyed by stable node id. Enables accurate drop
* targeting for variable-height rows when the whole list is rendered. */
itemHeightsRef: MutableRefObject<Map<ID, number>>;
dragOverlayOffset: number;
/** Optional override (item-height units) for the platform overlay-Y correction. */
overlayYCorrection?: number;
autoExpandDelay: number;
/** Whether hovering "inside" a collapsed node auto-expands it. Default: true. */
autoExpand?: boolean;
/** Whether the overlay springs ("magnetic snap") when the drop level changes. Default: true. */
magneticSnap?: boolean;
/** Pixels per nesting level, used for magnetic overlay shift. */
indentationMultiplier: number;
/** Callback to determine if a drop is allowed on a specific target. */
canDrop?: (draggedNode: TreeNode<ID>, targetNode: TreeNode<ID>, position: DropPosition) => boolean;
/** Maximum nesting depth allowed. */
maxDepth?: number;
/** Callback to determine if a node can accept children. */
canNodeHaveChildren?: (node: TreeNode<ID>) => boolean;
/** Ref for scrolling to a node after drop. */
scrollToNodeHandlerRef: RefObject<ScrollToNodeHandlerRef<ID> | null>;
/** Auto-scroll configuration for after drop. */
autoScrollToDroppedNode?: boolean | DropAutoScrollOptions;
/** Callback to determine if a node can be dragged. */
canDrag?: (node: TreeNode<ID>) => boolean;
}
interface UseDragDropReturn<ID> {
panResponder: PanResponderInstance;
overlayY: Animated.Value;
overlayX: Animated.Value;
isDragging: boolean;
draggedNode: __FlattenedTreeNode__<ID> | null;
handleNodeTouchStart: (nodeId: ID, pageY: number, locationY: number, nodeIndex: number) => void;
handleNodeTouchEnd: () => void;
cancelLongPressTimer: () => void;
/** onScroll handler for the host list. Owns the scroll-offset bookkeeping:
* real scroll events are ignored while a drag is active (the auto-scroll
* RAF loop is the sole writer of the offset then - lagging events would
* fight its accumulated value and make the offset oscillate), and any
* scroll cancels a pending long-press. */
handleScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
scrollOffsetRef: MutableRefObject<number>;
headerOffsetRef: MutableRefObject<number>;
/** Live container height; kept fresh via the container's onLayout so the
* auto-scroll edge/clamp math survives a mid-session resize. */
containerHeightRef: MutableRefObject<number>;
}
export declare function useDragDrop<ID>(params: UseDragDropParams<ID>): UseDragDropReturn<ID>;
export {};
//# sourceMappingURL=useDragDrop.d.ts.map