@shopify/flash-list 1.8.0 → 2.0.0-alpha.2

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 (170) hide show
  1. package/README.md +147 -26
  2. package/dist/FlashListProps.d.ts +65 -2
  3. package/dist/FlashListProps.d.ts.map +1 -1
  4. package/dist/__tests__/AverageWindow.test.js +35 -0
  5. package/dist/__tests__/AverageWindow.test.js.map +1 -1
  6. package/dist/enableNewCore.d.ts +3 -0
  7. package/dist/enableNewCore.d.ts.map +1 -0
  8. package/dist/enableNewCore.js +25 -0
  9. package/dist/enableNewCore.js.map +1 -0
  10. package/dist/index.d.ts +5 -0
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +28 -8
  13. package/dist/index.js.map +1 -1
  14. package/dist/recyclerview/RecycleKeyManager.d.ts +82 -0
  15. package/dist/recyclerview/RecycleKeyManager.d.ts.map +1 -0
  16. package/dist/recyclerview/RecycleKeyManager.js +135 -0
  17. package/dist/recyclerview/RecycleKeyManager.js.map +1 -0
  18. package/dist/recyclerview/RecyclerView.d.ts +12 -0
  19. package/dist/recyclerview/RecyclerView.d.ts.map +1 -0
  20. package/dist/recyclerview/RecyclerView.js +283 -0
  21. package/dist/recyclerview/RecyclerView.js.map +1 -0
  22. package/dist/recyclerview/RecyclerViewContextProvider.d.ts +12 -0
  23. package/dist/recyclerview/RecyclerViewContextProvider.d.ts.map +1 -0
  24. package/dist/recyclerview/RecyclerViewContextProvider.js +11 -0
  25. package/dist/recyclerview/RecyclerViewContextProvider.js.map +1 -0
  26. package/dist/recyclerview/RecyclerViewManager.d.ts +52 -0
  27. package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -0
  28. package/dist/recyclerview/RecyclerViewManager.js +323 -0
  29. package/dist/recyclerview/RecyclerViewManager.js.map +1 -0
  30. package/dist/recyclerview/RecyclerViewProps.d.ts +9 -0
  31. package/dist/recyclerview/RecyclerViewProps.d.ts.map +1 -0
  32. package/dist/recyclerview/RecyclerViewProps.js +3 -0
  33. package/dist/recyclerview/RecyclerViewProps.js.map +1 -0
  34. package/dist/recyclerview/ViewHolder.d.ts +45 -0
  35. package/dist/recyclerview/ViewHolder.d.ts.map +1 -0
  36. package/dist/recyclerview/ViewHolder.js +96 -0
  37. package/dist/recyclerview/ViewHolder.js.map +1 -0
  38. package/dist/recyclerview/ViewHolderCollection.d.ts +57 -0
  39. package/dist/recyclerview/ViewHolderCollection.d.ts.map +1 -0
  40. package/dist/recyclerview/ViewHolderCollection.js +75 -0
  41. package/dist/recyclerview/ViewHolderCollection.js.map +1 -0
  42. package/dist/recyclerview/components/CompatScroller.d.ts +7 -0
  43. package/dist/recyclerview/components/CompatScroller.d.ts.map +1 -0
  44. package/dist/recyclerview/components/CompatScroller.js +8 -0
  45. package/dist/recyclerview/components/CompatScroller.js.map +1 -0
  46. package/dist/recyclerview/components/CompatView.d.ts +7 -0
  47. package/dist/recyclerview/components/CompatView.d.ts.map +1 -0
  48. package/dist/recyclerview/components/CompatView.js +8 -0
  49. package/dist/recyclerview/components/CompatView.js.map +1 -0
  50. package/dist/recyclerview/components/ScrollAnchor.d.ts +28 -0
  51. package/dist/recyclerview/components/ScrollAnchor.d.ts.map +1 -0
  52. package/dist/recyclerview/components/ScrollAnchor.js +35 -0
  53. package/dist/recyclerview/components/ScrollAnchor.js.map +1 -0
  54. package/dist/recyclerview/components/StickyHeaders.d.ts +38 -0
  55. package/dist/recyclerview/components/StickyHeaders.d.ts.map +1 -0
  56. package/dist/recyclerview/components/StickyHeaders.js +119 -0
  57. package/dist/recyclerview/components/StickyHeaders.js.map +1 -0
  58. package/dist/recyclerview/helpers/ConsecutiveNumbers.d.ts +51 -0
  59. package/dist/recyclerview/helpers/ConsecutiveNumbers.d.ts.map +1 -0
  60. package/dist/recyclerview/helpers/ConsecutiveNumbers.js +122 -0
  61. package/dist/recyclerview/helpers/ConsecutiveNumbers.js.map +1 -0
  62. package/dist/recyclerview/helpers/EngagedIndicesTracker.d.ts +59 -0
  63. package/dist/recyclerview/helpers/EngagedIndicesTracker.d.ts.map +1 -0
  64. package/dist/recyclerview/helpers/EngagedIndicesTracker.js +138 -0
  65. package/dist/recyclerview/helpers/EngagedIndicesTracker.js.map +1 -0
  66. package/dist/recyclerview/hooks/useBoundDetection.d.ts +19 -0
  67. package/dist/recyclerview/hooks/useBoundDetection.d.ts.map +1 -0
  68. package/dist/recyclerview/hooks/useBoundDetection.js +103 -0
  69. package/dist/recyclerview/hooks/useBoundDetection.js.map +1 -0
  70. package/dist/recyclerview/hooks/useLayoutState.d.ts +12 -0
  71. package/dist/recyclerview/hooks/useLayoutState.d.ts.map +1 -0
  72. package/dist/recyclerview/hooks/useLayoutState.js +43 -0
  73. package/dist/recyclerview/hooks/useLayoutState.js.map +1 -0
  74. package/dist/recyclerview/hooks/useOnLoad.d.ts +25 -0
  75. package/dist/recyclerview/hooks/useOnLoad.d.ts.map +1 -0
  76. package/dist/recyclerview/hooks/useOnLoad.js +73 -0
  77. package/dist/recyclerview/hooks/useOnLoad.js.map +1 -0
  78. package/dist/recyclerview/hooks/useRecyclerViewController.d.ts +72 -0
  79. package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -0
  80. package/dist/recyclerview/hooks/useRecyclerViewController.js +370 -0
  81. package/dist/recyclerview/hooks/useRecyclerViewController.js.map +1 -0
  82. package/dist/recyclerview/hooks/useRecyclerViewManager.d.ts +6 -0
  83. package/dist/recyclerview/hooks/useRecyclerViewManager.d.ts.map +1 -0
  84. package/dist/recyclerview/hooks/useRecyclerViewManager.js +27 -0
  85. package/dist/recyclerview/hooks/useRecyclerViewManager.js.map +1 -0
  86. package/dist/recyclerview/hooks/useRecyclingState.d.ts +16 -0
  87. package/dist/recyclerview/hooks/useRecyclingState.d.ts.map +1 -0
  88. package/dist/recyclerview/hooks/useRecyclingState.js +54 -0
  89. package/dist/recyclerview/hooks/useRecyclingState.js.map +1 -0
  90. package/dist/recyclerview/hooks/useSecondaryProps.d.ts +27 -0
  91. package/dist/recyclerview/hooks/useSecondaryProps.d.ts.map +1 -0
  92. package/dist/recyclerview/hooks/useSecondaryProps.js +93 -0
  93. package/dist/recyclerview/hooks/useSecondaryProps.js.map +1 -0
  94. package/dist/recyclerview/hooks/useUnmountFlag.d.ts +11 -0
  95. package/dist/recyclerview/hooks/useUnmountFlag.d.ts.map +1 -0
  96. package/dist/recyclerview/hooks/useUnmountFlag.js +28 -0
  97. package/dist/recyclerview/hooks/useUnmountFlag.js.map +1 -0
  98. package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts +65 -0
  99. package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts.map +1 -0
  100. package/dist/recyclerview/layout-managers/GridLayoutManager.js +204 -0
  101. package/dist/recyclerview/layout-managers/GridLayoutManager.js.map +1 -0
  102. package/dist/recyclerview/layout-managers/LayoutManager.d.ts +281 -0
  103. package/dist/recyclerview/layout-managers/LayoutManager.d.ts.map +1 -0
  104. package/dist/recyclerview/layout-managers/LayoutManager.js +250 -0
  105. package/dist/recyclerview/layout-managers/LayoutManager.js.map +1 -0
  106. package/dist/recyclerview/layout-managers/LinearLayoutManager.d.ts +52 -0
  107. package/dist/recyclerview/layout-managers/LinearLayoutManager.d.ts.map +1 -0
  108. package/dist/recyclerview/layout-managers/LinearLayoutManager.js +191 -0
  109. package/dist/recyclerview/layout-managers/LinearLayoutManager.js.map +1 -0
  110. package/dist/recyclerview/layout-managers/MasonryLayoutManager.d.ts +73 -0
  111. package/dist/recyclerview/layout-managers/MasonryLayoutManager.d.ts.map +1 -0
  112. package/dist/recyclerview/layout-managers/MasonryLayoutManager.js +274 -0
  113. package/dist/recyclerview/layout-managers/MasonryLayoutManager.js.map +1 -0
  114. package/dist/recyclerview/utils/adjustOffsetForRTL.d.ts +12 -0
  115. package/dist/recyclerview/utils/adjustOffsetForRTL.d.ts.map +1 -0
  116. package/dist/recyclerview/utils/adjustOffsetForRTL.js +18 -0
  117. package/dist/recyclerview/utils/adjustOffsetForRTL.js.map +1 -0
  118. package/dist/recyclerview/utils/componentUtils.d.ts +19 -0
  119. package/dist/recyclerview/utils/componentUtils.d.ts.map +1 -0
  120. package/dist/recyclerview/utils/componentUtils.js +32 -0
  121. package/dist/recyclerview/utils/componentUtils.js.map +1 -0
  122. package/dist/recyclerview/utils/findVisibleIndex.d.ts +24 -0
  123. package/dist/recyclerview/utils/findVisibleIndex.d.ts.map +1 -0
  124. package/dist/recyclerview/utils/findVisibleIndex.js +82 -0
  125. package/dist/recyclerview/utils/findVisibleIndex.js.map +1 -0
  126. package/dist/recyclerview/utils/measureLayout.d.ts +56 -0
  127. package/dist/recyclerview/utils/measureLayout.d.ts.map +1 -0
  128. package/dist/recyclerview/utils/measureLayout.js +77 -0
  129. package/dist/recyclerview/utils/measureLayout.js.map +1 -0
  130. package/dist/tsconfig.tsbuildinfo +1 -1
  131. package/dist/utils/AverageWindow.d.ts +13 -0
  132. package/dist/utils/AverageWindow.d.ts.map +1 -1
  133. package/dist/utils/AverageWindow.js +30 -1
  134. package/dist/utils/AverageWindow.js.map +1 -1
  135. package/package.json +1 -1
  136. package/src/FlashListProps.ts +73 -2
  137. package/src/__tests__/AverageWindow.test.ts +49 -1
  138. package/src/enableNewCore.ts +22 -0
  139. package/src/index.ts +21 -0
  140. package/src/recyclerview/RecycleKeyManager.ts +185 -0
  141. package/src/recyclerview/RecyclerView.tsx +500 -0
  142. package/src/recyclerview/RecyclerViewContextProvider.ts +19 -0
  143. package/src/recyclerview/RecyclerViewManager.ts +379 -0
  144. package/src/recyclerview/RecyclerViewProps.ts +10 -0
  145. package/src/recyclerview/ViewHolder.tsx +173 -0
  146. package/src/recyclerview/ViewHolderCollection.tsx +164 -0
  147. package/src/recyclerview/components/CompatScroller.ts +9 -0
  148. package/src/recyclerview/components/CompatView.ts +9 -0
  149. package/src/recyclerview/components/ScrollAnchor.tsx +53 -0
  150. package/src/recyclerview/components/StickyHeaders.tsx +210 -0
  151. package/src/recyclerview/helpers/ConsecutiveNumbers.ts +120 -0
  152. package/src/recyclerview/helpers/EngagedIndicesTracker.ts +191 -0
  153. package/src/recyclerview/hooks/useBoundDetection.ts +127 -0
  154. package/src/recyclerview/hooks/useLayoutState.ts +46 -0
  155. package/src/recyclerview/hooks/useOnLoad.ts +78 -0
  156. package/src/recyclerview/hooks/useRecyclerViewController.tsx +487 -0
  157. package/src/recyclerview/hooks/useRecyclerViewManager.ts +30 -0
  158. package/src/recyclerview/hooks/useRecyclingState.ts +63 -0
  159. package/src/recyclerview/hooks/useSecondaryProps.tsx +119 -0
  160. package/src/recyclerview/hooks/useUnmountFlag.ts +26 -0
  161. package/src/recyclerview/layout-managers/GridLayoutManager.ts +215 -0
  162. package/src/recyclerview/layout-managers/LayoutManager.ts +493 -0
  163. package/src/recyclerview/layout-managers/LinearLayoutManager.ts +167 -0
  164. package/src/recyclerview/layout-managers/MasonryLayoutManager.ts +302 -0
  165. package/src/recyclerview/utils/adjustOffsetForRTL.ts +17 -0
  166. package/src/recyclerview/utils/componentUtils.ts +28 -0
  167. package/src/recyclerview/utils/findVisibleIndex.ts +94 -0
  168. package/src/recyclerview/utils/measureLayout.ts +89 -0
  169. package/src/utils/AverageWindow.ts +33 -0
  170. package/src/viewability/ViewToken.ts +1 -1
