react-native-leader-line
Version:
React Native port of leader-line library for drawing arrow lines and connectors
48 lines • 1.58 kB
JavaScript
import { useCallback, useEffect, useState } from "react";
// Simplified attachment hook for basic functionality
export const useAttachment = (options) => {
const [startPoint, setStartPoint] = useState(null);
const [endPoint, setEndPoint] = useState(null);
const [isConnected, setIsConnected] = useState(false);
const forceUpdate = useCallback(() => {
// Force re-calculation of points
setIsConnected(false);
setTimeout(() => setIsConnected(true), 0);
}, []);
const reset = useCallback(() => {
setStartPoint(null);
setEndPoint(null);
setIsConnected(false);
}, []);
useEffect(() => {
// Basic implementation - would need full attachment logic
if (options.startAttachment && options.endAttachment) {
setIsConnected(true);
}
}, [options.startAttachment, options.endAttachment]);
return {
startPoint,
endPoint,
startSocket: "center",
endSocket: "center",
isConnected,
startState: {
isConnected,
lastUpdate: Date.now(),
computedSocket: "center",
effectivePoint: startPoint || { x: 0, y: 0 },
isVisible: true,
},
endState: {
isConnected,
lastUpdate: Date.now(),
computedSocket: "center",
effectivePoint: endPoint || { x: 0, y: 0 },
isVisible: true,
},
forceUpdate,
reset,
};
};
export default useAttachment;
//# sourceMappingURL=useAttachment.js.map