@shopify/flash-list 2.0.0-rc.3 → 2.0.0-rc.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/recyclerview/RecyclerView.d.ts.map +1 -1
  6. package/dist/recyclerview/RecyclerView.js +20 -5
  7. package/dist/recyclerview/RecyclerView.js.map +1 -1
  8. package/dist/recyclerview/RecyclerViewContextProvider.d.ts +37 -3
  9. package/dist/recyclerview/RecyclerViewContextProvider.d.ts.map +1 -1
  10. package/dist/recyclerview/RecyclerViewContextProvider.js +4 -0
  11. package/dist/recyclerview/RecyclerViewContextProvider.js.map +1 -1
  12. package/dist/recyclerview/RecyclerViewManager.d.ts +3 -1
  13. package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -1
  14. package/dist/recyclerview/RecyclerViewManager.js +12 -3
  15. package/dist/recyclerview/RecyclerViewManager.js.map +1 -1
  16. package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -1
  17. package/dist/recyclerview/hooks/useRecyclerViewController.js +19 -14
  18. package/dist/recyclerview/hooks/useRecyclerViewController.js.map +1 -1
  19. package/dist/recyclerview/hooks/useUnmountFlag.d.ts.map +1 -1
  20. package/dist/recyclerview/hooks/useUnmountFlag.js +1 -0
  21. package/dist/recyclerview/hooks/useUnmountFlag.js.map +1 -1
  22. package/dist/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +1 -1
  24. package/src/index.ts +1 -1
  25. package/src/recyclerview/RecyclerView.tsx +19 -6
  26. package/src/recyclerview/RecyclerViewContextProvider.ts +42 -3
  27. package/src/recyclerview/RecyclerViewManager.ts +10 -4
  28. package/src/recyclerview/hooks/useRecyclerViewController.tsx +16 -6
  29. package/src/recyclerview/hooks/useUnmountFlag.ts +1 -0
@@ -51,7 +51,7 @@ export function useRecyclerViewController<T>(
51
51
  const [_, setRenderId] = useState(0);
52
52
  const pauseOffsetCorrection = useRef(false);
53
53
  const initialScrollCompletedRef = useRef(false);
54
- const lastDataLengthRef = useRef(recyclerViewManager.props.data?.length ?? 0);
54
+ const lastDataLengthRef = useRef(recyclerViewManager.getDataLength());
55
55
  const { setTimeout } = useUnmountAwareTimeout();
56
56
 
57
57
  // Track the first visible item for maintaining scroll position
@@ -91,7 +91,12 @@ export function useRecyclerViewController<T>(
91
91
 
92
92
  const computeFirstVisibleIndexForOffsetCorrection = useCallback(() => {
93
93
  const { data, keyExtractor } = recyclerViewManager.props;
94
- if (data && keyExtractor) {
94
+ if (
95
+ recyclerViewManager.getIsFirstLayoutComplete() &&
96
+ keyExtractor &&
97
+ recyclerViewManager.getDataLength() > 0 &&
98
+ recyclerViewManager.shouldMaintainVisibleContentPosition()
99
+ ) {
95
100
  // Update the tracked first visible item
96
101
  const firstVisibleIndex = Math.max(
97
102
  0,
@@ -123,7 +128,7 @@ export function useRecyclerViewController<T>(
123
128
  pendingScrollCallbacks.current = [];
124
129
  callbacks.forEach((callback) => callback());
125
130
 
126
- const currentDataLength = data?.length ?? 0;
131
+ const currentDataLength = recyclerViewManager.getDataLength();
127
132
 
128
133
  if (
129
134
  recyclerViewManager.getIsFirstLayoutComplete() &&
@@ -162,7 +167,11 @@ export function useRecyclerViewController<T>(
162
167
  firstVisibleItemLayout.current = {
163
168
  ...recyclerViewManager.getLayout(currentIndexOfFirstVisibleItem),
164
169
  };
165
- if (diff !== 0 && !pauseOffsetCorrection.current) {
170
+ if (
171
+ diff !== 0 &&
172
+ !pauseOffsetCorrection.current &&
173
+ !recyclerViewManager.animationOptimizationsEnabled
174
+ ) {
166
175
  // console.log("diff", diff, firstVisibleItemKey.current);
167
176
  if (PlatformConfig.supportsOffsetCorrection) {
168
177
  // console.log("scrollBy", diff);
@@ -195,7 +204,7 @@ export function useRecyclerViewController<T>(
195
204
 
196
205
  computeFirstVisibleIndexForOffsetCorrection();
197
206
  }
198
- lastDataLengthRef.current = data?.length ?? 0;
207
+ lastDataLengthRef.current = recyclerViewManager.getDataLength();
199
208
  }, [
200
209
  recyclerViewManager,
201
210
  scrollAnchorRef,
@@ -381,6 +390,7 @@ export function useRecyclerViewController<T>(
381
390
  const performScrollStep = (currentStep: number) => {
382
391
  // Check if component is unmounted or we've completed all steps
383
392
  if (isUnmounted.current) {
393
+ resolve();
384
394
  return;
385
395
  } else if (currentStep >= steps) {
386
396
  // All steps completed, perform final scroll
@@ -537,7 +547,7 @@ export function useRecyclerViewController<T>(
537
547
  * Disables item recycling in preparation for layout animations.
538
548
  */
539
549
  prepareForLayoutAnimationRender: () => {
540
- recyclerViewManager.disableRecycling(true);
550
+ recyclerViewManager.animationOptimizationsEnabled = true;
541
551
  },
542
552
  };
543
553
  }, [
@@ -16,6 +16,7 @@ export const useUnmountFlag = () => {
16
16
  // Use layoutEffect to set up cleanup on unmount
17
17
  // This ensures the flag is set before any other cleanup effects run
18
18
  useLayoutEffect(() => {
19
+ isUnmounted.current = false;
19
20
  // Cleanup function that runs when the component unmounts
20
21
  return () => {
21
22
  isUnmounted.current = true;