@react-native-ohos/flash-list 1.8.3-rc.2 → 1.8.3-rc.4

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 (206) hide show
  1. package/LICENSE +6 -6
  2. package/README.OpenSource +10 -10
  3. package/README.md +9 -9
  4. package/dist/AnimatedFlashList.d.ts +28 -25
  5. package/dist/AnimatedFlashList.d.ts.map +1 -1
  6. package/dist/AnimatedFlashList.js +30 -30
  7. package/dist/FlashList.d.ts +179 -179
  8. package/dist/FlashList.d.ts.map +1 -1
  9. package/dist/FlashList.js +599 -598
  10. package/dist/FlashList.js.map +1 -1
  11. package/dist/FlashListProps.d.ts +278 -278
  12. package/dist/FlashListProps.js +31 -31
  13. package/dist/GridLayoutProviderWithProps.d.ts +64 -64
  14. package/dist/GridLayoutProviderWithProps.js +137 -136
  15. package/dist/GridLayoutProviderWithProps.js.map +1 -1
  16. package/dist/MasonryFlashList.d.ts +73 -73
  17. package/dist/MasonryFlashList.d.ts.map +1 -1
  18. package/dist/MasonryFlashList.js +274 -274
  19. package/dist/MasonryFlashList.js.map +1 -1
  20. package/dist/PureComponentWrapper.d.ts +44 -44
  21. package/dist/PureComponentWrapper.js +59 -59
  22. package/dist/PureComponentWrapper.js.map +1 -1
  23. package/dist/benchmark/AutoScrollHelper.d.ts +40 -40
  24. package/dist/benchmark/AutoScrollHelper.js +90 -90
  25. package/dist/benchmark/AutoScrollHelper.js.map +1 -1
  26. package/dist/benchmark/JSFPSMonitor.d.ts +45 -45
  27. package/dist/benchmark/JSFPSMonitor.js +87 -87
  28. package/dist/benchmark/JSFPSMonitor.js.map +1 -1
  29. package/dist/benchmark/roundToDecimalPlaces.d.ts +24 -24
  30. package/dist/benchmark/roundToDecimalPlaces.js +31 -30
  31. package/dist/benchmark/roundToDecimalPlaces.js.map +1 -1
  32. package/dist/benchmark/useBenchmark.d.ts +57 -57
  33. package/dist/benchmark/useBenchmark.js +189 -188
  34. package/dist/benchmark/useBenchmark.js.map +1 -1
  35. package/dist/benchmark/useBlankAreaTracker.d.ts +56 -56
  36. package/dist/benchmark/useBlankAreaTracker.js +89 -88
  37. package/dist/benchmark/useBlankAreaTracker.js.map +1 -1
  38. package/dist/benchmark/useDataMultiplier.d.ts +31 -31
  39. package/dist/benchmark/useDataMultiplier.js +47 -46
  40. package/dist/benchmark/useDataMultiplier.js.map +1 -1
  41. package/dist/benchmark/useFlatListBenchmark.d.ts +35 -34
  42. package/dist/benchmark/useFlatListBenchmark.d.ts.map +1 -1
  43. package/dist/benchmark/useFlatListBenchmark.js +122 -121
  44. package/dist/benchmark/useFlatListBenchmark.js.map +1 -1
  45. package/dist/errors/CustomError.d.ts +30 -30
  46. package/dist/errors/CustomError.js +36 -36
  47. package/dist/errors/CustomError.js.map +1 -1
  48. package/dist/errors/ExceptionList.d.ts +46 -46
  49. package/dist/errors/ExceptionList.js +48 -48
  50. package/dist/errors/Warnings.d.ts +31 -31
  51. package/dist/errors/Warnings.js +35 -35
  52. package/dist/fabric/AutoLayoutNativeComponent.d.ts +41 -41
  53. package/dist/fabric/AutoLayoutNativeComponent.d.ts.map +1 -1
  54. package/dist/fabric/AutoLayoutNativeComponent.js +28 -28
  55. package/dist/fabric/CellContainerNativeComponent.d.ts +30 -30
  56. package/dist/fabric/CellContainerNativeComponent.d.ts.map +1 -1
  57. package/dist/fabric/CellContainerNativeComponent.js +28 -28
  58. package/dist/index.d.ts +36 -36
  59. package/dist/index.js +54 -52
  60. package/dist/index.js.map +1 -1
  61. package/dist/native/auto-layout/AutoLayoutView.d.ts +44 -44
  62. package/dist/native/auto-layout/AutoLayoutView.d.ts.map +1 -1
  63. package/dist/native/auto-layout/AutoLayoutView.js +70 -70
  64. package/dist/native/auto-layout/AutoLayoutView.js.map +1 -1
  65. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.d.ts +26 -25
  66. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.d.ts.map +1 -1
  67. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.android.js +28 -28
  68. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts +27 -27
  69. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts.map +1 -1
  70. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.d.ts +26 -25
  71. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.d.ts.map +1 -1
  72. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.harmony.js +28 -28
  73. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.d.ts +26 -25
  74. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.d.ts.map +1 -1
  75. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.ios.js +28 -28
  76. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.js +28 -28
  77. package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts +38 -38
  78. package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.js +25 -25
  79. package/dist/native/cell-container/CellContainer.android.d.ts +28 -28
  80. package/dist/native/cell-container/CellContainer.android.d.ts.map +1 -1
  81. package/dist/native/cell-container/CellContainer.android.js +31 -31
  82. package/dist/native/cell-container/CellContainer.d.ts +30 -29
  83. package/dist/native/cell-container/CellContainer.d.ts.map +1 -1
  84. package/dist/native/cell-container/CellContainer.harmony.d.ts +28 -28
  85. package/dist/native/cell-container/CellContainer.harmony.d.ts.map +1 -1
  86. package/dist/native/cell-container/CellContainer.harmony.js +31 -31
  87. package/dist/native/cell-container/CellContainer.ios.d.ts +28 -28
  88. package/dist/native/cell-container/CellContainer.ios.d.ts.map +1 -1
  89. package/dist/native/cell-container/CellContainer.ios.js +31 -31
  90. package/dist/native/cell-container/CellContainer.js +33 -33
  91. package/dist/native/cell-container/CellContainer.web.d.ts +29 -28
  92. package/dist/native/cell-container/CellContainer.web.d.ts.map +1 -1
  93. package/dist/native/cell-container/CellContainer.web.js +35 -35
  94. package/dist/native/config/PlatformHelper.android.d.ts +48 -48
  95. package/dist/native/config/PlatformHelper.android.d.ts.map +1 -1
  96. package/dist/native/config/PlatformHelper.android.js +45 -45
  97. package/dist/native/config/PlatformHelper.d.ts +48 -48
  98. package/dist/native/config/PlatformHelper.d.ts.map +1 -1
  99. package/dist/native/config/PlatformHelper.harmony.d.ts +48 -48
  100. package/dist/native/config/PlatformHelper.harmony.d.ts.map +1 -1
  101. package/dist/native/config/PlatformHelper.harmony.js +44 -44
  102. package/dist/native/config/PlatformHelper.ios.d.ts +48 -48
  103. package/dist/native/config/PlatformHelper.ios.d.ts.map +1 -1
  104. package/dist/native/config/PlatformHelper.ios.js +44 -44
  105. package/dist/native/config/PlatformHelper.js +45 -45
  106. package/dist/native/config/PlatformHelper.web.d.ts +49 -49
  107. package/dist/native/config/PlatformHelper.web.d.ts.map +1 -1
  108. package/dist/native/config/PlatformHelper.web.js +47 -47
  109. package/dist/tsconfig.tsbuildinfo +1 -1
  110. package/dist/utils/AverageWindow.d.ts +43 -43
  111. package/dist/utils/AverageWindow.js +71 -71
  112. package/dist/utils/ContentContainerUtils.d.ts +49 -49
  113. package/dist/utils/ContentContainerUtils.d.ts.map +1 -1
  114. package/dist/utils/ContentContainerUtils.js +70 -70
  115. package/dist/utils/ContentContainerUtils.js.map +1 -1
  116. package/dist/viewability/ViewToken.d.ts +30 -30
  117. package/dist/viewability/ViewToken.js +25 -25
  118. package/dist/viewability/ViewabilityHelper.d.ts +48 -48
  119. package/dist/viewability/ViewabilityHelper.js +129 -129
  120. package/dist/viewability/ViewabilityHelper.js.map +1 -1
  121. package/dist/viewability/ViewabilityManager.d.ts +47 -47
  122. package/dist/viewability/ViewabilityManager.d.ts.map +1 -1
  123. package/dist/viewability/ViewabilityManager.js +130 -130
  124. package/dist/viewability/ViewabilityManager.js.map +1 -1
  125. package/harmony/flash_list/BuildProfile.ets +16 -16
  126. package/harmony/flash_list/LICENSE +7 -7
  127. package/harmony/flash_list/build-profile.json5 +7 -7
  128. package/harmony/flash_list/hvigorfile.ts +1 -1
  129. package/harmony/flash_list/index.ets +27 -27
  130. package/harmony/flash_list/obfuscation-rules.txt +17 -17
  131. package/harmony/flash_list/oh-package.json5 +23 -23
  132. package/harmony/flash_list/src/main/cpp/AutoLayoutNode.cpp +63 -140
  133. package/harmony/flash_list/src/main/cpp/AutoLayoutNode.h +53 -53
  134. package/harmony/flash_list/src/main/cpp/AutoLayoutShadow.cpp +31 -24
  135. package/harmony/flash_list/src/main/cpp/AutoLayoutShadow.h +66 -66
  136. package/harmony/flash_list/src/main/cpp/AutoLayoutViewComponentInstance.cpp +208 -208
  137. package/harmony/flash_list/src/main/cpp/AutoLayoutViewComponentInstance.h +78 -78
  138. package/harmony/flash_list/src/main/cpp/AutoLayoutViewEventEmitRequestHandler.h +53 -53
  139. package/harmony/flash_list/src/main/cpp/AutoLayoutViewJSIBinder.h +50 -50
  140. package/harmony/flash_list/src/main/cpp/CMakeLists.txt +6 -6
  141. package/harmony/flash_list/src/main/cpp/CellContainerComponentInstance.cpp +79 -79
  142. package/harmony/flash_list/src/main/cpp/CellContainerComponentInstance.h +63 -63
  143. package/harmony/flash_list/src/main/cpp/CellContainerJSIBinder.h +38 -38
  144. package/harmony/flash_list/src/main/cpp/ComponentDescriptors.h +40 -40
  145. package/harmony/flash_list/src/main/cpp/EventEmitters.cpp +39 -39
  146. package/harmony/flash_list/src/main/cpp/EventEmitters.h +48 -48
  147. package/harmony/flash_list/src/main/cpp/FlashListPackage.h +77 -77
  148. package/harmony/flash_list/src/main/cpp/FlashListStackNode.cpp +87 -87
  149. package/harmony/flash_list/src/main/cpp/FlashListStackNode.h +56 -56
  150. package/harmony/flash_list/src/main/cpp/Props.cpp +51 -51
  151. package/harmony/flash_list/src/main/cpp/Props.h +64 -64
  152. package/harmony/flash_list/src/main/cpp/ShadowNodes.cpp +33 -33
  153. package/harmony/flash_list/src/main/cpp/ShadowNodes.h +48 -48
  154. package/harmony/flash_list/src/main/ets/Logger.ets +63 -63
  155. package/harmony/flash_list/src/main/ets/RNAutoLayoutShadow.ets +153 -153
  156. package/harmony/flash_list/src/main/ets/RNAutoLayoutView.ets +276 -276
  157. package/harmony/flash_list/src/main/ets/RNCellContainer.ets +113 -113
  158. package/harmony/flash_list/src/main/module.json5 +9 -9
  159. package/harmony/flash_list/src/main/resources/base/element/color.json +7 -7
  160. package/harmony/flash_list/src/main/resources/base/element/string.json +15 -15
  161. package/harmony/flash_list/src/main/resources/base/profile/main_pages.json +5 -5
  162. package/harmony/flash_list/src/main/resources/en_US/element/string.json +15 -15
  163. package/harmony/flash_list/src/main/resources/zh_CN/element/string.json +15 -15
  164. package/harmony/flash_list.har +0 -0
  165. package/jestSetup.js +40 -40
  166. package/package.json +82 -82
  167. package/src/AnimatedFlashList.ts +35 -35
  168. package/src/FlashList.tsx +949 -949
  169. package/src/FlashListProps.ts +359 -359
  170. package/src/GridLayoutProviderWithProps.ts +204 -204
  171. package/src/MasonryFlashList.tsx +499 -499
  172. package/src/PureComponentWrapper.tsx +65 -65
  173. package/src/benchmark/AutoScrollHelper.ts +94 -94
  174. package/src/benchmark/JSFPSMonitor.ts +98 -98
  175. package/src/benchmark/roundToDecimalPlaces.ts +28 -28
  176. package/src/benchmark/useBenchmark.ts +264 -264
  177. package/src/benchmark/useBlankAreaTracker.ts +141 -141
  178. package/src/benchmark/useDataMultiplier.ts +43 -43
  179. package/src/benchmark/useFlatListBenchmark.ts +131 -131
  180. package/src/errors/CustomError.ts +34 -34
  181. package/src/errors/ExceptionList.ts +52 -52
  182. package/src/errors/Warnings.ts +39 -39
  183. package/src/fabric/AutoLayoutNativeComponent.ts +52 -52
  184. package/src/fabric/CellContainerNativeComponent.ts +35 -35
  185. package/src/index.ts +67 -67
  186. package/src/native/auto-layout/AutoLayoutView.tsx +97 -97
  187. package/src/native/auto-layout/AutoLayoutViewNativeComponent.android.ts +31 -31
  188. package/src/native/auto-layout/AutoLayoutViewNativeComponent.harmony.ts +31 -31
  189. package/src/native/auto-layout/AutoLayoutViewNativeComponent.ios.ts +31 -31
  190. package/src/native/auto-layout/AutoLayoutViewNativeComponent.ts +31 -31
  191. package/src/native/auto-layout/AutoLayoutViewNativeComponentProps.ts +41 -41
  192. package/src/native/cell-container/CellContainer.android.ts +31 -31
  193. package/src/native/cell-container/CellContainer.harmony.ts +31 -31
  194. package/src/native/cell-container/CellContainer.ios.ts +31 -31
  195. package/src/native/cell-container/CellContainer.tsx +38 -38
  196. package/src/native/cell-container/CellContainer.web.tsx +33 -33
  197. package/src/native/config/PlatformHelper.android.ts +53 -53
  198. package/src/native/config/PlatformHelper.harmony.ts +52 -52
  199. package/src/native/config/PlatformHelper.ios.ts +52 -52
  200. package/src/native/config/PlatformHelper.ts +53 -53
  201. package/src/native/config/PlatformHelper.web.ts +58 -58
  202. package/src/utils/AverageWindow.ts +73 -73
  203. package/src/utils/ContentContainerUtils.ts +116 -116
  204. package/src/viewability/ViewToken.ts +31 -31
  205. package/src/viewability/ViewabilityHelper.ts +190 -190
  206. package/src/viewability/ViewabilityManager.ts +169 -169
