UNPKG

react-native-toast-notifications

Version:

[![Version][version-badge]][package] [![MIT License][license-badge]][license]

27 lines (25 loc) 806 B
import { useEffect, useState } from "react"; import { Dimensions } from "react-native"; export function useDimensions() { const [dimensions, setDimensions] = useState(Dimensions.get("window")); const onChange = ({ window }) => { setDimensions(window); }; useEffect(() => { const subscription = Dimensions.addEventListener("change", onChange); return () => { // @ts-expect-error - React Native >= 0.65 if (typeof (subscription === null || subscription === void 0 ? void 0 : subscription.remove) === "function") { // @ts-expect-error subscription.remove(); } else { // React Native < 0.65 Dimensions.removeEventListener("change", onChange); } }; }, []); return dimensions; } //# sourceMappingURL=useDimensions.js.map