package/README.md CHANGED
@@ -1,24 +1,16 @@
1
1
  ![FlashList Image](./FlashList.png)
2
2
 
3
- <div align="center">
4
- <a href="https://shopify.github.io/flash-list/">Website</a> •
5
- <a href="https://discord.gg/k2gzABTfav">Discord</a> •
6
- <a href="https://shopify.github.io/flash-list/docs/">Getting started</a> •
7
- <a href="https://shopify.github.io/flash-list/docs/usage">Usage</a> •
8
- <a href="https://shopify.github.io/flash-list/docs/performance-troubleshooting">Performance</a> •
9
- <a href="https://shopify.github.io/flash-list/docs/fundamentals/performant-components">Writing performant components</a> •
10
- <a href="https://shopify.github.io/flash-list/docs/known-issues">Known Issues</a>
11
- <br><br>
3
+ # FlashList v2
12
4
 
13
- **Fast & performant React Native list. No more blank cells.**
5
+ FlashList v2 has been rebuilt from the ground up and delivers fast performance, higher precision, and better ease of use compared to v1. We've achieved all this while moving to a JS-only solution! One of the key advantages of FlashList v2 is that it doesn't require any estimates. It also introduces several new features compared to v1.
14
6
 
15
- Swap from FlatList in seconds. Get instant performance.
7
+ > ⚠️ **IMPORTANT:** FlashList v2.x has been designed to fully leverage the new architecture. **Old architecture will only be supported while FlashList v2 is in alpha/beta and will be dropped once it's ready.** When run on old architecture, we just fall back to v1.x which doesn't have any of the new features.
16
8
 
