fix(virtual-scroll): working in angular

This commit is contained in:
Manu Mtz.-Almeida
2018-02-01 22:18:19 +01:00
parent c189094f64
commit 0babb2ece2
20 changed files with 313 additions and 164 deletions

View File

@ -53,9 +53,9 @@
return el;
}
virtual.itemRender = (el, item, type) => {
if (type === 0) return renderItem(el, item);
return renderHeader(el, item);
virtual.itemRender = (el, cell) => {
if (cell.type === 0) return renderItem(el, cell.value);
return renderHeader(el, cell.value);
};
virtual.items = Array.from({length: 1000}, (x, i) => i);
};

View File

@ -61,9 +61,9 @@
return el;
}
virtual.itemRender = (el, item, type) => {
if (type === 0) return renderItem(el, item);
return renderHeader(el, item);
virtual.itemRender = (el, cell) => {
if (cell.type === 0) return renderItem(el, cell.value);
return renderHeader(el, cell.value);
};

View File

@ -25,7 +25,7 @@ export interface VirtualNode {
export type NodeHeightFn = (node: VirtualNode, index: number) => number;
export type HeaderFn = (item: any, index: number, items: any[]) => string | null;
export type ItemHeightFn = (item: any, index?: number) => number;
export type ItemRenderFn = (el: HTMLElement|null, item: any, type: CellType, index?: number) => HTMLElement;
export type ItemRenderFn = (el: HTMLElement|null, cell: Cell, domIndex?: number) => HTMLElement;
export type DomRenderFn = (dom: VirtualNode[], height: number) => void;
export function updateVDom(dom: VirtualNode[], heightIndex: Uint32Array, cells: Cell[], top: number, bottom: number) {
@ -84,9 +84,9 @@ export function doRender(el: HTMLElement, itemRender: ItemRenderFn, dom: Virtual
if (node.change === 2) {
if (i < children.length) {
child = children[i] as HTMLElement;
itemRender(child, cell.value, cell.type, cell.index);
itemRender(child, cell, i);
} else {
child = itemRender(null, cell.value, cell.type, cell.index);
child = itemRender(null, cell, i);
child.classList.add('virtual-item');
el.appendChild(child);
}

View File

@ -235,7 +235,7 @@ export class VirtualScroll {
private updateState() {
const shouldEnable = !!(
this.scrollEl &&
this.items &&
this.cells &&
(this.itemRender || this.domRender) &&
this.viewportHeight > 1
);