(viewport: CdkVirtualScrollViewport)
| 1510 | } |
| 1511 | |
| 1512 | private _setupVirtualScrolling(viewport: CdkVirtualScrollViewport) { |
| 1513 | const virtualScrollScheduler = |
| 1514 | typeof requestAnimationFrame !== 'undefined' ? animationFrameScheduler : asapScheduler; |
| 1515 | |
| 1516 | // Render nothing since the virtual scroll viewport will take over. |
| 1517 | this.viewChange.next({start: 0, end: 0}); |
| 1518 | |
| 1519 | // Forward the rendered range computed by the virtual scroll viewport to the table. |
| 1520 | viewport.renderedRangeStream |
| 1521 | // We need the scheduler here, because the virtual scrolling module uses an identical |
| 1522 | // one for scroll listeners. Without it the two go out of sync and the list starts |
| 1523 | // jumping back to the beginning whenever it needs to re-render. |
| 1524 | .pipe(auditTime(0, virtualScrollScheduler), takeUntil(this._onDestroy)) |
| 1525 | .subscribe(this.viewChange); |
| 1526 | |
| 1527 | viewport.attach({ |
| 1528 | dataStream: this._dataStream, |
| 1529 | measureRangeSize: (range, orientation) => this._measureRangeSize(range, orientation), |
| 1530 | }); |
| 1531 | |
| 1532 | // The `StyickyStyler` sticks elements by applying a `top` or `bottom` position offset to |
| 1533 | // them. However, the virtual scroll viewport applies a `translateY` offset to a container |
| 1534 | // div that encapsulates the table. The translation causes the rows to also be offset by the |
| 1535 | // distance from the top of the scroll viewport in addition to their `top` offset. This logic |
| 1536 | // negates the translation to move the rows to their correct positions. |
| 1537 | combineLatest([viewport.renderedContentOffset, this._headerRowStickyUpdates]) |
| 1538 | .pipe(takeUntil(this._onDestroy)) |
| 1539 | .subscribe(([offsetFromTop, update]) => { |
| 1540 | if (!update.sizes || !update.offsets || !update.elements) { |
| 1541 | return; |
| 1542 | } |
| 1543 | |
| 1544 | for (let i = 0; i < update.elements.length; i++) { |
| 1545 | const cells = update.elements[i]; |
| 1546 | |
| 1547 | if (cells) { |
| 1548 | const current = update.offsets[i]!; |
| 1549 | const offset = |
| 1550 | offsetFromTop !== 0 ? Math.max(offsetFromTop - current, current) : -current; |
| 1551 | |
| 1552 | for (const cell of cells) { |
| 1553 | cell.style.top = `${-offset}px`; |
| 1554 | } |
| 1555 | } |
| 1556 | } |
| 1557 | }); |
| 1558 | |
| 1559 | combineLatest([viewport.renderedContentOffset, this._footerRowStickyUpdates]) |
| 1560 | .pipe(takeUntil(this._onDestroy)) |
| 1561 | .subscribe(([offsetFromTop, update]) => { |
| 1562 | if (!update.sizes || !update.offsets || !update.elements) { |
| 1563 | return; |
| 1564 | } |
| 1565 | |
| 1566 | for (let i = 0; i < update.elements.length; i++) { |
| 1567 | const cells = update.elements[i]; |
| 1568 | |
| 1569 | if (cells) { |
no test coverage detected