@@ -20,7 +20,6 @@ import {
2020 ViewChild ,
2121 ViewEncapsulation ,
2222} from '@angular/core' ;
23- import { DomSanitizer , SafeStyle } from '@angular/platform-browser' ;
2423import { animationFrameScheduler , fromEvent , Observable , Subject } from 'rxjs' ;
2524import { sampleTime , take , takeUntil } from 'rxjs/operators' ;
2625import { CdkVirtualForOf } from './virtual-for-of' ;
@@ -68,11 +67,8 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
6867 */
6968 _totalContentSize = 0 ;
7069
71- /** The transform used to offset the rendered content wrapper element. */
72- _renderedContentTransform : SafeStyle ;
73-
74- /** The raw string version of the rendered content transform. */
75- private _rawRenderedContentTransform : string ;
70+ /** The the rendered content transform. */
71+ private _renderedContentTransform : string ;
7672
7773 /** The currently rendered range of indices. */
7874 private _renderedRange : ListRange = { start : 0 , end : 0 } ;
@@ -107,8 +103,9 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
107103 /** A list of functions to run after the next change detection cycle. */
108104 private _runAfterChangeDetection : Function [ ] = [ ] ;
109105
110- constructor ( public elementRef : ElementRef , private _changeDetectorRef : ChangeDetectorRef ,
111- private _ngZone : NgZone , private _sanitizer : DomSanitizer ,
106+ constructor ( public elementRef : ElementRef ,
107+ private _changeDetectorRef : ChangeDetectorRef ,
108+ private _ngZone : NgZone ,
112109 @Inject ( VIRTUAL_SCROLL_STRATEGY ) private _scrollStrategy : VirtualScrollStrategy ) { }
113110
114111 ngOnInit ( ) {
@@ -223,17 +220,16 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
223220 let transform = `translate${ axis } (${ Number ( offset ) } px)` ;
224221 this . _renderedContentOffset = offset ;
225222 if ( to === 'to-end' ) {
226- // TODO(mmalerba): The viewport should rewrite this as a `to-start` offset on the next render
227- // cycle. Otherwise elements will appear to expand in the wrong direction (e.g.
228- // `mat-expansion-panel` would expand upward).
229223 transform += ` translate${ axis } (-100%)` ;
224+ // The viewport should rewrite this as a `to-start` offset on the next render cycle. Otherwise
225+ // elements will appear to expand in the wrong direction (e.g. `mat-expansion-panel` would
226+ // expand upward).
230227 this . _renderedContentOffsetNeedsRewrite = true ;
231228 }
232- if ( this . _rawRenderedContentTransform != transform ) {
229+ if ( this . _renderedContentTransform != transform ) {
233230 // We know this value is safe because we parse `offset` with `Number()` before passing it
234231 // into the string.
235- this . _rawRenderedContentTransform = transform ;
236- this . _renderedContentTransform = this . _sanitizer . bypassSecurityTrustStyle ( transform ) ;
232+ this . _renderedContentTransform = transform ;
237233 this . _markChangeDetectionNeeded ( ( ) => {
238234 if ( this . _renderedContentOffsetNeedsRewrite ) {
239235 this . _renderedContentOffset -= this . measureRenderedContentSize ( ) ;
@@ -317,6 +313,11 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
317313
318314 // Apply changes to Angular bindings.
319315 this . _ngZone . run ( ( ) => this . _changeDetectorRef . detectChanges ( ) ) ;
316+ // Apply the content transform. The transform can't be set via an Angular binding because
317+ // bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of
318+ // string literals, a variable that can only be 'X' or 'Y', and user input that is run through
319+ // the `Number` function first to coerce it to a numeric value.
320+ this . _contentWrapper . nativeElement . style . transform = this . _renderedContentTransform ;
320321 // Apply the pending scroll offset separately, since it can't be set up as an Angular binding.
321322 if ( this . _pendingScrollOffset != null ) {
322323 if ( this . orientation === 'horizontal' ) {
0 commit comments