From 9585f5d3dc11d2f58fd52217614a9f0207fcff06 Mon Sep 17 00:00:00 2001 From: rayane-djouah <77965000+rayane-djouah@users.noreply.github.com> Date: Thu, 21 Dec 2023 16:41:52 +0100 Subject: [PATCH] introducing useResponsiveLayout hook --- src/hooks/useResponsiveLayout.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/hooks/useResponsiveLayout.ts diff --git a/src/hooks/useResponsiveLayout.ts b/src/hooks/useResponsiveLayout.ts new file mode 100644 index 000000000000..b386fc985604 --- /dev/null +++ b/src/hooks/useResponsiveLayout.ts @@ -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>(); + return {shouldUseNarrowLayout: isSmallScreenWidth || (params?.isInRHP ?? false)}; + } catch (error) { + return { + shouldUseNarrowLayout: isSmallScreenWidth, + }; + } +}