File tree Expand file tree Collapse file tree 2 files changed +14
-8
lines changed
hooks/useReportScrollManager Expand file tree Collapse file tree 2 files changed +14
-8
lines changed Original file line number Diff line number Diff 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} ;
Original file line number Diff line number Diff 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?
You can’t perform that action at this time.
0 commit comments