Skip to content

Commit ab6a563

Browse files
committed
feat(template): add scrollMargin configuration to RxVirtualView
Introduced a new `scrollMargin` property in the `RxVirtualViewConfig` interface and updated the `RxVirtualViewObserver` directive to utilize this configuration. This enhancement allows for more precise observation of the virtual view within a specified scroll area, improving visibility handling in various scenarios.
1 parent e21fe9a commit ab6a563

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

libs/template/virtual-view/src/lib/virtual-view-observer.directive.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { distinctUntilChanged, finalize, map } from 'rxjs/operators';
1919
import { _RxVirtualViewObserver } from './model';
2020
import { RxaResizeObserver } from './resize-observer';
2121
import { PLATFORM } from './util';
22+
import { VIRTUAL_VIEW_CONFIG_TOKEN } from './virtual-view.config';
2223
import { VirtualViewCache } from './virtual-view-cache';
2324

2425
/**
@@ -52,6 +53,7 @@ export class RxVirtualViewObserver
5253
extends _RxVirtualViewObserver
5354
implements OnInit, OnDestroy
5455
{
56+
#config = inject(VIRTUAL_VIEW_CONFIG_TOKEN);
5557
#platform = inject(PLATFORM);
5658
#elementRef = inject<ElementRef<HTMLElement>>(ElementRef);
5759

@@ -73,6 +75,13 @@ export class RxVirtualViewObserver
7375
*/
7476
rootMargin = input('');
7577

78+
/**
79+
* The scroll margin to observe.
80+
*
81+
* This is useful when you want to observe the virtual view in a specific area of the scroll container.
82+
*/
83+
scrollMargin = input(this.#config.scrollMargin);
84+
7685
/**
7786
* The threshold to observe.
7887
*
@@ -111,6 +120,8 @@ export class RxVirtualViewObserver
111120
{
112121
root: this.#rootElement(),
113122
rootMargin: this.rootMargin(),
123+
// @ts-expect-error - scrollMargin is not available in the type of IntersectionObserverInit
124+
scrollMargin: this.scrollMargin(),
114125
threshold: this.threshold(),
115126
},
116127
);

libs/template/virtual-view/src/lib/virtual-view.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ export interface RxVirtualViewConfig {
1717
cacheEnabled: boolean;
1818
startWithPlaceholderAsap: boolean;
1919

20+
/**
21+
* The scroll margin to observe.
22+
*
23+
* Docs: https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#scrollmargin
24+
*/
25+
scrollMargin: string;
26+
2027
/**
2128
* Whether to enable the visibility after hydration. (DEFAULT: true)
2229
*
@@ -51,6 +58,8 @@ export const VIRTUAL_VIEW_CONFIG_DEFAULT: RxVirtualViewConfig = {
5158
cacheEnabled: true,
5259
enableAfterHydration: true,
5360

61+
scrollMargin: '100px',
62+
5463
cache: {
5564
contentCacheSize: 20,
5665
placeholderCacheSize: 20,

0 commit comments

Comments
 (0)