@@ -14,15 +14,29 @@ const MAX_VIRTUAL_COUNT = 100000;
14
14
const OFFSET_ADJUST_MIN_THRESHOLD = 1000 ;
15
15
16
16
export class IronListAdapter {
17
- constructor ( { createElements, updateElement, scrollTarget, scrollContainer, elementsContainer, reorderElements } ) {
17
+ constructor ( {
18
+ createElements,
19
+ updateElement,
20
+ scrollTarget,
21
+ scrollContainer,
22
+ reorderElements,
23
+ elementsContainer,
24
+ __disableHeightPlaceholder,
25
+ } ) {
18
26
this . isAttached = true ;
19
27
this . _vidxOffset = 0 ;
20
28
this . createElements = createElements ;
21
29
this . updateElement = updateElement ;
22
30
this . scrollTarget = scrollTarget ;
23
31
this . scrollContainer = scrollContainer ;
24
- this . elementsContainer = elementsContainer || scrollContainer ;
25
32
this . reorderElements = reorderElements ;
33
+ this . elementsContainer = elementsContainer || scrollContainer ;
34
+
35
+ // Internal option that disables the heavy height placeholder calculation
36
+ // (see __afterElementsUpdated) for components that always render virtual
37
+ // elements with a non-zero height. Not for public use.
38
+ this . __disableHeightPlaceholder = __disableHeightPlaceholder ?? false ;
39
+
26
40
// Iron-list uses this value to determine how many pages of elements to render
27
41
this . _maxPages = 1.3 ;
28
42
@@ -270,33 +284,35 @@ export class IronListAdapter {
270
284
* @param {!Array<!HTMLElement> } updatedElements
271
285
*/
272
286
__afterElementsUpdated ( updatedElements ) {
273
- updatedElements . forEach ( ( el ) => {
274
- const elementHeight = el . offsetHeight ;
275
- if ( elementHeight === 0 ) {
276
- // If the elements have 0 height after update (for example due to lazy rendering),
277
- // it results in iron-list requesting to create an unlimited count of elements.
278
- // Assign a temporary placeholder sizing to elements that would otherwise end up having
279
- // no height.
280
- el . style . paddingTop = `${ this . __placeholderHeight } px` ;
281
- el . style . opacity = '0' ;
282
- el . __virtualizerPlaceholder = true ;
283
-
284
- // Manually schedule the resize handler to make sure the placeholder padding is
285
- // cleared in case the resize observer never triggers.
286
- this . __placeholderClearDebouncer = Debouncer . debounce ( this . __placeholderClearDebouncer , animationFrame , ( ) =>
287
- this . _resizeHandler ( ) ,
288
- ) ;
289
- } else {
290
- // Add element height to the queue
291
- this . __elementHeightQueue . push ( elementHeight ) ;
292
- this . __elementHeightQueue . shift ( ) ;
293
-
294
- // Calculate new placeholder height based on the average of the defined values in the
295
- // element height queue
296
- const filteredHeights = this . __elementHeightQueue . filter ( ( h ) => h !== undefined ) ;
297
- this . __placeholderHeight = Math . round ( filteredHeights . reduce ( ( a , b ) => a + b , 0 ) / filteredHeights . length ) ;
298
- }
299
- } ) ;
287
+ if ( ! this . __disableHeightPlaceholder ) {
288
+ updatedElements . forEach ( ( el ) => {
289
+ const elementHeight = el . offsetHeight ;
290
+ if ( elementHeight === 0 ) {
291
+ // If the elements have 0 height after update (for example due to lazy rendering),
292
+ // it results in iron-list requesting to create an unlimited count of elements.
293
+ // Assign a temporary placeholder sizing to elements that would otherwise end up having
294
+ // no height.
295
+ el . style . paddingTop = `${ this . __placeholderHeight } px` ;
296
+ el . style . opacity = '0' ;
297
+ el . __virtualizerPlaceholder = true ;
298
+
299
+ // Manually schedule the resize handler to make sure the placeholder padding is
300
+ // cleared in case the resize observer never triggers.
301
+ this . __placeholderClearDebouncer = Debouncer . debounce ( this . __placeholderClearDebouncer , animationFrame , ( ) =>
302
+ this . _resizeHandler ( ) ,
303
+ ) ;
304
+ } else {
305
+ // Add element height to the queue
306
+ this . __elementHeightQueue . push ( elementHeight ) ;
307
+ this . __elementHeightQueue . shift ( ) ;
308
+
309
+ // Calculate new placeholder height based on the average of the defined values in the
310
+ // element height queue
311
+ const filteredHeights = this . __elementHeightQueue . filter ( ( h ) => h !== undefined ) ;
312
+ this . __placeholderHeight = Math . round ( filteredHeights . reduce ( ( a , b ) => a + b , 0 ) / filteredHeights . length ) ;
313
+ }
314
+ } ) ;
315
+ }
300
316
301
317
if ( this . __pendingScrollToIndex !== undefined && ! this . __hasPlaceholders ( ) ) {
302
318
this . scrollToIndex ( this . __pendingScrollToIndex ) ;
0 commit comments