UNPKG

@kietpt2003/react-native-core-ui

Version:
46 lines (45 loc) 2.08 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx } from "react/jsx-runtime"; import React from "react"; import { typedMemo } from "../utils/DraggableFlatList/typedMemo"; import { useStableCallback } from "../hooks/DraggableFlatList/useStableCallback"; import { useRefs } from "../context/DraggableFlatList/refContext"; import { useDraggableFlatListContext } from "../context/DraggableFlatList/draggableFlatListContext"; function RowItem(props) { const propsRef = React.useRef(props); propsRef.current = props; const { activeKey } = useDraggableFlatListContext(); const activeKeyRef = React.useRef(activeKey); activeKeyRef.current = activeKey; const { keyToIndexRef } = useRefs(); const drag = useStableCallback(() => { const { drag, itemKey, debug } = propsRef.current; if (activeKeyRef.current) { // already dragging an item, noop if (debug) console.log("## attempt to drag item while another item is already active, noop"); } drag(itemKey); }); const { renderItem, item, itemKey, extraData } = props; const getIndex = useStableCallback(() => { return keyToIndexRef.current.get(itemKey); }); return (_jsx(MemoizedInner, { isActive: activeKey === itemKey, drag: drag, renderItem: renderItem, item: item, getIndex: getIndex, extraData: extraData })); } function Inner(_a) { var { renderItem, extraData } = _a, rest = __rest(_a, ["renderItem", "extraData"]); return renderItem(Object.assign({}, rest)); } const MemoizedInner = typedMemo(Inner); export default typedMemo(RowItem);