-
Notifications
You must be signed in to change notification settings - Fork 1.3k
docs: Add examples section #9094
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
Changes from all commits
a5ffe95
f1b3f50
b39e88f
b2a54cd
7cc4f1f
32def4f
4def8bc
209a191
3612294
2ed2f40
66c2779
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,10 +48,12 @@ export interface WaterfallLayoutOptions { | |
|
|
||
| class WaterfallLayoutInfo extends LayoutInfo { | ||
| column = 0; | ||
| index = 0; | ||
|
|
||
| copy(): WaterfallLayoutInfo { | ||
| let res = super.copy() as WaterfallLayoutInfo; | ||
| res.column = this.column; | ||
| res.index = this.index; | ||
| return res; | ||
| } | ||
| } | ||
|
|
@@ -123,18 +125,19 @@ export class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions | |
| // Setup an array of column heights | ||
| let columnHeights = Array(numColumns).fill(minSpace.height); | ||
| let newLayoutInfos = new Map(); | ||
| let index = 0; | ||
| let addNode = (key: Key, node: Node<T>) => { | ||
| let oldLayoutInfo = this.layoutInfos.get(key); | ||
| let height = itemHeight; | ||
| let estimatedSize = true; | ||
| if (oldLayoutInfo) { | ||
| height = oldLayoutInfo.rect.height; | ||
| height = oldLayoutInfo.rect.height / oldLayoutInfo.rect.width * itemWidth; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the card size changes (e.g. user drags slider in photo library example), re-calculate the height proportionally. |
||
| estimatedSize = invalidationContext.sizeChanged || oldLayoutInfo.estimatedSize || oldLayoutInfo.content !== node; | ||
| } | ||
|
|
||
| // Figure out which column to place the item in, and compute its position. | ||
| // Preserve the previous column index so items don't jump around during resizing unless the number of columns changed. | ||
| let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined; | ||
| let prevColumn = numColumns === this.numColumns && oldLayoutInfo && oldLayoutInfo.index === index && oldLayoutInfo.rect.y < this.virtualizer!.visibleRect.maxY ? oldLayoutInfo.column : undefined; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't preserve the column if the index within the collection changed. When filtering the photo library, the cards were staying where they were previously, resulting in "holes" appearing. We want to re-flow in this case. |
||
| let column = prevColumn ?? columnHeights.reduce((minIndex, h, i) => h < columnHeights[minIndex] ? i : minIndex, 0); | ||
| let x = horizontalSpacing + column * (itemWidth + horizontalSpacing) + this.margin; | ||
| let y = columnHeights[column]; | ||
|
|
@@ -145,6 +148,7 @@ export class WaterfallLayout<T extends object, O extends WaterfallLayoutOptions | |
| layoutInfo.allowOverflow = true; | ||
| layoutInfo.content = node; | ||
| layoutInfo.column = column; | ||
| layoutInfo.index = index++; | ||
| newLayoutInfos.set(key, layoutInfo); | ||
|
|
||
| columnHeights[column] += layoutInfo.rect.height + minSpace.height; | ||
|
|
||
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.
We don't really have a way to enforce this...