Skip to content

Commit

Permalink
Merge pull request #40286 from ikevin127/fix/38855
Browse files Browse the repository at this point in the history
[CP Staging] Chat is not scrolled to the new message on a newly created WS chat after whisper message

(cherry picked from commit 39841b8)
  • Loading branch information
luacmartins authored and OSBotify committed Apr 23, 2024
1 parent b52da48 commit 412e07b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/hooks/useReportScrollManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ function useReportScrollManager(): ReportScrollManagerData {
* Scroll to the bottom of the flatlist.
*/
const scrollToBottom = useCallback(() => {
if (!flatListRef?.current) {
return;
}
// We're deferring execution here because on iOS: mWeb (WebKit based browsers)
// scrollToOffset method doesn't work unless called on the next tick
requestAnimationFrame(() => {
if (!flatListRef?.current) {
return;
}

flatListRef.current.scrollToOffset({animated: false, offset: 0});
flatListRef.current.scrollToOffset({animated: false, offset: 0});
});
}, [flatListRef]);

return {ref: flatListRef, scrollToIndex, scrollToBottom};
Expand Down
10 changes: 6 additions & 4 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,16 @@ function ReportActionsList({

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 || !hasNewestReportActionRef.current) {
// 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.
// Additionally, since the first report action could be a whisper message (new WS) ->
// hasNewestReportAction will be false, check isWhisperAction is false before returning early.
if (!isFromCurrentUser || (!hasNewestReportActionRef.current && !ReportActionsUtils.isWhisperAction(sortedReportActions?.[0]))) {
return;
}
InteractionManager.runAfterInteractions(() => reportScrollManager.scrollToBottom());
},
[reportScrollManager],
[sortedReportActions, reportScrollManager],
);
useEffect(() => {
// Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function?
Expand Down

0 comments on commit 412e07b

Please sign in to comment.