Skip to content

Commit

Permalink
Merge pull request #55790 from Expensify/amy-revert-auto-scroll
Browse files Browse the repository at this point in the history
[CP Staging] Revert PR #54071

(cherry picked from commit f8cdd0d)

(CP triggered by mountiny)
  • Loading branch information
amyevans authored and OSBotify committed Jan 27, 2025
1 parent 274efc4 commit 0a211a2
Showing 1 changed file with 12 additions and 37 deletions.
49 changes: 12 additions & 37 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ function ReportActionsList({
const lastMessageTime = useRef<string | null>(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});
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0a211a2

Please sign in to comment.