Skip to content

Commit 41602b2

Browse files
committed
Fix auto scroll issue
1 parent ea3b1af commit 41602b2

2 files changed

Lines changed: 23 additions & 3 deletions

File tree

src/pages/inbox/ConciergeDraftContext.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,14 @@ function ConciergeDraftGate({reportID, children}: React.PropsWithChildren<{repor
7777
channelName,
7878
eventType,
7979
(eventData) => {
80-
setDraft((currentDraft) => applyConciergeDraftEvent(currentDraft, eventData as ConciergeDraftEvent, reportID));
80+
const conciergeDraftEvent = eventData as ConciergeDraftEvent;
81+
setDraft((currentDraft) => applyConciergeDraftEvent(currentDraft, conciergeDraftEvent, reportID));
8182
},
8283
handleResubscribe,
8384
);
8485

8586
listener.catch((error: unknown) => {
86-
Log.hmmm('[ConciergeDraftGate] Failed to subscribe to Pusher concierge draft events', {eventType, reportID, error});
87+
Log.hmmm('Failed to subscribe to Pusher concierge draft events', {eventType, reportID, error});
8788
});
8889

8990
return listener;

src/pages/inbox/report/ReportActionsList.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {OnyxEntry} from 'react-native-onyx';
99
import {renderScrollComponent as renderActionSheetAwareScrollView} from '@components/ActionSheetAwareScrollView';
1010
import Button from '@components/Button';
1111
import InvertedFlatList from '@components/FlatList/InvertedFlatList';
12+
import {AUTOSCROLL_TO_TOP_THRESHOLD} from '@components/FlatList/hooks/useFlatListScrollKey';
1213
import {usePersonalDetails} from '@components/OnyxListItemProvider';
1314
import ReportActionsSkeletonView from '@components/ReportActionsSkeletonView';
1415
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
@@ -236,6 +237,10 @@ function ReportActionsList({
236237

237238
return getSortedReportActions([...sortedVisibleReportActions, draftReportAction], true);
238239
}, [draftReportAction, sortedVisibleReportActions]);
240+
const draftMessageHTML = draftReportAction ? getReportActionMessage(draftReportAction)?.html : undefined;
241+
const isSyntheticDraftVisible = !!draftReportAction && !sortedVisibleReportActions.some((action) => action.reportActionID === draftReportAction.reportActionID);
242+
const draftAutoScrollKey = isSyntheticDraftVisible ? `${draftReportAction.reportActionID}:${draftMessageHTML ?? ''}` : '';
243+
const previousDraftAutoScrollKey = usePrevious(draftAutoScrollKey);
239244
const topReportAction = renderedVisibleReportActions.at(-1);
240245
const [shouldScrollToEndAfterLayout, setShouldScrollToEndAfterLayout] = useState(shouldFocusToTopOnMount && !reportActionID);
241246
const isAnonymousUser = useIsAnonymousUser();
@@ -400,6 +405,21 @@ function ReportActionsList({
400405
resetKey: linkedReportActionID,
401406
});
402407

408+
useEffect(() => {
409+
if (!draftAutoScrollKey || previousDraftAutoScrollKey === draftAutoScrollKey) {
410+
return;
411+
}
412+
413+
if (scrollOffsetRef.current >= AUTOSCROLL_TO_TOP_THRESHOLD || !hasNewestReportActionRef.current) {
414+
return;
415+
}
416+
417+
setIsFloatingMessageCounterVisible(false);
418+
requestAnimationFrame(() => {
419+
reportScrollManager.scrollToBottom();
420+
});
421+
}, [draftAutoScrollKey, previousDraftAutoScrollKey, reportScrollManager, setIsFloatingMessageCounterVisible]);
422+
403423
useEffect(() => {
404424
const shouldTriggerScroll = shouldFocusToTopOnMount && prevHasCreatedActionAdded && !hasCreatedActionAdded;
405425
if (!shouldTriggerScroll) {
@@ -789,7 +809,6 @@ function ReportActionsList({
789809

790810
// Native mobile does not render updates flatlist the changes even though component did update called.
791811
// To notify there something changes we can use extraData prop to flatlist
792-
const draftMessageHTML = draftReportAction ? getReportActionMessage(draftReportAction)?.html : undefined;
793812
const extraData = useMemo(
794813
() => [shouldUseNarrowLayout ? unreadMarkerReportActionID : undefined, isArchivedNonExpenseReport(report, isReportArchived), draftReportAction?.reportActionID, draftMessageHTML],
795814
[draftMessageHTML, draftReportAction?.reportActionID, unreadMarkerReportActionID, shouldUseNarrowLayout, report, isReportArchived],

0 commit comments

Comments
 (0)