UNPKG

react-native-leader-line

Version:

React Native port of leader-line library for drawing arrow lines and connectors

118 lines 3.99 kB
/** * @fileoverview Hook for Imperative Leader Line API * @description React hook that provides imperative leader line functionality * @version 1.2.0 * @author Federico Garcia * * @example Basic Usage * ```tsx * import React, { useRef } from 'react'; * import { View } from 'react-native'; * import { useImperativeLeaderLine } from 'react-native-leader-line'; * * const MyComponent = () => { * const startRef = useRef(null); * const endRef = useRef(null); * * const { createLine, LeaderLineContainer } = useImperativeLeaderLine(); * * const handleCreateLine = () => { * const line = createLine(startRef, endRef, { * color: 'blue', * size: 4, * endPlug: 'arrow1' * }); * * // Use imperative API * setTimeout(() => line.setOptions({ color: 'red' }), 1000); * setTimeout(() => line.hide(), 2000); * }; * * return ( * <View> * <View ref={startRef} /> * <View ref={endRef} /> * <LeaderLineContainer /> * <Button onPress={handleCreateLine} title="Create Line" /> * </View> * ); * }; * ``` */ import React from 'react'; import { LeaderLineImperative, ImperativeLeaderLineOptions } from '../components/LeaderLineImperative'; import { Point } from '../types'; /** * @interface ImperativeLineInstance * @description Interface for managing imperative leader line instances */ export interface ImperativeLineInstance { /** Unique identifier for this line instance */ id: string; /** The leader line instance */ line: LeaderLineImperative; /** React component to render */ component: React.ReactElement; } /** * @interface UseImperativeLeaderLineReturn * @description Return value from useImperativeLeaderLine hook */ export interface UseImperativeLeaderLineReturn { /** Create a new leader line */ createLine: (start: React.RefObject<any> | Point, end: React.RefObject<any> | Point, options?: ImperativeLeaderLineOptions) => LeaderLineImperative; /** Remove a specific line by ID */ removeLine: (lineId: string) => void; /** Remove all lines */ removeAllLines: () => void; /** Get all active lines */ getActiveLines: () => ImperativeLineInstance[]; /** Container component to render all lines */ LeaderLineContainer: React.ComponentType; } /** * @hook useImperativeLeaderLine * @description Hook for managing imperative leader lines in React components * @returns {UseImperativeLeaderLineReturn} Imperative API functions and components * * @example Multiple Lines Management * ```tsx * const { createLine, removeLine, removeAllLines, LeaderLineContainer } = useImperativeLeaderLine(); * * const line1 = createLine(ref1, ref2, { color: 'red' }); * const line2 = createLine(ref2, ref3, { color: 'blue' }); * * // Remove specific line * removeLine(line1.id); * * // Remove all lines * removeAllLines(); * ``` */ export declare function useImperativeLeaderLine(): UseImperativeLeaderLineReturn; /** * @hook useLeaderLineCompatibility * @description Hook that provides global leader-line compatibility * @returns {Object} Global LeaderLine constructor and utilities * * @example Global API (leader-line compatibility) * ```tsx * const { LeaderLine } = useLeaderLineCompatibility(); * * // Use like original leader-line * const line = new LeaderLine(startElement, endElement, { * color: 'coral', * size: 4 * }); * ``` */ export declare function useLeaderLineCompatibility(): { LeaderLine: { (this: any, start: React.RefObject<any> | Point, end: React.RefObject<any> | Point, options?: ImperativeLeaderLineOptions): any; prototype: LeaderLineImperative; }; LeaderLineContainer: React.ComponentType<{}>; createLine: (start: React.RefObject<any> | Point, end: React.RefObject<any> | Point, options?: ImperativeLeaderLineOptions) => LeaderLineImperative; }; export default useImperativeLeaderLine; //# sourceMappingURL=useImperativeLeaderLine.d.ts.map