17
- </div>
9
+ > ⚠️ **IMPORTANT:** FlashList v2.x is in alpha and may have some issues. Please report any issues or edge cases you run into. We're actively working on testing and optimizing v2 so some things might change in the final version.
18
10
 
19
- ## React Native's new architecture support
11
+ ### Web support
20
12
 
21
- FlashList is compatible with React Native's new architecture however, it's not fully optimized for it yet. You will still gain performance benefits from using FlashList over FlatList. Stayed tuned for more improvements.
13
+ Web support might be added sometime in the future. We plan on shipping the RN version first.
22
14
 
23
15
  ## Installation
24
16
 
@@ -26,9 +18,7 @@ Add the package to your project via `yarn add @shopify/flash-list` and run `pod
26
18
 
27
19
  ## Usage
28
20
 
29
- We recommend reading the detailed documentation for using `FlashList` [here](https://shopify.github.io/flash-list/docs/usage).
30
-
31
- But if you are familiar with [FlatList](https://reactnative.dev/docs/flatlist), you already know how to use `FlashList`. You can try out `FlashList` by changing the component name and adding the `estimatedItemSize` prop or refer to the example below:
21
+ But if you are familiar with [FlatList](https://reactnative.dev/docs/flatlist), you already know how to use `FlashList`. You can try out `FlashList` by changing the component name or refer to the example below:
32
22
 
33
23
  ```jsx
34
24
  import React from "react";
@@ -49,20 +39,151 @@ const MyList = () => {
49
39
  <FlashList
50
40
  data={DATA}
51
41
  renderItem={({ item }) => <Text>{item.title}</Text>}
52
- estimatedItemSize={200}
53
42
  />
54
43
  );
55
44
  };
