Skip to content

Commit

Permalink
Merge pull request #39685 from nkdengineer/fix/39198
Browse files Browse the repository at this point in the history
fix: expense chat doesn't scroll to bottom when we create a distance request
  • Loading branch information
aldo-expensify authored Apr 12, 2024
2 parents 45627ca + e615d8e commit e8c57de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,7 @@ function createDistanceRequest(
moneyRequestReportID,
);

const activeReportID = isMoneyRequestReport ? report?.reportID ?? '' : chatReport.reportID;
const parameters: CreateDistanceRequestParams = {
comment,
iouReportID: iouReport.reportID,
Expand All @@ -1583,8 +1584,8 @@ function createDistanceRequest(
};

API.write(WRITE_COMMANDS.CREATE_DISTANCE_REQUEST, parameters, onyxData);
Navigation.dismissModal(isMoneyRequestReport ? report?.reportID : chatReport.reportID);
Report.notifyNewAction(chatReport.reportID, userAccountID);
Navigation.dismissModal(activeReportID);
Report.notifyNewAction(activeReportID, userAccountID);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ function ReportActionsList({
const lastActionIndex = sortedVisibleReportActions[0]?.reportActionID;
const reportActionSize = useRef(sortedVisibleReportActions.length);
const hasNewestReportAction = sortedReportActions?.[0].created === report.lastVisibleActionCreated;

const hasNewestReportActionRef = useRef(hasNewestReportAction);
hasNewestReportActionRef.current = hasNewestReportAction;
const previousLastIndex = useRef(lastActionIndex);

const isLastPendingActionIsDelete = sortedReportActions?.[0]?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
Expand Down Expand Up @@ -322,14 +323,13 @@ function ReportActionsList({
(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 || !hasNewestReportAction) {
if (!isFromCurrentUser || !hasNewestReportActionRef.current) {
return;
}
InteractionManager.runAfterInteractions(() => reportScrollManager.scrollToBottom());
},
[hasNewestReportAction, reportScrollManager],
[reportScrollManager],
);

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 e8c57de

Please sign in to comment.