Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recyclerlistview-gridlayoutprovider",
"version": "1.0.5",
"version": "1.0.5-beta",
"description": "Grid Layout Provider built on top of RecyclerListView!",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -35,7 +35,9 @@
},
"homepage": "https://github.com/muskeinsingh/recyclerlistview-gridlayoutmanager",
"devDependencies": {
"recyclerlistview": "^2.0.0-beta.4"
"recyclerlistview": "^2.0.0-beta.4",
"tslint": "^6.1.2",
"typescript": "3.7.2"
},
"peerDependencies": {
"recyclerlistview": ">=2.0.0-beta.4"
Expand Down
21 changes: 15 additions & 6 deletions src/GridLayoutProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ export class GridLayoutProvider extends LayoutProvider {
private _renderWindowSize?: Dimension;
private _isHorizontal?: boolean;
private _acceptableRelayoutDelta: number;
private _isPreciseLayout?: boolean;
constructor(
maxSpan: number,
getLayoutType: (index: number) => string | number,
getSpan: (index: number) => number,
// If horizonal return width while spans will be rowspans. Opposite holds true if not horizontal
getHeightOrWidth: (index: number) => number,
acceptableRelayoutDelta?: number,
// temp variable for showing buckets using precise layout
isPreciseLayout?: boolean
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this as class variable? this.isPreciseLayout?

) {
super(
getLayoutType,
(type: string | number, dimension: Dimension, index: number) => {
(_: string | number, dimension: Dimension, index: number) => {
this.setLayout(dimension, index);
},
);
this._getHeightOrWidth = getHeightOrWidth;
this._getSpan = getSpan;
this._maxSpan = maxSpan;
this._acceptableRelayoutDelta = ((acceptableRelayoutDelta === undefined) || (acceptableRelayoutDelta === null)) ? 1 : acceptableRelayoutDelta;
this._isPreciseLayout = isPreciseLayout;
}

public newLayoutManager(renderWindowSize: Dimension, isHorizontal?: boolean, cachedLayouts?: Layout[]): LayoutManager {
Expand All @@ -43,15 +47,20 @@ export class GridLayoutProvider extends LayoutProvider {
}
if (this._renderWindowSize) {
if (this._isHorizontal) {
dimension.width = this._getHeightOrWidth(index);
dimension.height = (this._renderWindowSize.height / maxSpan) * itemSpan;

const dimensionHeight = (this._renderWindowSize.height / maxSpan) * itemSpan;
dimension.width = this._preciseDimensionValue(this._getHeightOrWidth(index));
dimension.height = this._preciseDimensionValue(dimensionHeight);
} else {
dimension.height = this._getHeightOrWidth(index);
dimension.width = (this._renderWindowSize.width / maxSpan) * itemSpan;
const dimensionWidth = (this._renderWindowSize.width / maxSpan) * itemSpan
dimension.height = this._preciseDimensionValue(this._getHeightOrWidth(index));
dimension.width = this._preciseDimensionValue(dimensionWidth);
}
} else {
throw new Error("setLayout called before layoutmanager was created, cannot be handled");
}
}

private _preciseDimensionValue(value: number): number {
return this._isPreciseLayout ? +value.toFixed(2) : value;
}
}