56
45
  ```
57
46
 
58
- To avoid common pitfalls, you can also follow these steps for migrating from `FlatList`, based on our own experiences:
59
-
60
- 1. Switch from `FlatList` to `FlashList` and render the list once. You should see a warning about missing `estimatedItemSize` and a suggestion. Set this value as the prop directly.
61
- 2. **Important**: Scan your [`renderItem`](https://shopify.github.io/flash-list/docs/usage/#renderitem) hierarchy for explicit `key` prop definitions and remove them. If you’re doing a `.map()` use indices as keys.
62
- 3. Check your [`renderItem`](https://shopify.github.io/flash-list/docs/usage/#renderitem) hierarchy for components that make use of `useState` and verify whether that state would need to be reset if a different item is passed to that component (see [Recycling](https://shopify.github.io/flash-list/docs/recycling))
63
- 4. If your list has heterogenous views, pass their types to `FlashList` using [`getItemType`](https://shopify.github.io/flash-list/docs/usage/#getitemtype) prop to improve performance.
64
- 5. Do not test performance with JS dev mode on. Make sure you’re in release mode. `FlashList` can appear slower while in dev mode due to a small render buffer.
47
+ ## New props
48
+
49
+ - `masonry`: Enable masonry layout for grid-like interfaces with varying item heights.
50
+
51
+ ```jsx
52
+ <FlashList
53
+ data={data}
54
+ masonry
55
+ numColumns={3}
56
+ renderItem={({ item }) => <MasonryItem item={item} />}
57
+ />
58
+ ```
59
+
60
+ - `optimizeItemArrangement`: When enabled, masonry layout will try to reduce differences in column height by modifying item order.
61
+ - `onStartReached`: Called when the scroll position gets within `onStartReachedThreshold` of the start of the content.
62
+
63
+ ```jsx
64
+ <FlashList
65
+ data={messageData}
66
+ onStartReached={() => loadOlderMessages()}
67
+ onStartReachedThreshold={0.1}
68
+ renderItem={({ item }) => <MessageItem message={item} />}
69
+ />
70
+ ```
71
+
72
+ - `onStartReachedThreshold`: How far from the start the top edge of the list must be to trigger `onStartReached`.
73
+ - `disableRecycling`: If true, the FlashList will not recycle items.
74
+ - `style`: Style for the FlashList's parent container. We highly recommend not adding padding which can impact the size of the ScrollView inside. We operate on the assumption that the size of parent view and ScrollView is the same. In most cases, `contentContainerStyle` should be enough so avoid using this.
75
+ - `maintainVisibleContentPosition`: Configuration for maintaining scroll position when content changes:
76
+ - `disabled`: Set to true to disable this feature (enabled by default).
77
+ - `autoscrollToTopThreshold`: Automatically scroll to maintain position when content is added at the top.
78
+ - `autoscrollToBottomThreshold`: Automatically scroll to maintain position when content is added at the bottom.
79
+ - `startRenderingFromBottom`: If true, initial render will start from the bottom, useful for chat interfaces.
80
+ ```jsx
81
+ <FlashList
82
+ data={chatMessages}
83
+ maintainVisibleContentPosition={{
84
+ autoscrollToBottomThreshold: 0.2,
85
+ startRenderingFromBottom: true,
86
+ }}
87
+ renderItem={({ item }) => <ChatMessage message={item} />}
88
+ />
89
+ ```
90
+ - `onCommitLayoutEffect`: Called before layout is committed. Can be used to measure list and make changes before paint. Doing setState inside the callback can lead to infinite loops. Make sure FlashList's props are memoized.
91
+
92
+ ## Deprecated (will be removed after alpha/beta)
93
+
94
+ - `estimatedItemSize`: No longer used.
95
+ - `estimatedListSize`: No longer used.
96
+ - `estimatedFirstItemOffset`: No longer used.
97
+ - `inverted`: We have added `maintainVisibleContentPosition` support, so we don't want to maintain inverted mode.
98
+ - `onBlankArea`: We don't have plans to add or continue supporting this prop.
99
+ - `disableHorizontalListHeightMeasurement`: No longer needed.
100
+ - `disableAutoLayout`: There's no auto layout in v2.
101
+ - `MasonryFlashList` will be replaced by `masonry` prop.
102
+ - `getColumnFlex` from `MasonryFlashList` will not be supported in FlashList v2 with `masonry` prop.
103
+
104
+ ## Changed props
105
+
106
+ - `overrideItemLayout`: This used to allow a way to change the span of items and provide size estimates. In v2, span is supported, but we no longer read the size estimates.
107
+ ```jsx
108
+ <FlashList
109
+ data={gridData}
110
+ numColumns={2}
111
+ overrideItemLayout={(layout, item) => {
112
+ layout.span = item.span; // Set span
113
+ }}
114
+ renderItem={({ item }) => <GridItem item={item} />}
115
+ />
116
+ ```
117
+
118
+ ## New features
119
+
120
+ - `masonry` is now a prop on FlashList. It's now also possible to use `overrideItemLayout` with `masonry`.
121
+ - `maintainVisibleContentPosition` is available and now enabled by default. We use this to reduce visible glitches as much as possible. Chat apps without inverted will also be possible. Please note that if you plan on adding a large number of rows on top of the list, then you may want to increase the drawDistance on the list.
122
+ - `onStartReached` callback is now available with a configurable threshold.
123
+ - We've also added support for RTL layouts.
124
+
125
+ ## Improvements
126
+
127
+ - `scrollToIndex` and `scrollToItem` are much more precise.
128
+ - Scrolling upwards after orientation change doesn't cause layout glitches. The same is true for scrolling to items and scrolling upwards.
129
+ - `stickyHeaders` use an Animated implementation, so minor gaps between them while scrolling aren't visible anymore.
130
+ - FlashList does not ask for any estimates, which makes it much easier to use.
131
+ - Horizontal Lists are much improved, and items can also resize within the lists. We no longer render an extra item to measure list height.
132
+ - In Grid layout, if side-by-side items have different heights, then the shorter item will match the height of the tallest item. This wasn't possible in v1.
133
+ - The ref of FlashList has many more useful methods like `getVisibleIndices` and `getLayout`.
134
+ - `contentContainerStyle` prop is fully supported now.
135
+
136
+ ## Things to know
137
+
138
+ - `keyExtractor` is important to prevent glitches due to item layout changes when going upwards. We highly recommend having a valid `keyExtractor` with v2.
139
+ - Avoid adding keys directly to components which can break recycling. Same as v1. More info [here](https://shopify.github.io/flash-list/docs/fundamentals/performant-components/#remove-key-prop).
140
+ - `useLayoutState`: This is similar to `useState` but communicates the change in state to FlashList. It's useful if you want to resize a child component based on a local state. Item layout changes will still be detected using `onLayout` callback in the absence of `useLayoutState`, which might not look as smooth on a case-by-case basis.
141
+
142
+ ```jsx
143
+ import { useLayoutState } from "@shopify/flash-list";
144
+
145
+ const MyItem = ({ item }) => {
146
+ const [isExpanded, setIsExpanded] = useLayoutState(false);
147
+ const height = isExpanded ? 150 : 80;
148
+
149
+ return (
150
+ <Pressable onPress={() => setIsExpanded(!isExpanded)}>
151
+ <View style={{ height, padding: 16 }}>
152
+ <Text>{item.title}</Text>
153
+ </View>
154
+ </Pressable>
155
+ );
156
+ };
157
+ ```
158
+
159
+ - `useRecyclingState`: Similar to `useState` but accepts a dependency array. On change of deps, the state gets reset without an additional `setState` call. Useful for maintaining local item state if really necessary. It also has the functionality of `useLayoutState` built in.
160
+
161
+ ```jsx
162
+ import { useRecyclingState } from "@shopify/flash-list";
163
+
164
+ const GridItem = ({ item }) => {
165
+ const [isExpanded, setIsExpanded] = useRecyclingState(
166
+ false,
167
+ [item.id],
168
+ () => {
169
+ // runs on reset. Can be used to reset scroll positions of nested horizontal lists
170
+ }
171
+ );
172
+ const height = isExpanded ? 100 : 50;
173
+
174
+ return (
175
+ <Pressable onPress={() => setIsExpanded(!isExpanded)}>
176
+ <View style={{ height, backgroundColor: item.color }}>
177
+ <Text>{item.title}</Text>
178
+ </View>
179
+ </Pressable>
180
+ );
181
+ };
182
+ ```
183
+
184
+ - If you're nesting horizontal FlashLists in vertical lists, we highly recommend the vertical list to be FlashList too. We have optimizations to wait for child layout to complete which can improve load times.
185
+ - For chat apps, consider increasing drawDistance to 500 or higher if you're going to add a lot of items to the top. Higher drawDistance can remove some flickers. 500-1000 for chat can be okay. We would like to hear from you if you run into issues.
65
186
 
66
187
  ## App / Playground
67
188
 
68
- The [fixture](https://github.com/Shopify/flash-list/tree/main/fixture) is an example app showing how to use the library.
189
+ The [fixture](https://github.com/Shopify/flash-list/tree/new-rlv-prototype/fixture) is an example app showing how to use the library.
@@ -18,7 +18,7 @@ export declare type RenderTarget = "Cell" | "StickyHeader" | "Measurement";
18
18
  export declare const RenderTargetOptions: Record<string, RenderTarget>;
19
19
  export declare type ListRenderItem<TItem> = (info: ListRenderItemInfo<TItem>) => React.ReactElement | null;
20
20
  export declare type ContentStyle = Pick<ViewStyle, "backgroundColor" | "paddingTop" | "paddingLeft" | "paddingRight" | "paddingBottom" | "padding" | "paddingVertical" | "paddingHorizontal">;
21
- export interface FlashListProps<TItem> extends ScrollViewProps {
21
+ export interface FlashListProps<TItem> extends Omit<ScrollViewProps, "maintainVisibleContentPosition"> {
22
22
  /**
23
23
  * Takes an item from `data` and renders it into the list. Typical usage:
24
24
  * ```ts
