@shopify/flash-list 1.8.0 → 2.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -26
- package/dist/FlashListProps.d.ts +65 -2
- package/dist/FlashListProps.d.ts.map +1 -1
- package/dist/__tests__/AverageWindow.test.js +35 -0
- package/dist/__tests__/AverageWindow.test.js.map +1 -1
- package/dist/enableNewCore.d.ts +3 -0
- package/dist/enableNewCore.d.ts.map +1 -0
- package/dist/enableNewCore.js +25 -0
- package/dist/enableNewCore.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -8
- package/dist/index.js.map +1 -1
- package/dist/recyclerview/RecycleKeyManager.d.ts +82 -0
- package/dist/recyclerview/RecycleKeyManager.d.ts.map +1 -0
- package/dist/recyclerview/RecycleKeyManager.js +135 -0
- package/dist/recyclerview/RecycleKeyManager.js.map +1 -0
- package/dist/recyclerview/RecyclerView.d.ts +12 -0
- package/dist/recyclerview/RecyclerView.d.ts.map +1 -0
- package/dist/recyclerview/RecyclerView.js +283 -0
- package/dist/recyclerview/RecyclerView.js.map +1 -0
- package/dist/recyclerview/RecyclerViewContextProvider.d.ts +12 -0
- package/dist/recyclerview/RecyclerViewContextProvider.d.ts.map +1 -0
- package/dist/recyclerview/RecyclerViewContextProvider.js +11 -0
- package/dist/recyclerview/RecyclerViewContextProvider.js.map +1 -0
- package/dist/recyclerview/RecyclerViewManager.d.ts +52 -0
- package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -0
- package/dist/recyclerview/RecyclerViewManager.js +323 -0
- package/dist/recyclerview/RecyclerViewManager.js.map +1 -0
- package/dist/recyclerview/RecyclerViewProps.d.ts +9 -0
- package/dist/recyclerview/RecyclerViewProps.d.ts.map +1 -0
- package/dist/recyclerview/RecyclerViewProps.js +3 -0
- package/dist/recyclerview/RecyclerViewProps.js.map +1 -0
- package/dist/recyclerview/ViewHolder.d.ts +45 -0
- package/dist/recyclerview/ViewHolder.d.ts.map +1 -0
- package/dist/recyclerview/ViewHolder.js +96 -0
- package/dist/recyclerview/ViewHolder.js.map +1 -0
- package/dist/recyclerview/ViewHolderCollection.d.ts +57 -0
- package/dist/recyclerview/ViewHolderCollection.d.ts.map +1 -0
- package/dist/recyclerview/ViewHolderCollection.js +75 -0
- package/dist/recyclerview/ViewHolderCollection.js.map +1 -0
- package/dist/recyclerview/components/CompatScroller.d.ts +7 -0
- package/dist/recyclerview/components/CompatScroller.d.ts.map +1 -0
- package/dist/recyclerview/components/CompatScroller.js +8 -0
- package/dist/recyclerview/components/CompatScroller.js.map +1 -0
- package/dist/recyclerview/components/CompatView.d.ts +7 -0
- package/dist/recyclerview/components/CompatView.d.ts.map +1 -0
- package/dist/recyclerview/components/CompatView.js +8 -0
- package/dist/recyclerview/components/CompatView.js.map +1 -0
- package/dist/recyclerview/components/ScrollAnchor.d.ts +28 -0
- package/dist/recyclerview/components/ScrollAnchor.d.ts.map +1 -0
- package/dist/recyclerview/components/ScrollAnchor.js +35 -0
- package/dist/recyclerview/components/ScrollAnchor.js.map +1 -0
- package/dist/recyclerview/components/StickyHeaders.d.ts +38 -0
- package/dist/recyclerview/components/StickyHeaders.d.ts.map +1 -0
- package/dist/recyclerview/components/StickyHeaders.js +119 -0
- package/dist/recyclerview/components/StickyHeaders.js.map +1 -0
- package/dist/recyclerview/helpers/ConsecutiveNumbers.d.ts +51 -0
- package/dist/recyclerview/helpers/ConsecutiveNumbers.d.ts.map +1 -0
- package/dist/recyclerview/helpers/ConsecutiveNumbers.js +122 -0
- package/dist/recyclerview/helpers/ConsecutiveNumbers.js.map +1 -0
- package/dist/recyclerview/helpers/EngagedIndicesTracker.d.ts +59 -0
- package/dist/recyclerview/helpers/EngagedIndicesTracker.d.ts.map +1 -0
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js +138 -0
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js.map +1 -0
- package/dist/recyclerview/hooks/useBoundDetection.d.ts +19 -0
- package/dist/recyclerview/hooks/useBoundDetection.d.ts.map +1 -0
- package/dist/recyclerview/hooks/useBoundDetection.js +103 -0
- package/dist/recyclerview/hooks/useBoundDetection.js.map +1 -0
- package/dist/recyclerview/hooks/useLayoutState.d.ts +12 -0
- package/dist/recyclerview/hooks/useLayoutState.d.ts.map +1 -0
- package/dist/recyclerview/hooks/useLayoutState.js +43 -0
- package/dist/recyclerview/hooks/useLayoutState.js.map +1 -0
- package/dist/recyclerview/hooks/useOnLoad.d.ts +25 -0
- package/dist/recyclerview/hooks/useOnLoad.d.ts.map +1 -0
- package/dist/recyclerview/hooks/useOnLoad.js +73 -0
- package/dist/recyclerview/hooks/useOnLoad.js.map +1 -0
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts +72 -0
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -0
- package/dist/recyclerview/hooks/useRecyclerViewController.js +370 -0
- package/dist/recyclerview/hooks/useRecyclerViewController.js.map +1 -0
- package/dist/recyclerview/hooks/useRecyclerViewManager.d.ts +6 -0
- package/dist/recyclerview/hooks/useRecyclerViewManager.d.ts.map +1 -0
- package/dist/recyclerview/hooks/useRecyclerViewManager.js +27 -0
- package/dist/recyclerview/hooks/useRecyclerViewManager.js.map +1 -0
- package/dist/recyclerview/hooks/useRecyclingState.d.ts +16 -0
- package/dist/recyclerview/hooks/useRecyclingState.d.ts.map +1 -0
- package/dist/recyclerview/hooks/useRecyclingState.js +54 -0
- package/dist/recyclerview/hooks/useRecyclingState.js.map +1 -0
- package/dist/recyclerview/hooks/useSecondaryProps.d.ts +27 -0
- package/dist/recyclerview/hooks/useSecondaryProps.d.ts.map +1 -0
- package/dist/recyclerview/hooks/useSecondaryProps.js +93 -0
- package/dist/recyclerview/hooks/useSecondaryProps.js.map +1 -0
- package/dist/recyclerview/hooks/useUnmountFlag.d.ts +11 -0
- package/dist/recyclerview/hooks/useUnmountFlag.d.ts.map +1 -0
- package/dist/recyclerview/hooks/useUnmountFlag.js +28 -0
- package/dist/recyclerview/hooks/useUnmountFlag.js.map +1 -0
- package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts +65 -0
- package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts.map +1 -0
- package/dist/recyclerview/layout-managers/GridLayoutManager.js +204 -0
- package/dist/recyclerview/layout-managers/GridLayoutManager.js.map +1 -0
- package/dist/recyclerview/layout-managers/LayoutManager.d.ts +281 -0
- package/dist/recyclerview/layout-managers/LayoutManager.d.ts.map +1 -0
- package/dist/recyclerview/layout-managers/LayoutManager.js +250 -0
- package/dist/recyclerview/layout-managers/LayoutManager.js.map +1 -0
- package/dist/recyclerview/layout-managers/LinearLayoutManager.d.ts +52 -0
- package/dist/recyclerview/layout-managers/LinearLayoutManager.d.ts.map +1 -0
- package/dist/recyclerview/layout-managers/LinearLayoutManager.js +191 -0
- package/dist/recyclerview/layout-managers/LinearLayoutManager.js.map +1 -0
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.d.ts +73 -0
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.d.ts.map +1 -0
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.js +274 -0
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.js.map +1 -0
- package/dist/recyclerview/utils/adjustOffsetForRTL.d.ts +12 -0
- package/dist/recyclerview/utils/adjustOffsetForRTL.d.ts.map +1 -0
- package/dist/recyclerview/utils/adjustOffsetForRTL.js +18 -0
- package/dist/recyclerview/utils/adjustOffsetForRTL.js.map +1 -0
- package/dist/recyclerview/utils/componentUtils.d.ts +19 -0
- package/dist/recyclerview/utils/componentUtils.d.ts.map +1 -0
- package/dist/recyclerview/utils/componentUtils.js +32 -0
- package/dist/recyclerview/utils/componentUtils.js.map +1 -0
- package/dist/recyclerview/utils/findVisibleIndex.d.ts +24 -0
- package/dist/recyclerview/utils/findVisibleIndex.d.ts.map +1 -0
- package/dist/recyclerview/utils/findVisibleIndex.js +82 -0
- package/dist/recyclerview/utils/findVisibleIndex.js.map +1 -0
- package/dist/recyclerview/utils/measureLayout.d.ts +56 -0
- package/dist/recyclerview/utils/measureLayout.d.ts.map +1 -0
- package/dist/recyclerview/utils/measureLayout.js +77 -0
- package/dist/recyclerview/utils/measureLayout.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/AverageWindow.d.ts +13 -0
- package/dist/utils/AverageWindow.d.ts.map +1 -1
- package/dist/utils/AverageWindow.js +30 -1
- package/dist/utils/AverageWindow.js.map +1 -1
- package/package.json +1 -1
- package/src/FlashListProps.ts +73 -2
- package/src/__tests__/AverageWindow.test.ts +49 -1
- package/src/enableNewCore.ts +22 -0
- package/src/index.ts +21 -0
- package/src/recyclerview/RecycleKeyManager.ts +185 -0
- package/src/recyclerview/RecyclerView.tsx +500 -0
- package/src/recyclerview/RecyclerViewContextProvider.ts +19 -0
- package/src/recyclerview/RecyclerViewManager.ts +379 -0
- package/src/recyclerview/RecyclerViewProps.ts +10 -0
- package/src/recyclerview/ViewHolder.tsx +173 -0
- package/src/recyclerview/ViewHolderCollection.tsx +164 -0
- package/src/recyclerview/components/CompatScroller.ts +9 -0
- package/src/recyclerview/components/CompatView.ts +9 -0
- package/src/recyclerview/components/ScrollAnchor.tsx +53 -0
- package/src/recyclerview/components/StickyHeaders.tsx +210 -0
- package/src/recyclerview/helpers/ConsecutiveNumbers.ts +120 -0
- package/src/recyclerview/helpers/EngagedIndicesTracker.ts +191 -0
- package/src/recyclerview/hooks/useBoundDetection.ts +127 -0
- package/src/recyclerview/hooks/useLayoutState.ts +46 -0
- package/src/recyclerview/hooks/useOnLoad.ts +78 -0
- package/src/recyclerview/hooks/useRecyclerViewController.tsx +487 -0
- package/src/recyclerview/hooks/useRecyclerViewManager.ts +30 -0
- package/src/recyclerview/hooks/useRecyclingState.ts +63 -0
- package/src/recyclerview/hooks/useSecondaryProps.tsx +119 -0
- package/src/recyclerview/hooks/useUnmountFlag.ts +26 -0
- package/src/recyclerview/layout-managers/GridLayoutManager.ts +215 -0
- package/src/recyclerview/layout-managers/LayoutManager.ts +493 -0
- package/src/recyclerview/layout-managers/LinearLayoutManager.ts +167 -0
- package/src/recyclerview/layout-managers/MasonryLayoutManager.ts +302 -0
- package/src/recyclerview/utils/adjustOffsetForRTL.ts +17 -0
- package/src/recyclerview/utils/componentUtils.ts +28 -0
- package/src/recyclerview/utils/findVisibleIndex.ts +94 -0
- package/src/recyclerview/utils/measureLayout.ts +89 -0
- package/src/utils/AverageWindow.ts +33 -0
- package/src/viewability/ViewToken.ts +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Hook that provides a way to track component unmounting state.
|
|
4
|
+
* This hook is particularly useful for preventing state updates or side effects
|
|
5
|
+
* after a component has unmounted, helping to avoid memory leaks and race conditions.
|
|
6
|
+
*
|
|
7
|
+
* @returns A ref containing a boolean flag that indicates whether the component is unmounted
|
|
8
|
+
* (true) or mounted (false)
|
|
9
|
+
*/
|
|
10
|
+
export declare const useUnmountFlag: () => import("react").MutableRefObject<boolean>;
|
|
11
|
+
//# sourceMappingURL=useUnmountFlag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUnmountFlag.d.ts","sourceRoot":"","sources":["../../../src/recyclerview/hooks/useUnmountFlag.ts"],"names":[],"mappings":";AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,iDAe1B,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useUnmountFlag = void 0;
|
|
4
|
+
var react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* Hook that provides a way to track component unmounting state.
|
|
7
|
+
* This hook is particularly useful for preventing state updates or side effects
|
|
8
|
+
* after a component has unmounted, helping to avoid memory leaks and race conditions.
|
|
9
|
+
*
|
|
10
|
+
* @returns A ref containing a boolean flag that indicates whether the component is unmounted
|
|
11
|
+
* (true) or mounted (false)
|
|
12
|
+
*/
|
|
13
|
+
var useUnmountFlag = function () {
|
|
14
|
+
// Create a ref to store the unmount state
|
|
15
|
+
// Using ref ensures the value persists between renders without causing re-renders
|
|
16
|
+
var isUnmounted = (0, react_1.useRef)(false);
|
|
17
|
+
// Use layoutEffect to set up cleanup on unmount
|
|
18
|
+
// This ensures the flag is set before any other cleanup effects run
|
|
19
|
+
(0, react_1.useLayoutEffect)(function () {
|
|
20
|
+
// Cleanup function that runs when the component unmounts
|
|
21
|
+
return function () {
|
|
22
|
+
isUnmounted.current = true;
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
return isUnmounted;
|
|
26
|
+
};
|
|
27
|
+
exports.useUnmountFlag = useUnmountFlag;
|
|
28
|
+
//# sourceMappingURL=useUnmountFlag.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUnmountFlag.js","sourceRoot":"","sources":["../../../src/recyclerview/hooks/useUnmountFlag.ts"],"names":[],"mappings":";;;AAAA,+BAAgD;AAEhD;;;;;;;GAOG;AACI,IAAM,cAAc,GAAG;IAC5B,0CAA0C;IAC1C,kFAAkF;IAClF,IAAM,WAAW,GAAG,IAAA,cAAM,EAAC,KAAK,CAAC,CAAC;IAElC,gDAAgD;IAChD,oEAAoE;IACpE,IAAA,uBAAe,EAAC;QACd,yDAAyD;QACzD,OAAO;YACL,WAAW,CAAC,OAAO,GAAG,IAAI,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC;AAfW,QAAA,cAAc,kBAezB"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { LayoutParams, RVDimension, RVLayoutInfo, RVLayoutManager } from "./LayoutManager";
|
|
2
|
+
/**
|
|
3
|
+
* GridLayoutManager implementation that arranges items in a grid pattern.
|
|
4
|
+
* Items are placed in rows and columns, with support for items spanning multiple columns.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RVGridLayoutManagerImpl extends RVLayoutManager {
|
|
7
|
+
/** The width of the bounded area for the grid */
|
|
8
|
+
private boundedSize;
|
|
9
|
+
constructor(params: LayoutParams, previousLayoutManager?: RVLayoutManager);
|
|
10
|
+
/**
|
|
11
|
+
* Updates layout parameters and triggers recomputation if necessary.
|
|
12
|
+
* @param params New layout parameters
|
|
13
|
+
*/
|
|
14
|
+
updateLayoutParams(params: LayoutParams): void;
|
|
15
|
+
/**
|
|
16
|
+
* Processes layout information for items, updating their dimensions.
|
|
17
|
+
* @param layoutInfo Array of layout information for items
|
|
18
|
+
* @param itemCount Total number of items in the list
|
|
19
|
+
*/
|
|
20
|
+
processLayoutInfo(layoutInfo: RVLayoutInfo[], itemCount: number): void;
|
|
21
|
+
/**
|
|
22
|
+
* Estimates layout dimensions for an item at the given index.
|
|
23
|
+
* @param index Index of the item to estimate layout for
|
|
24
|
+
*/
|
|
25
|
+
estimateLayout(index: number): void;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the total size of the layout area.
|
|
28
|
+
* @returns RVDimension containing width and height of the layout
|
|
29
|
+
*/
|
|
30
|
+
getLayoutSize(): RVDimension;
|
|
31
|
+
/**
|
|
32
|
+
* Recomputes layouts for items in the given range.
|
|
33
|
+
* @param startIndex Starting index of items to recompute
|
|
34
|
+
* @param endIndex Ending index of items to recompute
|
|
35
|
+
*/
|
|
36
|
+
recomputeLayouts(startIndex: number, endIndex: number): void;
|
|
37
|
+
/**
|
|
38
|
+
* Calculates the width of an item based on its span.
|
|
39
|
+
* @param index Index of the item
|
|
40
|
+
* @returns Width of the item
|
|
41
|
+
*/
|
|
42
|
+
private getWidth;
|
|
43
|
+
/**
|
|
44
|
+
* Processes items in a row and returns the tallest item.
|
|
45
|
+
* Also handles height normalization for items in the same row.
|
|
46
|
+
* Tallest item per row helps in forcing tallest items height on neighbouring items.
|
|
47
|
+
* @param index Index of the last item in the row
|
|
48
|
+
* @returns The tallest item in the row
|
|
49
|
+
*/
|
|
50
|
+
private processAndReturnTallestItemInRow;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if an item can fit within the bounded width.
|
|
53
|
+
* @param itemX Starting X position of the item
|
|
54
|
+
* @param width Width of the item
|
|
55
|
+
* @returns True if the item fits within bounds
|
|
56
|
+
*/
|
|
57
|
+
private checkBounds;
|
|
58
|
+
/**
|
|
59
|
+
* Locates the index of the first item in the current row.
|
|
60
|
+
* @param startIndex Index to start searching from
|
|
61
|
+
* @returns Index of the first item in the row
|
|
62
|
+
*/
|
|
63
|
+
private locateFirstNeighbourIndex;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=GridLayoutManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GridLayoutManager.d.ts","sourceRoot":"","sources":["../../../src/recyclerview/layout-managers/GridLayoutManager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,WAAW,EAEX,YAAY,EACZ,eAAe,EAChB,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,qBAAa,uBAAwB,SAAQ,eAAe;IAC1D,iDAAiD;IACjD,OAAO,CAAC,WAAW,CAAS;gBAEhB,MAAM,EAAE,YAAY,EAAE,qBAAqB,CAAC,EAAE,eAAe;IAKzE;;;OAGG;IACH,kBAAkB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAqB9C;;;;OAIG;IACH,iBAAiB,CAAC,UAAU,EAAE,YAAY,EAAE,EAAE,SAAS,EAAE,MAAM;IAU/D;;;OAGG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM;IAS5B;;;OAGG;IACH,aAAa,IAAI,WAAW;IAW5B;;;;OAIG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAqB5D;;;;OAIG;IACH,OAAO,CAAC,QAAQ;IAKhB;;;;;;OAMG;IACH,OAAO,CAAC,gCAAgC;IAsDxC;;;;;OAKG;IACH,OAAO,CAAC,WAAW;IAKnB;;;;OAIG;IACH,OAAO,CAAC,yBAAyB;CAYlC"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RVGridLayoutManagerImpl = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var LayoutManager_1 = require("./LayoutManager");
|
|
6
|
+
/**
|
|
7
|
+
* GridLayoutManager implementation that arranges items in a grid pattern.
|
|
8
|
+
* Items are placed in rows and columns, with support for items spanning multiple columns.
|
|
9
|
+
*/
|
|
10
|
+
var RVGridLayoutManagerImpl = /** @class */ (function (_super) {
|
|
11
|
+
tslib_1.__extends(RVGridLayoutManagerImpl, _super);
|
|
12
|
+
function RVGridLayoutManagerImpl(params, previousLayoutManager) {
|
|
13
|
+
var _this = _super.call(this, params, previousLayoutManager) || this;
|
|
14
|
+
_this.boundedSize = params.windowSize.width;
|
|
15
|
+
return _this;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Updates layout parameters and triggers recomputation if necessary.
|
|
19
|
+
* @param params New layout parameters
|
|
20
|
+
*/
|
|
21
|
+
RVGridLayoutManagerImpl.prototype.updateLayoutParams = function (params) {
|
|
22
|
+
var prevNumColumns = this.maxColumns;
|
|
23
|
+
_super.prototype.updateLayoutParams.call(this, params);
|
|
24
|
+
if (this.boundedSize !== params.windowSize.width ||
|
|
25
|
+
prevNumColumns !== params.maxColumns) {
|
|
26
|
+
this.boundedSize = params.windowSize.width;
|
|
27
|
+
if (this.layouts.length > 0) {
|
|
28
|
+
//update all widths
|
|
29
|
+
for (var i = 0; i < this.layouts.length; i++) {
|
|
30
|
+
this.layouts[i].width = this.getWidth(i);
|
|
31
|
+
}
|
|
32
|
+
//console.log("-----> recomputeLayouts");
|
|
33
|
+
this.recomputeLayouts(0, this.layouts.length - 1);
|
|
34
|
+
this.requiresRepaint = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Processes layout information for items, updating their dimensions.
|
|
40
|
+
* @param layoutInfo Array of layout information for items
|
|
41
|
+
* @param itemCount Total number of items in the list
|
|
42
|
+
*/
|
|
43
|
+
RVGridLayoutManagerImpl.prototype.processLayoutInfo = function (layoutInfo, itemCount) {
|
|
44
|
+
var e_1, _a;
|
|
45
|
+
try {
|
|
46
|
+
for (var layoutInfo_1 = tslib_1.__values(layoutInfo), layoutInfo_1_1 = layoutInfo_1.next(); !layoutInfo_1_1.done; layoutInfo_1_1 = layoutInfo_1.next()) {
|
|
47
|
+
var info = layoutInfo_1_1.value;
|
|
48
|
+
var index = info.index, dimensions = info.dimensions;
|
|
49
|
+
var layout = this.layouts[index];
|
|
50
|
+
layout.height = dimensions.height;
|
|
51
|
+
layout.isHeightMeasured = true;
|
|
52
|
+
layout.isWidthMeasured = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
56
|
+
finally {
|
|
57
|
+
try {
|
|
58
|
+
if (layoutInfo_1_1 && !layoutInfo_1_1.done && (_a = layoutInfo_1.return)) _a.call(layoutInfo_1);
|
|
59
|
+
}
|
|
60
|
+
finally { if (e_1) throw e_1.error; }
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Estimates layout dimensions for an item at the given index.
|
|
65
|
+
* @param index Index of the item to estimate layout for
|
|
66
|
+
*/
|
|
67
|
+
RVGridLayoutManagerImpl.prototype.estimateLayout = function (index) {
|
|
68
|
+
var layout = this.layouts[index];
|
|
69
|
+
layout.width = this.getWidth(index);
|
|
70
|
+
layout.height = this.getEstimatedHeight(index);
|
|
71
|
+
layout.isWidthMeasured = true;
|
|
72
|
+
layout.enforcedWidth = true;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Returns the total size of the layout area.
|
|
76
|
+
* @returns RVDimension containing width and height of the layout
|
|
77
|
+
*/
|
|
78
|
+
RVGridLayoutManagerImpl.prototype.getLayoutSize = function () {
|
|
79
|
+
if (this.layouts.length === 0)
|
|
80
|
+
return { width: 0, height: 0 };
|
|
81
|
+
var lastRowTallestItem = this.processAndReturnTallestItemInRow(this.layouts.length - 1);
|
|
82
|
+
return {
|
|
83
|
+
width: this.boundedSize,
|
|
84
|
+
height: lastRowTallestItem.y + lastRowTallestItem.height,
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Recomputes layouts for items in the given range.
|
|
89
|
+
* @param startIndex Starting index of items to recompute
|
|
90
|
+
* @param endIndex Ending index of items to recompute
|
|
91
|
+
*/
|
|
92
|
+
RVGridLayoutManagerImpl.prototype.recomputeLayouts = function (startIndex, endIndex) {
|
|
93
|
+
var newStartIndex = this.locateFirstNeighbourIndex(startIndex);
|
|
94
|
+
var startVal = this.getLayout(newStartIndex);
|
|
95
|
+
var startX = startVal.x;
|
|
96
|
+
var startY = startVal.y;
|
|
97
|
+
for (var i = newStartIndex; i <= endIndex; i++) {
|
|
98
|
+
var layout = this.getLayout(i);
|
|
99
|
+
if (!this.checkBounds(startX, layout.width)) {
|
|
100
|
+
var tallestItem = this.processAndReturnTallestItemInRow(i);
|
|
101
|
+
startY = tallestItem.y + tallestItem.height;
|
|
102
|
+
startX = 0;
|
|
103
|
+
}
|
|
104
|
+
layout.x = startX;
|
|
105
|
+
layout.y = startY;
|
|
106
|
+
startX += layout.width;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Calculates the width of an item based on its span.
|
|
111
|
+
* @param index Index of the item
|
|
112
|
+
* @returns Width of the item
|
|
113
|
+
*/
|
|
114
|
+
RVGridLayoutManagerImpl.prototype.getWidth = function (index) {
|
|
115
|
+
var _a;
|
|
116
|
+
var span = (_a = this.getSpanSizeInfo(index).span) !== null && _a !== void 0 ? _a : 1;
|
|
117
|
+
return (this.boundedSize / this.maxColumns) * span;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Processes items in a row and returns the tallest item.
|
|
121
|
+
* Also handles height normalization for items in the same row.
|
|
122
|
+
* Tallest item per row helps in forcing tallest items height on neighbouring items.
|
|
123
|
+
* @param index Index of the last item in the row
|
|
124
|
+
* @returns The tallest item in the row
|
|
125
|
+
*/
|
|
126
|
+
RVGridLayoutManagerImpl.prototype.processAndReturnTallestItemInRow = function (index) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
var startIndex = this.locateFirstNeighbourIndex(index);
|
|
129
|
+
var y = this.layouts[startIndex].y;
|
|
130
|
+
var tallestItem;
|
|
131
|
+
var maxHeight = 0;
|
|
132
|
+
var i = startIndex;
|
|
133
|
+
var isMeasured = false;
|
|
134
|
+
// TODO: Manage precision problems
|
|
135
|
+
while (Math.ceil(this.layouts[i].y) === Math.ceil(y)) {
|
|
136
|
+
var layout = this.layouts[i];
|
|
137
|
+
isMeasured = isMeasured || Boolean(layout.isHeightMeasured);
|
|
138
|
+
maxHeight = Math.max(maxHeight, layout.height);
|
|
139
|
+
if (layout.height > ((_a = layout.minHeight) !== null && _a !== void 0 ? _a : 0) &&
|
|
140
|
+
layout.height > ((_b = tallestItem === null || tallestItem === void 0 ? void 0 : tallestItem.height) !== null && _b !== void 0 ? _b : 0)) {
|
|
141
|
+
tallestItem = layout;
|
|
142
|
+
}
|
|
143
|
+
i++;
|
|
144
|
+
if (i >= this.layouts.length) {
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
tallestItem = tallestItem !== null && tallestItem !== void 0 ? tallestItem : this.layouts[startIndex];
|
|
149
|
+
if (!isMeasured) {
|
|
150
|
+
return tallestItem;
|
|
151
|
+
}
|
|
152
|
+
if (tallestItem) {
|
|
153
|
+
var targetHeight = tallestItem.height;
|
|
154
|
+
if (maxHeight - tallestItem.height > 1) {
|
|
155
|
+
targetHeight = 0;
|
|
156
|
+
this.requiresRepaint = true;
|
|
157
|
+
}
|
|
158
|
+
i = startIndex;
|
|
159
|
+
// TODO: Manage precision problems
|
|
160
|
+
while (Math.ceil(this.layouts[i].y) === Math.ceil(y)) {
|
|
161
|
+
this.layouts[i].minHeight = targetHeight;
|
|
162
|
+
if (targetHeight > 0) {
|
|
163
|
+
this.layouts[i].height = targetHeight;
|
|
164
|
+
}
|
|
165
|
+
i++;
|
|
166
|
+
if (i >= this.layouts.length) {
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
tallestItem.minHeight = 0;
|
|
171
|
+
}
|
|
172
|
+
return tallestItem;
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Checks if an item can fit within the bounded width.
|
|
176
|
+
* @param itemX Starting X position of the item
|
|
177
|
+
* @param width Width of the item
|
|
178
|
+
* @returns True if the item fits within bounds
|
|
179
|
+
*/
|
|
180
|
+
RVGridLayoutManagerImpl.prototype.checkBounds = function (itemX, width) {
|
|
181
|
+
// TODO: Manage precision problems
|
|
182
|
+
return itemX + width <= this.boundedSize + 0.9;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Locates the index of the first item in the current row.
|
|
186
|
+
* @param startIndex Index to start searching from
|
|
187
|
+
* @returns Index of the first item in the row
|
|
188
|
+
*/
|
|
189
|
+
RVGridLayoutManagerImpl.prototype.locateFirstNeighbourIndex = function (startIndex) {
|
|
190
|
+
if (startIndex === 0) {
|
|
191
|
+
return 0;
|
|
192
|
+
}
|
|
193
|
+
var i = startIndex - 1;
|
|
194
|
+
for (; i >= 0; i--) {
|
|
195
|
+
if (this.layouts[i].x === 0) {
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return Math.max(i, 0);
|
|
200
|
+
};
|
|
201
|
+
return RVGridLayoutManagerImpl;
|
|
202
|
+
}(LayoutManager_1.RVLayoutManager));
|
|
203
|
+
exports.RVGridLayoutManagerImpl = RVGridLayoutManagerImpl;
|
|
204
|
+
//# sourceMappingURL=GridLayoutManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GridLayoutManager.js","sourceRoot":"","sources":["../../../src/recyclerview/layout-managers/GridLayoutManager.ts"],"names":[],"mappings":";;;;AAAA,iDAMyB;AAEzB;;;GAGG;AACH;IAA6C,mDAAe;IAI1D,iCAAY,MAAoB,EAAE,qBAAuC;QAAzE,YACE,kBAAM,MAAM,EAAE,qBAAqB,CAAC,SAErC;QADC,KAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC;;IAC7C,CAAC;IAED;;;OAGG;IACH,oDAAkB,GAAlB,UAAmB,MAAoB;QACrC,IAAM,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC;QACvC,iBAAM,kBAAkB,YAAC,MAAM,CAAC,CAAC;QACjC,IACE,IAAI,CAAC,WAAW,KAAK,MAAM,CAAC,UAAU,CAAC,KAAK;YAC5C,cAAc,KAAK,MAAM,CAAC,UAAU,EACpC;YACA,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC;YAC3C,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE;gBAC3B,mBAAmB;gBACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;oBAC5C,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;iBAC1C;gBACD,yCAAyC;gBAEzC,IAAI,CAAC,gBAAgB,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;gBAClD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;aAC7B;SACF;IACH,CAAC;IAED;;;;OAIG;IACH,mDAAiB,GAAjB,U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
|
|
1
|
+
import { ConsecutiveNumbers } from "../helpers/ConsecutiveNumbers";
|
|
2
|
+
/**
|
|
3
|
+
* Base abstract class for layout managers in the recycler view system.
|
|
4
|
+
* Provides common functionality for managing item layouts and dimensions.
|
|
5
|
+
* Supports both horizontal and vertical layouts with dynamic item sizing.
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class RVLayoutManager {
|
|
8
|
+
/** Whether the layout is horizontal (true) or vertical (false) */
|
|
9
|
+
protected horizontal: boolean;
|
|
10
|
+
/** Array of layout information for all items */
|
|
11
|
+
protected layouts: RVLayout[];
|
|
12
|
+
/** Dimensions of the visible window/viewport */
|
|
13
|
+
protected windowSize: RVDimension;
|
|
14
|
+
/** Information about item spans and sizes */
|
|
15
|
+
protected spanSizeInfo: SpanSizeInfo;
|
|
16
|
+
/** Maximum number of columns in the layout */
|
|
17
|
+
protected maxColumns: number;
|
|
18
|
+
/** Optional callback to override default item layout */
|
|
19
|
+
protected overrideItemLayout?: (index: number, layout: SpanSizeInfo) => void;
|
|
20
|
+
/** Whether to optimize item placement for better space utilization */
|
|
21
|
+
protected optimizeItemArrangement: boolean;
|
|
22
|
+
/** Flag indicating if the layout requires repainting */
|
|
23
|
+
requiresRepaint: boolean;
|
|
24
|
+
/** Optional function to determine item type */
|
|
25
|
+
private _getItemType?;
|
|
26
|
+
/** Window for tracking average heights by item type */
|
|
27
|
+
private heightAverageWindow;
|
|
28
|
+
/** Window for tracking average widths by item type */
|
|
29
|
+
private widthAverageWindow;
|
|
30
|
+
/** Maximum number of items to process in a single layout pass */
|
|
31
|
+
private maxItemsToProcess;
|
|
32
|
+
constructor(params: LayoutParams, previousLayoutManager?: RVLayoutManager);
|
|
33
|
+
/**
|
|
34
|
+
* Gets the type of an item at the given index.
|
|
35
|
+
* @param index Index of the item
|
|
36
|
+
* @returns Item type or "default" if not specified
|
|
37
|
+
*/
|
|
38
|
+
private getItemType;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the estimated width for an item based on its type.
|
|
41
|
+
* @param index Index of the item
|
|
42
|
+
* @returns Estimated width
|
|
43
|
+
*/
|
|
44
|
+
protected getEstimatedWidth(index: number): number;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the estimated height for an item based on its type.
|
|
47
|
+
* @param index Index of the item
|
|
48
|
+
* @returns Estimated height
|
|
49
|
+
*/
|
|
50
|
+
protected getEstimatedHeight(index: number): number;
|
|
51
|
+
/**
|
|
52
|
+
* Abstract method to process layout information for items.
|
|
53
|
+
* @param layoutInfo Array of layout information for items
|
|
54
|
+
* @param itemCount Total number of items in the list
|
|
55
|
+
* @returns Index of first modified layout or void
|
|
56
|
+
*/
|
|
57
|
+
protected abstract processLayoutInfo(layoutInfo: RVLayoutInfo[], itemCount: number): number | void;
|
|
58
|
+
/**
|
|
59
|
+
* Checks if the layout is horizontal.
|
|
60
|
+
* @returns True if horizontal, false if vertical
|
|
61
|
+
*/
|
|
62
|
+
isHorizontal(): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Gets the dimensions of the visible window.
|
|
65
|
+
* @returns Window dimensions
|
|
66
|
+
*/
|
|
67
|
+
getWindowsSize(): RVDimension;
|
|
68
|
+
/**
|
|
69
|
+
* Gets indices of items currently visible in the viewport.
|
|
70
|
+
* Uses binary search for efficient lookup.
|
|
71
|
+
* @param unboundDimensionStart Start position of viewport
|
|
72
|
+
* @param unboundDimensionEnd End position of viewport
|
|
73
|
+
* @returns ConsecutiveNumbers containing visible indices
|
|
74
|
+
*/
|
|
75
|
+
getVisibleLayouts(unboundDimensionStart: number, unboundDimensionEnd: number): ConsecutiveNumbers;
|
|
76
|
+
/**
|
|
77
|
+
* Removes layout information for specified indices and recomputes layout.
|
|
78
|
+
* @param indices Array of indices to remove
|
|
79
|
+
*/
|
|
80
|
+
deleteLayout(indices: number[]): void;
|
|
81
|
+
/**
|
|
82
|
+
* Updates layout information for items and recomputes layout if necessary.
|
|
83
|
+
* @param layoutInfo Array of layout information for items (real measurements)
|
|
84
|
+
* @param totalItemCount Total number of items in the list
|
|
85
|
+
*/
|
|
86
|
+
modifyLayout(layoutInfo: RVLayoutInfo[], totalItemCount: number): void;
|
|
87
|
+
/**
|
|
88
|
+
* Gets layout information for an item at the given index.
|
|
89
|
+
* Creates and initializes a new layout if one doesn't exist.
|
|
90
|
+
* @param index Index of the item
|
|
91
|
+
* @returns Layout information for the item
|
|
92
|
+
*/
|
|
93
|
+
getLayout(index: number): RVLayout;
|
|
94
|
+
/**
|
|
95
|
+
* Updates layout parameters and triggers recomputation if necessary.
|
|
96
|
+
* @param params New layout parameters
|
|
97
|
+
*/
|
|
98
|
+
updateLayoutParams(params: LayoutParams): void;
|
|
99
|
+
/**
|
|
100
|
+
* Abstract method to recompute layouts for items in the given range.
|
|
101
|
+
* @param startIndex Starting index of items to recompute
|
|
102
|
+
* @param endIndex Ending index of items to recompute
|
|
103
|
+
*/
|
|
104
|
+
abstract recomputeLayouts(startIndex: number, endIndex: number): void;
|
|
105
|
+
/**
|
|
106
|
+
* Abstract method to get the total size of the layout area.
|
|
107
|
+
* @returns RVDimension containing width and height of the layout
|
|
108
|
+
*/
|
|
109
|
+
abstract getLayoutSize(): RVDimension;
|
|
110
|
+
/**
|
|
111
|
+
* Abstract method to estimate layout dimensions for an item.
|
|
112
|
+
* @param index Index of the item to estimate layout for
|
|
113
|
+
*/
|
|
114
|
+
protected abstract estimateLayout(index: number): void;
|
|
115
|
+
/**
|
|
116
|
+
* Gets span size information for an item, applying any overrides.
|
|
117
|
+
* @param index Index of the item
|
|
118
|
+
* @returns SpanSizeInfo for the item
|
|
119
|
+
*/
|
|
120
|
+
protected getSpanSizeInfo(index: number): SpanSizeInfo;
|
|
121
|
+
/**
|
|
122
|
+
* Gets the maximum index to process in a single layout pass.
|
|
123
|
+
* @param startIndex Starting index
|
|
124
|
+
* @returns Maximum index to process
|
|
125
|
+
*/
|
|
126
|
+
private getMaxRecomputeIndex;
|
|
127
|
+
/**
|
|
128
|
+
* Gets the minimum index to process in a single layout pass.
|
|
129
|
+
* @param startIndex Starting index
|
|
130
|
+
* @returns Minimum index to process
|
|
131
|
+
*/
|
|
132
|
+
private getMinRecomputeIndex;
|
|
133
|
+
/**
|
|
134
|
+
* Computes size estimates and finds the minimum recompute index.
|
|
135
|
+
* @param layoutInfo Array of layout information for items
|
|
136
|
+
* @returns Minimum index that needs recomputation
|
|
137
|
+
*/
|
|
138
|
+
private computeEstimatesAndMinRecomputeIndex;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Configuration parameters for the layout manager
|
|
142
|
+
*/
|
|
143
|
+
export interface LayoutParams {
|
|
144
|
+
/**
|
|
145
|
+
* The dimensions of the visible window/viewport that displays list items
|
|
146
|
+
* Used to determine which items are visible and need to be rendered
|
|
147
|
+
*/
|
|
148
|
+
windowSize: RVDimension;
|
|
149
|
+
/**
|
|
150
|
+
* Determines if the list scrolls horizontally (true) or vertically (false)
|
|
151
|
+
* Affects how items are positioned and which dimension is used for scrolling
|
|
152
|
+
*/
|
|
153
|
+
horizontal?: boolean;
|
|
154
|
+
/**
|
|
155
|
+
* Maximum number of columns in a grid layout
|
|
156
|
+
* Controls how many items can be placed side by side
|
|
157
|
+
*/
|
|
158
|
+
maxColumns?: number;
|
|
159
|
+
/**
|
|
160
|
+
* When true, attempts to optimize item placement for better space utilization
|
|
161
|
+
* May affect the ordering of items to minimize empty space
|
|
162
|
+
*/
|
|
163
|
+
optimizeItemArrangement?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Callback to manually override layout properties for specific items
|
|
166
|
+
* Allows custom control over span and size for individual items
|
|
167
|
+
*/
|
|
168
|
+
overrideItemLayout?: (index: number, layout: SpanSizeInfo) => void;
|
|
169
|
+
/**
|
|
170
|
+
* Function to determine the type of an item at a specific index
|
|
171
|
+
* Used for size estimation and optimization based on item types
|
|
172
|
+
*/
|
|
173
|
+
getItemType?: (index: number) => string | number;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Information about an item's layout including its index and dimensions
|
|
177
|
+
* Used when updating layout information for specific items
|
|
178
|
+
*/
|
|
179
|
+
export interface RVLayoutInfo {
|
|
180
|
+
/**
|
|
181
|
+
* The index of the item in the data array
|
|
182
|
+
* Used to identify which item this layout information belongs to
|
|
183
|
+
*/
|
|
184
|
+
index: number;
|
|
185
|
+
/**
|
|
186
|
+
* The width and height dimensions of the item
|
|
187
|
+
* Used to update the layout manager's knowledge of item sizes
|
|
188
|
+
*/
|
|
189
|
+
dimensions: RVDimension;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Information about an item's span and size in a grid layout
|
|
193
|
+
* Used when overriding default layout behavior for specific items
|
|
194
|
+
*/
|
|
195
|
+
export interface SpanSizeInfo {
|
|
196
|
+
/**
|
|
197
|
+
* Number of columns/cells this item should span horizontally
|
|
198
|
+
* Used in grid layouts to allow items to take up multiple columns
|
|
199
|
+
*/
|
|
200
|
+
span?: number;
|
|
201
|
+
/**
|
|
202
|
+
* Custom size value for the item
|
|
203
|
+
* Can be used to override the default size calculation
|
|
204
|
+
*/
|
|
205
|
+
size?: number;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Complete layout information for a list item
|
|
209
|
+
* Extends RVDimension with positioning and constraint properties
|
|
210
|
+
* Used to position and size ViewHolder components in the list
|
|
211
|
+
*/
|
|
212
|
+
export interface RVLayout extends RVDimension {
|
|
213
|
+
/**
|
|
214
|
+
* X-coordinate (horizontal position) in pixels
|
|
215
|
+
* Used to position the item horizontally with absolute positioning
|
|
216
|
+
*/
|
|
217
|
+
x: number;
|
|
218
|
+
/**
|
|
219
|
+
* Y-coordinate (vertical position) in pixels
|
|
220
|
+
* Used to position the item vertically with absolute positioning
|
|
221
|
+
*/
|
|
222
|
+
y: number;
|
|
223
|
+
/**
|
|
224
|
+
* Indicates if the width has been measured from the actual rendered item
|
|
225
|
+
* When false, width may be an estimated value
|
|
226
|
+
*/
|
|
227
|
+
isWidthMeasured?: boolean;
|
|
228
|
+
/**
|
|
229
|
+
* Indicates if the height has been measured from the actual rendered item
|
|
230
|
+
* When false, height may be an estimated value
|
|
231
|
+
*/
|
|
232
|
+
isHeightMeasured?: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Minimum height constraint in pixels
|
|
235
|
+
* Applied to the ViewHolder's style to ensure item doesn't shrink below this value
|
|
236
|
+
*/
|
|
237
|
+
minHeight?: number;
|
|
238
|
+
/**
|
|
239
|
+
* Minimum width constraint in pixels
|
|
240
|
+
* Applied to the ViewHolder's style to ensure item doesn't shrink below this value
|
|
241
|
+
*/
|
|
242
|
+
minWidth?: number;
|
|
243
|
+
/**
|
|
244
|
+
* Maximum height constraint in pixels
|
|
245
|
+
* Applied to the ViewHolder's style to limit item's vertical growth
|
|
246
|
+
*/
|
|
247
|
+
maxHeight?: number;
|
|
248
|
+
/**
|
|
249
|
+
* Maximum width constraint in pixels
|
|
250
|
+
* Applied to the ViewHolder's style to limit item's horizontal growth
|
|
251
|
+
*/
|
|
252
|
+
maxWidth?: number;
|
|
253
|
+
/**
|
|
254
|
+
* When true, the width value is strictly enforced on the ViewHolder
|
|
255
|
+
* When false, the width is determined by content
|
|
256
|
+
*/
|
|
257
|
+
enforcedWidth?: boolean;
|
|
258
|
+
/**
|
|
259
|
+
* When true, the height value is strictly enforced on the ViewHolder
|
|
260
|
+
* When false, the height is determined by content
|
|
261
|
+
*/
|
|
262
|
+
enforcedHeight?: boolean;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Basic dimension interface representing width and height
|
|
266
|
+
* Used throughout the recycler view system to track item sizes
|
|
267
|
+
* and viewport dimensions
|
|
268
|
+
*/
|
|
269
|
+
export interface RVDimension {
|
|
270
|
+
/**
|
|
271
|
+
* Width in pixels
|
|
272
|
+
* Used for horizontal measurement and positioning
|
|
273
|
+
*/
|
|
274
|
+
width: number;
|
|
275
|
+
/**
|
|
276
|
+
* Height in pixels
|
|
277
|
+
* Used for vertical measurement and positioning
|
|
278
|
+
*/
|
|
279
|
+
height: number;
|
|
280
|
+
}
|
|
281
|
+
//# sourceMappingURL=LayoutManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LayoutManager.d.ts","sourceRoot":"","sources":["../../../src/recyclerview/layout-managers/LayoutManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAOnE;;;;GAIG;AACH,8BAAsB,eAAe;IACnC,kEAAkE;IAClE,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC;IAC9B,gDAAgD;IAChD,SAAS,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;IAC9B,gDAAgD;IAChD,SAAS,CAAC,UAAU,EAAE,WAAW,CAAC;IAClC,6CAA6C;IAC7C,SAAS,CAAC,YAAY,EAAE,YAAY,CAAM;IAC1C,8CAA8C;IAC9C,SAAS,CAAC,UAAU,EAAE,MAAM,CAAC;IAC7B,wDAAwD;IACxD,SAAS,CAAC,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAE7E,sEAAsE;IACtE,SAAS,CAAC,uBAAuB,EAAE,OAAO,CAAC;IAE3C,wDAAwD;IACjD,eAAe,EAAE,OAAO,CAAS;IAExC,+CAA+C;IAC/C,OAAO,CAAC,YAAY,CAAC,CAAqC;IAC1D,uDAAuD;IACvD,OAAO,CAAC,mBAAmB,CAAyB;IACpD,sDAAsD;IACtD,OAAO,CAAC,kBAAkB,CAAyB;IACnD,iEAAiE;IACjE,OAAO,CAAC,iBAAiB,CAAe;gBAE5B,MAAM,EAAE,YAAY,EAAE,qBAAqB,CAAC,EAAE,eAAe;IAezE;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAInB;;;;OAIG;IACH,SAAS,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIlD;;;;OAIG;IACH,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAA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