Repository navigation
fix(grid): preserve row order after viewport resize #17783
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
075de7c
fix(grid): preserve row order after viewport resize
teodosiah 16b5003
Merge branch 'master' into thristodorova/fix-17575
teodosiah 691a606
Merge branch 'master' into thristodorova/fix-17575
teodosiah 70bb95b
Merge branch 'master' into thristodorova/fix-17575
teodosiah d9d64d0
fix(for-of): address copilot comment
teodosiah 9da5bd6
Merge branch 'master' into thristodorova/fix-17575
teodosiah fea4fe4
refactor(for-of): reuse scroll offset sync and share prepend logic
teodosiah 059aa9b
fix(for-of): use isRTL getter and make grow test fail before fix
teodosiah a8796f8
Merge branch 'master' into thristodorova/fix-17575
teodosiah 1814a10
Merge branch 'master' into thristodorova/fix-17575
ChronosSF 154dc95
Merge branch 'master' into thristodorova/fix-17575
kdinev 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -1486,8 +1486,14 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U | |
|
|
||
| protected _recalcOnContainerChange(containerSizeInfo: { prevSize: number; newSize: number } | null = null) { | ||
| const prevChunkSize = this.state.chunkSize; | ||
| const prevStartIndex = this.state.startIndex!; | ||
| this.applyChunkSizeChange(); | ||
| this._recalcScrollBarSize(containerSizeInfo); | ||
| if (prevStartIndex !== this.state.startIndex) { | ||
| // items were prepended to fill the grown container, so sync the display container offset | ||
| // to keep the scroll position's content in view | ||
| this._updateScrollOffset(); | ||
| } | ||
| if (prevChunkSize !== this.state.chunkSize) { | ||
| this.chunkLoad.emit(this.state); | ||
| } | ||
|
|
@@ -1523,24 +1529,53 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U | |
| * If there exists an element that we can create embedded view for creates it, appends it and updates chunkSize | ||
| */ | ||
| protected addLastElem() { | ||
| let elemIndex = this.state.startIndex! + this.state.chunkSize!; | ||
| if (this.insertChunkElem()) { | ||
| this._zone.run(() => this.cdr.markForCheck()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates an embedded view for the item after the current chunk and updates chunkSize. | ||
| * When the chunk already reaches the end of the data, the view is created for the item before it | ||
| * and prepended instead, so that the rendered items stay in order. | ||
| */ | ||
| protected insertChunkElem(): EmbeddedViewRef<any> | null { | ||
| if (!this.isRemote && !this.igxForOf) { | ||
| return; | ||
| return null; | ||
| } | ||
|
|
||
| let elemIndex = this.state.startIndex! + this.state.chunkSize!; | ||
| let prepend = false; | ||
| if (elemIndex >= this.igxForOf!.length) { | ||
| elemIndex = this.igxForOf!.length - this.state.chunkSize!; | ||
| if (!this.isRemote && this.state.startIndex! > 0) { | ||
| elemIndex = --this.state.startIndex!; | ||
| prepend = true; | ||
|
Comment on lines
+1551
to
+1552
Member
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. @teodosiah ,enabled auto-merge but it won't happen until this comment is resolved one way or another. If you think it's wrong, you can resolve it with an explanation. |
||
| } else { | ||
| elemIndex = this.igxForOf!.length - this.state.chunkSize!; | ||
| } | ||
| } | ||
| const input = this.igxForOf![elemIndex]; | ||
| const embeddedView = this.dc.instance._vcr.createEmbeddedView( | ||
| this._template, | ||
| new IgxForOfContext<T, U>(input, this.igxForOf!, this.getContextIndex(input), this.igxForOf!.length) as any | ||
| this.createTemplateContext(input) as any, | ||
| { index: prepend ? 0 : undefined } | ||
| ); | ||
|
|
||
| this._embeddedViews.push(embeddedView); | ||
| if (prepend) { | ||
| this._embeddedViews.unshift(embeddedView); | ||
| } else { | ||
| this._embeddedViews.push(embeddedView); | ||
| } | ||
| this.state.chunkSize!++; | ||
| return embeddedView; | ||
| } | ||
|
|
||
| this._zone.run(() => this.cdr.markForCheck()); | ||
| /** | ||
| * @hidden | ||
| * Creates the template context for an item rendered by insertChunkElem(). | ||
| */ | ||
| protected createTemplateContext(input: T): IgxForOfContext<T, U> { | ||
| return new IgxForOfContext<T, U>(input, this.igxForOf!, this.getContextIndex(input), this.igxForOf!.length); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1580,9 +1615,9 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U | |
|
|
||
| protected _updateScrollOffset() { | ||
| let scrollOffset = 0; | ||
| const currentScroll = this.scrollPosition; | ||
| const currentScroll = Math.abs(this.scrollPosition); | ||
| if (this._virtRatio !== 1) { | ||
| this._calcVirtualScrollPosition(this.scrollPosition); | ||
| this._calcVirtualScrollPosition(currentScroll); | ||
| scrollOffset = this.fixedUpdateAllElements(this._virtScrollPosition); | ||
| } else { | ||
| const scroll = this.scrollComponent.nativeElement; | ||
|
|
@@ -1591,7 +1626,7 @@ export class IgxForOfDirective<T, U extends T[] = T[]> extends IgxForOfToken<T,U | |
| } | ||
| const dir = this.igxForScrollOrientation === 'horizontal' ? 'left' : 'transform'; | ||
| this.dc.instance._viewContainer.element.nativeElement.style[dir] = this.igxForScrollOrientation === 'horizontal' ? | ||
| -(scrollOffset) + 'px' : | ||
| (this.isRTL ? scrollOffset : -scrollOffset) + 'px' : | ||
| `translateY(${-scrollOffset}px)`; | ||
| } | ||
|
|
||
|
|
@@ -1968,23 +2003,14 @@ export class IgxGridForOfDirective<T, U extends T[] = T[]> extends IgxForOfDirec | |
| } | ||
|
|
||
| protected override addLastElem() { | ||
| let elemIndex = this.state.startIndex! + this.state.chunkSize!; | ||
| if (!this.isRemote && !this.igxForOf) { | ||
| return; | ||
| const embeddedView = this.insertChunkElem(); | ||
| if (embeddedView) { | ||
| this.subscribeToViewObserver(this.getViewObservedNode(embeddedView)); | ||
| } | ||
| } | ||
|
|
||
| if (elemIndex >= this.igxForOf!.length) { | ||
| elemIndex = this.igxForOf!.length - this.state.chunkSize!; | ||
| } | ||
| const input = this.igxForOf![elemIndex]; | ||
| const embeddedView = this.dc.instance._vcr.createEmbeddedView( | ||
| this._template, | ||
| new IgxGridForOfContext<T, U>(input, this.igxForOf!, this.getContextIndex(input), this.igxForOf!.length) as any | ||
| ); | ||
|
|
||
| this._embeddedViews.push(embeddedView); | ||
| this.subscribeToViewObserver(this.getViewObservedNode(embeddedView)); | ||
| this.state.chunkSize!++; | ||
| protected override createTemplateContext(input: T): IgxGridForOfContext<T, U> { | ||
| return new IgxGridForOfContext<T, U>(input, this.igxForOf!, this.getContextIndex(input), this.igxForOf!.length); | ||
| } | ||
|
|
||
| protected _updateViews(prevChunkSize: number | undefined) { | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.