@@ -164,7 +164,7 @@ export interface FlashListProps<TItem> extends ScrollViewProps {
164
164
  * How far from the end (in units of visible length of the list) the bottom edge of the
165
165
  * list must be from the end of the content to trigger the `onEndReached` callback.
166
166
  * Thus a value of 0.5 will trigger `onEndReached` when the end of the content is
167
- * within half the visible length of the list.
167
+ * within half the visible length of the list. Default value is 0.5.
168
168
  */
169
169
  onEndReachedThreshold?: number | null | undefined;
170
170
  /**
@@ -252,5 +252,68 @@ export interface FlashListProps<TItem> extends ScrollViewProps {
252
252
  * `false` again.
253
253
  */
254
254
  disableAutoLayout?: boolean;
255
+ /**
256
+ * New arch only
257
+ * Enable masonry layout.
258
+ */
259
+ masonry?: boolean;
260
+ /**
261
+ * New arch only
262
+ * If enabled, MasonryFlashList will try to reduce difference in column height by modifying item order.
263
+ */
264
+ optimizeItemArrangement?: boolean;
265
+ /**
266
+ * New arch only
267
+ * Called once when the scroll position gets within onStartReachedThreshold of the start of the content.
268
+ */
269
+ onStartReached?: FlashListProps<TItem>["onEndReached"];
270
+ /**
271
+ * New arch only
272
+ * How far from the start (in units of visible length of the list) the top edge of the
273
+ * list must be from the start of the content to trigger the `onStartReached` callback.
274
+ * Thus a value of 0.5 will trigger `onStartReached` when the start of the content is
275
+ * within half the visible length of the list. Default value is 0.2.
276
+ */
277
+ onStartReachedThreshold?: FlashListProps<TItem>["onEndReachedThreshold"];
278
+ /**
279
+ * New arch only
280
+ * If true, the RecyclerView will not recycle items.
281
+ */
282
+ disableRecycling?: boolean;
283
+ /**
284
+ * New arch only
285
+ * Style for the RecyclerView's parent container.
286
+ * Please avoid anything which can mess size of children in this view. For example, margin is okay but padding is not.
287
+ */
288
+ style?: ViewStyle;
289
+ /**
290
+ * New arch only
291
+ * Configuration for maintaining scroll position when content changes.
292
+ * Useful for chat-like interfaces where new messages can be added at the top or bottom.
293
+ */
294
+ maintainVisibleContentPosition?: {
295
+ /**
296
+ * maintainVisibleContentPosition is enabled by default.
297
+ */
298
+ disabled?: boolean;
299
+ /**
300
+ * When content is added at the top, automatically scroll to maintain position if the user is within this threshold of the top
301
+ */
302
+ autoscrollToTopThreshold?: number;
303
+ /**
304
+ * When content is added at the bottom, automatically scroll to maintain position if the user is within this threshold of the bottom
305
+ */
306
+ autoscrollToBottomThreshold?: number;
307
+ /**
308
+ * If true, initial render will start from the bottom of the list, useful for chat-like interfaces when there are only few messages
309
+ */
310
+ startRenderingFromBottom?: boolean;
311
+ };
312
+ /**
313
+ * New arch only
314
+ * Called when the layout is committed. Can be used to measure list.
315
+ * Doing set state inside the callback can lead to infinite loops. Make sure FlashList's props are memoized.
316
+ */
317
+ onCommitLayoutEffect?: () => void;
255
318
  }
256
319
  //# sourceMappingURL=FlashListProps.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FlashListProps.d.ts","sourceRoot":"","sources":["../src/FlashListProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EACL,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,8BAA8B,EAC9B,SAAS,EACV,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAEhD,MAAM,WAAW,kBAAkB,CAAC,KAAK;IACvC,IAAI,EAAE,KAAK,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,MAAM,EAAE,YAAY,CAAC;IACrB,SAAS,CAAC,EAAE,GAAG,CAAC;CACjB;AAED,oBAAY,YAAY,GAAG,MAAM,GAAG,cAAc,GAAG,aAAa,CAAC;AAEnE,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAI5D,CAAC;AAEF,oBAAY,cAAc,CAAC,KAAK,IAAI,CAClC,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC,KAC5B,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC;AAE/B,oBAAY,YAAY,GAAG,IAAI,CAC7B,SAAS,EACP,iBAAiB,GACjB,YAAY,GACZ,aAAa,GACb,cAAc,GACd,eAAe,GACf,SAAS,GACT,iBAAiB,GACjB,mBAAmB,CACtB,CAAC;AAEF,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GG;IACH,kBAAkB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAExC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;IAExC;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,CAAC;IAEzD;;;OAGG;IACH,8BAA8B,CAAC,EAAE,8BAA8B,GAAG,SAAS,CAAC;IAE5E;;;;OAIG;IACH,sCAAsC,CAAC,EAAE,OAAO,CAAC;IAEjD;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAElC;;;OAGG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,cAAc,CAAC,CAAC;IAEvD;;;;;;OAMG;IACH,uBAAuB,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC;IAEzE;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC;IAElB;;;;OAIG;IACH,8BAA8B,CAAC,EAAE;QAC/B;;WAEG;QACH,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB;;WAEG;QACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;QAClC;;WAEG;QACH,2BAA2B,CAAC,EAAE,MAAM,CAAC;QACrC;;WAEG;QACH,wBAAwB,CAAC,EAAE,OAAO,CAAC;KACpC,CAAC;IAEF;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAC;CACnC"}
@@ -66,4 +66,39 @@ describe("AverageWindow", function () {
66
66
  }
67
67
  });
68
68
  });
