Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] Revert PR #54071 #55790

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading