Skip to content

Commit

Permalink
Merge pull request #38940 from tienifr/fix/38059
Browse files Browse the repository at this point in the history
fix: broken login page when refreshing
  • Loading branch information
arosiclair authored Mar 27, 2024
2 parents abb0304 + f778dd1 commit d93cb32
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/hooks/useResponsiveLayout.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import {navigationRef} from '@libs/Navigation/Navigation';
import NAVIGATORS from '@src/NAVIGATORS';
import {useEffect, useState} from 'react';
import Navigation from '@libs/Navigation/Navigation';
import useWindowDimensions from './useWindowDimensions';

type ResponsiveLayoutResult = {
shouldUseNarrowLayout: boolean;
isSmallScreenWidth: boolean;
isInModal: boolean;
};

/**
* Hook to determine if we are on mobile devices or in the Modal Navigator
*/
export default function useResponsiveLayout(): ResponsiveLayoutResult {
const {isSmallScreenWidth} = useWindowDimensions();
const state = navigationRef?.current?.getRootState();
const lastRoute = state?.routes?.at(-1);
const lastRouteName = lastRoute?.name;
const isInModal = lastRouteName === NAVIGATORS.LEFT_MODAL_NAVIGATOR || lastRouteName === NAVIGATORS.RIGHT_MODAL_NAVIGATOR;

const [isInModal, setIsInModal] = useState(Navigation.isDisplayedInModal());

useEffect(() => {
Navigation.isNavigationReady().then(() => {
setIsInModal(Navigation.isDisplayedInModal());
});
}, []);

const shouldUseNarrowLayout = isSmallScreenWidth || isInModal;
return {shouldUseNarrowLayout, isSmallScreenWidth, isInModal};
}
9 changes: 9 additions & 0 deletions src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ function navigateWithSwitchPolicyID(params: SwitchPolicyIDParams) {
return switchPolicyID(navigationRef.current, params);
}

/** Check if the modal is being displayed */
function isDisplayedInModal() {
const state = navigationRef?.current?.getRootState();
const lastRoute = state?.routes?.at(-1);
const lastRouteName = lastRoute?.name;
return lastRouteName === NAVIGATORS.LEFT_MODAL_NAVIGATOR || lastRouteName === NAVIGATORS.RIGHT_MODAL_NAVIGATOR;
}

export default {
setShouldPopAllStateOnUP,
navigate,
Expand All @@ -370,6 +378,7 @@ export default {
parseHybridAppUrl,
navigateWithSwitchPolicyID,
resetToHome,
isDisplayedInModal,
};

export {navigationRef};

0 comments on commit d93cb32

Please sign in to comment.