Skip to content

Commit dabe385

Browse files
authored
Merge pull request Expensify#88536 from callstack-internal/VickyStash/bugfix/88238-fix-new-message-indication
2 parents 1d9eb57 + 9ed4d7b commit dabe385

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

src/components/FlashList/InvertedFlashList/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,18 @@ type InvertedFlashListProps<T> = FlashListProps<T> & {
1717

1818
/** Ref to the underlying list instance. */
1919
ref: FlatListRefType;
20+
21+
/** Whether the list should handle `maintainVisibleContentPosition` */
22+
shouldMaintainVisibleContentPosition?: boolean;
2023
};
2124

22-
function InvertedFlashList<T>({data, keyExtractor, initialScrollKey, onStartReached: onStartReachedProp, ...restProps}: InvertedFlashListProps<T>) {
25+
function InvertedFlashList<T>({data, keyExtractor, initialScrollKey, onStartReached: onStartReachedProp, shouldMaintainVisibleContentPosition, ...restProps}: InvertedFlashListProps<T>) {
2326
const {displayedData, onStartReached, maintainVisibleContentPosition} = useFlashListScrollKey<T>({
2427
data,
2528
keyExtractor,
2629
initialScrollKey,
2730
onStartReached: onStartReachedProp,
31+
shouldMaintainVisibleContentPosition,
2832
});
2933

3034
return (

src/components/FlashList/useFlashListScrollKey.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ type FlashListScrollKeyProps<T> = {
1313

1414
/** Callback invoked when the user scrolls close to the start of the list. */
1515
onStartReached: FlashListProps<T>['onStartReached'];
16+
17+
/** Whether the list should handle `maintainVisibleContentPosition` */
18+
shouldMaintainVisibleContentPosition?: boolean;
1619
};
1720

18-
export default function useFlashListScrollKey<T>({data, keyExtractor, initialScrollKey, onStartReached}: FlashListScrollKeyProps<T>) {
21+
export default function useFlashListScrollKey<T>({data, keyExtractor, initialScrollKey, onStartReached, shouldMaintainVisibleContentPosition}: FlashListScrollKeyProps<T>) {
1922
const [isInitialRender, setIsInitialRender] = useState(true);
2023
const [hasLinkingSettled, setHasLinkingSettled] = useState(!initialScrollKey);
2124

@@ -33,9 +36,7 @@ export default function useFlashListScrollKey<T>({data, keyExtractor, initialScr
3336
});
3437
}, [isInitialRender, initialScrollKey]);
3538

36-
// `undefined` = leave FlashList's default (MVCP enabled) while we're still pinning the linked item.
37-
// `{disabled: true}` once that's done so MVCP can't interfere afterward.
38-
const maintainVisibleContentPosition: FlashListProps<T>['maintainVisibleContentPosition'] = hasLinkingSettled ? {disabled: true} : undefined;
39+
const maintainVisibleContentPosition: FlashListProps<T>['maintainVisibleContentPosition'] = {disabled: !shouldMaintainVisibleContentPosition && hasLinkingSettled};
3940

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

src/pages/inbox/report/ReportActionsList.tsx

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

235235
const lastAction = sortedVisibleReportActions.at(0);
236+
const [shouldMaintainVisibleContentPosition, setShouldMaintainVisibleContentPosition] = useState(() => scrollOffsetRef.current > CONST.REPORT.ACTIONS.ACTION_VISIBLE_THRESHOLD);
236237
const sortedVisibleReportActionsObjects: OnyxTypes.ReportActions = useMemo(
237238
() =>
238239
sortedVisibleReportActions.reduce((actions, action) => {
@@ -363,7 +364,9 @@ function ReportActionsList({
363364
unreadMarkerReportActionIndex,
364365
isInverted: true,
365366
onTrackScrolling: (event: NativeSyntheticEvent<NativeScrollEvent>) => {
366-
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);
367370
onScroll?.(event);
368371
// We use a timeout to wait for the scroll to finish before resetting the flag.
369372
// onMomentumScrollEnd would be ideal but it doesn't work on web.
@@ -927,6 +930,7 @@ function ReportActionsList({
927930
extraData={extraData}
928931
key={listID}
929932
getItemType={(item) => item.actionName}
933+
shouldMaintainVisibleContentPosition={shouldMaintainVisibleContentPosition}
930934
initialScrollKey={linkedReportActionID}
931935
onContentSizeChange={() => {
932936
trackVerticalScrolling(undefined);

0 commit comments

Comments
 (0)