Skip to content

Commit

Permalink
Add useIsReportOpenInRHP
Browse files Browse the repository at this point in the history
  • Loading branch information
WojtekBoman committed Apr 25, 2024
1 parent a45ae4f commit f5fbd15
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
9 changes: 9 additions & 0 deletions src/hooks/useIsReportOpenInRHP.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {useNavigationState} from '@react-navigation/native';
import getTopmostRouteName from '@libs/Navigation/getTopmostRouteName';
import SCREENS from '@src/SCREENS';

// This hook checks if the currently open route is ReportScreen in RHP.
export default function useIsReportOpenInRHP() {
const activeRoute = useNavigationState(getTopmostRouteName);
return activeRoute === SCREENS.SEARCH.REPORT_RHP;
}
7 changes: 5 additions & 2 deletions src/hooks/useThumbnailDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {useMemo} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import type {DimensionValue} from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
import CONST from '@src/CONST';
import useResponsiveLayout from './useResponsiveLayout';
import useIsReportOpenInRHP from './useIsReportOpenInRHP';
import useWindowDimensions from './useWindowDimensions';

type ThumbnailDimensions = {
thumbnailDimensionsStyles: {
Expand All @@ -13,7 +14,9 @@ type ThumbnailDimensions = {
};

export default function useThumbnailDimensions(width: number, height: number): ThumbnailDimensions {
const {shouldUseNarrowLayout} = useResponsiveLayout();
const isReportOpenInRHP = useIsReportOpenInRHP();
const {isSmallScreenWidth} = useWindowDimensions();
const shouldUseNarrowLayout = isSmallScreenWidth || isReportOpenInRHP;
const fixedDimension = shouldUseNarrowLayout ? CONST.THUMBNAIL_IMAGE.SMALL_SCREEN.SIZE : CONST.THUMBNAIL_IMAGE.WIDE_SCREEN.SIZE;
const thumbnailDimensionsStyles = useMemo(() => {
if (!width || !height) {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/Navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const dismissModal = (reportID?: string, ref = navigationRef) => {
const report = getReport(reportID);
originalDismissModalWithReport({reportID, ...report}, ref);
};
// Re-exporting the closeRHPFlow here to fill in default value for navigationRef. The dismissModal isn't defined in this file to avoid cyclic dependencies.
// Re-exporting the closeRHPFlow here to fill in default value for navigationRef. The closeRHPFlow isn't defined in this file to avoid cyclic dependencies.
const closeRHPFlow = (ref = navigationRef) => originalCloseRHPFlow(ref);

// Re-exporting the dismissModalWithReport here to fill in default value for navigationRef. The dismissModalWithReport isn't defined in this file to avoid cyclic dependencies.
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/closeRHPFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import NAVIGATORS from '@src/NAVIGATORS';
import type {RootStackParamList} from './types';

/**
* Closes the last RHP flow, if there is only one, it closes the entire navigator.
* Closes the last RHP flow, if there is only one, closes the entire RHP.
*/
export default function closeRHPFlow(navigationRef: NavigationContainerRef<RootStackParamList>) {
if (!navigationRef.isReady()) {
Expand Down
10 changes: 6 additions & 4 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import TaskHeaderActionButton from '@components/TaskHeaderActionButton';
import type {CurrentReportIDContextValue} from '@components/withCurrentReportID';
import withCurrentReportID from '@components/withCurrentReportID';
import useAppFocusEvent from '@hooks/useAppFocusEvent';
import useIsReportOpenInRHP from '@hooks/useIsReportOpenInRHP';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useThemeStyles from '@hooks/useThemeStyles';
import useViewportOffsetTop from '@hooks/useViewportOffsetTop';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Timing from '@libs/actions/Timing';
import Navigation from '@libs/Navigation/Navigation';
import clearReportNotifications from '@libs/Notification/clearReportNotifications';
Expand Down Expand Up @@ -158,8 +159,9 @@ function ReportScreen({
const flatListRef = useRef<FlatList>(null);
const reactionListRef = useRef<ReactionListRef>(null);
const {isOffline} = useNetwork();
const {shouldUseNarrowLayout, isInModal} = useResponsiveLayout();

const isReportOpenInRHP = useIsReportOpenInRHP();
const {isSmallScreenWidth} = useWindowDimensions();
const shouldUseNarrowLayout = isSmallScreenWidth || isReportOpenInRHP;
/**
* Create a lightweight Report so as to keep the re-rendering as light as possible by
* passing in only the required props.
Expand Down Expand Up @@ -372,7 +374,7 @@ function ReportScreen({
return reportIDFromRoute !== '' && !!report.reportID && !isTransitioning;
}, [report, reportIDFromRoute]);

const isLoading = !reportIDFromRoute || (!isSidebarLoaded && !isInModal) || PersonalDetailsUtils.isPersonalDetailsEmpty();
const isLoading = !reportIDFromRoute || (!isSidebarLoaded && !isReportOpenInRHP) || PersonalDetailsUtils.isPersonalDetailsEmpty();
const shouldShowSkeleton =
!isLinkedMessageAvailable &&
(isLinkingToMessage ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import type {PopoverMenuItem} from '@components/PopoverMenu';
import PopoverMenu from '@components/PopoverMenu';
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
import Tooltip from '@components/Tooltip/PopoverAnchorTooltip';
import useIsReportOpenInRHP from '@hooks/useIsReportOpenInRHP';
import useLocalize from '@hooks/useLocalize';
import usePermissions from '@hooks/usePermissions';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
Expand Down Expand Up @@ -118,7 +118,9 @@ function AttachmentPickerWithMenuItems({
const {translate} = useLocalize();
const {windowHeight, windowWidth} = useWindowDimensions();
const {canUseTrackExpense} = usePermissions();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {isSmallScreenWidth} = useWindowDimensions();
const isReportOpenInRHP = useIsReportOpenInRHP();
const shouldUseNarrowLayout = isReportOpenInRHP || isSmallScreenWidth;

/**
* Returns the list of IOU Options
Expand Down

0 comments on commit f5fbd15

Please sign in to comment.