@@ -20,7 +20,6 @@ import {
20
20
ViewChild ,
21
21
ViewEncapsulation ,
22
22
} from '@angular/core' ;
23
- import { DomSanitizer , SafeStyle } from '@angular/platform-browser' ;
24
23
import { animationFrameScheduler , fromEvent , Observable , Subject } from 'rxjs' ;
25
24
import { sampleTime , take , takeUntil } from 'rxjs/operators' ;
26
25
import { CdkVirtualForOf } from './virtual-for-of' ;
@@ -68,11 +67,8 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
68
67
*/
69
68
_totalContentSize = 0 ;
70
69
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 ;
76
72
77
73
/** The currently rendered range of indices. */
78
74
private _renderedRange : ListRange = { start : 0 , end : 0 } ;
@@ -107,8 +103,9 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
107
103
/** A list of functions to run after the next change detection cycle. */
108
104
private _runAfterChangeDetection : Function [ ] = [ ] ;
109
105
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 ,
112
109
@Inject ( VIRTUAL_SCROLL_STRATEGY ) private _scrollStrategy : VirtualScrollStrategy ) { }
113
110
114
111
ngOnInit ( ) {
@@ -223,17 +220,16 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
223
220
let transform = `translate${ axis } (${ Number ( offset ) } px)` ;
224
221
this . _renderedContentOffset = offset ;
225
222
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).
229
223
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).
230
227
this . _renderedContentOffsetNeedsRewrite = true ;
231
228
}
232
- if ( this . _rawRenderedContentTransform != transform ) {
229
+ if ( this . _renderedContentTransform != transform ) {
233
230
// We know this value is safe because we parse `offset` with `Number()` before passing it
234
231
// into the string.
235
- this . _rawRenderedContentTransform = transform ;
236
- this . _renderedContentTransform = this . _sanitizer . bypassSecurityTrustStyle ( transform ) ;
232
+ this . _renderedContentTransform = transform ;
237
233
this . _markChangeDetectionNeeded ( ( ) => {
238
234
if ( this . _renderedContentOffsetNeedsRewrite ) {
239
235
this . _renderedContentOffset -= this . measureRenderedContentSize ( ) ;
@@ -317,6 +313,11 @@ export class CdkVirtualScrollViewport implements OnInit, OnDestroy {
317
313
318
314
// Apply changes to Angular bindings.
319
315
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 ;
320
321
// Apply the pending scroll offset separately, since it can't be set up as an Angular binding.
321
322
if ( this . _pendingScrollOffset != null ) {
322
323
if ( this . orientation === 'horizontal' ) {
0 commit comments