From 0a211a21d998dbfef30a38cbf02048a7e41dd42c Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Mon, 27 Jan 2025 11:27:24 -0500 Subject: [PATCH] Merge pull request #55790 from Expensify/amy-revert-auto-scroll [CP Staging] Revert PR #54071 (cherry picked from commit f8cdd0dc94ac8e6b52ecc76533a257fe41dc1cc9) (CP triggered by mountiny) --- src/pages/home/report/ReportActionsList.tsx | 49 +++++---------------- 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index 328628f7a9d3..fd67f2e1bdfe 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -190,7 +190,6 @@ function ReportActionsList({ const lastMessageTime = useRef(null); const [isVisible, setIsVisible] = useState(Visibility.isVisible); const isFocused = useIsFocused(); - const [pendingBottomScroll, setPendingBottomScroll] = useState(false); const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID}`); const [accountID] = useOnyx(ONYXKEYS.SESSION, {selector: (session) => session?.accountID}); @@ -456,48 +455,24 @@ function ReportActionsList({ // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps }, []); - const isNewMessageDisplayed = useMemo(() => { - const prevActions = Object.values(prevSortedVisibleReportActionsObjects); - const lastPrevVisibleAction = prevActions.at(0); - return lastAction?.reportActionID !== lastPrevVisibleAction?.reportActionID; - }, [prevSortedVisibleReportActionsObjects, lastAction]); - const scrollToBottomForCurrentUserAction = useCallback( (isFromCurrentUser: boolean) => { - // If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where - // they are now in the list. - if (!isFromCurrentUser || scrollingVerticalOffset.current === 0 || !isReportScreenTopmostCentralPane()) { - return; - } - if (!hasNewestReportActionRef.current) { - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID)); - return; - } - if (!isNewMessageDisplayed) { - setPendingBottomScroll(true); - } else { - InteractionManager.runAfterInteractions(() => { - reportScrollManager.scrollToBottom(); - }); - } - }, - [reportScrollManager, report.reportID, isNewMessageDisplayed], - ); - - useEffect(() => { - if (!pendingBottomScroll || scrollingVerticalOffset.current === 0) { - return; - } - - if (isNewMessageDisplayed) { InteractionManager.runAfterInteractions(() => { setIsFloatingMessageCounterVisible(false); + // If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where + // they are now in the list. + if (!isFromCurrentUser || !isReportScreenTopmostCentralPane()) { + return; + } + if (!hasNewestReportActionRef.current) { + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.reportID)); + return; + } reportScrollManager.scrollToBottom(); - setPendingBottomScroll(false); }); - } - }, [pendingBottomScroll, reportScrollManager, isNewMessageDisplayed]); - + }, + [reportScrollManager, report.reportID], + ); useEffect(() => { // Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function? // Answer: On web, when navigating to another report screen, the previous report screen doesn't get unmounted,