diff --git a/src/hooks/useWindowDimensions/index.native.js b/src/hooks/useWindowDimensions/index.native.ts similarity index 89% rename from src/hooks/useWindowDimensions/index.native.js rename to src/hooks/useWindowDimensions/index.native.ts index 358e43f1b75d..5b0ec2002201 100644 --- a/src/hooks/useWindowDimensions/index.native.js +++ b/src/hooks/useWindowDimensions/index.native.ts @@ -1,17 +1,18 @@ // eslint-disable-next-line no-restricted-imports import {useWindowDimensions} from 'react-native'; import variables from '../../styles/variables'; +import WindowDimensions from './types'; /** * A convenience wrapper around React Native's useWindowDimensions hook that also provides booleans for our breakpoints. - * @returns {Object} */ -export default function () { +export default function (): WindowDimensions { const {width: windowWidth, height: windowHeight} = useWindowDimensions(); const isExtraSmallScreenHeight = windowHeight <= variables.extraSmallMobileResponsiveHeightBreakpoint; const isSmallScreenWidth = true; const isMediumScreenWidth = false; const isLargeScreenWidth = false; + return { windowWidth, windowHeight, diff --git a/src/hooks/useWindowDimensions/index.js b/src/hooks/useWindowDimensions/index.ts similarity index 93% rename from src/hooks/useWindowDimensions/index.js rename to src/hooks/useWindowDimensions/index.ts index 1a1f7eed5a67..f9fee6301d06 100644 --- a/src/hooks/useWindowDimensions/index.js +++ b/src/hooks/useWindowDimensions/index.ts @@ -1,12 +1,12 @@ // eslint-disable-next-line no-restricted-imports import {Dimensions, useWindowDimensions} from 'react-native'; import variables from '../../styles/variables'; +import WindowDimensions from './types'; /** * A convenience wrapper around React Native's useWindowDimensions hook that also provides booleans for our breakpoints. - * @returns {Object} */ -export default function () { +export default function (): WindowDimensions { const {width: windowWidth, height: windowHeight} = useWindowDimensions(); // When the soft keyboard opens on mWeb, the window height changes. Use static screen height instead to get real screenHeight. const screenHeight = Dimensions.get('screen').height; @@ -14,6 +14,7 @@ export default function () { const isSmallScreenWidth = windowWidth <= variables.mobileResponsiveWidthBreakpoint; const isMediumScreenWidth = windowWidth > variables.mobileResponsiveWidthBreakpoint && windowWidth <= variables.tabletResponsiveWidthBreakpoint; const isLargeScreenWidth = windowWidth > variables.tabletResponsiveWidthBreakpoint; + return { windowWidth, windowHeight, diff --git a/src/hooks/useWindowDimensions/types.ts b/src/hooks/useWindowDimensions/types.ts new file mode 100644 index 000000000000..9b59d4968935 --- /dev/null +++ b/src/hooks/useWindowDimensions/types.ts @@ -0,0 +1,10 @@ +type WindowDimensions = { + windowWidth: number; + windowHeight: number; + isExtraSmallScreenHeight: boolean; + isSmallScreenWidth: boolean; + isMediumScreenWidth: boolean; + isLargeScreenWidth: boolean; +}; + +export default WindowDimensions;