Skip to content

Commit

Permalink
introducing useResponsiveLayout hook
Browse files Browse the repository at this point in the history
  • Loading branch information
rayane-djouah committed Dec 21, 2023
1 parent 8970aa3 commit 9585f5d
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 9585f5d

Please sign in to comment.