@shopify/flash-list 1.0.1
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.
- package/CHANGELOG.md +159 -0
- package/LICENSE.md +7 -0
- package/README.md +65 -0
- package/RNFlashList.podspec +26 -0
- package/android/build.gradle +59 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/AutoLayoutShadow.kt +94 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/AutoLayoutView.kt +79 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/AutoLayoutViewManager.kt +69 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/CellContainer.java +16 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/CellContainerImpl.kt +16 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/CellContainerManager.kt +27 -0
- package/android/src/main/kotlin/com/shopify/reactnative/flash_list/FlashListPackage.kt +19 -0
- package/android/src/test/java/com/shopify/reactnative/flash_list/AutoLayoutShadowTest.kt +146 -0
- package/android/src/test/java/com/shopify/reactnative/flash_list/models/Rect.kt +59 -0
- package/android/src/test/java/com/shopify/reactnative/flash_list/models/TestCollection.kt +6 -0
- package/android/src/test/java/com/shopify/reactnative/flash_list/models/TestDataModel.kt +8 -0
- package/android/src/test/resources/LayoutTestData.json +708 -0
- package/dist/AnimatedFlashList.d.ts +6 -0
- package/dist/AnimatedFlashList.d.ts.map +1 -0
- package/dist/AnimatedFlashList.js +8 -0
- package/dist/AnimatedFlashList.js.map +1 -0
- package/dist/FlashList.d.ts +121 -0
- package/dist/FlashList.d.ts.map +1 -0
- package/dist/FlashList.js +502 -0
- package/dist/FlashList.js.map +1 -0
- package/dist/FlashListProps.d.ts +251 -0
- package/dist/FlashListProps.d.ts.map +1 -0
- package/dist/FlashListProps.js +3 -0
- package/dist/FlashListProps.js.map +1 -0
- package/dist/GridLayoutProviderWithProps.d.ts +30 -0
- package/dist/GridLayoutProviderWithProps.d.ts.map +1 -0
- package/dist/GridLayoutProviderWithProps.js +80 -0
- package/dist/GridLayoutProviderWithProps.js.map +1 -0
- package/dist/PureComponentWrapper.d.ts +22 -0
- package/dist/PureComponentWrapper.d.ts.map +1 -0
- package/dist/PureComponentWrapper.js +37 -0
- package/dist/PureComponentWrapper.js.map +1 -0
- package/dist/__tests__/AverageWindow.test.d.ts +2 -0
- package/dist/__tests__/AverageWindow.test.d.ts.map +1 -0
- package/dist/__tests__/AverageWindow.test.js +69 -0
- package/dist/__tests__/AverageWindow.test.js.map +1 -0
- package/dist/__tests__/FlashList.test.d.ts +2 -0
- package/dist/__tests__/FlashList.test.d.ts.map +1 -0
- package/dist/__tests__/FlashList.test.js +656 -0
- package/dist/__tests__/FlashList.test.js.map +1 -0
- package/dist/__tests__/GridLayoutProviderWithProps.test.d.ts +2 -0
- package/dist/__tests__/GridLayoutProviderWithProps.test.d.ts.map +1 -0
- package/dist/__tests__/GridLayoutProviderWithProps.test.js +133 -0
- package/dist/__tests__/GridLayoutProviderWithProps.test.js.map +1 -0
- package/dist/__tests__/PlatformHelper.web.test.d.ts +2 -0
- package/dist/__tests__/PlatformHelper.web.test.d.ts.map +1 -0
- package/dist/__tests__/PlatformHelper.web.test.js +25 -0
- package/dist/__tests__/PlatformHelper.web.test.js.map +1 -0
- package/dist/__tests__/ViewabilityHelper.test.d.ts +2 -0
- package/dist/__tests__/ViewabilityHelper.test.d.ts.map +1 -0
- package/dist/__tests__/ViewabilityHelper.test.js +187 -0
- package/dist/__tests__/ViewabilityHelper.test.js.map +1 -0
- package/dist/__tests__/helpers/mountFlashList.d.ts +20 -0
- package/dist/__tests__/helpers/mountFlashList.d.ts.map +1 -0
- package/dist/__tests__/helpers/mountFlashList.js +44 -0
- package/dist/__tests__/helpers/mountFlashList.js.map +1 -0
- package/dist/__tests__/useBlankAreaTracker.test.d.ts +2 -0
- package/dist/__tests__/useBlankAreaTracker.test.d.ts.map +1 -0
- package/dist/__tests__/useBlankAreaTracker.test.js +179 -0
- package/dist/__tests__/useBlankAreaTracker.test.js.map +1 -0
- package/dist/benchmark/AutoScrollHelper.d.ts +18 -0
- package/dist/benchmark/AutoScrollHelper.d.ts.map +1 -0
- package/dist/benchmark/AutoScrollHelper.js +68 -0
- package/dist/benchmark/AutoScrollHelper.js.map +1 -0
- package/dist/benchmark/JSFPSMonitor.d.ts +23 -0
- package/dist/benchmark/JSFPSMonitor.d.ts.map +1 -0
- package/dist/benchmark/JSFPSMonitor.js +65 -0
- package/dist/benchmark/JSFPSMonitor.js.map +1 -0
- package/dist/benchmark/roundToDecimalPlaces.d.ts +2 -0
- package/dist/benchmark/roundToDecimalPlaces.d.ts.map +1 -0
- package/dist/benchmark/roundToDecimalPlaces.js +9 -0
- package/dist/benchmark/roundToDecimalPlaces.js.map +1 -0
- package/dist/benchmark/useBenchmark.d.ts +35 -0
- package/dist/benchmark/useBenchmark.d.ts.map +1 -0
- package/dist/benchmark/useBenchmark.js +167 -0
- package/dist/benchmark/useBenchmark.js.map +1 -0
- package/dist/benchmark/useBlankAreaTracker.d.ts +34 -0
- package/dist/benchmark/useBlankAreaTracker.d.ts.map +1 -0
- package/dist/benchmark/useBlankAreaTracker.js +67 -0
- package/dist/benchmark/useBlankAreaTracker.js.map +1 -0
- package/dist/benchmark/useDataMultiplier.d.ts +9 -0
- package/dist/benchmark/useDataMultiplier.d.ts.map +1 -0
- package/dist/benchmark/useDataMultiplier.js +25 -0
- package/dist/benchmark/useDataMultiplier.js.map +1 -0
- package/dist/benchmark/useFlatListBenchmark.d.ts +13 -0
- package/dist/benchmark/useFlatListBenchmark.d.ts.map +1 -0
- package/dist/benchmark/useFlatListBenchmark.js +100 -0
- package/dist/benchmark/useFlatListBenchmark.js.map +1 -0
- package/dist/errors/CustomError.d.ts +8 -0
- package/dist/errors/CustomError.d.ts.map +1 -0
- package/dist/errors/CustomError.js +14 -0
- package/dist/errors/CustomError.js.map +1 -0
- package/dist/errors/ExceptionList.d.ts +20 -0
- package/dist/errors/ExceptionList.d.ts.map +1 -0
- package/dist/errors/ExceptionList.js +22 -0
- package/dist/errors/ExceptionList.js.map +1 -0
- package/dist/errors/Warnings.d.ts +10 -0
- package/dist/errors/Warnings.d.ts.map +1 -0
- package/dist/errors/Warnings.js +15 -0
- package/dist/errors/Warnings.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/native/auto-layout/AutoLayoutView.d.ts +21 -0
- package/dist/native/auto-layout/AutoLayoutView.d.ts.map +1 -0
- package/dist/native/auto-layout/AutoLayoutView.js +48 -0
- package/dist/native/auto-layout/AutoLayoutView.js.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts +4 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.js +6 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.js.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.web.d.ts +5 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.web.d.ts.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.web.js +6 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponent.web.js.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts +14 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts.map +1 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.js +3 -0
- package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.js.map +1 -0
- package/dist/native/cell-container/CellContainer.d.ts +6 -0
- package/dist/native/cell-container/CellContainer.d.ts.map +1 -0
- package/dist/native/cell-container/CellContainer.js +9 -0
- package/dist/native/cell-container/CellContainer.js.map +1 -0
- package/dist/native/cell-container/CellContainer.web.d.ts +7 -0
- package/dist/native/cell-container/CellContainer.web.d.ts.map +1 -0
- package/dist/native/cell-container/CellContainer.web.js +13 -0
- package/dist/native/cell-container/CellContainer.web.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/utils/AverageWindow.d.ts +21 -0
- package/dist/utils/AverageWindow.d.ts.map +1 -0
- package/dist/utils/AverageWindow.js +49 -0
- package/dist/utils/AverageWindow.js.map +1 -0
- package/dist/utils/PlatformHelper.d.ts +14 -0
- package/dist/utils/PlatformHelper.d.ts.map +1 -0
- package/dist/utils/PlatformHelper.js +16 -0
- package/dist/utils/PlatformHelper.js.map +1 -0
- package/dist/utils/PlatformHelper.web.d.ts +14 -0
- package/dist/utils/PlatformHelper.web.d.ts.map +1 -0
- package/dist/utils/PlatformHelper.web.js +18 -0
- package/dist/utils/PlatformHelper.web.js.map +1 -0
- package/dist/viewability/ViewToken.d.ts +8 -0
- package/dist/viewability/ViewToken.d.ts.map +1 -0
- package/dist/viewability/ViewToken.js +3 -0
- package/dist/viewability/ViewToken.js.map +1 -0
- package/dist/viewability/ViewabilityHelper.d.ts +25 -0
- package/dist/viewability/ViewabilityHelper.d.ts.map +1 -0
- package/dist/viewability/ViewabilityHelper.js +104 -0
- package/dist/viewability/ViewabilityHelper.js.map +1 -0
- package/dist/viewability/ViewabilityManager.d.ts +24 -0
- package/dist/viewability/ViewabilityManager.d.ts.map +1 -0
- package/dist/viewability/ViewabilityManager.js +94 -0
- package/dist/viewability/ViewabilityManager.js.map +1 -0
- package/ios/RNFlashList.xcodeproj/project.pbxproj +3 -0
- package/ios/RNFlashList.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/Sources/AutoLayoutView.swift +218 -0
- package/ios/Sources/AutoLayoutViewManager.m +14 -0
- package/ios/Sources/AutoLayoutViewManager.swift +12 -0
- package/ios/Sources/CellContainer.swift +9 -0
- package/ios/Sources/CellContainerManager.m +8 -0
- package/ios/Sources/CellContainerManager.swift +12 -0
- package/ios/Sources/FlatListPro-Bridging-Header.h +8 -0
- package/ios/Tests/AutoLayoutViewTests.swift +113 -0
- package/jestSetup.js +15 -0
- package/package.json +75 -0
- package/src/AnimatedFlashList.ts +11 -0
- package/src/FlashList.tsx +801 -0
- package/src/FlashListProps.ts +312 -0
- package/src/GridLayoutProviderWithProps.ts +137 -0
- package/src/PureComponentWrapper.tsx +42 -0
- package/src/__tests__/AverageWindow.test.ts +80 -0
- package/src/__tests__/FlashList.test.tsx +738 -0
- package/src/__tests__/GridLayoutProviderWithProps.test.ts +150 -0
- package/src/__tests__/PlatformHelper.web.test.ts +29 -0
- package/src/__tests__/ViewabilityHelper.test.ts +283 -0
- package/src/__tests__/helpers/mountFlashList.tsx +62 -0
- package/src/__tests__/useBlankAreaTracker.test.tsx +206 -0
- package/src/benchmark/AutoScrollHelper.ts +70 -0
- package/src/benchmark/JSFPSMonitor.ts +74 -0
- package/src/benchmark/roundToDecimalPlaces.ts +4 -0
- package/src/benchmark/useBenchmark.ts +240 -0
- package/src/benchmark/useBlankAreaTracker.ts +117 -0
- package/src/benchmark/useDataMultiplier.ts +19 -0
- package/src/benchmark/useFlatListBenchmark.ts +107 -0
- package/src/errors/CustomError.ts +10 -0
- package/src/errors/ExceptionList.ts +23 -0
- package/src/errors/Warnings.ts +18 -0
- package/src/index.ts +32 -0
- package/src/native/auto-layout/AutoLayoutView.tsx +72 -0
- package/src/native/auto-layout/AutoLayoutViewNativeComponent.ts +7 -0
- package/src/native/auto-layout/AutoLayoutViewNativeComponent.web.ts +8 -0
- package/src/native/auto-layout/AutoLayoutViewNativeComponentProps.ts +14 -0
- package/src/native/cell-container/CellContainer.ts +7 -0
- package/src/native/cell-container/CellContainer.web.tsx +9 -0
- package/src/utils/AverageWindow.ts +49 -0
- package/src/utils/PlatformHelper.ts +16 -0
- package/src/utils/PlatformHelper.web.ts +20 -0
- package/src/viewability/ViewToken.ts +7 -0
- package/src/viewability/ViewabilityHelper.ts +162 -0
- package/src/viewability/ViewabilityManager.ts +133 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimatedFlashList.js","sourceRoot":"","sources":["../src/AnimatedFlashList.ts"],"names":[],"mappings":";;;AAAA,6CAAwC;AAExC,kEAAoC;AAGpC,IAAM,iBAAiB,GACrB,uBAAQ,CAAC,uBAAuB,CAC9B,mBAAS,CACV,CAAC;AAEJ,kBAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { DataProvider, RecyclerListView, RecyclerListViewProps } from "recyclerlistview";
|
|
3
|
+
import GridLayoutProviderWithProps from "./GridLayoutProviderWithProps";
|
|
4
|
+
import { FlashListProps } from "./FlashListProps";
|
|
5
|
+
export interface FlashListState<T> {
|
|
6
|
+
dataProvider: DataProvider;
|
|
7
|
+
numColumns: number;
|
|
8
|
+
layoutProvider: GridLayoutProviderWithProps<T>;
|
|
9
|
+
data?: ReadonlyArray<T> | null;
|
|
10
|
+
extraData?: ExtraData<unknown>;
|
|
11
|
+
renderItem?: FlashListProps<T>["renderItem"];
|
|
12
|
+
}
|
|
13
|
+
interface ExtraData<T> {
|
|
14
|
+
value?: T;
|
|
15
|
+
}
|
|
16
|
+
declare class FlashList<T> extends React.PureComponent<FlashListProps<T>, FlashListState<T>> {
|
|
17
|
+
private rlvRef?;
|
|
18
|
+
private stickyContentContainerRef?;
|
|
19
|
+
private listFixedDimensionSize;
|
|
20
|
+
private transformStyle;
|
|
21
|
+
private distanceFromWindow;
|
|
22
|
+
private contentStyle;
|
|
23
|
+
private loadStartTime;
|
|
24
|
+
private isListLoaded;
|
|
25
|
+
private windowCorrectionConfig;
|
|
26
|
+
private emptyObject;
|
|
27
|
+
private postLoadTimeoutId?;
|
|
28
|
+
private sizeWarningTimeoutId?;
|
|
29
|
+
private isEmptyList;
|
|
30
|
+
private viewabilityManager;
|
|
31
|
+
private itemAnimator?;
|
|
32
|
+
static defaultProps: {
|
|
33
|
+
data: never[];
|
|
34
|
+
numColumns: number;
|
|
35
|
+
};
|
|
36
|
+
constructor(props: FlashListProps<T>);
|
|
37
|
+
private validateProps;
|
|
38
|
+
static getDerivedStateFromProps<T>(nextProps: FlashListProps<T>, prevState: FlashListState<T>): FlashListState<T>;
|
|
39
|
+
private static getInitialMutableState;
|
|
40
|
+
private static getLayoutProvider;
|
|
41
|
+
private onEndReached;
|
|
42
|
+
private getRefreshControl;
|
|
43
|
+
componentDidMount(): void;
|
|
44
|
+
componentWillUnmount(): void;
|
|
45
|
+
render(): JSX.Element;
|
|
46
|
+
private onScrollBeginDrag;
|
|
47
|
+
private onScroll;
|
|
48
|
+
private getUpdatedWindowCorrectionConfig;
|
|
49
|
+
private isInitialScrollIndexInFirstRow;
|
|
50
|
+
private validateListSize;
|
|
51
|
+
private handleSizeChange;
|
|
52
|
+
private container;
|
|
53
|
+
private itemContainer;
|
|
54
|
+
private updateDistanceFromWindow;
|
|
55
|
+
private getTransform;
|
|
56
|
+
private getContentContainerInfo;
|
|
57
|
+
private separator;
|
|
58
|
+
private header;
|
|
59
|
+
private footer;
|
|
60
|
+
private getComponentForHeightMeasurement;
|
|
61
|
+
private getValidComponent;
|
|
62
|
+
private applyWindowCorrection;
|
|
63
|
+
private rowRendererWithIndex;
|
|
64
|
+
/**
|
|
65
|
+
* This will prevent render item calls unless data changes.
|
|
66
|
+
* 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.
|
|
67
|
+
* @module getCellContainerChild acts as the new rowRenderer and is called directly from our child container.
|
|
68
|
+
*/
|
|
69
|
+
private emptyRowRenderer;
|
|
70
|
+
private getCellContainerChild;
|
|
71
|
+
private recyclerRef;
|
|
72
|
+
private stickyContentRef;
|
|
73
|
+
private stickyRowRenderer;
|
|
74
|
+
private get isStickyEnabled();
|
|
75
|
+
private onItemLayout;
|
|
76
|
+
private raiseOnLoadEventIfNeeded;
|
|
77
|
+
private runAfterOnLoad;
|
|
78
|
+
private clearPostLoadTimeout;
|
|
79
|
+
/**
|
|
80
|
+
* Disables recycling for the next frame so that layout animations run well.
|
|
81
|
+
* Warning: Avoid this when making large changes to the data as the list might draw too much to run animations. Single item insertions/deletions
|
|
82
|
+
* should be good. With recycling paused the list cannot do much optimization.
|
|
83
|
+
* The next render will run as normal and reuse items.
|
|
84
|
+
*/
|
|
85
|
+
prepareForLayoutAnimationRender(): void;
|
|
86
|
+
scrollToEnd(params?: {
|
|
87
|
+
animated?: boolean | null | undefined;
|
|
88
|
+
}): void;
|
|
89
|
+
scrollToIndex(params: {
|
|
90
|
+
animated?: boolean | null | undefined;
|
|
91
|
+
index: number;
|
|
92
|
+
viewOffset?: number | undefined;
|
|
93
|
+
viewPosition?: number | undefined;
|
|
94
|
+
}): void;
|
|
95
|
+
scrollToItem(params: {
|
|
96
|
+
animated?: boolean | null | undefined;
|
|
97
|
+
item: any;
|
|
98
|
+
viewPosition?: number | undefined;
|
|
99
|
+
}): void;
|
|
100
|
+
scrollToOffset(params: {
|
|
101
|
+
animated?: boolean | null | undefined;
|
|
102
|
+
offset: number;
|
|
103
|
+
}): void;
|
|
104
|
+
getScrollableNode(): number | null;
|
|
105
|
+
/**
|
|
106
|
+
* Allows access to internal recyclerlistview. This is useful for enabling access to its public APIs.
|
|
107
|
+
* Warning: We may swap recyclerlistview for something else in the future. Use with caution.
|
|
108
|
+
*/
|
|
109
|
+
get recyclerlistview_unsafe(): RecyclerListView<RecyclerListViewProps, any> | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* 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.
|
|
112
|
+
*/
|
|
113
|
+
get firstItemOffset(): number;
|
|
114
|
+
/**
|
|
115
|
+
* Tells the list an interaction has occurred, which should trigger viewability calculations, e.g. if waitForInteractions is true and the user has not scrolled.
|
|
116
|
+
* This is typically called by taps on items or by navigation actions.
|
|
117
|
+
*/
|
|
118
|
+
recordInteraction: () => void;
|
|
119
|
+
}
|
|
120
|
+
export default FlashList;
|
|
121
|
+
//# sourceMappingURL=FlashList.d.ts.map
|
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slib_1 = require("tslib");
|
|
4
|
+
var react_1 = tslib_1.__importDefault(require("react"));
|
|
5
|
+
var react_native_1 = require("react-native");
|
|
6
|
+
var recyclerlistview_1 = require("recyclerlistview");
|
|
7
|
+
var sticky_1 = tslib_1.__importDefault(require("recyclerlistview/sticky"));
|
|
8
|
+
var AutoLayoutView_1 = tslib_1.__importDefault(require("./native/auto-layout/AutoLayoutView"));
|
|
9
|
+
var CellContainer_1 = tslib_1.__importDefault(require("./native/cell-container/CellContainer"));
|
|
10
|
+
var PureComponentWrapper_1 = require("./PureComponentWrapper");
|
|
11
|
+
var GridLayoutProviderWithProps_1 = tslib_1.__importDefault(require("./GridLayoutProviderWithProps"));
|
|
12
|
+
var CustomError_1 = tslib_1.__importDefault(require("./errors/CustomError"));
|
|
13
|
+
var ExceptionList_1 = tslib_1.__importDefault(require("./errors/ExceptionList"));
|
|
14
|
+
var Warnings_1 = tslib_1.__importDefault(require("./errors/Warnings"));
|
|
15
|
+
var ViewabilityManager_1 = tslib_1.__importDefault(require("./viewability/ViewabilityManager"));
|
|
16
|
+
var PlatformHelper_1 = require("./utils/PlatformHelper");
|
|
17
|
+
var StickyHeaderContainer = sticky_1.default;
|
|
18
|
+
var FlashList = /** @class */ (function (_super) {
|
|
19
|
+
tslib_1.__extends(FlashList, _super);
|
|
20
|
+
function FlashList(props) {
|
|
21
|
+
var _this = this;
|
|
22
|
+
var _a;
|
|
23
|
+
_this = _super.call(this, props) || this;
|
|
24
|
+
_this.listFixedDimensionSize = 0;
|
|
25
|
+
_this.transformStyle = { transform: [{ scaleY: -1 }] };
|
|
26
|
+
_this.distanceFromWindow = 0;
|
|
27
|
+
_this.contentStyle = {};
|
|
28
|
+
_this.loadStartTime = 0;
|
|
29
|
+
_this.isListLoaded = false;
|
|
30
|
+
_this.windowCorrectionConfig = {
|
|
31
|
+
value: {
|
|
32
|
+
windowShift: 0,
|
|
33
|
+
startCorrection: 0,
|
|
34
|
+
endCorrection: 0,
|
|
35
|
+
},
|
|
36
|
+
applyToItemScroll: true,
|
|
37
|
+
applyToInitialOffset: true,
|
|
38
|
+
};
|
|
39
|
+
_this.emptyObject = {};
|
|
40
|
+
_this.isEmptyList = false;
|
|
41
|
+
_this.onEndReached = function () {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
(_b = (_a = _this.props).onEndReached) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
44
|
+
};
|
|
45
|
+
_this.getRefreshControl = function () {
|
|
46
|
+
if (_this.props.onRefresh) {
|
|
47
|
+
return (react_1.default.createElement(react_native_1.RefreshControl, { refreshing: Boolean(_this.props.refreshing), progressViewOffset: _this.props.progressViewOffset, onRefresh: _this.props.onRefresh }));
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
_this.onScrollBeginDrag = function (event) {
|
|
51
|
+
var _a, _b;
|
|
52
|
+
_this.recordInteraction();
|
|
53
|
+
(_b = (_a = _this.props).onScrollBeginDrag) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
54
|
+
};
|
|
55
|
+
_this.onScroll = function (event) {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
_this.recordInteraction();
|
|
58
|
+
_this.viewabilityManager.updateViewableItems();
|
|
59
|
+
(_b = (_a = _this.props).onScroll) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
60
|
+
};
|
|
61
|
+
_this.handleSizeChange = function (event) {
|
|
62
|
+
var _a;
|
|
63
|
+
_this.validateListSize(event);
|
|
64
|
+
var newSize = _this.props.horizontal
|
|
65
|
+
? event.nativeEvent.layout.height
|
|
66
|
+
: event.nativeEvent.layout.width;
|
|
67
|
+
var oldSize = _this.listFixedDimensionSize;
|
|
68
|
+
_this.listFixedDimensionSize = newSize;
|
|
69
|
+
// >0 check is to avoid rerender on mount where it would be redundant
|
|
70
|
+
if (oldSize > 0 && oldSize !== newSize) {
|
|
71
|
+
(_a = _this.rlvRef) === null || _a === void 0 ? void 0 : _a.forceRerender();
|
|
72
|
+
}
|
|
73
|
+
if (_this.props.onLayout) {
|
|
74
|
+
_this.props.onLayout(event);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
_this.container = function (props, children) {
|
|
78
|
+
_this.clearPostLoadTimeout();
|
|
79
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
80
|
+
react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { enabled: 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 }),
|
|
81
|
+
react_1.default.createElement(AutoLayoutView_1.default, tslib_1.__assign({}, props, { onBlankAreaEvent: _this.props.onBlankArea, onLayout: _this.updateDistanceFromWindow, disableAutoLayout: _this.props.disableAutoLayout }), children),
|
|
82
|
+
_this.isEmptyList
|
|
83
|
+
? _this.getValidComponent(_this.props.ListEmptyComponent)
|
|
84
|
+
: null,
|
|
85
|
+
react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { enabled: 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 }),
|
|
86
|
+
_this.getComponentForHeightMeasurement()));
|
|
87
|
+
};
|
|
88
|
+
_this.itemContainer = function (props, parentProps) {
|
|
89
|
+
var _a;
|
|
90
|
+
var CellRendererComponent = (_a = _this.props.CellRendererComponent) !== null && _a !== void 0 ? _a : CellContainer_1.default;
|
|
91
|
+
return (react_1.default.createElement(CellRendererComponent, tslib_1.__assign({}, props, { style: tslib_1.__assign(tslib_1.__assign(tslib_1.__assign(tslib_1.__assign({}, props.style), { flexDirection: _this.props.horizontal ? "row" : "column", alignItems: "stretch" }), _this.getTransform()), (0, PlatformHelper_1.getCellContainerPlatformStyles)(_this.props.inverted, parentProps)), index: parentProps.index }),
|
|
92
|
+
react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { extendedState: parentProps.extendedState, internalSnapshot: parentProps.internalSnapshot, data: parentProps.data, arg: parentProps.index, renderer: _this.getCellContainerChild })));
|
|
93
|
+
};
|
|
94
|
+
_this.updateDistanceFromWindow = function (event) {
|
|
95
|
+
_this.distanceFromWindow = _this.props.horizontal
|
|
96
|
+
? event.nativeEvent.layout.x
|
|
97
|
+
: event.nativeEvent.layout.y;
|
|
98
|
+
_this.windowCorrectionConfig.value.windowShift = -_this.distanceFromWindow;
|
|
99
|
+
};
|
|
100
|
+
_this.separator = function (index) {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
var leadingItem = (_a = _this.props.data) === null || _a === void 0 ? void 0 : _a[index];
|
|
103
|
+
var trailingItem = (_b = _this.props.data) === null || _b === void 0 ? void 0 : _b[index + 1];
|
|
104
|
+
if (trailingItem === undefined) {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
var props = {
|
|
108
|
+
leadingItem: leadingItem,
|
|
109
|
+
trailingItem: trailingItem,
|
|
110
|
+
// TODO: Missing sections as we don't have this feature implemented yet. Implement section, leadingSection and trailingSection.
|
|
111
|
+
// https://github.com/facebook/react-native/blob/8bd3edec88148d0ab1f225d2119435681fbbba33/Libraries/Lists/VirtualizedSectionList.js#L285-L294
|
|
112
|
+
};
|
|
113
|
+
var Separator = _this.props.ItemSeparatorComponent;
|
|
114
|
+
return Separator && react_1.default.createElement(Separator, tslib_1.__assign({}, props));
|
|
115
|
+
};
|
|
116
|
+
_this.header = function () {
|
|
117
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
118
|
+
react_1.default.createElement(react_native_1.View, { style: {
|
|
119
|
+
paddingTop: _this.contentStyle.paddingTop,
|
|
120
|
+
paddingLeft: _this.contentStyle.paddingLeft,
|
|
121
|
+
} }),
|
|
122
|
+
react_1.default.createElement(react_native_1.View, { style: [_this.props.ListHeaderComponentStyle, _this.getTransform()] }, _this.getValidComponent(_this.props.ListHeaderComponent))));
|
|
123
|
+
};
|
|
124
|
+
_this.footer = function () {
|
|
125
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
126
|
+
react_1.default.createElement(react_native_1.View, { style: [_this.props.ListFooterComponentStyle, _this.getTransform()] }, _this.getValidComponent(_this.props.ListFooterComponent)),
|
|
127
|
+
react_1.default.createElement(react_native_1.View, { style: {
|
|
128
|
+
paddingBottom: _this.contentStyle.paddingBottom,
|
|
129
|
+
paddingRight: _this.contentStyle.paddingRight,
|
|
130
|
+
} })));
|
|
131
|
+
};
|
|
132
|
+
_this.getComponentForHeightMeasurement = function () {
|
|
133
|
+
return _this.props.horizontal &&
|
|
134
|
+
!_this.props.disableHorizontalListHeightMeasurement &&
|
|
135
|
+
!_this.isListLoaded &&
|
|
136
|
+
_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)))) : null;
|
|
137
|
+
};
|
|
138
|
+
_this.applyWindowCorrection = function (_, __, correctionObject) {
|
|
139
|
+
var _a;
|
|
140
|
+
correctionObject.windowShift = -_this.distanceFromWindow;
|
|
141
|
+
(_a = _this.stickyContentContainerRef) === null || _a === void 0 ? void 0 : _a.setEnabled(_this.isStickyEnabled);
|
|
142
|
+
};
|
|
143
|
+
_this.rowRendererWithIndex = function (index) {
|
|
144
|
+
var _a, _b, _c, _d;
|
|
145
|
+
// known issue: expected to pass separators which isn't available in RLV
|
|
146
|
+
return (_b = (_a = _this.props).renderItem) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
147
|
+
item: (_c = _this.props.data) === null || _c === void 0 ? void 0 : _c[index],
|
|
148
|
+
index: index,
|
|
149
|
+
extraData: (_d = _this.state.extraData) === null || _d === void 0 ? void 0 : _d.value,
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* This will prevent render item calls unless data changes.
|
|
154
|
+
* 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.
|
|
155
|
+
* @module getCellContainerChild acts as the new rowRenderer and is called directly from our child container.
|
|
156
|
+
*/
|
|
157
|
+
_this.emptyRowRenderer = function () {
|
|
158
|
+
return null;
|
|
159
|
+
};
|
|
160
|
+
_this.getCellContainerChild = function (index) {
|
|
161
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
162
|
+
react_1.default.createElement(react_native_1.View, { style: {
|
|
163
|
+
flexDirection: _this.props.horizontal || _this.props.numColumns === 1
|
|
164
|
+
? "column"
|
|
165
|
+
: "row",
|
|
166
|
+
} }, _this.rowRendererWithIndex(index)),
|
|
167
|
+
_this.separator(index)));
|
|
168
|
+
};
|
|
169
|
+
_this.recyclerRef = function (ref) {
|
|
170
|
+
_this.rlvRef = ref;
|
|
171
|
+
};
|
|
172
|
+
_this.stickyContentRef = function (ref) {
|
|
173
|
+
_this.stickyContentContainerRef = ref;
|
|
174
|
+
};
|
|
175
|
+
_this.stickyRowRenderer = function (_, __, index, ___) {
|
|
176
|
+
return (react_1.default.createElement(PureComponentWrapper_1.PureComponentWrapper, { ref: _this.stickyContentRef, enabled: _this.isStickyEnabled, arg: index, renderer: _this.rowRendererWithIndex }));
|
|
177
|
+
};
|
|
178
|
+
_this.onItemLayout = function (index) {
|
|
179
|
+
// Informing the layout provider about change to an item's layout. It already knows the dimensions so there's not need to pass them.
|
|
180
|
+
_this.state.layoutProvider.reportItemLayout(index);
|
|
181
|
+
_this.raiseOnLoadEventIfNeeded();
|
|
182
|
+
};
|
|
183
|
+
_this.raiseOnLoadEventIfNeeded = function () {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
if (!_this.isListLoaded) {
|
|
186
|
+
_this.isListLoaded = true;
|
|
187
|
+
(_b = (_a = _this.props).onLoad) === null || _b === void 0 ? void 0 : _b.call(_a, {
|
|
188
|
+
elapsedTimeInMs: Date.now() - _this.loadStartTime,
|
|
189
|
+
});
|
|
190
|
+
_this.runAfterOnLoad();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
_this.runAfterOnLoad = function () {
|
|
194
|
+
if (_this.props.estimatedItemSize === undefined) {
|
|
195
|
+
_this.sizeWarningTimeoutId = setTimeout(function () {
|
|
196
|
+
var averageItemSize = Math.floor(_this.state.layoutProvider.averageItemSize);
|
|
197
|
+
console.warn(Warnings_1.default.estimatedItemSizeMissingWarning.replace("@size", averageItemSize.toString()));
|
|
198
|
+
}, 1000);
|
|
199
|
+
}
|
|
200
|
+
_this.postLoadTimeoutId = setTimeout(function () {
|
|
201
|
+
// This force update is required to remove dummy element rendered to measure horizontal list height when the list doesn't update on its own.
|
|
202
|
+
// In most cases this timeout will never be triggered because list usually updates atleast once and this timeout is cleared on update.
|
|
203
|
+
if (_this.props.horizontal) {
|
|
204
|
+
_this.forceUpdate();
|
|
205
|
+
}
|
|
206
|
+
}, 500);
|
|
207
|
+
};
|
|
208
|
+
_this.clearPostLoadTimeout = function () {
|
|
209
|
+
if (_this.postLoadTimeoutId !== undefined) {
|
|
210
|
+
clearTimeout(_this.postLoadTimeoutId);
|
|
211
|
+
_this.postLoadTimeoutId = undefined;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Tells the list an interaction has occurred, which should trigger viewability calculations, e.g. if waitForInteractions is true and the user has not scrolled.
|
|
216
|
+
* This is typically called by taps on items or by navigation actions.
|
|
217
|
+
*/
|
|
218
|
+
_this.recordInteraction = function () {
|
|
219
|
+
_this.viewabilityManager.recordInteraction();
|
|
220
|
+
};
|
|
221
|
+
_this.loadStartTime = Date.now();
|
|
222
|
+
_this.validateProps();
|
|
223
|
+
if (props.estimatedListSize) {
|
|
224
|
+
if (props.horizontal) {
|
|
225
|
+
_this.listFixedDimensionSize = props.estimatedListSize.height;
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
_this.listFixedDimensionSize = props.estimatedListSize.width;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
_this.distanceFromWindow =
|
|
232
|
+
(_a = props.estimatedFirstItemOffset) !== null && _a !== void 0 ? _a : ((props.ListHeaderComponent && 1) || 0);
|
|
233
|
+
// eslint-disable-next-line react/state-in-constructor
|
|
234
|
+
_this.state = FlashList.getInitialMutableState(_this);
|
|
235
|
+
_this.viewabilityManager = new ViewabilityManager_1.default(_this);
|
|
236
|
+
_this.itemAnimator = (0, PlatformHelper_1.getItemAnimator)();
|
|
237
|
+
return _this;
|
|
238
|
+
}
|
|
239
|
+
FlashList.prototype.validateProps = function () {
|
|
240
|
+
var _a;
|
|
241
|
+
if (this.props.onRefresh && typeof this.props.refreshing !== "boolean") {
|
|
242
|
+
throw new CustomError_1.default(ExceptionList_1.default.refreshBooleanMissing);
|
|
243
|
+
}
|
|
244
|
+
if (Number((_a = this.props.stickyHeaderIndices) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
|
|
245
|
+
this.props.horizontal) {
|
|
246
|
+
throw new CustomError_1.default(ExceptionList_1.default.stickyWhileHorizontalNotSupported);
|
|
247
|
+
}
|
|
248
|
+
if (Number(this.props.numColumns) > 1 && this.props.horizontal) {
|
|
249
|
+
throw new CustomError_1.default(ExceptionList_1.default.columnsWhileHorizontalNotSupported);
|
|
250
|
+
}
|
|
251
|
+
// `createAnimatedComponent` always passes a blank style object. To avoid warning while using AnimatedFlashList we've modified the check
|
|
252
|
+
if (Object.keys(this.props.style || {}).length > 0) {
|
|
253
|
+
console.warn(Warnings_1.default.styleUnsupported);
|
|
254
|
+
}
|
|
255
|
+
var contentStyleInfo = this.getContentContainerInfo();
|
|
256
|
+
if (contentStyleInfo.unsupportedKeys) {
|
|
257
|
+
console.warn(Warnings_1.default.styleContentContainerUnsupported);
|
|
258
|
+
}
|
|
259
|
+
if (contentStyleInfo.paddingIgnored) {
|
|
260
|
+
console.warn(Warnings_1.default.styleUnsupportedPaddingType);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
// Some of the state variables need to update when props change
|
|
264
|
+
FlashList.getDerivedStateFromProps = function (nextProps, prevState) {
|
|
265
|
+
var _a;
|
|
266
|
+
var newState = tslib_1.__assign({}, prevState);
|
|
267
|
+
if (prevState.numColumns !== nextProps.numColumns) {
|
|
268
|
+
newState.numColumns = nextProps.numColumns || 1;
|
|
269
|
+
newState.layoutProvider = FlashList.getLayoutProvider(newState.numColumns, nextProps);
|
|
270
|
+
}
|
|
271
|
+
if (nextProps.data !== prevState.data) {
|
|
272
|
+
newState.data = nextProps.data;
|
|
273
|
+
newState.dataProvider = prevState.dataProvider.cloneWithRows(nextProps.data);
|
|
274
|
+
if (nextProps.renderItem !== prevState.renderItem) {
|
|
275
|
+
newState.extraData = tslib_1.__assign({}, prevState.extraData);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (nextProps.extraData !== ((_a = prevState.extraData) === null || _a === void 0 ? void 0 : _a.value)) {
|
|
279
|
+
newState.extraData = { value: nextProps.extraData };
|
|
280
|
+
}
|
|
281
|
+
newState.renderItem = nextProps.renderItem;
|
|
282
|
+
newState.layoutProvider.updateProps(nextProps);
|
|
283
|
+
return newState;
|
|
284
|
+
};
|
|
285
|
+
FlashList.getInitialMutableState = function (flashList) {
|
|
286
|
+
var getStableId;
|
|
287
|
+
if (flashList.props.keyExtractor !== null &&
|
|
288
|
+
flashList.props.keyExtractor !== undefined) {
|
|
289
|
+
getStableId = function (index) {
|
|
290
|
+
// We assume `keyExtractor` function will never change from being `null | undefined` to defined and vice versa.
|
|
291
|
+
// Similarly, data should never be `null | undefined` when `getStableId` is called.
|
|
292
|
+
return flashList.props.keyExtractor(flashList.props.data[index], index).toString();
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
return {
|
|
296
|
+
data: null,
|
|
297
|
+
layoutProvider: null,
|
|
298
|
+
dataProvider: new recyclerlistview_1.DataProvider(function (r1, r2) {
|
|
299
|
+
return r1 !== r2;
|
|
300
|
+
}, getStableId),
|
|
301
|
+
numColumns: 0,
|
|
302
|
+
};
|
|
303
|
+
};
|
|
304
|
+
// Using only grid layout provider as it can also act as a listview, sizeProvider is a function to support future overrides
|
|
305
|
+
FlashList.getLayoutProvider = function (numColumns, props) {
|
|
306
|
+
return new GridLayoutProviderWithProps_1.default(
|
|
307
|
+
// max span or, total columns
|
|
308
|
+
numColumns, function (index, props) {
|
|
309
|
+
var _a;
|
|
310
|
+
// type of the item for given index
|
|
311
|
+
var type = (_a = props.getItemType) === null || _a === void 0 ? void 0 : _a.call(props, props.data[index], index, props.extraData);
|
|
312
|
+
return type || 0;
|
|
313
|
+
}, function (index, props, mutableLayout) {
|
|
314
|
+
var _a, _b;
|
|
315
|
+
// span of the item at given index, item can choose to span more than one column
|
|
316
|
+
(_a = props.overrideItemLayout) === null || _a === void 0 ? void 0 : _a.call(props, mutableLayout, props.data[index], index, numColumns, props.extraData);
|
|
317
|
+
return (_b = mutableLayout === null || mutableLayout === void 0 ? void 0 : mutableLayout.span) !== null && _b !== void 0 ? _b : 1;
|
|
318
|
+
}, function (index, props, mutableLayout) {
|
|
319
|
+
var _a;
|
|
320
|
+
// estimated size of the item an given index
|
|
321
|
+
(_a = props.overrideItemLayout) === null || _a === void 0 ? void 0 : _a.call(props, mutableLayout, props.data[index], index, numColumns, props.extraData);
|
|
322
|
+
return mutableLayout === null || mutableLayout === void 0 ? void 0 : mutableLayout.size;
|
|
323
|
+
}, props);
|
|
324
|
+
};
|
|
325
|
+
FlashList.prototype.componentDidMount = function () {
|
|
326
|
+
var _a;
|
|
327
|
+
if (((_a = this.props.data) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
328
|
+
this.raiseOnLoadEventIfNeeded();
|
|
329
|
+
}
|
|
330
|
+
};
|
|
331
|
+
FlashList.prototype.componentWillUnmount = function () {
|
|
332
|
+
this.viewabilityManager.dispose();
|
|
333
|
+
this.clearPostLoadTimeout();
|
|
334
|
+
if (this.sizeWarningTimeoutId !== undefined) {
|
|
335
|
+
clearTimeout(this.sizeWarningTimeoutId);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
FlashList.prototype.render = function () {
|
|
339
|
+
this.isEmptyList = this.state.dataProvider.getSize() === 0;
|
|
340
|
+
this.contentStyle = this.getContentContainerInfo().style;
|
|
341
|
+
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, restProps = tslib_1.__rest(_a, ["drawDistance", "removeClippedSubviews", "stickyHeaderIndices", "horizontal", "onEndReachedThreshold", "estimatedListSize", "initialScrollIndex", "style", "contentContainerStyle"]);
|
|
342
|
+
// RecyclerListView simply ignores if initialScrollIndex is set to 0 because it doesn't understand headers
|
|
343
|
+
// Using initialOffset to force RLV to scroll to the right place
|
|
344
|
+
var initialOffset = (this.isInitialScrollIndexInFirstRow() && this.distanceFromWindow) ||
|
|
345
|
+
undefined;
|
|
346
|
+
var finalDrawDistance = drawDistance === undefined
|
|
347
|
+
? PlatformHelper_1.PlatformConfig.defaultDrawDistance
|
|
348
|
+
: drawDistance;
|
|
349
|
+
return (react_1.default.createElement(StickyHeaderContainer, { overrideRowRenderer: this.stickyRowRenderer, applyWindowCorrection: this.applyWindowCorrection, stickyHeaderIndices: stickyHeaderIndices, style: this.props.horizontal
|
|
350
|
+
? this.emptyObject
|
|
351
|
+
: tslib_1.__assign({ flex: 1 }, this.getTransform()) },
|
|
352
|
+
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(),
|
|
353
|
+
// Min values are being used to suppress RLV's bounded exception
|
|
354
|
+
style: { minHeight: 1, minWidth: 1 }, contentContainerStyle: {
|
|
355
|
+
backgroundColor: this.contentStyle.backgroundColor,
|
|
356
|
+
// Required to handle a scrollview bug. Check: https://github.com/Shopify/flash-list/pull/187
|
|
357
|
+
minHeight: 1,
|
|
358
|
+
minWidth: 1,
|
|
359
|
+
} }, 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) ||
|
|
360
|
+
undefined, initialOffset: initialOffset, onItemLayout: this.onItemLayout, onScroll: this.onScroll, onVisibleIndicesChanged: this.viewabilityManager.shouldListenToVisibleIndices
|
|
361
|
+
? this.viewabilityManager.onVisibleIndicesChanged
|
|
362
|
+
: undefined, windowCorrectionConfig: this.getUpdatedWindowCorrectionConfig(), itemAnimator: this.itemAnimator, suppressBoundedSizeException: true }))));
|
|
363
|
+
};
|
|
364
|
+
FlashList.prototype.getUpdatedWindowCorrectionConfig = function () {
|
|
365
|
+
// 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
|
|
366
|
+
// This isn't clean but it's the only way to get RLV to scroll to the right place
|
|
367
|
+
// TODO: Remove this when RLV fixes this. Current implementation will also fail if column span is overridden in the first row.
|
|
368
|
+
if (this.isInitialScrollIndexInFirstRow()) {
|
|
369
|
+
this.windowCorrectionConfig.applyToInitialOffset = false;
|
|
370
|
+
}
|
|
371
|
+
else {
|
|
372
|
+
this.windowCorrectionConfig.applyToInitialOffset = true;
|
|
373
|
+
}
|
|
374
|
+
this.windowCorrectionConfig.value.windowShift = -this.distanceFromWindow;
|
|
375
|
+
return this.windowCorrectionConfig;
|
|
376
|
+
};
|
|
377
|
+
FlashList.prototype.isInitialScrollIndexInFirstRow = function () {
|
|
378
|
+
var _a;
|
|
379
|
+
return (((_a = this.props.initialScrollIndex) !== null && _a !== void 0 ? _a : this.state.numColumns) <
|
|
380
|
+
this.state.numColumns);
|
|
381
|
+
};
|
|
382
|
+
FlashList.prototype.validateListSize = function (event) {
|
|
383
|
+
var _a = event.nativeEvent.layout, height = _a.height, width = _a.width;
|
|
384
|
+
if (Math.floor(height) <= 1 || Math.floor(width) <= 1) {
|
|
385
|
+
console.warn(Warnings_1.default.unusableRenderedSize);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
FlashList.prototype.getTransform = function () {
|
|
389
|
+
return (this.props.inverted && this.transformStyle) || undefined;
|
|
390
|
+
};
|
|
391
|
+
FlashList.prototype.getContentContainerInfo = function () {
|
|
392
|
+
var _a = (this.props.contentContainerStyle || {}), paddingTop = _a.paddingTop, paddingRight = _a.paddingRight, paddingBottom = _a.paddingBottom, paddingLeft = _a.paddingLeft, padding = _a.padding, paddingVertical = _a.paddingVertical, paddingHorizontal = _a.paddingHorizontal, backgroundColor = _a.backgroundColor, rest = tslib_1.__rest(_a, ["paddingTop", "paddingRight", "paddingBottom", "paddingLeft", "padding", "paddingVertical", "paddingHorizontal", "backgroundColor"]);
|
|
393
|
+
var unsupportedKeys = Object.keys(rest).length > 0;
|
|
394
|
+
if (this.props.horizontal) {
|
|
395
|
+
var paddingIgnored = padding || paddingVertical || paddingTop || paddingBottom;
|
|
396
|
+
return {
|
|
397
|
+
style: {
|
|
398
|
+
paddingLeft: paddingLeft || paddingHorizontal || padding || 0,
|
|
399
|
+
paddingRight: paddingRight || paddingHorizontal || padding || 0,
|
|
400
|
+
backgroundColor: backgroundColor,
|
|
401
|
+
},
|
|
402
|
+
unsupportedKeys: unsupportedKeys,
|
|
403
|
+
paddingIgnored: paddingIgnored,
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
var paddingIgnored = padding || paddingHorizontal || paddingLeft || paddingRight;
|
|
408
|
+
return {
|
|
409
|
+
style: {
|
|
410
|
+
paddingTop: paddingTop || paddingVertical || padding || 0,
|
|
411
|
+
paddingBottom: paddingBottom || paddingVertical || padding || 0,
|
|
412
|
+
backgroundColor: backgroundColor,
|
|
413
|
+
},
|
|
414
|
+
unsupportedKeys: unsupportedKeys,
|
|
415
|
+
paddingIgnored: paddingIgnored,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
};
|
|
419
|
+
FlashList.prototype.getValidComponent = function (component) {
|
|
420
|
+
var PassedComponent = component;
|
|
421
|
+
return ((react_1.default.isValidElement(PassedComponent) && PassedComponent) ||
|
|
422
|
+
(PassedComponent && react_1.default.createElement(PassedComponent, null)) ||
|
|
423
|
+
null);
|
|
424
|
+
};
|
|
425
|
+
Object.defineProperty(FlashList.prototype, "isStickyEnabled", {
|
|
426
|
+
get: function () {
|
|
427
|
+
var _a;
|
|
428
|
+
var currentOffset = ((_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getCurrentScrollOffset()) || 0;
|
|
429
|
+
return currentOffset >= this.distanceFromWindow;
|
|
430
|
+
},
|
|
431
|
+
enumerable: false,
|
|
432
|
+
configurable: true
|
|
433
|
+
});
|
|
434
|
+
/**
|
|
435
|
+
* Disables recycling for the next frame so that layout animations run well.
|
|
436
|
+
* Warning: Avoid this when making large changes to the data as the list might draw too much to run animations. Single item insertions/deletions
|
|
437
|
+
* should be good. With recycling paused the list cannot do much optimization.
|
|
438
|
+
* The next render will run as normal and reuse items.
|
|
439
|
+
*/
|
|
440
|
+
FlashList.prototype.prepareForLayoutAnimationRender = function () {
|
|
441
|
+
var _a;
|
|
442
|
+
if (this.props.keyExtractor === null ||
|
|
443
|
+
this.props.keyExtractor === undefined) {
|
|
444
|
+
console.warn(Warnings_1.default.missingKeyExtractor);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
(_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.prepareForLayoutAnimationRender();
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
FlashList.prototype.scrollToEnd = function (params) {
|
|
451
|
+
var _a;
|
|
452
|
+
(_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.scrollToEnd(Boolean(params === null || params === void 0 ? void 0 : params.animated));
|
|
453
|
+
};
|
|
454
|
+
FlashList.prototype.scrollToIndex = function (params) {
|
|
455
|
+
var _a;
|
|
456
|
+
// known issue: no support for view offset/position
|
|
457
|
+
(_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.scrollToIndex(params.index, Boolean(params.animated));
|
|
458
|
+
};
|
|
459
|
+
FlashList.prototype.scrollToItem = function (params) {
|
|
460
|
+
var _a;
|
|
461
|
+
(_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.scrollToItem(params.item, Boolean(params.animated));
|
|
462
|
+
};
|
|
463
|
+
FlashList.prototype.scrollToOffset = function (params) {
|
|
464
|
+
var _a;
|
|
465
|
+
var x = this.props.horizontal ? params.offset : 0;
|
|
466
|
+
var y = this.props.horizontal ? 0 : params.offset;
|
|
467
|
+
(_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.scrollToOffset(x, y, Boolean(params.animated));
|
|
468
|
+
};
|
|
469
|
+
FlashList.prototype.getScrollableNode = function () {
|
|
470
|
+
var _a, _b;
|
|
471
|
+
return ((_b = (_a = this.rlvRef) === null || _a === void 0 ? void 0 : _a.getScrollableNode) === null || _b === void 0 ? void 0 : _b.call(_a)) || null;
|
|
472
|
+
};
|
|
473
|
+
Object.defineProperty(FlashList.prototype, "recyclerlistview_unsafe", {
|
|
474
|
+
/**
|
|
475
|
+
* Allows access to internal recyclerlistview. This is useful for enabling access to its public APIs.
|
|
476
|
+
* Warning: We may swap recyclerlistview for something else in the future. Use with caution.
|
|
477
|
+
*/
|
|
478
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
479
|
+
get: function () {
|
|
480
|
+
return this.rlvRef;
|
|
481
|
+
},
|
|
482
|
+
enumerable: false,
|
|
483
|
+
configurable: true
|
|
484
|
+
});
|
|
485
|
+
Object.defineProperty(FlashList.prototype, "firstItemOffset", {
|
|
486
|
+
/**
|
|
487
|
+
* 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.
|
|
488
|
+
*/
|
|
489
|
+
get: function () {
|
|
490
|
+
return this.distanceFromWindow;
|
|
491
|
+
},
|
|
492
|
+
enumerable: false,
|
|
493
|
+
configurable: true
|
|
494
|
+
});
|
|
495
|
+
FlashList.defaultProps = {
|
|
496
|
+
data: [],
|
|
497
|
+
numColumns: 1,
|
|
498
|
+
};
|
|
499
|
+
return FlashList;
|
|
500
|
+
}(react_1.default.PureComponent));
|
|
501
|
+
exports.default = FlashList;
|
|
502
|
+
//# sourceMappingURL=FlashList.js.map
|