UNPKG

@td-design/react-native

Version:

react-native UI组件库

28 lines (27 loc) 978 B
import { useCallback } from 'react'; import { useSafeState } from '@td-design/rn-hooks'; import { computeCellWidth } from './utils'; export default function useTable(_ref) { let { columns } = _ref; /**当前容器的宽度,用来计算表格的长度 */ const [containerWidth, setContainerWidth] = useSafeState(0); const [headerHeight, setHeaderHeight] = useSafeState(0); const [containerHeight, setContainerHeight] = useSafeState(0); const contentHeight = containerHeight - headerHeight; /** 计算单元格的长度 */ const cellWidth = computeCellWidth(containerWidth, columns); /** 获取容器宽度 如果有tableWidth则用tableWidth */ const handleLayout = useCallback((w, h) => { setContainerWidth(w); setContainerHeight(h); }, []); return { contentHeight, handleLayout, cellWidth, handleHeaderLayout: useCallback(e => setHeaderHeight(e.nativeEvent.layout.height), []) }; } //# sourceMappingURL=useTable.js.map