package/dist/FlashList.js CHANGED
@@ -1,599 +1,600 @@
1
- "use strict";
2
- /**
3
- * MIT License
4
- *
5
- * Copyright (C) 2024 Huawei Device Co., Ltd.
6
- *
7
- * Permission is hereby granted, free of charge, to any person obtaining a copy
8
- * of this software and associated documentation files (the "Software"), to deal
9
- * in the Software without restriction, including without limitation the rights
10
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- * copies of the Software, and to permit persons to whom the Software is
12
- * furnished to do so, subject to the following conditions:
13
- *
14
- * The above copyright notice and this permission notice shall be included in all
15
- * copies or substantial portions of the Software.
16
- *
17
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
- * SOFTWARE.
24
- */
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- var tslib_1 = require("tslib");
27
- var react_1 = tslib_1.__importDefault(require("react"));
28
- var react_native_1 = require("react-native");
29
- var recyclerlistview_1 = require("recyclerlistview");
30
- var sticky_1 = tslib_1.__importDefault(require("recyclerlistview/sticky"));
31
- var AutoLayoutView_1 = tslib_1.__importDefault(require("./native/auto-layout/AutoLayoutView"));
32
- var CellContainer_1 = tslib_1.__importDefault(require("./native/cell-container/CellContainer"));
33
- var PureComponentWrapper_1 = require("./PureComponentWrapper");
34
- var GridLayoutProviderWithProps_1 = tslib_1.__importDefault(require("./GridLayoutProviderWithProps"));
35
- var CustomError_1 = tslib_1.__importDefault(require("./errors/CustomError"));
36
- var ExceptionList_1 = tslib_1.__importDefault(require("./errors/ExceptionList"));
37
- var Warnings_1 = tslib_1.__importDefault(require("./errors/Warnings"));
38
- var ViewabilityManager_1 = tslib_1.__importDefault(require("./viewability/ViewabilityManager"));
39
- var FlashListProps_1 = require("./FlashListProps");
40
- var PlatformHelper_1 = require("./native/config/PlatformHelper");
41
- var ContentContainerUtils_1 = require("./utils/ContentContainerUtils");
42
- var StickyHeaderContainer = sticky_1.default;
43
- var FlashList = /** @class */ (function (_super) {
44
- tslib_1.__extends(FlashList, _super);
45
- function FlashList(props) {
46
- var _a;
47
- var _this = _super.call(this, props) || this;
48
- _this.listFixedDimensionSize = 0;
49
- _this.distanceFromWindow = 0;
50
- _this.contentStyle = {
51
- paddingBottom: 0,
52
- paddingTop: 0,
53
- paddingLeft: 0,
54
- paddingRight: 0,
55
- };
56
- _this.loadStartTime = 0;
57
- _this.isListLoaded = false;
58
- _this.windowCorrectionConfig = {
59
- value: {
60
- windowShift: 0,
61
- startCorrection: 0,
62
- endCorrection: 0,
63
- },
64
- applyToItemScroll: true,
65
- applyToInitialOffset: true,
66
- };
67
- _this.isEmptyList = false;
68
- _this.onEndReached = function () {
69
- var _a, _b;
70
- (_b = (_a = _this.props).onEndReached) === null || _b === void 0 ? void 0 : _b.call(_a);
71
- };
72
- _this.getRefreshControl = function () {
73
- if (_this.props.onRefresh) {
74
- return (react_1.default.createElement(react_native_1.RefreshControl, { refreshing: Boolean(_this.props.refreshing), progressViewOffset: _this.props.progressViewOffset, onRefresh: _this.props.onRefresh }));
75
- }
76
- };
77
- _this.onScrollBeginDrag = function (event) {
78
- var _a, _b;
79
- _this.recordInteraction();
80
- (_b = (_a = _this.props).onScrollBeginDrag) === null || _b === void 0 ? void 0 : _b.call(_a, event);
81
- };
82
- _this.onScroll = function (event) {
83
- var _a, _b;
84
- _this.recordInteraction();
85
- _this.viewabilityManager.updateViewableItems();
86
- (_b = (_a = _this.props).onScroll) === null || _b === void 0 ? void 0 : _b.call(_a, event);
87
- };
88
- _this.handleSizeChange = function (event) {
89
- var _a;
90
- _this.validateListSize(event);
91
- var newSize = _this.props.horizontal
92
- ? event.nativeEvent.layout.height
93
- : event.nativeEvent.layout.width;
94
- var oldSize = _this.listFixedDimensionSize;
95
- _this.listFixedDimensionSize = newSize;
96
- // >0 check is to avoid rerender on mount where it would be redundant
97
- if (oldSize > 0 && oldSize !== newSize) {
98
- (_a = _this.rlvRef) === null || _a === void 0 ? void 0 : _a.forceRerender();
99
- }
100
- if (_this.props.onLayout) {
101
- _this.props.onLayout(event);
102
- }
103
- };
104
- _this.container = function (props, children) {
105
- _this.clearPostLoadTimeout();
106
- return (react_1.default.createElement(react_1.default.Fragment, null,
107
- react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { enabled: _this.isListLoaded || children.length > 0 || _this.isEmptyList, contentStyle: _this.props.contentContainerStyle, horizontal: _this.props.horizontal, header: _this.props.ListHeaderComponent, extraData: _this.state.extraData, headerStyle: _this.props.ListHeaderComponentStyle, inverted: _this.props.inverted, renderer: _this.header }),
108
- react_1.default.createElement(AutoLayoutView_1.default, tslib_1.__assign({}, props, { onBlankAreaEvent: _this.props.onBlankArea, onLayout: _this.updateDistanceFromWindow, disableAutoLayout: _this.props.disableAutoLayout }), children),
109
- _this.isEmptyList
110
- ? _this.getValidComponent(_this.props.ListEmptyComponent)
111
- : null,
112
- react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { enabled: _this.isListLoaded || children.length > 0 || _this.isEmptyList, contentStyle: _this.props.contentContainerStyle, horizontal: _this.props.horizontal, header: _this.props.ListFooterComponent, extraData: _this.state.extraData, headerStyle: _this.props.ListFooterComponentStyle, inverted: _this.props.inverted, renderer: _this.footer }),
113
- _this.getComponentForHeightMeasurement()));
114
- };
115
- _this.itemContainer = function (props, parentProps) {
116
- var _a;
117
- var CellRendererComponent = (_a = _this.props.CellRendererComponent) !== null && _a !== void 0 ? _a : CellContainer_1.default;
118
- return (react_1.default.createElement(CellRendererComponent, tslib_1.__assign({}, props, { style: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, props.style), { flexDirection: _this.props.horizontal ? "row" : "column", alignItems: "stretch" }), (0, PlatformHelper_1.getCellContainerPlatformStyles)(_this.props.inverted, parentProps)), index: parentProps.index }),
119
- react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { extendedState: parentProps.extendedState, internalSnapshot: parentProps.internalSnapshot, data: parentProps.data, arg: parentProps.index, renderer: _this.getCellContainerChild })));
120
- };
121
- _this.updateDistanceFromWindow = function (event) {
122
- var newDistanceFromWindow = _this.props.horizontal
123
- ? event.nativeEvent.layout.x
124
- : event.nativeEvent.layout.y;
125
- if (_this.distanceFromWindow !== newDistanceFromWindow) {
126
- _this.distanceFromWindow = newDistanceFromWindow;
127
- _this.windowCorrectionConfig.value.windowShift = -_this.distanceFromWindow;
128
- _this.viewabilityManager.updateViewableItems();
129
- }
130
- };
131
- _this.separator = function (index) {
132
- // Make sure we have data and don't read out of bounds
133
- if (_this.props.data === null ||
134
- _this.props.data === undefined ||
135
- index + 1 >= _this.props.data.length) {
136
- return null;
137
- }
138
- var leadingItem = _this.props.data[index];
139
- var trailingItem = _this.props.data[index + 1];
140
- var props = {
141
- leadingItem: leadingItem,
142
- trailingItem: trailingItem,
143
- // TODO: Missing sections as we don't have this feature implemented yet. Implement section, leadingSection and trailingSection.
144
- // https://github.com/facebook/react-native/blob/8bd3edec88148d0ab1f225d2119435681fbbba33/Libraries/Lists/VirtualizedSectionList.js#L285-L294
145
- };
146
- var Separator = _this.props.ItemSeparatorComponent;
147
- return Separator && react_1.default.createElement(Separator, tslib_1.__assign({}, props));
148
- };
149
- _this.header = function () {
150
- return (react_1.default.createElement(react_1.default.Fragment, null,
151
- react_1.default.createElement(react_native_1.View, { style: {
152
- paddingTop: _this.contentStyle.paddingTop,
153
- paddingLeft: _this.contentStyle.paddingLeft,
154
- } }),
155
- react_1.default.createElement(react_native_1.View, { style: [_this.props.ListHeaderComponentStyle] }, _this.getValidComponent(_this.props.ListHeaderComponent))));
156
- };
157
- _this.footer = function () {
158
- var _a;
159
- /** The web version of CellContainer uses a div directly which doesn't compose styles the way a View does.
160
- * We will skip using CellContainer on web to avoid this issue. `getFooterContainer` on web will
161
- * return a View. */
162
- var FooterContainer = (_a = (0, PlatformHelper_1.getFooterContainer)()) !== null && _a !== void 0 ? _a : CellContainer_1.default;
163
- return (react_1.default.createElement(react_1.default.Fragment, null,
164
- react_1.default.createElement(FooterContainer, { index: -1, style: [_this.props.ListFooterComponentStyle] }, _this.getValidComponent(_this.props.ListFooterComponent)),
165
- react_1.default.createElement(react_native_1.View, { style: {
166
- paddingBottom: _this.contentStyle.paddingBottom,
167
- paddingRight: _this.contentStyle.paddingRight,
168
- } })));
169
- };
170
- _this.getComponentForHeightMeasurement = function () {
171
- return _this.props.horizontal &&
172
- !_this.props.disableHorizontalListHeightMeasurement &&
173
- !_this.isListLoaded &&
174
- _this.state.dataProvider.getSize() > 0 ? (react_1.default.createElement(react_native_1.View, { style: { opacity: 0 }, pointerEvents: "none" }, _this.rowRendererWithIndex(Math.min(_this.state.dataProvider.getSize() - 1, 1), FlashListProps_1.RenderTargetOptions.Measurement))) : null;
175
- };
176
- _this.applyWindowCorrection = function (_, __, correctionObject) {
177
- var _a;
178
- correctionObject.windowShift = -_this.distanceFromWindow;
179
- (_a = _this.stickyContentContainerRef) === null || _a === void 0 ? void 0 : _a.setEnabled(_this.isStickyEnabled);
180
- };
181
- _this.rowRendererSticky = function (index) {
182
- return _this.rowRendererWithIndex(index, FlashListProps_1.RenderTargetOptions.StickyHeader);
183
- };
184
- _this.rowRendererWithIndex = function (index, target) {
185
- var _a, _b, _c;
186
- // known issue: expected to pass separators which isn't available in RLV
187
- return (_b = (_a = _this.props).renderItem) === null || _b === void 0 ? void 0 : _b.call(_a, {
188
- item: _this.state.data[index],
189
- index: index,
190
- target: target,
191
- extraData: (_c = _this.state.extraData) === null || _c === void 0 ? void 0 : _c.value,
192
- });
193
- };
194
- /**
195
- * This will prevent render item calls unless data changes.
196
- * Output of this method is received as children object so returning null here is no issue as long as we handle it inside our child container.
197
- * @module getCellContainerChild acts as the new rowRenderer and is called directly from our child container.
198
- */
199
- _this.emptyRowRenderer = function () {
200
- return null;
201
- };
202
- _this.getCellContainerChild = function (index) {
203
- return (react_1.default.createElement(react_1.default.Fragment, null,
204
- react_1.default.createElement(react_native_1.View, { style: {
205
- flexDirection: _this.props.horizontal || _this.props.numColumns === 1
206
- ? "column"
207
- : "row",
208
- } }, _this.rowRendererWithIndex(index, FlashListProps_1.RenderTargetOptions.Cell)),
209
- _this.separator(index)));
210
- };
211
- _this.recyclerRef = function (ref) {
212
- _this.rlvRef = ref;
213
- };
214
- _this.stickyContentRef = function (ref) {
215
- _this.stickyContentContainerRef = ref;
216
- };
217
- _this.stickyOverrideRowRenderer = function (_, rowData, index, ___) {
218
- return (react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { ref: _this.stickyContentRef, enabled: _this.isStickyEnabled,
219
- // We're passing rowData to ensure that sticky headers are updated when data changes
220
- rowData: rowData, arg: index, renderer: _this.rowRendererSticky }));
221
- };
222
- _this.onItemLayout = function (index) {
223
- // Informing the layout provider about change to an item's layout. It already knows the dimensions so there's not need to pass them.
224
- _this.state.layoutProvider.reportItemLayout(index);
225
- _this.raiseOnLoadEventIfNeeded();
226
- };
227
- _this.raiseOnLoadEventIfNeeded = function () {
228
- var _a, _b;
229
- if (!_this.isListLoaded) {
230
- _this.isListLoaded = true;
231
- (_b = (_a = _this.props).onLoad) === null || _b === void 0 ? void 0 : _b.call(_a, {
232
- elapsedTimeInMs: Date.now() - _this.loadStartTime,
233
- });
234
- _this.runAfterOnLoad();
235
- }
236
- };
237
- _this.runAfterOnLoad = function () {
238
- if (_this.props.estimatedItemSize === undefined) {
239
- _this.itemSizeWarningTimeoutId = setTimeout(function () {
240
- var averageItemSize = Math.floor(_this.state.layoutProvider.averageItemSize);
241
- console.warn(Warnings_1.default.estimatedItemSizeMissingWarning.replace("@size", averageItemSize.toString()));
242
- }, 1000);
243
- }
244
- _this.postLoadTimeoutId = setTimeout(function () {
245
- // This force update is required to remove dummy element rendered to measure horizontal list height when the list doesn't update on its own.
246
- // In most cases this timeout will never be triggered because list usually updates atleast once and this timeout is cleared on update.
247
- if (_this.props.horizontal) {
248
- _this.forceUpdate();
249
- }
250
- }, 500);
251
- };
252
- _this.clearPostLoadTimeout = function () {
253
- if (_this.postLoadTimeoutId !== undefined) {
254
- clearTimeout(_this.postLoadTimeoutId);
255
- _this.postLoadTimeoutId = undefined;
256
- }
257
- };
258
- _this.clearRenderSizeWarningTimeout = function () {
259
- if (_this.renderedSizeWarningTimeoutId !== undefined) {
260
- clearTimeout(_this.renderedSizeWarningTimeoutId);
261
- _this.renderedSizeWarningTimeoutId = undefined;
262
- }
263
- };
264
- /**
265
- * Tells the list an interaction has occurred, which should trigger viewability calculations, e.g. if waitForInteractions is true and the user has not scrolled.
266
- * This is typically called by taps on items or by navigation actions.
267
- */
268
- _this.recordInteraction = function () {
269
- _this.viewabilityManager.recordInteraction();
270
- };
271
- /**
272
- * Retriggers viewability calculations. Useful to imperatively trigger viewability calculations.
273
- */
274
- _this.recomputeViewableItems = function () {
275
- _this.viewabilityManager.recomputeViewableItems();
276
- };
277
- _this.loadStartTime = Date.now();
278
- _this.validateProps();
279
- if (props.estimatedListSize) {
280
- if (props.horizontal) {
281
- _this.listFixedDimensionSize = props.estimatedListSize.height;
282
- }
283
- else {
284
- _this.listFixedDimensionSize = props.estimatedListSize.width;
285
- }
286
- }
287
- _this.distanceFromWindow =
288
- (_a = props.estimatedFirstItemOffset) !== null && _a !== void 0 ? _a : ((props.ListHeaderComponent && 1) || 0);
289
- // eslint-disable-next-line react/state-in-constructor
290
- _this.state = FlashList.getInitialMutableState(_this);
291
- _this.viewabilityManager = new ViewabilityManager_1.default(_this);
292
- _this.itemAnimator = (0, PlatformHelper_1.getItemAnimator)();
293
- return _this;
294
- }
295
- FlashList.prototype.validateProps = function () {
296
- var _a, _b;
297
- if (this.props.onRefresh && typeof this.props.refreshing !== "boolean") {
298
- throw new CustomError_1.default(ExceptionList_1.default.refreshBooleanMissing);
299
- }
300
- if (Number((_a = this.props.stickyHeaderIndices) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
301
- this.props.horizontal) {
302
- throw new CustomError_1.default(ExceptionList_1.default.stickyWhileHorizontalNotSupported);
303
- }
304
- if (Number(this.props.numColumns) > 1 && this.props.horizontal) {
305
- throw new CustomError_1.default(ExceptionList_1.default.columnsWhileHorizontalNotSupported);
306
- }
307
- // `createAnimatedComponent` always passes a blank style object. To avoid warning while using AnimatedFlashList we've modified the check
308
- // `style` prop can be an array. So we need to validate every object in array. Check: https://github.com/Shopify/flash-list/issues/651
309
- if (__DEV__ &&
310
- Object.keys(react_native_1.StyleSheet.flatten((_b = this.props.style) !== null && _b !== void 0 ? _b : {})).length > 0) {
311
- console.warn(Warnings_1.default.styleUnsupported);
312
- }
313
- if ((0, ContentContainerUtils_1.hasUnsupportedKeysInContentContainerStyle)(this.props.contentContainerStyle)) {
314
- console.warn(Warnings_1.default.styleContentContainerUnsupported);
315
- }
316
- };
317
- // Some of the state variables need to update when props change
318
- FlashList.getDerivedStateFromProps = function (nextProps, prevState) {
319
- var _a, _b, _c;
320
- var newState = tslib_1.__assign({}, prevState);
321
- if (prevState.numColumns !== nextProps.numColumns) {
322
- newState.numColumns = nextProps.numColumns || 1;
323
- newState.layoutProvider = FlashList.getLayoutProvider(newState.numColumns, nextProps);
324
- }
325
- else if (prevState.layoutProvider.updateProps(nextProps).hasExpired) {
326
- newState.layoutProvider = FlashList.getLayoutProvider(newState.numColumns, nextProps);
327
- }
328
- // RLV retries to reposition the first visible item on layout provider change.
329
- // It's not required in our case so we're disabling it
330
- newState.layoutProvider.shouldRefreshWithAnchoring = Boolean(!((_a = prevState.layoutProvider) === null || _a === void 0 ? void 0 : _a.hasExpired));
331
- if (nextProps.data !== prevState.data || prevState.lastInverted !== nextProps.inverted) {
332
- var processedData = nextProps.inverted
333
- ? (nextProps.data ? tslib_1.__spreadArray([], tslib_1.__read(nextProps.data), false).reverse() : nextProps.data)
334
- : nextProps.data;
335
- newState.data = processedData;
336
- newState.dataProvider = prevState.dataProvider.cloneWithRows(processedData);
337
- if (nextProps.renderItem !== prevState.renderItem) {
338
- newState.extraData = tslib_1.__assign({}, prevState.extraData);
339
- }
340
- }
341
- if (nextProps.extraData !== ((_b = prevState.extraData) === null || _b === void 0 ? void 0 : _b.value)) {
342
- newState.extraData = { value: nextProps.extraData };
343
- }
344
- newState.renderItem = nextProps.renderItem;
345
- newState.lastInverted = (_c = nextProps.inverted) !== null && _c !== void 0 ? _c : undefined;
346
- return newState;
347
- };
348
- FlashList.getInitialMutableState = function (flashList) {
349
- var getStableId;
350
- if (flashList.props.keyExtractor !== null &&
351
- flashList.props.keyExtractor !== undefined) {
352
- getStableId = function (index) {
353
- // We assume `keyExtractor` function will never change from being `null | undefined` to defined and vice versa.
354
- // Similarly, data should never be `null | undefined` when `getStableId` is called.
355
- return (flashList.props.keyExtractor)(flashList.props.data[index], index).toString();
356
- };
357
- }
358
- return {
359
- data: null,
360
- layoutProvider: null,
361
- dataProvider: new recyclerlistview_1.DataProvider(function (r1, r2) {
362
- return r1 !== r2;
363
- }, getStableId),
364
- numColumns: 0,
365
- };
366
- };
367
- // Using only grid layout provider as it can also act as a listview, sizeProvider is a function to support future overrides
368
- FlashList.getLayoutProvider = function (numColumns, flashListProps) {
369
- return new GridLayoutProviderWithProps_1.default(
370
- // max span or, total columns
371
- numColumns, function (index, props) {
372
- var _a;
373
- // type of the item for given index
374
- var type = (_a = props.getItemType) === null || _a === void 0 ? void 0 : _a.call(props, props.data[index], index, props.extraData);
375
- return type || 0;
376
- }, function (index, props, mutableLayout) {
377
- var _a, _b;
378
- // span of the item at given index, item can choose to span more than one column
379
- (_a = props.overrideItemLayout) === null || _a === void 0 ? void 0 : _a.call(props, mutableLayout, props.data[index], index, numColumns, props.extraData);
380
- return (_b = mutableLayout === null || mutableLayout === void 0 ? void 0 : mutableLayout.span) !== null && _b !== void 0 ? _b : 1;
381
- }, function (index, props, mutableLayout) {
382
- var _a;
383
- // estimated size of the item an given index
384
- (_a = props.overrideItemLayout) === null || _a === void 0 ? void 0 : _a.call(props, mutableLayout, props.data[index], index, numColumns, props.extraData);
385
- console.log('mutableLayout:', mutableLayout);
386
- return mutableLayout === null || mutableLayout === void 0 ? void 0 : mutableLayout.size;
387
- }, flashListProps);
388
- };
389
- FlashList.prototype.componentDidMount = function () {
390
- var _a;
391
- if (((_a = this.props.data) === null || _a === void 0 ? void 0 : _a.length) === 0) {
392
- this.raiseOnLoadEventIfNeeded();
393
- }
394
- };
395
- FlashList.prototype.componentWillUnmount = function () {
396
- this.viewabilityManager.dispose();
397
- this.clearPostLoadTimeout();
398
- this.clearRenderSizeWarningTimeout();
399
- if (this.itemSizeWarningTimeoutId !== undefined) {
400
- clearTimeout(this.itemSizeWarningTimeoutId);
401
- }
402
- };
403
- FlashList.prototype.render = function () {
404
- this.isEmptyList = this.state.dataProvider.getSize() === 0;
405
- (0, ContentContainerUtils_1.updateContentStyle)(this.contentStyle, this.props.contentContainerStyle);
406
- var _a = this.props, drawDistance = _a.drawDistance, removeClippedSubviews = _a.removeClippedSubviews, stickyHeaderIndices = _a.stickyHeaderIndices, horizontal = _a.horizontal, onEndReachedThreshold = _a.onEndReachedThreshold, estimatedListSize = _a.estimatedListSize, initialScrollIndex = _a.initialScrollIndex, style = _a.style, contentContainerStyle = _a.contentContainerStyle, renderScrollComponent = _a.renderScrollComponent, restProps = tslib_1.__rest(_a, ["drawDistance", "removeClippedSubviews", "stickyHeaderIndices", "horizontal", "onEndReachedThreshold", "estimatedListSize", "initialScrollIndex", "style", "contentContainerStyle", "renderScrollComponent"]);
407
- // RecyclerListView simply ignores if initialScrollIndex is set to 0 because it doesn't understand headers
408
- // Using initialOffset to force RLV to scroll to the right place
409
- var initialOffset = (this.isInitialScrollIndexInFirstRow() && this.distanceFromWindow) ||
410
- undefined;
411
- var finalDrawDistance = drawDistance === undefined
412
- ? PlatformHelper_1.PlatformConfig.defaultDrawDistance
413
- : drawDistance;
414
- return (react_1.default.createElement(StickyHeaderContainer, { overrideRowRenderer: this.stickyOverrideRowRenderer, applyWindowCorrection: this.applyWindowCorrection, stickyHeaderIndices: stickyHeaderIndices, style: this.props.horizontal
415
- ? {}
416
- : { flex: 1, overflow: "hidden" } },
417
- react_1.default.createElement(recyclerlistview_1.ProgressiveListView, tslib_1.__assign({}, restProps, { ref: this.recyclerRef, layoutProvider: this.state.layoutProvider, dataProvider: this.state.dataProvider, rowRenderer: this.emptyRowRenderer, canChangeSize: true, isHorizontal: Boolean(horizontal), scrollViewProps: tslib_1.__assign({ onScrollBeginDrag: this.onScrollBeginDrag, onLayout: this.handleSizeChange, refreshControl: this.props.refreshControl || this.getRefreshControl(),
418
- // Min values are being used to suppress RLV's bounded exception
419
- style: { minHeight: 1, minWidth: 1 }, contentContainerStyle: tslib_1.__assign({ backgroundColor: this.contentStyle.backgroundColor,
420
- // Required to handle a scrollview bug. Check: https://github.com/Shopify/flash-list/pull/187
421
- minHeight: 1, minWidth: 1 }, (0, ContentContainerUtils_1.getContentContainerPadding)(this.contentStyle, horizontal)) }, this.props.overrideProps), forceNonDeterministicRendering: true, renderItemContainer: this.itemContainer, renderContentContainer: this.container, onEndReached: this.onEndReached, onEndReachedThresholdRelative: onEndReachedThreshold || undefined, extendedState: this.state.extraData, layoutSize: estimatedListSize, maxRenderAhead: 3 * finalDrawDistance, finalRenderAheadOffset: finalDrawDistance, renderAheadStep: finalDrawDistance, initialRenderIndex: (!this.isInitialScrollIndexInFirstRow() && initialScrollIndex) ||
422
- undefined, initialOffset: initialOffset, onItemLayout: this.onItemLayout, onScroll: this.onScroll, onVisibleIndicesChanged: this.viewabilityManager.shouldListenToVisibleIndices
423
- ? this.viewabilityManager.onVisibleIndicesChanged
424
- : undefined, windowCorrectionConfig: this.getUpdatedWindowCorrectionConfig(), itemAnimator: this.itemAnimator, suppressBoundedSizeException: true, externalScrollView: renderScrollComponent }))));
425
- };
426
- FlashList.prototype.getUpdatedWindowCorrectionConfig = function () {
427
- // If the initial scroll index is in the first row then we're forcing RLV to use initialOffset and thus we need to disable window correction
428
- // This isn't clean but it's the only way to get RLV to scroll to the right place
429
- // TODO: Remove this when RLV fixes this. Current implementation will also fail if column span is overridden in the first row.
430
- if (this.isInitialScrollIndexInFirstRow()) {
431
- this.windowCorrectionConfig.applyToInitialOffset = false;
432
- }
433
- else {
434
- this.windowCorrectionConfig.applyToInitialOffset = true;
435
- }
436
- this.windowCorrectionConfig.value.windowShift = -this.distanceFromWindow;
437
- return this.windowCorrectionConfig;
438
- };
439
- FlashList.prototype.isInitialScrollIndexInFirstRow = function () {
440
- var _a;
441
- return (((_a = this.props.initialScrollIndex) !== null && _a !== void 0 ? _a : this.state.numColumns) <
442
- this.state.numColumns);
443
- };
444
- FlashList.prototype.validateListSize = function (event) {
445
- var _a = event.nativeEvent.layout, height = _a.height, width = _a.width;
446
- this.clearRenderSizeWarningTimeout();
447
- if (Math.floor(height) <= 1 || Math.floor(width) <= 1) {
448
- this.renderedSizeWarningTimeoutId = setTimeout(function () {
449
- console.warn(Warnings_1.default.unusableRenderedSize);
450
- }, 1000);
451
- }
452
- };
453
- FlashList.prototype.getValidComponent = function (component) {
454
- var PassedComponent = component;
455
- return ((react_1.default.isValidElement(PassedComponent) && PassedComponent) ||
456
- (PassedComponent && react_1.default.createElement(PassedComponent, null)) ||
457
- null);
458
- };
459
- Object.defineProperty(FlashList.prototype, "isStickyEnabled", {
460
- get: function () {
461
- var _a;
462
- var currentOffset = ((_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getCurrentScrollOffset()) || 0;
463
- return currentOffset >= this.distanceFromWindow;
464
- },
465
- enumerable: false,
466
- configurable: true
467
- });
468
- /**
469
- * Disables recycling for the next frame so that layout animations run well.
470
- * Warning: Avoid this when making large changes to the data as the list might draw too much to run animations. Single item insertions/deletions
471
- * should be good. With recycling paused the list cannot do much optimization.
472
- * The next render will run as normal and reuse items.
473
- */
474
- FlashList.prototype.prepareForLayoutAnimationRender = function () {
475
- var _a;
476
- if (this.props.keyExtractor === null ||
477
- this.props.keyExtractor === undefined) {
478
- console.warn(Warnings_1.default.missingKeyExtractor);
479
- }
480
- else {
481
- (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.prepareForLayoutAnimationRender();
482
- }
483
- };
484
- FlashList.prototype.scrollToEnd = function (params) {
485
- var _a;
486
- (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.scrollToEnd(Boolean(params === null || params === void 0 ? void 0 : params.animated));
487
- };
488
- FlashList.prototype.scrollToIndex = function (params) {
489
- var _a, _b, _c, _d, _e;
490
- var layout = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getLayout(params.index);
491
- var listSize = (_b = this.rlvRef) === null || _b === void 0 ? void 0 : _b.getRenderedSize();
492
- if (layout && listSize) {
493
- var itemOffset = this.props.horizontal ? layout.x : layout.y;
494
- var fixedDimension = this.props.horizontal
495
- ? listSize.width
496
- : listSize.height;
497
- var itemSize = this.props.horizontal ? layout.width : layout.height;
498
- var scrollOffset = Math.max(0, itemOffset - ((_c = params.viewPosition) !== null && _c !== void 0 ? _c : 0) * (fixedDimension - itemSize)) - ((_d = params.viewOffset) !== null && _d !== void 0 ? _d : 0);
499
- (_e = this.rlvRef) === null || _e === void 0 ? void 0 : _e.scrollToOffset(scrollOffset, scrollOffset, Boolean(params.animated), true);
500
- }
501
- };
502
- FlashList.prototype.scrollToItem = function (params) {
503
- var _a, _b;
504
- var index = (_b = (_a = this.props.data) === null || _a === void 0 ? void 0 : _a.indexOf(params.item)) !== null && _b !== void 0 ? _b : -1;
505
- if (index >= 0) {
506
- this.scrollToIndex(tslib_1.__assign(tslib_1.__assign({}, params), { index: index }));
507
- }
508
- };
509
- FlashList.prototype.scrollToOffset = function (params) {
510
- var _a;
511
- var x = this.props.horizontal ? params.offset : 0;
512
- var y = this.props.horizontal ? 0 : params.offset;
513
- (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.scrollToOffset(x, y, Boolean(params.animated));
514
- };
515
- FlashList.prototype.getScrollableNode = function () {
516
- var _a, _b;
517
- return ((_b = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getScrollableNode) === null || _b === void 0 ? void 0 : _b.call(_a)) || null;
518
- };
519
- Object.defineProperty(FlashList.prototype, "recyclerlistview_unsafe", {
520
- /**
521
- * Allows access to internal recyclerlistview. This is useful for enabling access to its public APIs.
522
- * Warning: We may swap recyclerlistview for something else in the future. Use with caution.
523
- */
524
- /* eslint-disable @typescript-eslint/naming-convention */
525
- get: function () {
526
- return this.rlvRef;
527
- },
528
- enumerable: false,
529
- configurable: true
530
- });
531
- Object.defineProperty(FlashList.prototype, "firstItemOffset", {
532
- /**
533
- * Specifies how far the first item is from top of the list. This would normally be a sum of header size and top/left padding applied to the list.
534
- */
535
- get: function () {
536
- return this.distanceFromWindow;
537
- },
538
- enumerable: false,
539
- configurable: true
540
- });
541
- /**
542
- * FlashList will skip using layout cache on next update. Can be useful when you know the layout will change drastically for example, orientation change when used as a carousel.
543
- */
544
- FlashList.prototype.clearLayoutCacheOnUpdate = function () {
545
- this.state.layoutProvider.markExpired();
546
- };
547
- /**
548
- * Returns the dimensions of the child container.
549
- * @returns {Object} The dimensions of the child container.
550
- */
551
- FlashList.prototype.getChildContainerDimensions = function () {
552
- var _a;
553
- return (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getContentDimension();
554
- };
555
- /**
556
- * Returns the layout of the item at the given index.
557
- * @param index - The index of the item to get the layout for.
558
- * @returns {Object} The layout of the item at the given index.
559
- */
560
- FlashList.prototype.getLayout = function (index) {
561
- var _a;
562
- var l = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getLayout(index);
563
- return l;
564
- };
565
- /**
566
- * Returns the size of the list.
567
- * @returns {Object} The size of the list.
568
- */
569
- FlashList.prototype.getWindowSize = function () {
570
- var _a;
571
- return (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getRenderedSize();
572
- };
573
- /**
574
- * Returns the absolute last scroll offset of the list.
575
- * @returns {number} The absolute last scroll offset of the list.
576
- */
577
- FlashList.prototype.getAbsoluteLastScrollOffset = function () {
578
- var _a, _b;
579
- return (_b = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getCurrentScrollOffset()) !== null && _b !== void 0 ? _b : 0;
580
- };
581
- /**
582
- * Returns the first item offset of the list.
583
- * @returns {number} The first item offset of the list.
584
- */
585
- FlashList.prototype.getFirstItemOffset = function () {
586
- return this.firstItemOffset;
587
- };
588
- FlashList.prototype.getFirstVisibleIndex = function () {
589
- var _a, _b;
590
- return (_b = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.findApproxFirstVisibleIndex()) !== null && _b !== void 0 ? _b : -1;
591
- };
592
- FlashList.defaultProps = {
593
- data: [],
594
- numColumns: 1,
595
- };
596
- return FlashList;
597
- }(react_1.default.PureComponent));
598
- exports.default = FlashList;
1
+ "use strict";
2
+ /**
3
+ * MIT License
4
+ *
5
+ * Copyright (C) 2024 Huawei Device Co., Ltd.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ var tslib_1 = require("tslib");
27
+ var react_1 = tslib_1.__importDefault(require("react"));
28
+ var react_native_1 = require("react-native");
29
+ var recyclerlistview_1 = require("recyclerlistview");
30
+ var sticky_1 = tslib_1.__importDefault(require("recyclerlistview/sticky"));
31
+ var AutoLayoutView_1 = tslib_1.__importDefault(require("./native/auto-layout/AutoLayoutView"));
32
+ var CellContainer_1 = tslib_1.__importDefault(require("./native/cell-container/CellContainer"));
33
+ var PureComponentWrapper_1 = require("./PureComponentWrapper");
34
+ var GridLayoutProviderWithProps_1 = tslib_1.__importDefault(require("./GridLayoutProviderWithProps"));
35
+ var CustomError_1 = tslib_1.__importDefault(require("./errors/CustomError"));
36
+ var ExceptionList_1 = tslib_1.__importDefault(require("./errors/ExceptionList"));
37
+ var Warnings_1 = tslib_1.__importDefault(require("./errors/Warnings"));
38
+ var ViewabilityManager_1 = tslib_1.__importDefault(require("./viewability/ViewabilityManager"));
39
+ var FlashListProps_1 = require("./FlashListProps");
40
+ var PlatformHelper_1 = require("./native/config/PlatformHelper");
41
+ var ContentContainerUtils_1 = require("./utils/ContentContainerUtils");
42
+ var StickyHeaderContainer = sticky_1.default;
43
+ var FlashList = /** @class */ (function (_super) {
44
+ tslib_1.__extends(FlashList, _super);
45
+ function FlashList(props) {
46
+ var _this = this;
47
+ var _a;
48
+ _this = _super.call(this, props) || this;
49
+ _this.listFixedDimensionSize = 0;
50
+ _this.distanceFromWindow = 0;
51
+ _this.contentStyle = {
52
+ paddingBottom: 0,
53
+ paddingTop: 0,
54
+ paddingLeft: 0,
55
+ paddingRight: 0,
56
+ };
57
+ _this.loadStartTime = 0;
58
+ _this.isListLoaded = false;
59
+ _this.windowCorrectionConfig = {
60
+ value: {
61
+ windowShift: 0,
62
+ startCorrection: 0,
63
+ endCorrection: 0,
64
+ },
65
+ applyToItemScroll: true,
66
+ applyToInitialOffset: true,
67
+ };
68
+ _this.isEmptyList = false;
69
+ _this.onEndReached = function () {
70
+ var _a, _b;
71
+ (_b = (_a = _this.props).onEndReached) === null || _b === void 0 ? void 0 : _b.call(_a);
72
+ };
73
+ _this.getRefreshControl = function () {
74
+ if (_this.props.onRefresh) {
75
+ return (react_1.default.createElement(react_native_1.RefreshControl, { refreshing: Boolean(_this.props.refreshing), progressViewOffset: _this.props.progressViewOffset, onRefresh: _this.props.onRefresh }));
76
+ }
77
+ };
78
+ _this.onScrollBeginDrag = function (event) {
79
+ var _a, _b;
80
+ _this.recordInteraction();
81
+ (_b = (_a = _this.props).onScrollBeginDrag) === null || _b === void 0 ? void 0 : _b.call(_a, event);
82
+ };
83
+ _this.onScroll = function (event) {
84
+ var _a, _b;
85
+ _this.recordInteraction();
86
+ _this.viewabilityManager.updateViewableItems();
87
+ (_b = (_a = _this.props).onScroll) === null || _b === void 0 ? void 0 : _b.call(_a, event);
88
+ };
89
+ _this.handleSizeChange = function (event) {
90
+ var _a;
91
+ _this.validateListSize(event);
92
+ var newSize = _this.props.horizontal
93
+ ? event.nativeEvent.layout.height
94
+ : event.nativeEvent.layout.width;
95
+ var oldSize = _this.listFixedDimensionSize;
96
+ _this.listFixedDimensionSize = newSize;
97
+ // >0 check is to avoid rerender on mount where it would be redundant
98
+ if (oldSize > 0 && oldSize !== newSize) {
99
+ (_a = _this.rlvRef) === null || _a === void 0 ? void 0 : _a.forceRerender();
100
+ }
101
+ if (_this.props.onLayout) {
102
+ _this.props.onLayout(event);
103
+ }
104
+ };
105
+ _this.container = function (props, children) {
106
+ _this.clearPostLoadTimeout();
107
+ return (react_1.default.createElement(react_1.default.Fragment, null,
108
+ react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { enabled: _this.isListLoaded || children.length > 0 || _this.isEmptyList, contentStyle: _this.props.contentContainerStyle, horizontal: _this.props.horizontal, header: _this.props.ListHeaderComponent, extraData: _this.state.extraData, headerStyle: _this.props.ListHeaderComponentStyle, inverted: _this.props.inverted, renderer: _this.header }),
109
+ react_1.default.createElement(AutoLayoutView_1.default, tslib_1.__assign({}, props, { onBlankAreaEvent: _this.props.onBlankArea, onLayout: _this.updateDistanceFromWindow, disableAutoLayout: _this.props.disableAutoLayout }), children),
110
+ _this.isEmptyList
111
+ ? _this.getValidComponent(_this.props.ListEmptyComponent)
112
+ : null,
113
+ react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { enabled: _this.isListLoaded || children.length > 0 || _this.isEmptyList, contentStyle: _this.props.contentContainerStyle, horizontal: _this.props.horizontal, header: _this.props.ListFooterComponent, extraData: _this.state.extraData, headerStyle: _this.props.ListFooterComponentStyle, inverted: _this.props.inverted, renderer: _this.footer }),
114
+ _this.getComponentForHeightMeasurement()));
115
+ };
116
+ _this.itemContainer = function (props, parentProps) {
117
+ var _a;
118
+ var CellRendererComponent = (_a = _this.props.CellRendererComponent) !== null && _a !== void 0 ? _a : CellContainer_1.default;
119
+ return (react_1.default.createElement(CellRendererComponent, tslib_1.__assign({}, props, { style: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, props.style), { flexDirection: _this.props.horizontal ? "row" : "column", alignItems: "stretch" }), (0, PlatformHelper_1.getCellContainerPlatformStyles)(_this.props.inverted, parentProps)), index: parentProps.index }),
120
+ react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { extendedState: parentProps.extendedState, internalSnapshot: parentProps.internalSnapshot, data: parentProps.data, arg: parentProps.index, renderer: _this.getCellContainerChild })));
121
+ };
122
+ _this.updateDistanceFromWindow = function (event) {
123
+ var newDistanceFromWindow = _this.props.horizontal
124
+ ? event.nativeEvent.layout.x
125
+ : event.nativeEvent.layout.y;
126
+ if (_this.distanceFromWindow !== newDistanceFromWindow) {
127
+ _this.distanceFromWindow = newDistanceFromWindow;
128
+ _this.windowCorrectionConfig.value.windowShift = -_this.distanceFromWindow;
129
+ _this.viewabilityManager.updateViewableItems();
130
+ }
131
+ };
132
+ _this.separator = function (index) {
133
+ // Make sure we have data and don't read out of bounds
134
+ if (_this.props.data === null ||
135
+ _this.props.data === undefined ||
136
+ index + 1 >= _this.props.data.length) {
137
+ return null;
138
+ }
139
+ var leadingItem = _this.props.data[index];
140
+ var trailingItem = _this.props.data[index + 1];
141
+ var props = {
142
+ leadingItem: leadingItem,
143
+ trailingItem: trailingItem,
144
+ // TODO: Missing sections as we don't have this feature implemented yet. Implement section, leadingSection and trailingSection.
145
+ // https://github.com/facebook/react-native/blob/8bd3edec88148d0ab1f225d2119435681fbbba33/Libraries/Lists/VirtualizedSectionList.js#L285-L294
146
+ };
147
+ var Separator = _this.props.ItemSeparatorComponent;
148
+ return Separator && react_1.default.createElement(Separator, tslib_1.__assign({}, props));
149
+ };
150
+ _this.header = function () {
151
+ return (react_1.default.createElement(react_1.default.Fragment, null,
152
+ react_1.default.createElement(react_native_1.View, { style: {
153
+ paddingTop: _this.contentStyle.paddingTop,
154
+ paddingLeft: _this.contentStyle.paddingLeft,
155
+ } }),
156
+ react_1.default.createElement(react_native_1.View, { style: [_this.props.ListHeaderComponentStyle] }, _this.getValidComponent(_this.props.ListHeaderComponent))));
157
+ };
158
+ _this.footer = function () {
159
+ var _a;
160
+ /** The web version of CellContainer uses a div directly which doesn't compose styles the way a View does.
161
+ * We will skip using CellContainer on web to avoid this issue. `getFooterContainer` on web will
162
+ * return a View. */
163
+ var FooterContainer = (_a = (0, PlatformHelper_1.getFooterContainer)()) !== null && _a !== void 0 ? _a : CellContainer_1.default;
164
+ return (react_1.default.createElement(react_1.default.Fragment, null,
165
+ react_1.default.createElement(FooterContainer, { index: -1, style: [_this.props.ListFooterComponentStyle] }, _this.getValidComponent(_this.props.ListFooterComponent)),
166
+ react_1.default.createElement(react_native_1.View, { style: {
167
+ paddingBottom: _this.contentStyle.paddingBottom,
168
+ paddingRight: _this.contentStyle.paddingRight,
169
+ } })));
170
+ };
171
+ _this.getComponentForHeightMeasurement = function () {
172
+ return _this.props.horizontal &&
173
+ !_this.props.disableHorizontalListHeightMeasurement &&
174
+ !_this.isListLoaded &&
175
+ _this.state.dataProvider.getSize() > 0 ? (react_1.default.createElement(react_native_1.View, { style: { opacity: 0 }, pointerEvents: "none" }, _this.rowRendererWithIndex(Math.min(_this.state.dataProvider.getSize() - 1, 1), FlashListProps_1.RenderTargetOptions.Measurement))) : null;
176
+ };
177
+ _this.applyWindowCorrection = function (_, __, correctionObject) {
178
+ var _a;
179
+ correctionObject.windowShift = -_this.distanceFromWindow;
180
+ (_a = _this.stickyContentContainerRef) === null || _a === void 0 ? void 0 : _a.setEnabled(_this.isStickyEnabled);
181
+ };
182
+ _this.rowRendererSticky = function (index) {
183
+ return _this.rowRendererWithIndex(index, FlashListProps_1.RenderTargetOptions.StickyHeader);
184
+ };
185
+ _this.rowRendererWithIndex = function (index, target) {
186
+ var _a, _b, _c;
187
+ // known issue: expected to pass separators which isn't available in RLV
188
+ return (_b = (_a = _this.props).renderItem) === null || _b === void 0 ? void 0 : _b.call(_a, {
189
+ item: _this.state.data[index],
190
+ index: index,
191
+ target: target,
192
+ extraData: (_c = _this.state.extraData) === null || _c === void 0 ? void 0 : _c.value,
193
+ });
194
+ };
195
+ /**
196
+ * This will prevent render item calls unless data changes.
197
+ * Output of this method is received as children object so returning null here is no issue as long as we handle it inside our child container.
198
+ * @module getCellContainerChild acts as the new rowRenderer and is called directly from our child container.
199
+ */
200
+ _this.emptyRowRenderer = function () {
201
+ return null;
202
+ };
203
+ _this.getCellContainerChild = function (index) {
204
+ return (react_1.default.createElement(react_1.default.Fragment, null,
205
+ react_1.default.createElement(react_native_1.View, { style: {
206
+ flexDirection: _this.props.horizontal || _this.props.numColumns === 1
207
+ ? "column"
208
+ : "row",
209
+ } }, _this.rowRendererWithIndex(index, FlashListProps_1.RenderTargetOptions.Cell)),
210
+ _this.separator(index)));
211
+ };
212
+ _this.recyclerRef = function (ref) {
213
+ _this.rlvRef = ref;
214
+ };
215
+ _this.stickyContentRef = function (ref) {
216
+ _this.stickyContentContainerRef = ref;
217
+ };
218
+ _this.stickyOverrideRowRenderer = function (_, rowData, index, ___) {
219
+ return (react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { ref: _this.stickyContentRef, enabled: _this.isStickyEnabled,
220
+ // We're passing rowData to ensure that sticky headers are updated when data changes
221
+ rowData: rowData, arg: index, renderer: _this.rowRendererSticky }));
222
+ };
223
+ _this.onItemLayout = function (index) {
224
+ // Informing the layout provider about change to an item's layout. It already knows the dimensions so there's not need to pass them.
225
+ _this.state.layoutProvider.reportItemLayout(index);
226
+ _this.raiseOnLoadEventIfNeeded();
227
+ };
228
+ _this.raiseOnLoadEventIfNeeded = function () {
229
+ var _a, _b;
230
+ if (!_this.isListLoaded) {
231
+ _this.isListLoaded = true;
232
+ (_b = (_a = _this.props).onLoad) === null || _b === void 0 ? void 0 : _b.call(_a, {
233
+ elapsedTimeInMs: Date.now() - _this.loadStartTime,
234
+ });
235
+ _this.runAfterOnLoad();
236
+ }
237
+ };
238
+ _this.runAfterOnLoad = function () {
239
+ if (_this.props.estimatedItemSize === undefined) {
240
+ _this.itemSizeWarningTimeoutId = setTimeout(function () {
241
+ var averageItemSize = Math.floor(_this.state.layoutProvider.averageItemSize);
242
+ console.warn(Warnings_1.default.estimatedItemSizeMissingWarning.replace("@size", averageItemSize.toString()));
243
+ }, 1000);
244
+ }
245
+ _this.postLoadTimeoutId = setTimeout(function () {
246
+ // This force update is required to remove dummy element rendered to measure horizontal list height when the list doesn't update on its own.
247
+ // In most cases this timeout will never be triggered because list usually updates atleast once and this timeout is cleared on update.
248
+ if (_this.props.horizontal) {
249
+ _this.forceUpdate();
250
+ }
251
+ }, 500);
252
+ };
253
+ _this.clearPostLoadTimeout = function () {
254
+ if (_this.postLoadTimeoutId !== undefined) {
255
+ clearTimeout(_this.postLoadTimeoutId);
256
+ _this.postLoadTimeoutId = undefined;
257
+ }
258
+ };
259
+ _this.clearRenderSizeWarningTimeout = function () {
260
+ if (_this.renderedSizeWarningTimeoutId !== undefined) {
261
+ clearTimeout(_this.renderedSizeWarningTimeoutId);
262
+ _this.renderedSizeWarningTimeoutId = undefined;
263
+ }
264
+ };
265
+ /**
266
+ * Tells the list an interaction has occurred, which should trigger viewability calculations, e.g. if waitForInteractions is true and the user has not scrolled.
267
+ * This is typically called by taps on items or by navigation actions.
268
+ */
269
+ _this.recordInteraction = function () {
270
+ _this.viewabilityManager.recordInteraction();
271
+ };
272
+ /**
273
+ * Retriggers viewability calculations. Useful to imperatively trigger viewability calculations.
274
+ */
275
+ _this.recomputeViewableItems = function () {
276
+ _this.viewabilityManager.recomputeViewableItems();
277
+ };
278
+ _this.loadStartTime = Date.now();
279
+ _this.validateProps();
280
+ if (props.estimatedListSize) {
281
+ if (props.horizontal) {
282
+ _this.listFixedDimensionSize = props.estimatedListSize.height;
283
+ }
284
+ else {
285
+ _this.listFixedDimensionSize = props.estimatedListSize.width;
286
+ }
287
+ }
288
+ _this.distanceFromWindow =
289
+ (_a = props.estimatedFirstItemOffset) !== null && _a !== void 0 ? _a : ((props.ListHeaderComponent && 1) || 0);
290
+ // eslint-disable-next-line react/state-in-constructor
291
+ _this.state = FlashList.getInitialMutableState(_this);
292
+ _this.viewabilityManager = new ViewabilityManager_1.default(_this);
293
+ _this.itemAnimator = (0, PlatformHelper_1.getItemAnimator)();
294
+ return _this;
295
+ }
296
+ FlashList.prototype.validateProps = function () {
297
+ var _a, _b;
298
+ if (this.props.onRefresh && typeof this.props.refreshing !== "boolean") {
299
+ throw new CustomError_1.default(ExceptionList_1.default.refreshBooleanMissing);
300
+ }
301
+ if (Number((_a = this.props.stickyHeaderIndices) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
302
+ this.props.horizontal) {
303
+ throw new CustomError_1.default(ExceptionList_1.default.stickyWhileHorizontalNotSupported);
304
+ }
305
+ if (Number(this.props.numColumns) > 1 && this.props.horizontal) {
306
+ throw new CustomError_1.default(ExceptionList_1.default.columnsWhileHorizontalNotSupported);
307
+ }
308
+ // `createAnimatedComponent` always passes a blank style object. To avoid warning while using AnimatedFlashList we've modified the check
309
+ // `style` prop can be an array. So we need to validate every object in array. Check: https://github.com/Shopify/flash-list/issues/651
310
+ if (__DEV__ &&
311
+ Object.keys(react_native_1.StyleSheet.flatten((_b = this.props.style) !== null && _b !== void 0 ? _b : {})).length > 0) {
312
+ console.warn(Warnings_1.default.styleUnsupported);
313
+ }
314
+ if ((0, ContentContainerUtils_1.hasUnsupportedKeysInContentContainerStyle)(this.props.contentContainerStyle)) {
315
+ console.warn(Warnings_1.default.styleContentContainerUnsupported);
316
+ }
317
+ };
318
+ // Some of the state variables need to update when props change
319
+ FlashList.getDerivedStateFromProps = function (nextProps, prevState) {
320
+ var _a, _b, _c;
321
+ var newState = tslib_1.__assign({}, prevState);
322
+ if (prevState.numColumns !== nextProps.numColumns) {
323
+ newState.numColumns = nextProps.numColumns || 1;
324
+ newState.layoutProvider = FlashList.getLayoutProvider(newState.numColumns, nextProps);
325
+ }
326
+ else if (prevState.layoutProvider.updateProps(nextProps).hasExpired) {
327
+ newState.layoutProvider = FlashList.getLayoutProvider(newState.numColumns, nextProps);
328
+ }
329
+ // RLV retries to reposition the first visible item on layout provider change.
330
+ // It's not required in our case so we're disabling it
331
+ newState.layoutProvider.shouldRefreshWithAnchoring = Boolean(!((_a = prevState.layoutProvider) === null || _a === void 0 ? void 0 : _a.hasExpired));
332
+ if (nextProps.data !== prevState.data || prevState.lastInverted !== nextProps.inverted) {
333
+ var processedData = nextProps.inverted
334
+ ? (nextProps.data ? tslib_1.__spreadArray([], tslib_1.__read(nextProps.data), false).reverse() : nextProps.data)
335
+ : nextProps.data;
336
+ newState.data = processedData;
337
+ newState.dataProvider = prevState.dataProvider.cloneWithRows(processedData);
338
+ if (nextProps.renderItem !== prevState.renderItem) {
339
+ newState.extraData = tslib_1.__assign({}, prevState.extraData);
340
+ }
341
+ }
342
+ if (nextProps.extraData !== ((_b = prevState.extraData) === null || _b === void 0 ? void 0 : _b.value)) {
343
+ newState.extraData = { value: nextProps.extraData };
344
+ }
345
+ newState.renderItem = nextProps.renderItem;
346
+ newState.lastInverted = (_c = nextProps.inverted) !== null && _c !== void 0 ? _c : undefined;
347
+ return newState;
348
+ };
349
+ FlashList.getInitialMutableState = function (flashList) {
350
+ var getStableId;
351
+ if (flashList.props.keyExtractor !== null &&
352
+ flashList.props.keyExtractor !== undefined) {
353
+ getStableId = function (index) {
354
+ // We assume `keyExtractor` function will never change from being `null | undefined` to defined and vice versa.
355
+ // Similarly, data should never be `null | undefined` when `getStableId` is called.
356
+ return flashList.props.keyExtractor(flashList.props.data[index], index).toString();
357
+ };
358
+ }
359
+ return {
360
+ data: null,
361
+ layoutProvider: null,
362
+ dataProvider: new recyclerlistview_1.DataProvider(function (r1, r2) {
363
+ return r1 !== r2;
364
+ }, getStableId),
365
+ numColumns: 0,
366
+ };
367
+ };
368
+ // Using only grid layout provider as it can also act as a listview, sizeProvider is a function to support future overrides
369
+ FlashList.getLayoutProvider = function (numColumns, flashListProps) {
370
+ return new GridLayoutProviderWithProps_1.default(
371
+ // max span or, total columns
372
+ numColumns, function (index, props) {
373
+ var _a;
374
+ // type of the item for given index
375
+ var type = (_a = props.getItemType) === null || _a === void 0 ? void 0 : _a.call(props, props.data[index], index, props.extraData);
376
+ return type || 0;
377
+ }, function (index, props, mutableLayout) {
378
+ var _a, _b;
379
+ // span of the item at given index, item can choose to span more than one column
380
+ (_a = props.overrideItemLayout) === null || _a === void 0 ? void 0 : _a.call(props, mutableLayout, props.data[index], index, numColumns, props.extraData);
381
+ return (_b = mutableLayout === null || mutableLayout === void 0 ? void 0 : mutableLayout.span) !== null && _b !== void 0 ? _b : 1;
382
+ }, function (index, props, mutableLayout) {
383
+ var _a;
384
+ // estimated size of the item an given index
385
+ (_a = props.overrideItemLayout) === null || _a === void 0 ? void 0 : _a.call(props, mutableLayout, props.data[index], index, numColumns, props.extraData);
386
+ console.log('mutableLayout:', mutableLayout);
387
+ return mutableLayout === null || mutableLayout === void 0 ? void 0 : mutableLayout.size;
388
+ }, flashListProps);
389
+ };
390
+ FlashList.prototype.componentDidMount = function () {
391
+ var _a;
392
+ if (((_a = this.props.data) === null || _a === void 0 ? void 0 : _a.length) === 0) {
393
+ this.raiseOnLoadEventIfNeeded();
394
+ }
395
+ };
396
+ FlashList.prototype.componentWillUnmount = function () {
397
+ this.viewabilityManager.dispose();
398
+ this.clearPostLoadTimeout();
399
+ this.clearRenderSizeWarningTimeout();
400
+ if (this.itemSizeWarningTimeoutId !== undefined) {
401
+ clearTimeout(this.itemSizeWarningTimeoutId);
402
+ }
403
+ };
404
+ FlashList.prototype.render = function () {
405
+ this.isEmptyList = this.state.dataProvider.getSize() === 0;
406
+ (0, ContentContainerUtils_1.updateContentStyle)(this.contentStyle, this.props.contentContainerStyle);
407
+ var _a = this.props, drawDistance = _a.drawDistance, removeClippedSubviews = _a.removeClippedSubviews, stickyHeaderIndices = _a.stickyHeaderIndices, horizontal = _a.horizontal, onEndReachedThreshold = _a.onEndReachedThreshold, estimatedListSize = _a.estimatedListSize, initialScrollIndex = _a.initialScrollIndex, style = _a.style, contentContainerStyle = _a.contentContainerStyle, renderScrollComponent = _a.renderScrollComponent, restProps = tslib_1.__rest(_a, ["drawDistance", "removeClippedSubviews", "stickyHeaderIndices", "horizontal", "onEndReachedThreshold", "estimatedListSize", "initialScrollIndex", "style", "contentContainerStyle", "renderScrollComponent"]);
408
+ // RecyclerListView simply ignores if initialScrollIndex is set to 0 because it doesn't understand headers
409
+ // Using initialOffset to force RLV to scroll to the right place
410
+ var initialOffset = (this.isInitialScrollIndexInFirstRow() && this.distanceFromWindow) ||
411
+ undefined;
412
+ var finalDrawDistance = drawDistance === undefined
413
+ ? PlatformHelper_1.PlatformConfig.defaultDrawDistance
414
+ : drawDistance;
415
+ return (react_1.default.createElement(StickyHeaderContainer, { overrideRowRenderer: this.stickyOverrideRowRenderer, applyWindowCorrection: this.applyWindowCorrection, stickyHeaderIndices: stickyHeaderIndices, style: this.props.horizontal
416
+ ? {}
417
+ : { flex: 1, overflow: "hidden" } },
418
+ react_1.default.createElement(recyclerlistview_1.ProgressiveListView, tslib_1.__assign({}, restProps, { ref: this.recyclerRef, layoutProvider: this.state.layoutProvider, dataProvider: this.state.dataProvider, rowRenderer: this.emptyRowRenderer, canChangeSize: true, isHorizontal: Boolean(horizontal), scrollViewProps: tslib_1.__assign({ onScrollBeginDrag: this.onScrollBeginDrag, onLayout: this.handleSizeChange, refreshControl: this.props.refreshControl || this.getRefreshControl(),
419
+ // Min values are being used to suppress RLV's bounded exception
420
+ style: { minHeight: 1, minWidth: 1 }, contentContainerStyle: tslib_1.__assign({ backgroundColor: this.contentStyle.backgroundColor,
421
+ // Required to handle a scrollview bug. Check: https://github.com/Shopify/flash-list/pull/187
422
+ minHeight: 1, minWidth: 1 }, (0, ContentContainerUtils_1.getContentContainerPadding)(this.contentStyle, horizontal)) }, this.props.overrideProps), forceNonDeterministicRendering: true, renderItemContainer: this.itemContainer, renderContentContainer: this.container, onEndReached: this.onEndReached, onEndReachedThresholdRelative: onEndReachedThreshold || undefined, extendedState: this.state.extraData, layoutSize: estimatedListSize, maxRenderAhead: 3 * finalDrawDistance, finalRenderAheadOffset: finalDrawDistance, renderAheadStep: finalDrawDistance, initialRenderIndex: (!this.isInitialScrollIndexInFirstRow() && initialScrollIndex) ||
423
+ undefined, initialOffset: initialOffset, onItemLayout: this.onItemLayout, onScroll: this.onScroll, onVisibleIndicesChanged: this.viewabilityManager.shouldListenToVisibleIndices
424
+ ? this.viewabilityManager.onVisibleIndicesChanged
425
+ : undefined, windowCorrectionConfig: this.getUpdatedWindowCorrectionConfig(), itemAnimator: this.itemAnimator, suppressBoundedSizeException: true, externalScrollView: renderScrollComponent }))));
426
+ };
427
+ FlashList.prototype.getUpdatedWindowCorrectionConfig = function () {
428
+ // If the initial scroll index is in the first row then we're forcing RLV to use initialOffset and thus we need to disable window correction
429
+ // This isn't clean but it's the only way to get RLV to scroll to the right place
430
+ // TODO: Remove this when RLV fixes this. Current implementation will also fail if column span is overridden in the first row.
431
+ if (this.isInitialScrollIndexInFirstRow()) {
432
+ this.windowCorrectionConfig.applyToInitialOffset = false;
433
+ }
434
+ else {
435
+ this.windowCorrectionConfig.applyToInitialOffset = true;
436
+ }
437
+ this.windowCorrectionConfig.value.windowShift = -this.distanceFromWindow;
438
+ return this.windowCorrectionConfig;
439
+ };
440
+ FlashList.prototype.isInitialScrollIndexInFirstRow = function () {
441
+ var _a;
442
+ return (((_a = this.props.initialScrollIndex) !== null && _a !== void 0 ? _a : this.state.numColumns) <
443
+ this.state.numColumns);
444
+ };
445
+ FlashList.prototype.validateListSize = function (event) {
446
+ var _a = event.nativeEvent.layout, height = _a.height, width = _a.width;
447
+ this.clearRenderSizeWarningTimeout();
448
+ if (Math.floor(height) <= 1 || Math.floor(width) <= 1) {
449
+ this.renderedSizeWarningTimeoutId = setTimeout(function () {
450
+ console.warn(Warnings_1.default.unusableRenderedSize);
451
+ }, 1000);
452
+ }
453
+ };
454
+ FlashList.prototype.getValidComponent = function (component) {
455
+ var PassedComponent = component;
456
+ return ((react_1.default.isValidElement(PassedComponent) && PassedComponent) ||
457
+ (PassedComponent && react_1.default.createElement(PassedComponent, null)) ||
458
+ null);
459
+ };
460
+ Object.defineProperty(FlashList.prototype, "isStickyEnabled", {
461
+ get: function () {
462
+ var _a;
463
+ var currentOffset = ((_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getCurrentScrollOffset()) || 0;
464
+ return currentOffset >= this.distanceFromWindow;
465
+ },
466
+ enumerable: false,
467
+ configurable: true
468
+ });
469
+ /**
470
+ * Disables recycling for the next frame so that layout animations run well.
471
+ * Warning: Avoid this when making large changes to the data as the list might draw too much to run animations. Single item insertions/deletions
472
+ * should be good. With recycling paused the list cannot do much optimization.
473
+ * The next render will run as normal and reuse items.
474
+ */
475
+ FlashList.prototype.prepareForLayoutAnimationRender = function () {
476
+ var _a;
477
+ if (this.props.keyExtractor === null ||
478
+ this.props.keyExtractor === undefined) {
479
+ console.warn(Warnings_1.default.missingKeyExtractor);
480
+ }
481
+ else {
482
+ (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.prepareForLayoutAnimationRender();
483
+ }
484
+ };
485
+ FlashList.prototype.scrollToEnd = function (params) {
486
+ var _a;
487
+ (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.scrollToEnd(Boolean(params === null || params === void 0 ? void 0 : params.animated));
488
+ };
489
+ FlashList.prototype.scrollToIndex = function (params) {
490
+ var _a, _b, _c, _d, _e;
491
+ var layout = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getLayout(params.index);
492
+ var listSize = (_b = this.rlvRef) === null || _b === void 0 ? void 0 : _b.getRenderedSize();
493
+ if (layout && listSize) {
494
+ var itemOffset = this.props.horizontal ? layout.x : layout.y;
495
+ var fixedDimension = this.props.horizontal
496
+ ? listSize.width
497
+ : listSize.height;
498
+ var itemSize = this.props.horizontal ? layout.width : layout.height;
499
+ var scrollOffset = Math.max(0, itemOffset - ((_c = params.viewPosition) !== null && _c !== void 0 ? _c : 0) * (fixedDimension - itemSize)) - ((_d = params.viewOffset) !== null && _d !== void 0 ? _d : 0);
500
+ (_e = this.rlvRef) === null || _e === void 0 ? void 0 : _e.scrollToOffset(scrollOffset, scrollOffset, Boolean(params.animated), true);
501
+ }
502
+ };
503
+ FlashList.prototype.scrollToItem = function (params) {
504
+ var _a, _b;
505
+ var index = (_b = (_a = this.props.data) === null || _a === void 0 ? void 0 : _a.indexOf(params.item)) !== null && _b !== void 0 ? _b : -1;
506
+ if (index >= 0) {
507
+ this.scrollToIndex(tslib_1.__assign(tslib_1.__assign({}, params), { index: index }));
508
+ }
509
+ };
510
+ FlashList.prototype.scrollToOffset = function (params) {
511
+ var _a;
512
+ var x = this.props.horizontal ? params.offset : 0;
513
+ var y = this.props.horizontal ? 0 : params.offset;
514
+ (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.scrollToOffset(x, y, Boolean(params.animated));
515
+ };
516
+ FlashList.prototype.getScrollableNode = function () {
517
+ var _a, _b;
518
+ return ((_b = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getScrollableNode) === null || _b === void 0 ? void 0 : _b.call(_a)) || null;
519
+ };
520
+ Object.defineProperty(FlashList.prototype, "recyclerlistview_unsafe", {
521
+ /**
522
+ * Allows access to internal recyclerlistview. This is useful for enabling access to its public APIs.
523
+ * Warning: We may swap recyclerlistview for something else in the future. Use with caution.
524
+ */
525
+ /* eslint-disable @typescript-eslint/naming-convention */
526
+ get: function () {
527
+ return this.rlvRef;
528
+ },
529
+ enumerable: false,
530
+ configurable: true
531
+ });
532
+ Object.defineProperty(FlashList.prototype, "firstItemOffset", {
533
+ /**
534
+ * Specifies how far the first item is from top of the list. This would normally be a sum of header size and top/left padding applied to the list.
535
+ */
536
+ get: function () {
537
+ return this.distanceFromWindow;
538
+ },
539
+ enumerable: false,
540
+ configurable: true
541
+ });
542
+ /**
543
+ * FlashList will skip using layout cache on next update. Can be useful when you know the layout will change drastically for example, orientation change when used as a carousel.
544
+ */
545
+ FlashList.prototype.clearLayoutCacheOnUpdate = function () {
546
+ this.state.layoutProvider.markExpired();
547
+ };
548
+ /**
549
+ * Returns the dimensions of the child container.
550
+ * @returns {Object} The dimensions of the child container.
551
+ */
552
+ FlashList.prototype.getChildContainerDimensions = function () {
553
+ var _a;
554
+ return (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getContentDimension();
555
+ };
556
+ /**
557
+ * Returns the layout of the item at the given index.
558
+ * @param index - The index of the item to get the layout for.
559
+ * @returns {Object} The layout of the item at the given index.
560
+ */
561
+ FlashList.prototype.getLayout = function (index) {
562
+ var _a;
563
+ var l = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getLayout(index);
564
+ return l;
565
+ };
566
+ /**
567
+ * Returns the size of the list.
568
+ * @returns {Object} The size of the list.
569
+ */
570
+ FlashList.prototype.getWindowSize = function () {
571
+ var _a;
572
+ return (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getRenderedSize();
573
+ };
574
+ /**
575
+ * Returns the absolute last scroll offset of the list.
576
+ * @returns {number} The absolute last scroll offset of the list.
577
+ */
578
+ FlashList.prototype.getAbsoluteLastScrollOffset = function () {
579
+ var _a, _b;
580
+ return (_b = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getCurrentScrollOffset()) !== null && _b !== void 0 ? _b : 0;
581
+ };
582
+ /**
583
+ * Returns the first item offset of the list.
584
+ * @returns {number} The first item offset of the list.
585
+ */
586
+ FlashList.prototype.getFirstItemOffset = function () {
587
+ return this.firstItemOffset;
588
+ };
589
+ FlashList.prototype.getFirstVisibleIndex = function () {
590
+ var _a, _b;
591
+ return (_b = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.findApproxFirstVisibleIndex()) !== null && _b !== void 0 ? _b : -1;
592
+ };
593
+ FlashList.defaultProps = {
594
+ data: [],
595
+ numColumns: 1,
596
+ };
597
+ return FlashList;
598
+ }(react_1.default.PureComponent));
599
+ exports.default = FlashList;
599
600
  //# sourceMappingURL=FlashList.js.map