Skip to content

Commit 4707963

Browse files
committed
Simplify the check
1 parent 0380b8b commit 4707963

2 files changed

Lines changed: 5 additions & 21 deletions

File tree

src/components/FlashList/useFlashListScrollKey.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import type {FlashListProps} from '@shopify/flash-list';
22
import {useEffect, useState} from 'react';
33

4-
// How long to keep MVCP enabled after `shouldMaintainVisibleContentPosition` drops back to false
5-
const MVCP_FALLOFF_MS = 500;
6-
74
type FlashListScrollKeyProps<T> = {
85
/** The array of items to render in the list. */
96
data: T[];
@@ -39,20 +36,7 @@ export default function useFlashListScrollKey<T>({data, keyExtractor, initialScr
3936
});
4037
}, [isInitialRender, initialScrollKey]);
4138

42-
// FlashList captures MVCP anchors on the render BEFORE a data change. Keep MVCP on at mount
43-
// (warmup) and while the caller raises the prop, then disable after a short falloff.
44-
const [isKeepingMVCPOn, setIsKeepingMVCPOn] = useState(true);
45-
useEffect(() => {
46-
if (shouldMaintainVisibleContentPosition) {
47-
setIsKeepingMVCPOn(true);
48-
return;
49-
}
50-
const timeoutID = setTimeout(() => setIsKeepingMVCPOn(false), MVCP_FALLOFF_MS);
51-
return () => clearTimeout(timeoutID);
52-
}, [shouldMaintainVisibleContentPosition]);
53-
54-
const shouldEnableMVCP = !!shouldMaintainVisibleContentPosition || isKeepingMVCPOn || !hasLinkingSettled;
55-
const maintainVisibleContentPosition: FlashListProps<T>['maintainVisibleContentPosition'] = {disabled: !shouldEnableMVCP};
39+
const maintainVisibleContentPosition: FlashListProps<T>['maintainVisibleContentPosition'] = {disabled: !shouldMaintainVisibleContentPosition && hasLinkingSettled};
5640

5741
if (!isInitialRender || !initialScrollKey) {
5842
return {displayedData: data, onStartReached, maintainVisibleContentPosition};

src/pages/inbox/report/ReportActionsList.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,7 @@ function ReportActionsList({
233233
const hasHeaderRendered = useRef(false);
234234

235235
const lastAction = sortedVisibleReportActions.at(0);
236-
const isLastActionFromCurrentUser = (isReportPreviewAction(lastAction) ? lastAction?.childLastActorAccountID : lastAction?.actorAccountID) === currentUserAccountID;
237-
const prevLastActionID = usePrevious(lastAction?.reportActionID);
238-
const shouldMaintainVisibleContentPosition = prevLastActionID !== undefined && prevLastActionID !== lastAction?.reportActionID && !isLastActionFromCurrentUser;
236+
const [shouldMaintainVisibleContentPosition, setShouldMaintainVisibleContentPosition] = useState(() => scrollOffsetRef.current > CONST.REPORT.ACTIONS.ACTION_VISIBLE_THRESHOLD);
239237
const sortedVisibleReportActionsObjects: OnyxTypes.ReportActions = useMemo(
240238
() =>
241239
sortedVisibleReportActions.reduce((actions, action) => {
@@ -366,7 +364,9 @@ function ReportActionsList({
366364
unreadMarkerReportActionIndex,
367365
isInverted: true,
368366
onTrackScrolling: (event: NativeSyntheticEvent<NativeScrollEvent>) => {
369-
scrollOffsetRef.current = event.nativeEvent.contentOffset.y;
367+
const offset = event.nativeEvent.contentOffset.y;
368+
scrollOffsetRef.current = offset;
369+
setShouldMaintainVisibleContentPosition(offset > CONST.REPORT.ACTIONS.ACTION_VISIBLE_THRESHOLD);
370370
onScroll?.(event);
371371
// We use a timeout to wait for the scroll to finish before resetting the flag.
372372
// onMomentumScrollEnd would be ideal but it doesn't work on web.

0 commit comments

Comments
 (0)