@@ -142,6 +142,7 @@ function ReportActionsList({
142
142
listID,
143
143
onContentSizeChange,
144
144
reportScrollManager,
145
+ enableAutoscrollToTopThreshold,
145
146
} ) {
146
147
const styles = useThemeStyles ( ) ;
147
148
const { translate} = useLocalize ( ) ;
@@ -189,12 +190,12 @@ function ReportActionsList({
189
190
} , [ opacity ] ) ;
190
191
191
192
useEffect ( ( ) => {
192
- if ( previousLastIndex . current !== lastActionIndex && reportActionSize . current > sortedVisibleReportActions . length ) {
193
+ if ( previousLastIndex . current !== lastActionIndex && reportActionSize . current > sortedVisibleReportActions . length && hasNewestReportAction ) {
193
194
reportScrollManager . scrollToBottom ( ) ;
194
195
}
195
196
previousLastIndex . current = lastActionIndex ;
196
197
reportActionSize . current = sortedVisibleReportActions . length ;
197
- } , [ lastActionIndex , sortedVisibleReportActions . length , reportScrollManager ] ) ;
198
+ } , [ lastActionIndex , sortedVisibleReportActions . length , reportScrollManager , hasNewestReportAction ] ) ;
198
199
199
200
useEffect ( ( ) => {
200
201
// If the reportID changes, we reset the userActiveSince to null, we need to do it because
@@ -277,6 +278,18 @@ function ReportActionsList({
277
278
// eslint-disable-next-line react-hooks/exhaustive-deps
278
279
} , [ ] ) ;
279
280
281
+ const scrollToBottomForCurrentUserAction = useCallback (
282
+ ( isFromCurrentUser ) => {
283
+ // If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where
284
+ // they are now in the list.
285
+ if ( ! isFromCurrentUser || ! hasNewestReportAction ) {
286
+ return ;
287
+ }
288
+ InteractionManager . runAfterInteractions ( ( ) => reportScrollManager . scrollToBottom ( ) ) ;
289
+ } ,
290
+ [ hasNewestReportAction , reportScrollManager ] ,
291
+ ) ;
292
+
280
293
useEffect ( ( ) => {
281
294
// Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function?
282
295
// Answer: On web, when navigating to another report screen, the previous report screen doesn't get unmounted,
@@ -292,14 +305,7 @@ function ReportActionsList({
292
305
293
306
// This callback is triggered when a new action arrives via Pusher and the event is emitted from Report.js. This allows us to maintain
294
307
// a single source of truth for the "new action" event instead of trying to derive that a new action has appeared from looking at props.
295
- const unsubscribe = Report . subscribeToNewActionEvent ( report . reportID , ( isFromCurrentUser ) => {
296
- // If a new comment is added and it's from the current user scroll to the bottom otherwise leave the user positioned where
297
- // they are now in the list.
298
- if ( ! isFromCurrentUser ) {
299
- return ;
300
- }
301
- InteractionManager . runAfterInteractions ( ( ) => reportScrollManager . scrollToBottom ( ) ) ;
302
- } ) ;
308
+ const unsubscribe = Report . subscribeToNewActionEvent ( report . reportID , scrollToBottomForCurrentUserAction ) ;
303
309
304
310
const cleanup = ( ) => {
305
311
if ( unsubscribe ) {
@@ -529,6 +535,7 @@ function ReportActionsList({
529
535
onScrollToIndexFailed = { ( ) => { } }
530
536
extraData = { extraData }
531
537
key = { listID }
538
+ enableAutoscrollToTopThreshold = { enableAutoscrollToTopThreshold }
532
539
/>
533
540
</ Animated . View >
534
541
</ >
0 commit comments