UNPKG

react-native-ui-lib

Version:

<p align="center"> <img src="https://user-images.githubusercontent.com/1780255/105469025-56759000-5ca0-11eb-993d-3568c1fd54f4.png" height="250px" style="display:block"/> </p> <p align="center">UI Toolset & Components Library for React Native</p> <p a

48 lines (44 loc) 1.08 kB
import React, { useCallback, useState } from 'react'; import { Constants } from "../../commons/new"; export default function useHiddenLocation(props) { const { containerRef } = props; const getHiddenLocation = ({ x = 0, y = 0, width = Constants.screenWidth, height = Constants.windowHeight, isDefault = true }) => { return { up: -y - height, down: Constants.windowHeight - y, left: -width - x, right: Constants.screenWidth - x, isDefault }; }; const [hiddenLocation, setHiddenLocation] = useState(getHiddenLocation({})); const onLayout = useCallback(event => { const { width, height } = event.nativeEvent.layout; if (containerRef.current) { containerRef.current.measureInWindow((x, y) => { setHiddenLocation(getHiddenLocation({ x, y, width, height, isDefault: false })); }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return { onLayout, hiddenLocation }; }