Skip to content

Commit 6526a6a

Browse files
committed
feat(demos): add scroll to demo
1 parent be8c438 commit 6526a6a

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

apps/demos/src/app/features/template/rx-virtual-for/rx-virtual-for.menu.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ export const RX_VIRTUAL_FOR_MENU_ITEMS = [
2323
label: 'Crazy Update',
2424
link: 'crazy-update',
2525
},
26+
{
27+
label: 'Scroll To',
28+
link: 'scroll-to',
29+
},
2630
];

apps/demos/src/app/features/template/rx-virtual-for/virtual-rendering/virtual-for-experiments.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { VirtualForMonkeyTestComponent } from './virtual-for-monkey-test.compone
2727
import { VirtualForReverseInfiniteScrollComponent } from './virtual-for-reverse-infinite-scroll.component';
2828
import { VirtualForScrollWindowDemoComponent } from './virtual-for-scroll-window-demo.component';
2929
import { VirtualForCustomScrollableDemoComponent } from './virtual-for-scrollable-demo.component';
30+
import { VirtualForScrollToDemoComponent } from './virtual-for-scrollto-demo.component';
3031

3132
@NgModule({
3233
imports: [
@@ -60,6 +61,10 @@ import { VirtualForCustomScrollableDemoComponent } from './virtual-for-scrollabl
6061
path: 'crazy-update',
6162
component: VirtualForCrazyUpdateComponent,
6263
},
64+
{
65+
path: 'scroll-to',
66+
component: VirtualForScrollToDemoComponent,
67+
},
6368
]),
6469
ValueProvidersModule,
6570
RxLet,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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

Comments
 (0)