@rdlabo/ngx-cdk-scroll-strategies 21.6.11 → 21.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  # @rdlabo/ngx-cdk-scroll-strategies
2
2
 
3
- This is strategies of dynamic item size for `@angular/cdk/scrolling`. This allows you set specify each item size in the array to be used for Virtual Scroll. Although the repository name includes “Ionic” this strategy only works with Angular.
3
+ ## Overview
4
4
 
5
- **Documentation:** [Read the full documentation](https://docs.rdlabo.dev/projects/ngx-cdk-scroll-strategies)
5
+ This is strategies of dynamic item size for `@angular/cdk/scrolling`. This allows you set specify each item size in the array to be used for Virtual Scroll. Although the repository name includes “Ionic” this strategy only works with Angular.
6
6
 
7
7
  This is a simple coding concept:
8
8
 
9
9
  ```html
10
- <cdk-virtual-scroll-viewport [itemDynamicSizes]="[{ itemSize: 100 } , { itemSize: 80} , { itemSize: 90 } , { itemSize: 100}]">
10
+ <cdk-virtual-scroll-viewport
11
+ [itemDynamicSizes]="[{ itemSize: 100 } , { itemSize: 80} , { itemSize: 90 } , { itemSize: 100}]"
12
+ >
11
13
  <div *cdkVirtualFor="let item of [100, 80, 90, 100]; trackBy: trackByFn" [style.height.px]="item">
12
14
  itemSize: {{ item }}
13
15
  </div>
@@ -20,129 +22,36 @@ Every data item must have one corresponding `itemDynamicSizes` entry in the same
20
22
 
21
23
  This library is based largely on this blog: https://dev.to/georgii/virtual-scrolling-of-content-with-variable-height-with-angular-3a52
22
24
 
23
- ## Installation
24
-
25
- ```bash
26
- npm install @rdlabo/ngx-cdk-scroll-strategies
27
- ```
28
-
29
- ## Usage
30
-
31
- ### Simple Usage
32
-
33
- > This is a simple example of how to use it.
34
-
35
- - Demo: https://rdlabo-ionic-angular-library.netlify.app/main/scroll-strategies/simple
36
- - Source: https://github.com/rdlabo-dev/ionic-angular-library/blob/main/projects/demo/src/app/scroll-strategies/pages/scroll-simple
37
-
38
- ```ts
39
- import { CdkDynamicSizeVirtualScroll, itemDynamicSize } from '@rdlabo/ngx-cdk-scroll-strategies';
40
-
41
- @Component({
42
- ...
43
- imports: [
44
- CdkDynamicSizeVirtualScroll
45
- ],
46
- })
47
- export class ScrollStrategiesPage implements OnInit {
48
- readonly items = signal<itemDynamicSize[]>([]);
49
- readonly dynamicSize = computed<itemDynamicSize[]>(() => {
50
- return this.items().map((item) => ({ trackId: item.trackId, itemSize: item.itemSize }));
51
- });
52
- }
53
- ```
54
-
55
- ```html
56
- <cdk-virtual-scroll-viewport [itemDynamicSizes]="dynamicSize()" minBufferPx="900" maxBufferPx="1350">
57
- <div *cdkVirtualFor="let item of items(); trackBy: trackByFn" class="dynamic-item" [style.height.px]="item.itemSize">
58
- itemSize: {{ item.itemSize }}
59
- </div>
60
- </cdk-virtual-scroll-viewport>
61
- ```
62
-
63
- Other than this, it works the same way as `@angular/cdk/scrolling`.
64
-
65
- ### Advanced Usage
66
-
67
- > This is a practical demo. Make scroll items separate components and get a height for each component.
68
- > It is difficult without basic knowledge of Angular.
25
+ ## Features
69
26
 
70
- - Demo: https://rdlabo-ionic-angular-library.netlify.app/main/scroll-strategies/advanced
71
- - Source: https://github.com/rdlabo-dev/ionic-angular-library/blob/main/projects/demo/src/app/scroll-strategies/pages/scroll-advanced
27
+ ### Choose by scrolling goal
72
28
 
73
- ### Reverse Usage
29
+ | Goal | Guide |
30
+ | --- | --- |
31
+ | Specify each item height | [Simple Usage](./docs/simple.md) |
32
+ | Measure item components | [Advanced Usage](./docs/advanced.md) |
33
+ | Reverse chat-style scrolling | [Reverse Scroll](./docs/reverse.md) |
74
34
 
75
- > This is a demo for reverse scrolling like WeChat.
35
+ ## Quick start
76
36
 
77
- - Demo: https://rdlabo-ionic-angular-library.netlify.app/main/scroll-strategies/reverse
78
- - Source: https://github.com/rdlabo-dev/ionic-angular-library/blob/main/projects/demo/src/app/scroll-strategies/pages/scroll-reverse
37
+ After [Installation](#installation), bind `[itemDynamicSizes]` instead of `[itemSize]`. See [Simple Usage](./docs/simple.md).
79
38
 
80
- If reverse scroll, add `isReverse` directive to `cdk-virtual-scroll-viewport` tag.
81
-
82
- ```html
83
- <cdk-virtual-scroll-viewport [itemDynamicSizes]="dynamicSize()" [isReverse]="true" minBufferPx="900" maxBufferPx="1350">
84
- <div class="reverse-items">
85
- <div *cdkVirtualFor="let item of items(); trackBy: trackByFn" class="dynamic-item" [style.height.px]="item.itemSize">
86
- itemSize: {{ item.itemSize }}
87
- </div>
88
- </div>
89
- </cdk-virtual-scroll-viewport>
90
- ```
91
-
92
- Add css to `cdk-virtual-scroll-viewport.reverse-scroll` at global css file like `styles.css`.
93
-
94
- ```css
95
- cdk-virtual-scroll-viewport {
96
- width: 100%;
97
- height: 100%;
98
-
99
- // .reverse-scroll class is added from this directive.
100
- &.reverse-scroll {
101
- display: flex;
102
- flex-direction: column-reverse;
103
-
104
- .cdk-virtual-scroll-content-wrapper {
105
- top: auto;
106
- bottom: 0;
107
- }
108
- }
109
- }
110
- ```
111
-
112
- And add item wrapper. `div.reverse-items` class is example. You can decide this.
113
-
114
- ```css
115
- div.reverse-items {
116
- height: 100%;
117
- display: flex;
118
- flex-direction: column-reverse;
119
-
120
- position: relative;
121
- bottom: 0;
122
- }
123
- ```
124
-
125
- **In Reverse Scroll, CdkVirtualScrollViewport's measureScrollOffset does not work. Please use the scrollOffset of this directive.**
126
- https://github.com/rdlabo-dev/ionic-angular-library/blob/main/projects/scroll-strategies/src/lib/dynamic-size-virtual-scroll-strategy.ts
127
-
128
- The reverse layout uses negative native `scrollTop` values. `scrollToIndex()` accepts a logical item index as usual and converts its cumulative offset to that native coordinate internally.
129
-
130
- ### Optional
131
-
132
- This package contains a Helper Service that simplifies development with Virtual Scroll.
39
+ ## Installation
133
40
 
134
- ```ts
135
- import { DynamicSizeVirtualScrollService } from '@rdlabo/ngx-cdk-scroll-strategies';
41
+ ```bash
42
+ npm install @rdlabo/ngx-cdk-scroll-strategies
136
43
  ```
137
44
 
138
- Detail is here: https://github.com/rdlabo-dev/ionic-angular-library/blob/main/projects/scroll-strategies/src/lib/dynamic-size-virtual-scroll.service.ts
139
-
140
- ## FQA
141
45
 
142
- ### Why don't use `autosize` directive?
46
+ ## Documentation
143
47
 
144
- `autosize` directive use average item size. This is not support "item size is changed" "item is removed". Because don't have item size cache.
48
+ Start with [Installation](#installation), then pick a guide.
145
49
 
146
- https://github.com/angular/components/blob/main/src/cdk-experimental/scrolling/auto-size-virtual-scroll.ts#L49C3-L59
50
+ - [Simple Usage](./docs/simple.md) — per-item heights.
51
+ - [Advanced Usage](./docs/advanced.md) — measured item components.
52
+ - [Reverse Scroll](./docs/reverse.md) — chat-style reverse lists.
53
+ - [FAQ](./docs/faq.md) — why not `autosize`.
147
54
 
148
- Dynamic size can be specified for more flexible application design.
55
+ <!-- rdlabo-docs-omit -->
56
+ **Full documentation:** [https://docs.rdlabo.dev/projects/ngx-cdk-scroll-strategies](https://docs.rdlabo.dev/projects/ngx-cdk-scroll-strategies)
57
+ <!-- /rdlabo-docs-omit -->
@@ -0,0 +1,7 @@
1
+ Call this after [Installation](../README.md#installation).
2
+
3
+ > This is a practical demo. Make scroll items separate components and get a height for each component.
4
+ > It is difficult without basic knowledge of Angular.
5
+
6
+ - Demo: https://rdlabo-ionic-angular-library.netlify.app/main/scroll-strategies/advanced
7
+ - Source: https://github.com/rdlabo-dev/ionic-angular-library/tree/v21.6.2/projects/demo/src/app/scroll-strategies/pages/scroll-advanced
package/docs/faq.md ADDED
@@ -0,0 +1,7 @@
1
+ ### Why don't use `autosize` directive?
2
+
3
+ `autosize` directive use average item size. This is not support "item size is changed" "item is removed". Because don't have item size cache.
4
+
5
+ https://github.com/angular/components/blob/main/src/cdk-experimental/scrolling/auto-size-virtual-scroll.ts#L49C3-L59
6
+
7
+ Dynamic size can be specified for more flexible application design.
@@ -0,0 +1,75 @@
1
+ Call this after [Installation](../README.md#installation).
2
+
3
+ > This is a demo for reverse scrolling like WeChat.
4
+
5
+ - Demo: https://rdlabo-ionic-angular-library.netlify.app/main/scroll-strategies/reverse
6
+ - Source: https://github.com/rdlabo-dev/ionic-angular-library/tree/v21.6.2/projects/demo/src/app/scroll-strategies/pages/scroll-reverse
7
+
8
+ If reverse scroll, add `isReverse` directive to `cdk-virtual-scroll-viewport` tag.
9
+
10
+ ```html
11
+ <cdk-virtual-scroll-viewport
12
+ [itemDynamicSizes]="dynamicSize()"
13
+ [isReverse]="true"
14
+ minBufferPx="900"
15
+ maxBufferPx="1350"
16
+ >
17
+ <div class="reverse-items">
18
+ <div
19
+ *cdkVirtualFor="let item of items(); trackBy: trackByFn"
20
+ class="dynamic-item"
21
+ [style.height.px]="item.itemSize"
22
+ >
23
+ itemSize: {{ item.itemSize }}
24
+ </div>
25
+ </div>
26
+ </cdk-virtual-scroll-viewport>
27
+ ```
28
+
29
+ Add css to `cdk-virtual-scroll-viewport.reverse-scroll` at global css file like `styles.css`.
30
+
31
+ ```css
32
+ cdk-virtual-scroll-viewport {
33
+ width: 100%;
34
+ height: 100%;
35
+
36
+ /* .reverse-scroll class is added from this directive. */
37
+ &.reverse-scroll {
38
+ display: flex;
39
+ flex-direction: column-reverse;
40
+
41
+ .cdk-virtual-scroll-content-wrapper {
42
+ top: auto;
43
+ bottom: 0;
44
+ }
45
+ }
46
+ }
47
+ ```
48
+
49
+ And add item wrapper. `div.reverse-items` class is example. You can decide this.
50
+
51
+ ```css
52
+ div.reverse-items {
53
+ height: 100%;
54
+ display: flex;
55
+ flex-direction: column-reverse;
56
+
57
+ position: relative;
58
+ bottom: 0;
59
+ }
60
+ ```
61
+
62
+ **In Reverse Scroll, CdkVirtualScrollViewport's measureScrollOffset does not work. Please use the scrollOffset of this directive.**
63
+ https://github.com/rdlabo-dev/ionic-angular-library/blob/v21.6.2/projects/scroll-strategies/src/lib/dynamic-size-virtual-scroll-strategy.ts
64
+
65
+ The reverse layout uses negative native `scrollTop` values. `scrollToIndex()` accepts a logical item index as usual and converts its cumulative offset to that native coordinate internally.
66
+
67
+ ### Optional
68
+
69
+ This package contains a Helper Service that simplifies development with Virtual Scroll.
70
+
71
+ ```ts
72
+ import { DynamicSizeVirtualScrollService } from '@rdlabo/ngx-cdk-scroll-strategies';
73
+ ```
74
+
75
+ Detail is here: https://github.com/rdlabo-dev/ionic-angular-library/blob/v21.6.2/projects/scroll-strategies/src/lib/dynamic-size-virtual-scroll.service.ts
package/docs/simple.md ADDED
@@ -0,0 +1,41 @@
1
+ Call this after [Installation](../README.md#installation).
2
+
3
+ > This is a simple example of how to use it.
4
+
5
+ - Demo: https://rdlabo-ionic-angular-library.netlify.app/main/scroll-strategies/simple
6
+ - Source: https://github.com/rdlabo-dev/ionic-angular-library/tree/v21.6.2/projects/demo/src/app/scroll-strategies/pages/scroll-simple
7
+
8
+ ```ts
9
+ import { CdkDynamicSizeVirtualScroll, itemDynamicSize } from '@rdlabo/ngx-cdk-scroll-strategies';
10
+
11
+ @Component({
12
+ ...
13
+ imports: [
14
+ CdkDynamicSizeVirtualScroll
15
+ ],
16
+ })
17
+ export class ScrollStrategiesPage implements OnInit {
18
+ readonly items = signal<itemDynamicSize[]>([]);
19
+ readonly dynamicSize = computed<itemDynamicSize[]>(() => {
20
+ return this.items().map((item) => ({ trackId: item.trackId, itemSize: item.itemSize }));
21
+ });
22
+ }
23
+ ```
24
+
25
+ ```html
26
+ <cdk-virtual-scroll-viewport
27
+ [itemDynamicSizes]="dynamicSize()"
28
+ minBufferPx="900"
29
+ maxBufferPx="1350"
30
+ >
31
+ <div
32
+ *cdkVirtualFor="let item of items(); trackBy: trackByFn"
33
+ class="dynamic-item"
34
+ [style.height.px]="item.itemSize"
35
+ >
36
+ itemSize: {{ item.itemSize }}
37
+ </div>
38
+ </cdk-virtual-scroll-viewport>
39
+ ```
40
+
41
+ Other than this, it works the same way as `@angular/cdk/scrolling`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rdlabo/ngx-cdk-scroll-strategies",
3
- "version": "21.6.11",
3
+ "version": "21.7.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:rdlabo-dev/ionic-angular-library.git"