69
+ describe("MultiTypeAverageWindow", function () {
70
+ it("should maintain separate averages for different types", function () {
71
+ var windowSize = 10;
72
+ var multiTypeAverageWindow = new AverageWindow_1.MultiTypeAverageWindow(windowSize);
73
+ multiTypeAverageWindow.addValue(10, "type1");
74
+ multiTypeAverageWindow.addValue(20, "type2");
75
+ expect(multiTypeAverageWindow.getCurrentValue("type1")).toBe(10);
76
+ expect(multiTypeAverageWindow.getCurrentValue("type2")).toBe(20);
77
+ });
78
+ it("should update averages correctly for each type", function () {
79
+ var windowSize = 5;
80
+ var multiTypeAverageWindow = new AverageWindow_1.MultiTypeAverageWindow(windowSize);
81
+ multiTypeAverageWindow.addValue(10, "type1");
82
+ multiTypeAverageWindow.addValue(20, "type1");
83
+ multiTypeAverageWindow.addValue(30, "type1");
84
+ multiTypeAverageWindow.addValue(5, "type2");
85
+ multiTypeAverageWindow.addValue(15, "type2");
86
+ expect(multiTypeAverageWindow.getCurrentValue("type1")).toBe(20);
87
+ expect(multiTypeAverageWindow.getCurrentValue("type2")).toBe(10);
88
+ });
89
+ it("should return 0 for non-existent types", function () {
90
+ var windowSize = 5;
91
+ var multiTypeAverageWindow = new AverageWindow_1.MultiTypeAverageWindow(windowSize);
92
+ expect(multiTypeAverageWindow.getCurrentValue("nonExistentType")).toBe(0);
93
+ });
94
+ it("should reset all averages", function () {
95
+ var windowSize = 5;
96
+ var multiTypeAverageWindow = new AverageWindow_1.MultiTypeAverageWindow(windowSize);
97
+ multiTypeAverageWindow.addValue(10, "type1");
98
+ multiTypeAverageWindow.addValue(20, "type2");
99
+ multiTypeAverageWindow.reset();
100
+ expect(multiTypeAverageWindow.getCurrentValue("type1")).toBe(0);
101
+ expect(multiTypeAverageWindow.getCurrentValue("type2")).toBe(0);
102
+ });
103
+ });
69
104
  //# sourceMappingURL=AverageWindow.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"AverageWindow.test.js","sourceRoot":"","sources":["../../src/__tests__/AverageWindow.test.ts"],"names":[],"mappings":";;AAAA,wDAAuD;AAEvD,QAAQ,CAAC,eAAe,EAAE;IACxB,IAAM,iBAAiB,GAAG,UACxB,aAA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CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function enableNewCore(enable: boolean): void;
2
+ export declare function isNewCoreEnabled(): boolean;
3
+ //# sourceMappingURL=enableNewCore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enableNewCore.d.ts","sourceRoot":"","sources":["../src/enableNewCore.ts"],"names":[],"mappings":"AACA,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,QAE5C;AAED,wBAAgB,gBAAgB,YAE/B"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isNewCoreEnabled = exports.enableNewCore = void 0;
4
+ var useNewCore;
5
+ function enableNewCore(enable) {
6
+ useNewCore = enable;
7
+ }
8
+ exports.enableNewCore = enableNewCore;
9
+ function isNewCoreEnabled() {
10
+ return useNewCore !== null && useNewCore !== void 0 ? useNewCore : isReactNativeNewArchitecture();
11
+ }
12
+ exports.isNewCoreEnabled = isNewCoreEnabled;
13
+ function isReactNativeNewArchitecture() {
14
+ try {
15
+ // Check for Fabric UI Manager
16
+ var hasFabricUIManager = Boolean(global === null || global === void 0 ? void 0 : global.nativeFabricUIManager);
17
+ // Check for TurboModule system
18
+ var hasTurboModule = Boolean(global === null || global === void 0 ? void 0 : global.__turboModuleProxy);
19
+ return hasFabricUIManager || hasTurboModule;
20
+ }
21
+ catch (_a) {
22
+ return false;
23
+ }
24
+ }
25
+ //# sourceMappingURL=enableNewCore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enableNewCore.js","sourceRoot":"","sources":["../src/enableNewCore.ts"],"names":[],"mappings":";;;AAAA,IAAI,UAA+B,CAAC;AACpC,SAAgB,aAAa,CAAC,MAAe;IAC3C,UAAU,GAAG,MAAM,CAAC;AACtB,CAAC;AAFD,sCAEC;AAED,SAAgB,gBAAgB;IAC9B,OAAO,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,4BAA4B,EAAE,CAAC;AACtD,CAAC;AAFD,4CAEC;AAED,SAAS,4BAA4B;IACnC,IAAI;QACF,8BAA8B;QAC9B,IAAM,kBAAkB,GAAG,OAAO,CAAE,MAAc,aAAd,MAAM,uBAAN,MAAM,CAAU,qBAAqB,CAAC,CAAC;QAE3E,+BAA+B;QAC/B,IAAM,cAAc,GAAG,OAAO,CAAE,MAAc,aAAd,MAAM,uBAAN,MAAM,CAAU,kBAAkB,CAAC,CAAC;QAEpE,OAAO,kBAAkB,IAAI,cAAc,CAAC;KAC7C;IAAC,WAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -7,8 +7,13 @@ export { useDataMultiplier } from "./benchmark/useDataMultiplier";
7
7
  export { useFlatListBenchmark, FlatListBenchmarkParams, } from "./benchmark/useFlatListBenchmark";
8
8
  export { useBlankAreaTracker, BlankAreaTrackerResult, BlankAreaTrackerConfig, } from "./benchmark/useBlankAreaTracker";
9
9
  export { MasonryFlashList, MasonryFlashListProps, MasonryFlashListScrollEvent, MasonryFlashListRef, MasonryListItem, MasonryListRenderItem, MasonryListRenderItemInfo, } from "./MasonryFlashList";
10
+ export { useLayoutState } from "./recyclerview/hooks/useLayoutState";
11
+ export { useRecyclingState } from "./recyclerview/hooks/useRecyclingState";
10
12
  export { JSFPSMonitor, JSFPSResult } from "./benchmark/JSFPSMonitor";
11
13
  export { autoScroll, Cancellable } from "./benchmark/AutoScrollHelper";
12
14
  export { default as ViewToken } from "./viewability/ViewToken";
13
15
  export { default as CellContainer } from "./native/cell-container/CellContainer";
