-
Notifications
You must be signed in to change notification settings - Fork 6.8k
virtual-scroll: add update method #11210
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
Conversation
/** Update the viewport dimensions and re-render. */ | ||
updateViewport() { | ||
const viewportEl = this.elementRef.nativeElement; | ||
this._viewportSize = this.orientation === 'horizontal' ? |
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.
since this also appears in the Promise above, can we extract it into a separate _measureViewportSize
method
@@ -137,6 +137,15 @@ export class CdkVirtualScrollViewport implements DoCheck, OnInit, OnDestroy { | |||
this._detachedSubject.complete(); | |||
} | |||
|
|||
/** Update the viewport dimensions and re-render. */ | |||
updateViewport() { |
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.
nit: updateViewportSize
to be a little more specific about the purpose
@mmalerba - Addressed feedback |
@@ -102,8 +102,7 @@ export class CdkVirtualScrollViewport implements DoCheck, OnInit, OnDestroy { | |||
ngOnInit() { | |||
const viewportEl = this.elementRef.nativeElement; | |||
Promise.resolve().then(() => { | |||
this._viewportSize = this.orientation === 'horizontal' ? |
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.
nit: can remove viewportEl
and use this.elementRef.nativeElement
when listening below
@@ -303,4 +299,11 @@ export class CdkVirtualScrollViewport implements DoCheck, OnInit, OnDestroy { | |||
} | |||
return this._forOf.measureRangeSize(range, this.orientation); | |||
} | |||
|
|||
/** Measure the viewport size. */ | |||
_measureViewportSize() { |
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.
nit: make this private
@mmalerba - done :) |
/** Update the viewport dimensions and re-render. */ | ||
updateViewportSize() { | ||
this._measureViewportSize(); | ||
this._scrollStrategy.onDataLengthChanged(); |
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.
It feels weird to be calling onDataLengthChanged
here since the data length did not change. Can you just leave a TODO so I remember to clean this up later. I'm going to add logic for handling content resize, this can probably call whatever method I create for that
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.
done
Also now that there are tests, it would be good to add a test for this case too. |
@mmalerba - done :) |
// TODO(mmalerba): Add test that it corrects the initial render if it didn't render enough, | ||
// once it actually does that. | ||
}); | ||
expect((viewport._renderedContentTransform as any).changingThisBreaksApplicationSecurity) |
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.
did this get copied down here by mistake?
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.
Yes - sorry.
@@ -56,6 +56,20 @@ describe('CdkVirtualScrollViewport', () => { | |||
|
|||
expect(viewport.getViewportSize()).toBe(testComponent.viewportSize); | |||
})); | |||
|
|||
it('should update viewport size', fakeAsync(() => { | |||
viewport.elementRef.nativeElement.style['height'] = '300px'; |
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.
testComponent.viewportSize = 300
|
||
expect(size).toBe(300); | ||
|
||
viewport.elementRef.nativeElement.style['height'] = '500px'; |
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.
testComponent.viewportSize = 500
it('should update viewport size', fakeAsync(() => { | ||
viewport.elementRef.nativeElement.style['height'] = '300px'; | ||
viewport.updateViewportSize(); | ||
const size = viewport.getViewportSize(); |
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.
don't need to save this, just expect(viewport.getViewportSize()).toBe(300)
|
||
viewport.elementRef.nativeElement.style['height'] = '500px'; | ||
viewport.updateViewportSize(); | ||
const newSize = viewport.getViewportSize(); |
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.
don't need to save in variable
@mmalerba - Done :) |
@@ -492,7 +502,6 @@ describe('CdkVirtualScrollViewport', () => { | |||
|
|||
// TODO(mmalerba): Add test that it corrects the initial render if it didn't render enough, | |||
// once it actually does that. | |||
}); |
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.
accidental change?
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.
Ya, thats what happens when I merge via Github haha
Closing in favor of #11476 |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Adds a method to force resize of the viewport. This is required when the container height/width changes.