From adc2d2706084e3202a9198da6716fa7ffa9afa3e Mon Sep 17 00:00:00 2001 From: Yehor Kharchenko Date: Wed, 5 Nov 2025 09:50:10 +0100 Subject: [PATCH 1/8] reverted changes that caused unpredictable behaviour --- .../WideRHPContextProvider/index.tsx | 77 +++++++++++++------ 1 file changed, 52 insertions(+), 25 deletions(-) diff --git a/src/components/WideRHPContextProvider/index.tsx b/src/components/WideRHPContextProvider/index.tsx index 5cadccf9be30..07a327d95719 100644 --- a/src/components/WideRHPContextProvider/index.tsx +++ b/src/components/WideRHPContextProvider/index.tsx @@ -5,13 +5,18 @@ import React, {createContext, useCallback, useContext, useEffect, useMemo, useSt // to interact with react-navigation components (e.g., CardContainer, interpolator), which also use Animated. // eslint-disable-next-line no-restricted-imports import {Animated, Dimensions, InteractionManager} from 'react-native'; +import type {OnyxCollection} from 'react-native-onyx'; +import useOnyx from '@hooks/useOnyx'; import useRootNavigationState from '@hooks/useRootNavigationState'; import {isFullScreenName} from '@libs/Navigation/helpers/isNavigatorName'; import navigationRef from '@libs/Navigation/navigationRef'; import type {NavigationRoute} from '@libs/Navigation/types'; import variables from '@styles/variables'; +import CONST from '@src/CONST'; import NAVIGATORS from '@src/NAVIGATORS'; +import ONYXKEYS from '@src/ONYXKEYS'; import SCREENS from '@src/SCREENS'; +import type {Report} from '@src/types/onyx'; import defaultWideRHPContextValue from './default'; import type {WideRHPContextType} from './types'; @@ -56,22 +61,6 @@ function extractNavigationKeys(state: NavigationState | PartialState isFullScreenName(route.name)); - const lastRHPRouteIndex = state.routes.findLastIndex((route) => route.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR); - - // Both routes have to be present and the RHP have to be after last full screen for it to be visible. - if (lastFullScreenRouteIndex === -1 || lastRHPRouteIndex === -1 || lastFullScreenRouteIndex > lastRHPRouteIndex) { - return undefined; - } - - return state?.routes.at(lastRHPRouteIndex)?.key; -} - /** * Calculates the optimal width for the receipt pane RHP based on window width. * Ensures the RHP doesn't exceed maximum width and maintains minimum responsive width. @@ -90,12 +79,42 @@ const receiptPaneRHPWidth = new Animated.Value(calculateReceiptPaneRHPWidth(Dime const WideRHPContext = createContext(defaultWideRHPContextValue); +const expenseReportSelector = (reports: OnyxCollection) => { + return Object.fromEntries( + Object.entries(reports ?? {}).map(([key, report]) => [ + key, + { + reportID: report?.reportID, + type: report?.type, + }, + ]), + ); +}; + function WideRHPContextProvider({children}: React.PropsWithChildren) { // We have a separate containers for allWideRHPRouteKeys and wideRHPRouteKeys because we may have two or more RHPs on the stack. // For convenience and proper overlay logic wideRHPRouteKeys will show only the keys existing in the last RHP. const [allWideRHPRouteKeys, setAllWideRHPRouteKeys] = useState([]); const [shouldRenderSecondaryOverlay, setShouldRenderSecondaryOverlay] = useState(false); const [expenseReportIDs, setExpenseReportIDs] = useState>(new Set()); + const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {selector: expenseReportSelector, canBeMissing: true}); + + // Return undefined if RHP is not the last route + const lastVisibleRHPRouteKey = useRootNavigationState((state) => { + // Safe handling when navigation is not yet initialized + if (!state) { + return undefined; + } + const lastFullScreenRouteIndex = state?.routes.findLastIndex((route) => isFullScreenName(route.name)); + const lastRHPRouteIndex = state?.routes.findLastIndex((route) => route.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR); + + // Both routes have to be present and the RHP have to be after last full screen for it to be visible. + if (lastFullScreenRouteIndex === -1 || lastRHPRouteIndex === -1 || lastFullScreenRouteIndex > lastRHPRouteIndex) { + return undefined; + } + + return state?.routes.at(lastRHPRouteIndex)?.key; + }); const wideRHPRouteKeys = useMemo(() => { const rootState = navigationRef.getRootState(); @@ -104,7 +123,6 @@ function WideRHPContextProvider({children}: React.PropsWithChildren) { return []; } - const lastVisibleRHPRouteKey = getLastVisibleRHPRouteKey(rootState); const lastRHPRoute = rootState.routes.find((route) => route.key === lastVisibleRHPRouteKey); if (!lastRHPRoute) { @@ -115,7 +133,7 @@ function WideRHPContextProvider({children}: React.PropsWithChildren) { const currentKeys = allWideRHPRouteKeys.filter((key) => lastRHPKeys.has(key)); return currentKeys; - }, [allWideRHPRouteKeys]); + }, [allWideRHPRouteKeys, lastVisibleRHPRouteKey]); /** * Determines whether the secondary overlay should be displayed. @@ -205,13 +223,22 @@ function WideRHPContextProvider({children}: React.PropsWithChildren) { * This enables optimistic wide RHP display for expense reports. * It helps us open expense as wide, before it fully loads. */ - const markReportIDAsExpense = useCallback((reportID: string) => { - setExpenseReportIDs((prev) => { - const newSet = new Set(prev); - newSet.add(reportID); - return newSet; - }); - }, []); + const markReportIDAsExpense = useCallback( + (reportID: string) => { + const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; + const isInvoice = report?.type === CONST.REPORT.TYPE.INVOICE; + const isTask = report?.type === CONST.REPORT.TYPE.TASK; + if (isInvoice || isTask) { + return; + } + setExpenseReportIDs((prev) => { + const newSet = new Set(prev); + newSet.add(reportID); + return newSet; + }); + }, + [allReports], + ); /** * Checks if a report ID is marked as an expense report. From 59ab9eebb754bd2d829d212440df41beef0c2591 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Tue, 14 Oct 2025 16:51:35 +0200 Subject: [PATCH 2/8] Hide loading bar on top bar when rhp is visible --- src/components/Navigation/TopBar.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/Navigation/TopBar.tsx b/src/components/Navigation/TopBar.tsx index 84eb0a5a8c6e..d2d4b94cd1d7 100644 --- a/src/components/Navigation/TopBar.tsx +++ b/src/components/Navigation/TopBar.tsx @@ -9,9 +9,11 @@ import Text from '@components/Text'; import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; +import useRootNavigationState from '@hooks/useRootNavigationState'; import useThemeStyles from '@hooks/useThemeStyles'; import SignInButton from '@pages/home/sidebar/SignInButton'; import {isAnonymousUser as isAnonymousUserUtil} from '@userActions/Session'; +import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Session} from '@src/types/onyx'; @@ -32,6 +34,7 @@ function TopBar({breadcrumbLabel, shouldDisplaySearch = true, shouldDisplayHelpB const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector, canBeMissing: true}); const shouldShowLoadingBarForReports = useLoadingBarVisibility(); const isAnonymousUser = isAnonymousUserUtil(session); + const isRhpVisible = useRootNavigationState((state) => state?.routes?.at(-1)?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR); const displaySignIn = isAnonymousUser; const displaySearch = !isAnonymousUser && shouldDisplaySearch; @@ -68,7 +71,7 @@ function TopBar({breadcrumbLabel, shouldDisplaySearch = true, shouldDisplayHelpB {shouldDisplayHelpButton && } {displaySearch && } - + ); } From 3d38b1349213cb9a0ff7806d0e020cd95aa8b0ce Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Tue, 14 Oct 2025 16:51:59 +0200 Subject: [PATCH 3/8] Preload SearchReport before opening --- src/components/Search/index.tsx | 3 ++- .../Search/openSearchReport/index.native.ts | 6 ++++++ src/components/Search/openSearchReport/index.ts | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/components/Search/openSearchReport/index.native.ts create mode 100644 src/components/Search/openSearchReport/index.ts diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 68fe666d1434..ef85f556d724 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -72,6 +72,7 @@ import type {SearchTransaction} from '@src/types/onyx/SearchResults'; import type {TransactionViolation} from '@src/types/onyx/TransactionViolation'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import arraysEqual from '@src/utils/arraysEqual'; +import openSearchReport from './openSearchReport'; import {useSearchContext} from './SearchContext'; import SearchList from './SearchList'; import {SearchScopeProvider} from './SearchScopeProvider'; @@ -710,7 +711,7 @@ function Search({ setOptimisticDataForTransactionThreadPreview(item, transactionPreviewData); } - requestAnimationFrame(() => Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo}))); + openSearchReport(reportID, backTo); }, [isMobileSelectionModeEnabled, toggleTransaction, hash, queryJSON, handleSearch, searchKey, markReportIDAsExpense], ); diff --git a/src/components/Search/openSearchReport/index.native.ts b/src/components/Search/openSearchReport/index.native.ts new file mode 100644 index 000000000000..46a4d63f8cf3 --- /dev/null +++ b/src/components/Search/openSearchReport/index.native.ts @@ -0,0 +1,6 @@ +import Navigation from '@libs/Navigation/Navigation'; +import ROUTES from '@src/ROUTES'; + +export default function openSearchReport(reportID: string, backTo: string) { + requestAnimationFrame(() => Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo}))); +} diff --git a/src/components/Search/openSearchReport/index.ts b/src/components/Search/openSearchReport/index.ts new file mode 100644 index 000000000000..3c85a5dd91f5 --- /dev/null +++ b/src/components/Search/openSearchReport/index.ts @@ -0,0 +1,16 @@ +import {CommonActions} from '@react-navigation/native'; +import Navigation, {navigationRef} from '@libs/Navigation/Navigation'; +import NAVIGATORS from '@src/NAVIGATORS'; +import ROUTES from '@src/ROUTES'; +import SCREENS from '@src/SCREENS'; + +export default function openSearchReport(reportID: string, backTo: string) { + navigationRef.dispatch({ + ...CommonActions.preload(NAVIGATORS.RIGHT_MODAL_NAVIGATOR, { + name: SCREENS.RIGHT_MODAL.SEARCH_REPORT, + params: {reportID, backTo}, + }), + target: navigationRef.getRootState().key, + }); + requestAnimationFrame(() => Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo}))); +} From d679b5337b7d7fa0c30282e7258eacf4d5f5bbbd Mon Sep 17 00:00:00 2001 From: Yehor Kharchenko Date: Mon, 27 Oct 2025 14:40:11 +0100 Subject: [PATCH 4/8] fixed loading bar on other rhps beside wide rhp --- src/components/Navigation/TopBar.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/Navigation/TopBar.tsx b/src/components/Navigation/TopBar.tsx index d2d4b94cd1d7..fa8118f494f3 100644 --- a/src/components/Navigation/TopBar.tsx +++ b/src/components/Navigation/TopBar.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useContext} from 'react'; import {View} from 'react-native'; import type {OnyxEntry} from 'react-native-onyx'; import LoadingBar from '@components/LoadingBar'; @@ -6,14 +6,13 @@ import {PressableWithoutFeedback} from '@components/Pressable'; import SearchButton from '@components/Search/SearchRouter/SearchButton'; import HelpButton from '@components/SidePanel/HelpComponents/HelpButton'; import Text from '@components/Text'; +import {WideRHPContext} from '@components/WideRHPContextProvider'; import useLoadingBarVisibility from '@hooks/useLoadingBarVisibility'; import useLocalize from '@hooks/useLocalize'; import useOnyx from '@hooks/useOnyx'; -import useRootNavigationState from '@hooks/useRootNavigationState'; import useThemeStyles from '@hooks/useThemeStyles'; import SignInButton from '@pages/home/sidebar/SignInButton'; import {isAnonymousUser as isAnonymousUserUtil} from '@userActions/Session'; -import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Session} from '@src/types/onyx'; @@ -34,7 +33,8 @@ function TopBar({breadcrumbLabel, shouldDisplaySearch = true, shouldDisplayHelpB const [session] = useOnyx(ONYXKEYS.SESSION, {selector: authTokenTypeSelector, canBeMissing: true}); const shouldShowLoadingBarForReports = useLoadingBarVisibility(); const isAnonymousUser = isAnonymousUserUtil(session); - const isRhpVisible = useRootNavigationState((state) => state?.routes?.at(-1)?.name === NAVIGATORS.RIGHT_MODAL_NAVIGATOR); + const {wideRHPRouteKeys} = useContext(WideRHPContext); + const isWideRhpVisible = !!wideRHPRouteKeys.length; const displaySignIn = isAnonymousUser; const displaySearch = !isAnonymousUser && shouldDisplaySearch; @@ -71,7 +71,7 @@ function TopBar({breadcrumbLabel, shouldDisplaySearch = true, shouldDisplayHelpB {shouldDisplayHelpButton && } {displaySearch && } - + ); } From db8ebaa5ff5d24b63ea9b0cb80efcb8515e018f9 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 27 Oct 2025 15:41:46 +0100 Subject: [PATCH 5/8] Add comment to openSearchReport --- src/components/Search/openSearchReport/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Search/openSearchReport/index.ts b/src/components/Search/openSearchReport/index.ts index 3c85a5dd91f5..05e06c549799 100644 --- a/src/components/Search/openSearchReport/index.ts +++ b/src/components/Search/openSearchReport/index.ts @@ -4,6 +4,7 @@ import NAVIGATORS from '@src/NAVIGATORS'; import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; +// The search report screen is preloaded before navigating to avoid lag when opening the page. If the content is rendered in the background and then navigated, the opening experience is smoother. export default function openSearchReport(reportID: string, backTo: string) { navigationRef.dispatch({ ...CommonActions.preload(NAVIGATORS.RIGHT_MODAL_NAVIGATOR, { From 2d14cb856190c7931d766785dd11a6bb5e29c21a Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 27 Oct 2025 15:54:40 +0100 Subject: [PATCH 6/8] Adjust navigating to search report after creating transaction thread --- src/components/Search/openSearchReport/index.native.ts | 2 +- src/components/Search/openSearchReport/index.ts | 2 +- src/libs/SearchUIUtils.ts | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/components/Search/openSearchReport/index.native.ts b/src/components/Search/openSearchReport/index.native.ts index 46a4d63f8cf3..4929d1a49257 100644 --- a/src/components/Search/openSearchReport/index.native.ts +++ b/src/components/Search/openSearchReport/index.native.ts @@ -1,6 +1,6 @@ import Navigation from '@libs/Navigation/Navigation'; import ROUTES from '@src/ROUTES'; -export default function openSearchReport(reportID: string, backTo: string) { +export default function openSearchReport(reportID: string | undefined, backTo: string) { requestAnimationFrame(() => Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID, backTo}))); } diff --git a/src/components/Search/openSearchReport/index.ts b/src/components/Search/openSearchReport/index.ts index 05e06c549799..3b6cf0179977 100644 --- a/src/components/Search/openSearchReport/index.ts +++ b/src/components/Search/openSearchReport/index.ts @@ -5,7 +5,7 @@ import ROUTES from '@src/ROUTES'; import SCREENS from '@src/SCREENS'; // The search report screen is preloaded before navigating to avoid lag when opening the page. If the content is rendered in the background and then navigated, the opening experience is smoother. -export default function openSearchReport(reportID: string, backTo: string) { +export default function openSearchReport(reportID: string | undefined, backTo: string) { navigationRef.dispatch({ ...CommonActions.preload(NAVIGATORS.RIGHT_MODAL_NAVIGATOR, { name: SCREENS.RIGHT_MODAL.SEARCH_REPORT, diff --git a/src/libs/SearchUIUtils.ts b/src/libs/SearchUIUtils.ts index ee3c76990b08..06cc6102a60e 100644 --- a/src/libs/SearchUIUtils.ts +++ b/src/libs/SearchUIUtils.ts @@ -7,6 +7,7 @@ import type DotLottieAnimation from '@components/LottieAnimations/types'; import type {MenuItemWithLink} from '@components/MenuItemList'; import type {MultiSelectItem} from '@components/Search/FilterDropdowns/MultiSelectPopup'; import type {SingleSelectItem} from '@components/Search/FilterDropdowns/SingleSelectPopup'; +import openSearchReport from '@components/Search/openSearchReport'; import type { SearchAction, SearchColumnType, @@ -1278,7 +1279,7 @@ function createAndOpenSearchTransactionThread(item: TransactionListItemType, has } if (shouldNavigate) { - Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: transactionThreadReport?.reportID, backTo})); + openSearchReport(transactionThreadReport?.reportID, backTo); } } From e491760a08004889bfd6cdb55878b517ee768212 Mon Sep 17 00:00:00 2001 From: Wojciech Boman Date: Mon, 27 Oct 2025 16:44:05 +0100 Subject: [PATCH 7/8] Adjust SearchUIUtilsTest tests --- tests/unit/Search/SearchUIUtilsTest.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/Search/SearchUIUtilsTest.ts b/tests/unit/Search/SearchUIUtilsTest.ts index f935dc08bd2d..c220e52a2aba 100644 --- a/tests/unit/Search/SearchUIUtilsTest.ts +++ b/tests/unit/Search/SearchUIUtilsTest.ts @@ -1,5 +1,6 @@ import type {OnyxCollection} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; +import openSearchReport from '@components/Search/openSearchReport'; import ChatListItem from '@components/SelectionListWithSections/ChatListItem'; import TransactionGroupListItem from '@components/SelectionListWithSections/Search/TransactionGroupListItem'; import TransactionListItem from '@components/SelectionListWithSections/Search/TransactionListItem'; @@ -12,7 +13,6 @@ import type { TransactionReportGroupListItemType, TransactionWithdrawalIDGroupListItemType, } from '@components/SelectionListWithSections/types'; -import Navigation from '@navigation/Navigation'; // eslint-disable-next-line no-restricted-syntax import type * as ReportUserActions from '@userActions/Report'; import {createTransactionThreadReport} from '@userActions/Report'; @@ -25,7 +25,6 @@ import IntlStore from '@src/languages/IntlStore'; import type {CardFeedForDisplay} from '@src/libs/CardFeedUtils'; import * as SearchUIUtils from '@src/libs/SearchUIUtils'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; import type * as OnyxTypes from '@src/types/onyx'; import type {Connections} from '@src/types/onyx/Policy'; import type {SearchDataTypes} from '@src/types/onyx/SearchResults'; @@ -45,6 +44,7 @@ jest.mock('@userActions/Search', () => ({ ...jest.requireActual('@userActions/Search'), updateSearchResultsWithTransactionThreadReportID: jest.fn(), })); +jest.mock('@components/Search/openSearchReport', () => jest.fn()); const adminAccountID = 18439984; const adminEmail = 'admin@policy.com'; @@ -2807,12 +2807,12 @@ describe('SearchUIUtils', () => { test('Should not navigate if shouldNavigate = false', () => { SearchUIUtils.createAndOpenSearchTransactionThread(transactionListItem, hash, backTo, undefined, false); - expect(Navigation.navigate).not.toHaveBeenCalled(); + expect(openSearchReport).not.toHaveBeenCalled(); }); test('Should handle navigation if shouldNavigate = true', () => { SearchUIUtils.createAndOpenSearchTransactionThread(transactionListItem, hash, backTo, undefined, true); - expect(Navigation.navigate).toHaveBeenCalledWith(ROUTES.SEARCH_REPORT.getRoute({reportID: threadReportID, backTo})); + expect(openSearchReport).toHaveBeenCalledWith(threadReportID, backTo); }); }); From 9f109ae8a09ed3a39f37f2ccadbdbf6593a40902 Mon Sep 17 00:00:00 2001 From: Yehor Kharchenko Date: Tue, 28 Oct 2025 10:38:33 +0100 Subject: [PATCH 8/8] adjust navigating to wide rhp in transactions list --- .../MoneyRequestReportTransactionList.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx index c4a8f0ea2901..be5267b4cf08 100644 --- a/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx +++ b/src/components/MoneyRequestReportView/MoneyRequestReportTransactionList.tsx @@ -10,6 +10,7 @@ import MenuItem from '@components/MenuItem'; import Modal from '@components/Modal'; import OfflineWithFeedback from '@components/OfflineWithFeedback'; import {usePersonalDetails} from '@components/OnyxListItemProvider'; +import openSearchReport from '@components/Search/openSearchReport'; import {useSearchContext} from '@components/Search/SearchContext'; import type {SearchColumnType, SortOrder} from '@components/Search/types'; import Text from '@components/Text'; @@ -49,7 +50,6 @@ import CONST from '@src/CONST'; import type {TranslationPaths} from '@src/languages/types'; import NAVIGATORS from '@src/NAVIGATORS'; import ONYXKEYS from '@src/ONYXKEYS'; -import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import type * as OnyxTypes from '@src/types/onyx'; import MoneyRequestReportTableHeader from './MoneyRequestReportTableHeader'; @@ -266,7 +266,7 @@ function MoneyRequestReportTransactionList({ if (reportIDToNavigate) { markReportIDAsExpense(reportIDToNavigate); } - Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute(routeParams)); + openSearchReport(routeParams.reportID, backTo); }); }, [report, reportActions, sortedTransactions, markReportIDAsExpense],