16
+ export { RecyclerView } from "./recyclerview/RecyclerView";
17
+ export { RecyclerViewProps } from "./recyclerview/RecyclerViewProps";
18
+ export { useRecyclerViewContext } from "./recyclerview/RecyclerViewContextProvider";
14
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,SAAS,EAA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qBAAqB,CAAC;AACnE,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,cAAc,GACf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EACL,oBAAoB,EACpB,uBAAuB,GACxB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,2BAA2B,EAC3B,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,4CAA4C,CAAC"}
package/dist/index.js CHANGED
@@ -1,15 +1,17 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.CellContainer = exports.Cancellable = exports.autoScroll = exports.JSFPSMonitor = exports.MasonryFlashList = exports.useBlankAreaTracker = exports.useFlatListBenchmark = exports.useDataMultiplier = exports.useBenchmark = exports.useOnNativeBlankAreaEvents = exports.AnimatedFlashList = exports.RenderTargetOptions = exports.FlashList = void 0;
7
- var FlashList_1 = require("./FlashList");
8
- Object.defineProperty(exports, "FlashList", { enumerable: true, get: function () { return __importDefault(FlashList_1).default; } });
3
+ exports.useRecyclerViewContext = exports.RecyclerView = exports.CellContainer = exports.Cancellable = exports.autoScroll = exports.JSFPSMonitor = exports.useRecyclingState = exports.useLayoutState = exports.MasonryFlashList = exports.useBlankAreaTracker = exports.useFlatListBenchmark = exports.useDataMultiplier = exports.useBenchmark = exports.useOnNativeBlankAreaEvents = exports.AnimatedFlashList = exports.RenderTargetOptions = exports.FlashList = void 0;
4
+ var tslib_1 = require("tslib");
5
+ var FlashList_1 = tslib_1.__importDefault(require("./FlashList"));
6
+ var enableNewCore_1 = require("./enableNewCore");
7
+ var RecyclerView_1 = require("./recyclerview/RecyclerView");
8
+ // Keep this unmodified for TS type checking
9
+ var FlashList_2 = require("./FlashList");
10
+ Object.defineProperty(exports, "FlashList", { enumerable: true, get: function () { return tslib_1.__importDefault(FlashList_2).default; } });
9
11
  var FlashListProps_1 = require("./FlashListProps");
10
12
  Object.defineProperty(exports, "RenderTargetOptions", { enumerable: true, get: function () { return FlashListProps_1.RenderTargetOptions; } });
11
13
  var AnimatedFlashList_1 = require("./AnimatedFlashList");
12
- Object.defineProperty(exports, "AnimatedFlashList", { enumerable: true, get: function () { return __importDefault(AnimatedFlashList_1).default; } });
14
+ Object.defineProperty(exports, "AnimatedFlashList", { enumerable: true, get: function () { return tslib_1.__importDefault(AnimatedFlashList_1).default; } });
13
15
  var AutoLayoutView_1 = require("./native/auto-layout/AutoLayoutView");
14
16
  Object.defineProperty(exports, "useOnNativeBlankAreaEvents", { enumerable: true, get: function () { return AutoLayoutView_1.useOnNativeBlankAreaEvents; } });
15
17
  var useBenchmark_1 = require("./benchmark/useBenchmark");
@@ -22,11 +24,29 @@ var useBlankAreaTracker_1 = require("./benchmark/useBlankAreaTracker");
22
24
  Object.defineProperty(exports, "useBlankAreaTracker", { enumerable: true, get: function () { return useBlankAreaTracker_1.useBlankAreaTracker; } });
23
25
  var MasonryFlashList_1 = require("./MasonryFlashList");
24
26
  Object.defineProperty(exports, "MasonryFlashList", { enumerable: true, get: function () { return MasonryFlashList_1.MasonryFlashList; } });
27
+ var useLayoutState_1 = require("./recyclerview/hooks/useLayoutState");
28
+ Object.defineProperty(exports, "useLayoutState", { enumerable: true, get: function () { return useLayoutState_1.useLayoutState; } });
29
+ var useRecyclingState_1 = require("./recyclerview/hooks/useRecyclingState");
30
+ Object.defineProperty(exports, "useRecyclingState", { enumerable: true, get: function () { return useRecyclingState_1.useRecyclingState; } });
25
31
  var JSFPSMonitor_1 = require("./benchmark/JSFPSMonitor");
26
32
  Object.defineProperty(exports, "JSFPSMonitor", { enumerable: true, get: function () { return JSFPSMonitor_1.JSFPSMonitor; } });
27
33
  var AutoScrollHelper_1 = require("./benchmark/AutoScrollHelper");
28
34
  Object.defineProperty(exports, "autoScroll", { enumerable: true, get: function () { return AutoScrollHelper_1.autoScroll; } });
29
35
  Object.defineProperty(exports, "Cancellable", { enumerable: true, get: function () { return AutoScrollHelper_1.Cancellable; } });
30
36
  var CellContainer_1 = require("./native/cell-container/CellContainer");
