11import { useFocusEffect } from '@react-navigation/native' ;
22import isEmpty from 'lodash/isEmpty' ;
3- import React , { memo , useCallback , useMemo , useState } from 'react' ;
3+ import React , { memo , useCallback , useEffect , useMemo , useState } from 'react' ;
44import { View } from 'react-native' ;
55import Animated , { FadeIn , FadeOut } from 'react-native-reanimated' ;
66import type { TupleToUnion } from 'type-fest' ;
@@ -26,6 +26,7 @@ import ControlSelection from '@libs/ControlSelection';
2626import { convertToDisplayString } from '@libs/CurrencyUtils' ;
2727import { canUseTouchScreen } from '@libs/DeviceCapabilities' ;
2828import { getThreadReportIDsForTransactions } from '@libs/MoneyRequestReportUtils' ;
29+ import { isFullScreenName } from '@libs/Navigation/helpers/isNavigatorName' ;
2930import { navigationRef } from '@libs/Navigation/Navigation' ;
3031import { getIOUActionForTransactionID } from '@libs/ReportActionsUtils' ;
3132import { generateReportID , getMoneyRequestSpendBreakdown , isIOUReport } from '@libs/ReportUtils' ;
@@ -39,7 +40,7 @@ import CONST from '@src/CONST';
3940import NAVIGATORS from '@src/NAVIGATORS' ;
4041import type { Route } from '@src/ROUTES' ;
4142import ROUTES from '@src/ROUTES' ;
42- import type SCREENS from '@src/SCREENS' ;
43+ import SCREENS from '@src/SCREENS' ;
4344import type * as OnyxTypes from '@src/types/onyx' ;
4445import MoneyRequestReportTableHeader from './MoneyRequestReportTableHeader' ;
4546import SearchMoneyRequestReportEmptyState from './SearchMoneyRequestReportEmptyState' ;
@@ -219,6 +220,34 @@ function MoneyRequestReportTransactionList({
219220 [ reportActions , sortedTransactions ] ,
220221 ) ;
221222
223+ useEffect ( ( ) => {
224+ const lastFullScreenRoute = navigationRef . getRootState ( ) ?. routes . findLast ( ( route ) => isFullScreenName ( route . name ) ) ;
225+
226+ // Only setActiveTransactionThreadIDs if current full screen report route is this report
227+ if ( lastFullScreenRoute ?. name !== NAVIGATORS . REPORTS_SPLIT_NAVIGATOR && lastFullScreenRoute ?. name !== NAVIGATORS . SEARCH_FULLSCREEN_NAVIGATOR ) {
228+ return ;
229+ }
230+
231+ // Check params contain reportID
232+ const lastRoute = lastFullScreenRoute ?. state ?. routes ?. at ( - 1 ) ;
233+ if ( ! lastRoute ?. params || ! ( 'reportID' in lastRoute . params ) ) {
234+ return ;
235+ }
236+
237+ // Check lastRoute is a report screen
238+ if ( lastRoute ?. name !== SCREENS . SEARCH . MONEY_REQUEST_REPORT && lastRoute ?. name !== SCREENS . REPORT ) {
239+ return ;
240+ }
241+
242+ // Check lastRoute params has reportID equal with this reportID
243+ if ( lastRoute . params . reportID !== report . reportID ) {
244+ return ;
245+ }
246+
247+ const sortedSiblingTransactionReportIDs = getThreadReportIDsForTransactions ( reportActions , transactions ) ;
248+ setActiveTransactionThreadIDs ( sortedSiblingTransactionReportIDs ) ;
249+ } , [ report . reportID , reportActions , transactions ] ) ;
250+
222251 const dateColumnSize = useMemo ( ( ) => {
223252 const shouldShowYearForSomeTransaction = transactions . some ( ( transaction ) => shouldShowTransactionYear ( transaction ) ) ;
224253 return shouldShowYearForSomeTransaction ? CONST . SEARCH . TABLE_COLUMN_SIZES . WIDE : CONST . SEARCH . TABLE_COLUMN_SIZES . NORMAL ;
0 commit comments