|
| 1 | +import { coerceNumberProperty } from '@angular/cdk/coercion'; |
| 2 | +import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling'; |
| 3 | +import { NgTemplateOutlet } from '@angular/common'; |
| 4 | +import { |
| 5 | + AfterViewInit, |
| 6 | + ChangeDetectionStrategy, |
| 7 | + Component, |
| 8 | + ElementRef, |
| 9 | + OnInit, |
| 10 | + QueryList, |
| 11 | + TemplateRef, |
| 12 | + ViewChild, |
| 13 | + ViewChildren, |
| 14 | +} from '@angular/core'; |
| 15 | +import { RxStrategyNames } from '@rx-angular/cdk/render-strategies'; |
| 16 | +import { patch, toDictionary, update } from '@rx-angular/cdk/transformations'; |
| 17 | +import { RxState } from '@rx-angular/state'; |
| 18 | +import { |
| 19 | + BehaviorSubject, |
| 20 | + combineLatest, |
| 21 | + defer, |
| 22 | + pairwise, |
| 23 | + ReplaySubject, |
| 24 | + Subject, |
| 25 | + switchMap, |
| 26 | +} from 'rxjs'; |
| 27 | +import { |
| 28 | + distinctUntilChanged, |
| 29 | + map, |
| 30 | + shareReplay, |
| 31 | + startWith, |
| 32 | + withLatestFrom, |
| 33 | +} from 'rxjs/operators'; |
| 34 | +import { ArrayProviderComponent } from '../../../../shared/debug-helper/value-provider/array-provider/array-provider.component'; |
| 35 | +import { TestItem } from '../../../../shared/debug-helper/value-provider/index'; |
| 36 | +import { |
| 37 | + AutoSizeVirtualScrollStrategy, |
| 38 | + RxVirtualFor, |
| 39 | + RxVirtualScrollViewportComponent, |
| 40 | +} from '@rx-angular/template/experimental/virtual-scrolling'; |
| 41 | + |
| 42 | +@Component({ |
| 43 | + selector: 'rxa-virtual-for-scroll-to', |
| 44 | + template: ` |
| 45 | + <h1 class="mat-headline mt-2">Scroll To</h1> |
| 46 | + <div class="container position-relative"> |
| 47 | + <rx-virtual-scroll-viewport |
| 48 | + autosize |
| 49 | + [initialScrollIndex]="initialScrollIndex" |
| 50 | + (scrolledIndexChange)="onScrolledIndexChange($event)" |
| 51 | + > |
| 52 | + <div class="item" *rxVirtualFor="let item of items"> |
| 53 | + {{ item }} |
| 54 | + </div> |
| 55 | + </rx-virtual-scroll-viewport> |
| 56 | + </div> |
| 57 | + `, |
| 58 | + styles: [ |
| 59 | + ` |
| 60 | + :host { |
| 61 | + display: flex; |
| 62 | + flex-flow: column; |
| 63 | + height: 100%; |
| 64 | + } |
| 65 | + .container { |
| 66 | + height: 100%; |
| 67 | + flex-grow: 1; |
| 68 | + } |
| 69 | + rx-virtual-scroll-viewport { |
| 70 | + position: absolute; |
| 71 | + width: 100%; |
| 72 | + height: 100%; |
| 73 | + top: 0; |
| 74 | + left: 0; |
| 75 | + } |
| 76 | +
|
| 77 | + .item { |
| 78 | + width: 100%; |
| 79 | + height: 50px; |
| 80 | + display: flex; |
| 81 | + align-items: center; |
| 82 | + justify-content: center; |
| 83 | + background: lightpink; |
| 84 | + border-top: 1px solid gray; |
| 85 | + } |
| 86 | + `, |
| 87 | + ], |
| 88 | + providers: [RxState], |
| 89 | + changeDetection: ChangeDetectionStrategy.OnPush, |
| 90 | + standalone: true, |
| 91 | + imports: [ |
| 92 | + RxVirtualScrollViewportComponent, |
| 93 | + AutoSizeVirtualScrollStrategy, |
| 94 | + RxVirtualFor, |
| 95 | + ], |
| 96 | +}) |
| 97 | +export class VirtualForScrollToDemoComponent implements OnInit { |
| 98 | + items: string[] | undefined; |
| 99 | + initialScrollIndex = 5; |
| 100 | + |
| 101 | + ngOnInit() { |
| 102 | + this.items = Array.from({ length: 100 }, (_, i) => i.toString()); |
| 103 | + } |
| 104 | + |
| 105 | + onScrolledIndexChange(index: number) { |
| 106 | + console.log('onScrolledIndexChange', index); |
| 107 | + } |
| 108 | +} |
0 commit comments