@@ -16,6 +16,7 @@ import {useSearchContext} from '@components/Search/SearchContext';
1616import type { SearchCustomColumnIds , SortOrder } from '@components/Search/types' ;
1717import SelectionList from '@components/SelectionList' ;
1818import SingleSelectListItem from '@components/SelectionList/ListItem/SingleSelectListItem' ;
19+ import ScrollView from '@components/ScrollView' ;
1920import Text from '@components/Text' ;
2021import { useWideRHPActions } from '@components/WideRHPContextProvider' ;
2122import useCopySelectionHelper from '@hooks/useCopySelectionHelper' ;
@@ -32,6 +33,7 @@ import useResponsiveLayoutOnWideRHP from '@hooks/useResponsiveLayoutOnWideRHP';
3233import useStyleUtils from '@hooks/useStyleUtils' ;
3334import useTheme from '@hooks/useTheme' ;
3435import useThemeStyles from '@hooks/useThemeStyles' ;
36+ import useWindowDimensions from '@hooks/useWindowDimensions' ;
3537import { turnOnMobileSelectionMode } from '@libs/actions/MobileSelectionMode' ;
3638import { setOptimisticTransactionThread } from '@libs/actions/Report' ;
3739import { getReportLayoutGroupBy , setReportLayoutGroupBy } from '@libs/actions/ReportLayout' ;
@@ -68,8 +70,6 @@ import {
6870} from '@libs/TransactionUtils' ;
6971import shouldShowTransactionYear from '@libs/TransactionUtils/shouldShowTransactionYear' ;
7072import Navigation from '@navigation/Navigation' ;
71- import ScrollView from '@components/ScrollView' ;
72- import useWindowDimensions from '@hooks/useWindowDimensions' ;
7373import type { ReportsSplitNavigatorParamList } from '@navigation/types' ;
7474import variables from '@styles/variables' ;
7575import { createTransactionThreadReport } from '@userActions/Report' ;
@@ -315,19 +315,19 @@ function MoneyRequestReportTransactionList({
315315 const minTableWidth = getTableMinWidth ( columnsToShow ) ;
316316 const shouldScrollHorizontally = ! shouldUseNarrowLayout && minTableWidth > windowWidth ;
317317 const horizontalScrollViewRef = useRef < RNScrollView > ( null ) ;
318- const [ horizontalScrollOffset , setHorizontalScrollOffset ] = useState ( 0 ) ;
318+ const horizontalScrollOffsetRef = useRef ( 0 ) ;
319319
320320 const handleHorizontalScroll = useCallback ( ( event : NativeSyntheticEvent < NativeScrollEvent > ) => {
321- setHorizontalScrollOffset ( event . nativeEvent . contentOffset . x ) ;
321+ horizontalScrollOffsetRef . current = event . nativeEvent . contentOffset . x ;
322322 } , [ ] ) ;
323323
324- // Restore horizontal scroll position synchronously before paint
324+ // Restore horizontal scroll position synchronously before paint when transactions change
325325 useLayoutEffect ( ( ) => {
326- if ( ! shouldScrollHorizontally || horizontalScrollOffset <= 0 ) {
326+ if ( ! shouldScrollHorizontally || horizontalScrollOffsetRef . current <= 0 ) {
327327 return ;
328328 }
329- horizontalScrollViewRef . current ?. scrollTo ( { x : horizontalScrollOffset , animated : false } ) ;
330- } , [ sortedTransactions , shouldScrollHorizontally , horizontalScrollOffset ] ) ;
329+ horizontalScrollViewRef . current ?. scrollTo ( { x : horizontalScrollOffsetRef . current , animated : false } ) ;
330+ } , [ sortedTransactions , shouldScrollHorizontally ] ) ;
331331
332332 const currentGroupBy = getReportLayoutGroupBy ( reportLayoutGroupBy ) ;
333333
@@ -639,7 +639,6 @@ function MoneyRequestReportTransactionList({
639639 showsHorizontalScrollIndicator
640640 style = { styles . flex1 }
641641 contentContainerStyle = { { width : minTableWidth } }
642- contentOffset = { { x : horizontalScrollOffset , y : 0 } }
643642 onScroll = { handleHorizontalScroll }
644643 scrollEventThrottle = { 16 }
645644 >
0 commit comments