Skip to content

Commit 412e07b

Browse files
luacmartinsOSBotify
authored andcommitted
Merge pull request #40286 from ikevin127/fix/38855
[CP Staging] Chat is not scrolled to the new message on a newly created WS chat after whisper message (cherry picked from commit 39841b8)
1 parent b52da48 commit 412e07b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/hooks/useReportScrollManager/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ function useReportScrollManager(): ReportScrollManagerData {
2121
* Scroll to the bottom of the flatlist.
2222
*/
2323
const scrollToBottom = useCallback(() => {
24-
if (!flatListRef?.current) {
25-
return;
26-
}
24+
// We're deferring execution here because on iOS: mWeb (WebKit based browsers)
25+
// scrollToOffset method doesn't work unless called on the next tick
26+
requestAnimationFrame(() => {
27+
if (!flatListRef?.current) {
28+
return;
29+
}
2730

28-
flatListRef.current.scrollToOffset({animated: false, offset: 0});
31+
flatListRef.current.scrollToOffset({animated: false, offset: 0});
32+
});
2933
}, [flatListRef]);
3034

3135
return {ref: flatListRef, scrollToIndex, scrollToBottom};

src/pages/home/report/ReportActionsList.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,16 @@ function ReportActionsList({
325325

326326
const scrollToBottomForCurrentUserAction = useCallback(
327327
(isFromCurrentUser: boolean) => {
328-
// If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where
329-
// they are now in the list.
330-
if (!isFromCurrentUser || !hasNewestReportActionRef.current) {
328+
// If a new comment is added and it's from the current user scroll to the bottom
329+
// otherwise leave the user positioned where they are now in the list.
330+
// Additionally, since the first report action could be a whisper message (new WS) ->
331+
// hasNewestReportAction will be false, check isWhisperAction is false before returning early.
332+
if (!isFromCurrentUser || (!hasNewestReportActionRef.current && !ReportActionsUtils.isWhisperAction(sortedReportActions?.[0]))) {
331333
return;
332334
}
333335
InteractionManager.runAfterInteractions(() => reportScrollManager.scrollToBottom());
334336
},
335-
[reportScrollManager],
337+
[sortedReportActions, reportScrollManager],
336338
);
337339
useEffect(() => {
338340
// Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function?

0 commit comments

Comments
 (0)