UNPKG

6 kBTypeScriptView Raw
1import { ComponentInterface } from '../../stencil-public-runtime';
2import { DomRenderFn, FooterHeightFn, HeaderFn, HeaderHeightFn, ItemHeightFn, ItemRenderFn } from '../../interface';
3export declare class VirtualScroll implements ComponentInterface {
4 private contentEl?;
5 private scrollEl?;
6 private range;
7 private timerUpdate;
8 private heightIndex?;
9 private viewportHeight;
10 private cells;
11 private virtualDom;
12 private isEnabled;
13 private viewportOffset;
14 private currentScrollTop;
15 private indexDirty;
16 private lastItemLen;
17 private rmEvent;
18 el: HTMLIonVirtualScrollElement;
19 totalHeight: number;
20 /**
21 * It is important to provide this
22 * if virtual item height will be significantly larger than the default
23 * The approximate height of each virtual item template's cell.
24 * This dimension is used to help determine how many cells should
25 * be created when initialized, and to help calculate the height of
26 * the scrollable area. This height value can only use `px` units.
27 * Note that the actual rendered size of each cell comes from the
28 * app's CSS, whereas this approximation is used to help calculate
29 * initial dimensions before the item has been rendered.
30 */
31 approxItemHeight: number;
32 /**
33 * The approximate height of each header template's cell.
34 * This dimension is used to help determine how many cells should
35 * be created when initialized, and to help calculate the height of
36 * the scrollable area. This height value can only use `px` units.
37 * Note that the actual rendered size of each cell comes from the
38 * app's CSS, whereas this approximation is used to help calculate
39 * initial dimensions before the item has been rendered.
40 */
41 approxHeaderHeight: number;
42 /**
43 * The approximate width of each footer template's cell.
44 * This dimension is used to help determine how many cells should
45 * be created when initialized, and to help calculate the height of
46 * the scrollable area. This height value can only use `px` units.
47 * Note that the actual rendered size of each cell comes from the
48 * app's CSS, whereas this approximation is used to help calculate
49 * initial dimensions before the item has been rendered.
50 */
51 approxFooterHeight: number;
52 /**
53 * Section headers and the data used within its given
54 * template can be dynamically created by passing a function to `headerFn`.
55 * For example, a large list of contacts usually has dividers between each
56 * letter in the alphabet. App's can provide their own custom `headerFn`
57 * which is called with each record within the dataset. The logic within
58 * the header function can decide if the header template should be used,
59 * and what data to give to the header template. The function must return
60 * `null` if a header cell shouldn't be created.
61 */
62 headerFn?: HeaderFn;
63 /**
64 * Section footers and the data used within its given
65 * template can be dynamically created by passing a function to `footerFn`.
66 * The logic within the footer function can decide if the footer template
67 * should be used, and what data to give to the footer template. The function
68 * must return `null` if a footer cell shouldn't be created.
69 */
70 footerFn?: HeaderFn;
71 /**
72 * The data that builds the templates within the virtual scroll.
73 * It's important to note that when this data has changed, then the
74 * entire virtual scroll is reset, which is an expensive operation and
75 * should be avoided if possible.
76 */
77 items?: any[];
78 /**
79 * An optional function that maps each item within their height.
80 * When this function is provides, heavy optimizations and fast path can be taked by
81 * `ion-virtual-scroll` leading to massive performance improvements.
82 *
83 * This function allows to skip all DOM reads, which can be Doing so leads
84 * to massive performance
85 */
86 itemHeight?: ItemHeightFn;
87 /**
88 * An optional function that maps each item header within their height.
89 */
90 headerHeight?: HeaderHeightFn;
91 /**
92 * An optional function that maps each item footer within their height.
93 */
94 footerHeight?: FooterHeightFn;
95 /**
96 * NOTE: only JSX API for stencil.
97 *
98 * Provide a render function for the items to be rendered. Returns a JSX virtual-dom.
99 */
100 renderItem?: (item: any, index: number) => any;
101 /**
102 * NOTE: only JSX API for stencil.
103 *
104 * Provide a render function for the header to be rendered. Returns a JSX virtual-dom.
105 */
106 renderHeader?: (item: any, index: number) => any;
107 /**
108 * NOTE: only JSX API for stencil.
109 *
110 * Provide a render function for the footer to be rendered. Returns a JSX virtual-dom.
111 */
112 renderFooter?: (item: any, index: number) => any;
113 /**
114 * NOTE: only Vanilla JS API.
115 */
116 nodeRender?: ItemRenderFn;
117 /** @internal */
118 domRender?: DomRenderFn;
119 itemsChanged(): void;
120 connectedCallback(): Promise<void>;
121 componentDidUpdate(): void;
122 disconnectedCallback(): void;
123 onResize(): void;
124 /**
125 * Returns the position of the virtual item at the given index.
126 */
127 positionForItem(index: number): Promise<number>;
128 /**
129 * This method marks a subset of items as dirty, so they can be re-rendered. Items should be marked as
130 * dirty any time the content or their style changes.
131 *
132 * The subset of items to be updated can are specifing by an offset and a length.
133 */
134 checkRange(offset: number, len?: number): Promise<void>;
135 /**
136 * This method marks the tail the items array as dirty, so they can be re-rendered.
137 *
138 * It's equivalent to calling:
139 *
140 * ```js
141 * virtualScroll.checkRange(lastItemLen);
142 * ```
143 */
144 checkEnd(): Promise<void>;
145 private onScroll;
146 private updateVirtualScroll;
147 private readVS;
148 private writeVS;
149 private updateCellHeight;
150 private setCellHeight;
151 private scheduleUpdate;
152 private updateState;
153 private calcCells;
154 private getHeightIndex;
155 private calcHeightIndex;
156 private enableScrollEvents;
157 private renderVirtualNode;
158 render(): any;
159}