-
Notifications
You must be signed in to change notification settings - Fork 427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move GridLayoutProvider inside RLV #462
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6d5d94f
moving grid layout provider and manager inside RLV
muskeinsingh 9bf4f39
moving grid layout provider and manager inside RLV
muskeinsingh 8cd1448
moving grid layout provider and manager inside RLV
muskeinsingh ba57c92
Update package.json
naqvitalha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { LayoutProvider, Dimension } from "./LayoutProvider"; | ||
import { Layout, LayoutManager } from "../layoutmanager/LayoutManager"; | ||
import { GridLayoutManager } from "../layoutmanager/GridLayoutManager"; | ||
|
||
export class GridLayoutProvider extends LayoutProvider { | ||
private _getHeightOrWidth: (index: number) => number; | ||
private _getSpan: (index: number) => number; | ||
private _maxSpan: number; | ||
private _renderWindowSize?: Dimension; | ||
private _isHorizontal?: boolean; | ||
private _acceptableRelayoutDelta: number; | ||
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, | ||
) { | ||
super( | ||
getLayoutType, | ||
(type: 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; | ||
} | ||
|
||
public newLayoutManager(renderWindowSize: Dimension, isHorizontal?: boolean, cachedLayouts?: Layout[]): LayoutManager { | ||
this._isHorizontal = isHorizontal; | ||
this._renderWindowSize = renderWindowSize; | ||
return new GridLayoutManager(this, renderWindowSize, this._getSpan, this._maxSpan, this._acceptableRelayoutDelta, this._isHorizontal, cachedLayouts); | ||
} | ||
|
||
private setLayout(dimension: Dimension, index: number): void { | ||
const maxSpan: number = this._maxSpan; | ||
const itemSpan: number = this._getSpan(index); | ||
if (itemSpan > maxSpan) { | ||
throw new Error("Item span for index " + index + " is more than the max span"); | ||
} | ||
if (this._renderWindowSize) { | ||
if (this._isHorizontal) { | ||
dimension.width = this._getHeightOrWidth(index); | ||
dimension.height = (this._renderWindowSize.height / maxSpan) * itemSpan; | ||
|
||
} else { | ||
dimension.height = this._getHeightOrWidth(index); | ||
dimension.width = (this._renderWindowSize.width / maxSpan) * itemSpan; | ||
} | ||
} else { | ||
throw new Error("setLayout called before layoutmanager was created, cannot be handled"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { LayoutProvider } from "./../dependencies/LayoutProvider"; | ||
import { WrapGridLayoutManager, Layout } from "./LayoutManager"; | ||
import { Dimension } from "../dependencies/LayoutProvider"; | ||
|
||
export class GridLayoutManager extends WrapGridLayoutManager { | ||
private _maxSpan: number; | ||
private _getSpan: (index: number) => number; | ||
private _isGridHorizontal: boolean | undefined; | ||
private _renderWindowSize: Dimension; | ||
private _acceptableRelayoutDelta: number; | ||
constructor( | ||
layoutProvider: LayoutProvider, | ||
renderWindowSize: Dimension, | ||
getSpan: (index: number) => number, | ||
maxSpan: number, | ||
acceptableRelayoutDelta: number, | ||
isHorizontal?: boolean, | ||
cachedLayouts?: Layout[], | ||
) { | ||
super(layoutProvider, renderWindowSize, isHorizontal, cachedLayouts); | ||
this._getSpan = getSpan; | ||
this._isGridHorizontal = isHorizontal; | ||
this._renderWindowSize = renderWindowSize; | ||
if (acceptableRelayoutDelta < 0) { | ||
throw new Error("acceptableRelayoutDelta cannot be less than 0"); | ||
} else { | ||
this._acceptableRelayoutDelta = acceptableRelayoutDelta; | ||
} | ||
if (maxSpan <= 0) { | ||
throw new Error("Max Column Span cannot be less than or equal to 0"); | ||
} else { | ||
this._maxSpan = maxSpan; | ||
} | ||
} | ||
|
||
public overrideLayout(index: number, dim: Dimension): boolean { | ||
// we are doing this because - when we provide decimal dimensions for a | ||
// certain cell - the onlayout returns a different dimension in certain high end devices. | ||
// This causes the layouting to behave weirdly as the new dimension might not adhere to the spans and the cells arrange themselves differently | ||
// So, whenever we have layouts for a certain index, we explicitly override the dimension to those very layout values | ||
// and call super so as to set the overridden flag as true | ||
const layout = this.getLayouts()[index]; | ||
const heightDiff = Math.abs(dim.height - layout.height); | ||
const widthDiff = Math.abs(dim.width - layout.width); | ||
if (layout) { | ||
if (this._isGridHorizontal) { | ||
if (heightDiff < this._acceptableRelayoutDelta) { | ||
if (widthDiff === 0) { | ||
return false; | ||
} | ||
dim.height = layout.height; | ||
} | ||
} else { | ||
if (widthDiff < this._acceptableRelayoutDelta) { | ||
if (heightDiff === 0) { | ||
return false; | ||
} | ||
dim.width = layout.width; | ||
} | ||
} | ||
} | ||
return super.overrideLayout(index, dim); | ||
} | ||
|
||
public getStyleOverridesForIndex(index: number): object | undefined { | ||
const columnSpanForIndex = this._getSpan(index); | ||
return this._isGridHorizontal | ||
? { | ||
height: | ||
(this._renderWindowSize.height / this._maxSpan) * columnSpanForIndex, | ||
} | ||
: { | ||
width: | ||
(this._renderWindowSize.width / this._maxSpan) * columnSpanForIndex, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 is still not published, let's keep it the same