Skip to content

Commit

Permalink
Merge pull request #33425 from rayane-djouah/introduce-useResponsiveL…
Browse files Browse the repository at this point in the history
…ayout-hook

[No QA] introducing useResponsiveLayout hook
  • Loading branch information
roryabraham authored Dec 30, 2023
2 parents 035f468 + 9585f5d commit f23b55a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/hooks/useResponsiveLayout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {ParamListBase, RouteProp, useRoute} from '@react-navigation/native';
import useWindowDimensions from './useWindowDimensions';

type RouteParams = ParamListBase & {
params: {isInRHP?: boolean};
};
type ResponsiveLayoutResult = {
shouldUseNarrowLayout: boolean;
};
/**
* Hook to determine if we are on mobile devices or in the RHP
*/
export default function useResponsiveLayout(): ResponsiveLayoutResult {
const {isSmallScreenWidth} = useWindowDimensions();
try {
// eslint-disable-next-line react-hooks/rules-of-hooks
const {params} = useRoute<RouteProp<RouteParams, 'params'>>();
return {shouldUseNarrowLayout: isSmallScreenWidth || (params?.isInRHP ?? false)};
} catch (error) {
return {
shouldUseNarrowLayout: isSmallScreenWidth,
};
}
}

0 comments on commit f23b55a

Please sign in to comment.