UNPKG

@fruits-chain/react-native-xiaoshu

Version:
30 lines (29 loc) • 942 B
"use strict"; import { useState, useLayoutEffect } from 'react'; import { useWindowDimensions } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; const getDefaultValue = (v, dv) => { if (typeof v === 'number') { return v; } if (typeof v === 'boolean' && v) { return dv; } return 0; }; const useSafeHeight = ({ top = true, bottom = true } = {}) => { const insets = useSafeAreaInsets(); const insetTop = getDefaultValue(top, insets.top); const insetBottom = getDefaultValue(bottom, insets.bottom); const dimensionsWindow = useWindowDimensions(); const [height, setHeight] = useState(dimensionsWindow.height - insetTop - insetBottom); useLayoutEffect(() => { setHeight(dimensionsWindow.height - insetTop - insetBottom); }, [dimensionsWindow.height, insetTop, insetBottom]); return height; }; export default useSafeHeight; //# sourceMappingURL=useSafeHeight.js.map