Skip to content

Commit dbcc38b

Browse files
committed
avoid scrollToBottom while linking
1 parent c2fc773 commit dbcc38b

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

src/pages/home/ReportScreen.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,7 @@ function ReportScreen({
268268
const shouldShowSkeleton =
269269
isPrepareLinkingToMessage || !isReportReadyForDisplay || isLoadingInitialReportActions || isLoading || (!!reportActionIDFromRoute && reportMetadata.isLoadingInitialReportActions);
270270

271-
const shouldShowReportActionList = useMemo(
272-
() => isReportReadyForDisplay && !isLoadingInitialReportActions && !isLoading,
273-
[isReportReadyForDisplay, isLoading, isLoadingInitialReportActions],
274-
);
271+
const shouldShowReportActionList = isReportReadyForDisplay && !isLoading;
275272

276273
const fetchReport = useCallback(() => {
277274
Report.openReport(reportIDFromRoute, reportActionIDFromRoute);

src/pages/home/report/ReportActionsList.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ function ReportActionsList({
142142
listID,
143143
onContentSizeChange,
144144
reportScrollManager,
145+
enableAutoscrollToTopThreshold,
145146
}) {
146147
const styles = useThemeStyles();
147148
const {translate} = useLocalize();
@@ -189,12 +190,12 @@ function ReportActionsList({
189190
}, [opacity]);
190191

191192
useEffect(() => {
192-
if (previousLastIndex.current !== lastActionIndex && reportActionSize.current > sortedVisibleReportActions.length) {
193+
if (previousLastIndex.current !== lastActionIndex && reportActionSize.current > sortedVisibleReportActions.length && hasNewestReportAction) {
193194
reportScrollManager.scrollToBottom();
194195
}
195196
previousLastIndex.current = lastActionIndex;
196197
reportActionSize.current = sortedVisibleReportActions.length;
197-
}, [lastActionIndex, sortedVisibleReportActions.length, reportScrollManager]);
198+
}, [lastActionIndex, sortedVisibleReportActions.length, reportScrollManager, hasNewestReportAction]);
198199

199200
useEffect(() => {
200201
// If the reportID changes, we reset the userActiveSince to null, we need to do it because
@@ -277,6 +278,18 @@ function ReportActionsList({
277278
// eslint-disable-next-line react-hooks/exhaustive-deps
278279
}, []);
279280

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+
280293
useEffect(() => {
281294
// Why are we doing this, when in the cleanup of the useEffect we are already calling the unsubscribe function?
282295
// Answer: On web, when navigating to another report screen, the previous report screen doesn't get unmounted,
@@ -292,14 +305,7 @@ function ReportActionsList({
292305

293306
// This callback is triggered when a new action arrives via Pusher and the event is emitted from Report.js. This allows us to maintain
294307
// 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);
303309

304310
const cleanup = () => {
305311
if (unsubscribe) {
@@ -529,6 +535,7 @@ function ReportActionsList({
529535
onScrollToIndexFailed={() => {}}
530536
extraData={extraData}
531537
key={listID}
538+
enableAutoscrollToTopThreshold={enableAutoscrollToTopThreshold}
532539
/>
533540
</Animated.View>
534541
</>

src/pages/home/report/ReportActionsView.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ function ReportActionsView({reportActions: allReportActions, ...props}) {
404404
listID={listID}
405405
onContentSizeChange={onContentSizeChange}
406406
reportScrollManager={reportScrollManager}
407+
enableAutoscrollToTopThreshold={hasNewestReportAction}
407408
/>
408409
<PopoverReactionList ref={reactionListRef} />
409410
</>

0 commit comments

Comments
 (0)