Skip to content

Commit

Permalink
Layout type check for computed layouts (#237)
Browse files Browse the repository at this point in the history
* layout type check for computed layouts

* cleanup

* new version

* review comments

* cleanup

* code review comments
  • Loading branch information
muskeinsingh authored and naqvitalha committed Aug 24, 2018
1 parent 8f248b9 commit 730cbde
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recyclerlistview",
"version": "1.4.0-beta.14",
"version": "1.4.0-beta.15",
"description": "The listview that you need and deserve. It was built for performance, uses cell recycling to achieve smooth scrolling.",
"main": "dist/reactnative/index.js",
"types": "dist/reactnative/index.d.ts",
Expand Down
10 changes: 6 additions & 4 deletions src/core/layoutmanager/LayoutManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ export class WrapGridLayoutManager extends LayoutManager {
}

const oldItemCount = this._layouts.length;

const itemDim = { height: 0, width: 0 };
let itemRect = null;

let oldLayout = null;

for (let i = startIndex; i < itemCount; i++) {
oldLayout = this._layouts[i];
if (oldLayout && oldLayout.isOverridden) {
const layoutType = this._layoutProvider.getLayoutTypeForIndex(i);
if (oldLayout && oldLayout.isOverridden && oldLayout.type === layoutType) {
itemDim.height = oldLayout.height;
itemDim.width = oldLayout.width;
} else {
this._layoutProvider.setComputedLayout(this._layoutProvider.getLayoutTypeForIndex(i), itemDim, i);
this._layoutProvider.setComputedLayout(layoutType, itemDim, i);
}
this.setMaxBounds(itemDim);
while (!this._checkBounds(startX, startY, itemDim, this._isHorizontal)) {
Expand All @@ -140,11 +140,12 @@ export class WrapGridLayoutManager extends LayoutManager {

//TODO: Talha creating array upfront will speed this up
if (i > oldItemCount - 1) {
this._layouts.push({ x: startX, y: startY, height: itemDim.height, width: itemDim.width });
this._layouts.push({ x: startX, y: startY, height: itemDim.height, width: itemDim.width, type: layoutType });
} else {
itemRect = this._layouts[i];
itemRect.x = startX;
itemRect.y = startY;
itemRect.type = layoutType;
itemRect.width = itemDim.width;
itemRect.height = itemDim.height;
}
Expand Down Expand Up @@ -203,6 +204,7 @@ export class WrapGridLayoutManager extends LayoutManager {

export interface Layout extends Dimension, Point {
isOverridden?: boolean;
type: string | number;
}
export interface Point {
x: number;
Expand Down

0 comments on commit 730cbde

Please sign in to comment.