31
- Object.defineProperty(exports, "CellContainer", { enumerable: true, get: function () { return __importDefault(CellContainer_1).default; } });
37
+ Object.defineProperty(exports, "CellContainer", { enumerable: true, get: function () { return tslib_1.__importDefault(CellContainer_1).default; } });
38
+ var RecyclerView_2 = require("./recyclerview/RecyclerView");
39
+ Object.defineProperty(exports, "RecyclerView", { enumerable: true, get: function () { return RecyclerView_2.RecyclerView; } });
40
+ var RecyclerViewContextProvider_1 = require("./recyclerview/RecyclerViewContextProvider");
41
+ Object.defineProperty(exports, "useRecyclerViewContext", { enumerable: true, get: function () { return RecyclerViewContextProvider_1.useRecyclerViewContext; } });
42
+ // @ts-ignore - This is ignored by TypeScript but will be present in the compiled JS
43
+ // In the compiled JS, this will override the previous FlashList export with a conditional one
44
+ if (typeof module !== "undefined" && module.exports) {
45
+ Object.defineProperty(module.exports, "FlashList", {
46
+ get: function () {
47
+ return (0, enableNewCore_1.isNewCoreEnabled)() ? RecyclerView_1.RecyclerView : FlashList_1.default;
48
+ },
49
+ configurable: true,
50
+ });
51
+ }
32
52
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAmD;AAA1C,uHAAA,OAAO,OAAa;AAC7B,mDAO0B;AADxB,qHAAA,mBAAmB,OAAA;AAErB,yDAAmE;AAA1D,uIAAA,OAAO,OAAqB;AACrC,sEAI6C;AAH3C,4HAAA,0BAA0B,OAAA;AAI5B,yDAIkC;AAHhC,4GAAA,YAAY,OAAA;AAId,mEAAkE;AAAzD,sHAAA,iBAAiB,OAAA;AAC1B,yEAG0C;AAFxC,4HAAA,oBAAoB,OAAA;AAGtB,uEAIyC;AAHvC,0HAAA,mBAAmB,OAAA;AAIrB,uDAQ4B;AAP1B,oHAAA,gBAAgB,OAAA;AAQlB,yDAAqE;AAA5D,4GAAA,YAAY,OAAA;AACrB,iEAAuE;AAA9D,8GAAA,UAAU,OAAA;AAAE,+GAAA,WAAW,OAAA;AAEhC,uEAAiF;AAAxE,+HAAA,OAAO,OAAiB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,kEAA2D;AAC3D,iDAAmD;AACnD,4DAA2D;AAE3D,4CAA4C;AAC5C,yCAAmD;AAA1C,+HAAA,OAAO,OAAa;AAC7B,mDAO0B;AADxB,qHAAA,mBAAmB,OAAA;AAErB,yDAAmE;AAA1D,+IAAA,OAAO,OAAqB;AACrC,sEAI6C;AAH3C,4HAAA,0BAA0B,OAAA;AAI5B,yDAIkC;AAHhC,4GAAA,YAAY,OAAA;AAId,mEAAkE;AAAzD,sHAAA,iBAAiB,OAAA;AAC1B,yEAG0C;AAFxC,4HAAA,oBAAoB,OAAA;AAGtB,uEAIyC;AAHvC,0HAAA,mBAAmB,OAAA;AAIrB,uDAQ4B;AAP1B,oHAAA,gBAAgB,OAAA;AAQlB,sEAAqE;AAA5D,gHAAA,cAAc,OAAA;AACvB,4EAA2E;AAAlE,sHAAA,iBAAiB,OAAA;AAC1B,yDAAqE;AAA5D,4GAAA,YAAY,OAAA;AACrB,iEAAuE;AAA9D,8GAAA,UAAU,OAAA;AAAE,+GAAA,WAAW,OAAA;AAEhC,uEAAiF;AAAxE,uIAAA,OAAO,OAAiB;AACjC,4DAA2D;AAAlD,4GAAA,YAAY,OAAA;AAErB,0FAAoF;AAA3E,qIAAA,sBAAsB,OAAA;AAE/B,oFAAoF;AACpF,8FAA8F;AAC9F,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,OAAO,EAAE;IACnD,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE;QACjD,GAAG,EAAE;YACH,OAAO,IAAA,gCAAgB,GAAE,CAAC,CAAC,CAAC,2BAAY,CAAC,CAAC,CAAC,mBAAiB,CAAC;QAC/D,CAAC;QACD,YAAY,EAAE,IAAI;KACnB,CAAC,CAAC;CACJ"}
@@ -0,0 +1,82 @@
1
+ export interface RecycleKeyManager {
2
+ /**
3
+ * Retrieves a unique key for an item type, maintaining a separate pool for each type.
4
+ * If a stableId is provided and exists, returns the associated key.
5
+ * Otherwise, generates a new key or reuses one from the pool.
6
+ * @param itemType - The type/category of the item (e.g., 'header', 'product', 'footer')
7
+ * @param stableId - Optional unique identifier for stable item tracking
8
+ * @param currentKey - Optional current key to maintain if it exists in the pool
9
+ * @returns A unique key for the item
10
+ */
11
+ getKey: (itemType: string, stableId: string, currentKey?: string) => string;
12
+ /**
13
+ * Recycles a key back into its item type's pool when the associated view is no longer visible.
14
+ * This allows the key to be reused for new items of the same type.
15
+ * @param key - The key to be recycled back into the pool
16
+ */
17
+ recycleKey: (key: string) => void;
18
+ /**
19
+ * Checks if a key is currently available in the recycling pool (not in use).
20
+ * @param key - The key to check
21
+ * @returns True if the key is available in the pool, false otherwise
22
+ */
23
+ hasKeyInPool: (key: string) => boolean;
24
+ /**
25
+ * Clears all recycled keys from the pool, resetting the recycling system.
26
+ * This is useful when the list needs to be completely reset.
27
+ */
28
+ clearPool: () => void;
29
+ }
30
+ export declare class RecycleKeyManagerImpl implements RecycleKeyManager {
31
+ private maxItems;
32
+ private keyPools;
33
+ private keyMap;
34
+ private stableIdMap;
35
+ private keyCounter;
36
+ /**
37
+ * Creates a new RecycleKeyManager with a specified maximum number of items.
38
+ * @param maxItems - Maximum number of unique keys that can be active simultaneously.
39
+ * Defaults to Number.MAX_SAFE_INTEGER if not specified.
40
+ */
41
+ constructor(maxItems?: number);
42
+ /**
43
+ * Gets a key for the specified item type, prioritizing stable ID associations.
44
+ * If a stable ID exists, returns its associated key. Otherwise, either reuses
45
+ * a key from the pool or generates a new one.
46
+ * @param itemType - The type/category of the item
47
+ * @param stableId - Optional unique identifier for stable item tracking
48
+ * @param currentKey - Optional current key to maintain if it exists in the pool
49
+ * @returns A unique key for the item
50
+ */
51
+ getKey(itemType: string, stableId: string, currentKey?: string): string;
52
+ /**
53
+ * Recycles a key by adding it back to its item type's pool and cleaning up
54
+ * associated mappings. This should be called when a view is no longer visible.
55
+ * @param key - The key to be recycled
56
+ */
57
+ recycleKey(key: string): void;
58
+ /**
59
+ * Checks if a key is currently available in the recycling pool.
60
+ * @param key - The key to check
61
+ * @returns True if the key is available in the pool, false otherwise
62
+ */
63
+ hasKeyInPool(key: string): boolean;
64
+ /**
65
+ * Clears all recycled keys from the pool, effectively resetting the recycling system.
66
+ * This operation does not affect currently active keys.
67
+ */
68
+ clearPool(): void;
69
+ /**
70
+ * Generates a unique sequential key using an internal counter.
71
+ * @returns A unique key as a string
72
+ */
73
+ private generateKey;
74
+ /**
75
+ * Ensures the total number of active keys doesn't exceed the maximum limit.
76
+ * If the limit is exceeded, recycles the oldest keys until within bounds.
77
+ * Note: This operation may impact performance when dealing with large lists.
78
+ * TODO: Check performance impact of this
79
+ */
80
+ private ensurePoolSize;
81
+ }
82
+ //# sourceMappingURL=RecycleKeyManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecycleKeyManager.d.ts","sourceRoot":"","sources":["../../src/recyclerview/RecycleKeyManager.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;OAQG;IACH,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAE5E;;;;OAIG;IACH,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAElC;;;;OAIG;IACH,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;IAEvC;;;OAGG;IACH,SAAS,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,qBAAa,qBAAsB,YAAW,iBAAiB;IAE7D,OAAO,CAAC,QAAQ,CAAS;IAGzB,OAAO,CAAC,QAAQ,CAA2B;IAG3C,OAAO,CAAC,MAAM,CAAuD;IAGrE,OAAO,CAAC,WAAW,CAAsB;IAGzC,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;OAIG;gBACS,QAAQ,GAAE,MAAgC;IAQtD;;;;;;;;OAQG;IACI,MAAM,CACX,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM;IAsCT;;;;OAIG;IACI,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAwBpC;;;;OAIG;IACI,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzC;;;OAGG;IACI,SAAS;IAIhB;;;OAGG;IACH,OAAO,CAAC,WAAW;IAInB;;;;;OAKG;IACH,OAAO,CAAC,cAAc;CAWvB"}