|
1 | 1 | import type {FlashListProps} from '@shopify/flash-list'; |
2 | 2 | import {useEffect, useState} from 'react'; |
3 | 3 |
|
4 | | -// How long to keep MVCP enabled after `shouldMaintainVisibleContentPosition` drops back to false |
5 | | -const MVCP_FALLOFF_MS = 500; |
6 | | - |
7 | 4 | type FlashListScrollKeyProps<T> = { |
8 | 5 | /** The array of items to render in the list. */ |
9 | 6 | data: T[]; |
@@ -39,20 +36,7 @@ export default function useFlashListScrollKey<T>({data, keyExtractor, initialScr |
39 | 36 | }); |
40 | 37 | }, [isInitialRender, initialScrollKey]); |
41 | 38 |
|
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}; |
56 | 40 |
|
57 | 41 | if (!isInitialRender || !initialScrollKey) { |
58 | 42 | return {displayedData: data, onStartReached, maintainVisibleContentPosition}; |
|
0 commit comments