diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 059b54485dae..82519bbec7b2 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -53,7 +53,6 @@ import { isExpenseReport, isInvoiceReport, isIOUReport, - isMoneyRequestReport, isTaskReport, isUnread, } from '@libs/ReportUtils'; @@ -184,14 +183,9 @@ function ReportActionsList({ const [tryNewDot] = useOnyx(ONYXKEYS.NVP_TRY_NEW_DOT, {canBeMissing: false}); const isTryNewDotNVPDismissed = !!tryNewDot?.classicRedirect?.dismissed; const [isScrollToBottomEnabled, setIsScrollToBottomEnabled] = useState(false); + const [shouldScrollToEndAfterLayout, setShouldScrollToEndAfterLayout] = useState(false); const [actionIdToHighlight, setActionIdToHighlight] = useState(''); - const isTransactionThreadReport = useMemo(() => isTransactionThread(parentReportAction), [parentReportAction]); - const isMoneyRequestOrInvoiceReport = useMemo(() => isMoneyRequestReport(report) || isInvoiceReport(report), [report]); - const shouldFocusToTopOnMount = useMemo(() => isTransactionThreadReport || isMoneyRequestOrInvoiceReport, [isMoneyRequestOrInvoiceReport, isTransactionThreadReport]); - const topReportAction = sortedVisibleReportActions.at(-1); - const [shouldScrollToEndAfterLayout, setShouldScrollToEndAfterLayout] = useState(shouldFocusToTopOnMount); - useEffect(() => { const unsubscribe = Visibility.onVisibilityChange(() => { setIsVisible(Visibility.isVisible()); @@ -348,9 +342,6 @@ function ReportActionsList({ onTrackScrolling: (event: NativeSyntheticEvent) => { scrollingVerticalOffset.current = event.nativeEvent.contentOffset.y; onScroll?.(event); - if (shouldScrollToEndAfterLayout) { - setShouldScrollToEndAfterLayout(false); - } }, }); @@ -400,10 +391,17 @@ function ReportActionsList({ return; } + const shouldScrollToEnd = + (isExpenseReport(report) || isTransactionThread(parentReportAction)) && isSearchTopmostFullScreenRoute() && hasNewestReportAction && !unreadMarkerReportActionID; + + if (shouldScrollToEnd) { + setShouldScrollToEndAfterLayout(true); + } + InteractionManager.runAfterInteractions(() => { setIsFloatingMessageCounterVisible(false); - if (!shouldScrollToEndAfterLayout) { + if (!shouldScrollToEnd) { reportScrollManager.scrollToBottom(); } }); @@ -721,9 +719,8 @@ function ReportActionsList({ setIsScrollToBottomEnabled(false); } if (shouldScrollToEndAfterLayout) { - InteractionManager.runAfterInteractions(() => { - reportScrollManager.scrollToEnd(); - }); + reportScrollManager.scrollToEnd(); + setShouldScrollToEndAfterLayout(false); } }, [isScrollToBottomEnabled, onLayout, reportScrollManager, shouldScrollToEndAfterLayout], @@ -759,13 +756,6 @@ function ReportActionsList({ return ; }, [shouldShowSkeleton]); - const renderTopReportAction = () => ( - <> - {!shouldShowReportRecipientLocalTime && !hideComposer ? : undefined} - {renderItem({item: topReportAction, index: sortedVisibleReportActions.length - 1} as ListRenderItemInfo)} - - ); - const onStartReached = useCallback(() => { if (!isSearchTopmostFullScreenRoute()) { loadNewerChats(false); @@ -790,7 +780,6 @@ function ReportActionsList({ style={[styles.flex1, !shouldShowReportRecipientLocalTime && !hideComposer ? styles.pb4 : {}]} fsClass={reportActionsListFSClass} > - {shouldScrollToEndAfterLayout && topReportAction ? renderTopReportAction() : undefined} zIndex: 10, }, - height4: { - height: 16, - }, - searchListContentContainerStyles: { paddingTop: variables.searchListContentMarginTop, },