Skip to content

Commit

Permalink
Merge pull request #29094 from software-mansion-labs/ts-migration-use…
Browse files Browse the repository at this point in the history
…-window-dimensions

[No QA][TS migration] Migrate useWindowDimensions
  • Loading branch information
chiragsalian authored Oct 17, 2023
2 parents b22fbba + 415360c commit eae02c6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// 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;
const isExtraSmallScreenHeight = screenHeight <= variables.extraSmallMobileResponsiveHeightBreakpoint;
const isSmallScreenWidth = windowWidth <= variables.mobileResponsiveWidthBreakpoint;
const isMediumScreenWidth = windowWidth > variables.mobileResponsiveWidthBreakpoint && windowWidth <= variables.tabletResponsiveWidthBreakpoint;
const isLargeScreenWidth = windowWidth > variables.tabletResponsiveWidthBreakpoint;

return {
windowWidth,
windowHeight,
Expand Down
10 changes: 10 additions & 0 deletions src/hooks/useWindowDimensions/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type WindowDimensions = {
windowWidth: number;
windowHeight: number;
isExtraSmallScreenHeight: boolean;
isSmallScreenWidth: boolean;
isMediumScreenWidth: boolean;
isLargeScreenWidth: boolean;
};

export default WindowDimensions;

0 comments on commit eae02c6

Please sign in to comment.