mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
fix(virtual-scroll): use FunctionalComponent for JSX integration
This commit is contained in:
@ -7,6 +7,8 @@ ion-virtual-scroll {
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
contain: strict;
|
contain: strict;
|
||||||
|
|
||||||
|
user-select: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.virtual-loading {
|
.virtual-loading {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Component, Element, EventListenerEnable, Listen, Method, Prop, QueueApi, State, Watch } from '@stencil/core';
|
import { Component, Element, EventListenerEnable, FunctionalComponent, Listen, Method, Prop, QueueApi, State, Watch } from '@stencil/core';
|
||||||
|
|
||||||
import { Cell, DomRenderFn, HeaderFn, ItemHeightFn, ItemRenderFn, VirtualNode } from '../../interface';
|
import { Cell, DomRenderFn, HeaderFn, ItemHeightFn, ItemRenderFn, VirtualNode } from '../../interface';
|
||||||
|
|
||||||
@ -141,8 +141,6 @@ export class VirtualScroll {
|
|||||||
|
|
||||||
@Listen('window:resize')
|
@Listen('window:resize')
|
||||||
onResize() {
|
onResize() {
|
||||||
this.indexDirty = 0;
|
|
||||||
this.calcCells();
|
|
||||||
this.updateVirtualScroll();
|
this.updateVirtualScroll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,25 +376,36 @@ export class VirtualScroll {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const renderItem = this.renderItem;
|
if (this.renderItem) {
|
||||||
if (renderItem) {
|
return (
|
||||||
return this.virtualDom.map(node => {
|
<VirtualProxy dom={this.virtualDom}>
|
||||||
const item = this.renderVirtualNode(node) as any;
|
{ this.virtualDom.map(node => this.renderVirtualNode(node)) }
|
||||||
const classes = ['virtual-item'];
|
</VirtualProxy>
|
||||||
if (!item.vattrs) {
|
);
|
||||||
item.vattrs = {};
|
|
||||||
}
|
|
||||||
if (!node.visible) {
|
|
||||||
classes.push('virtual-loading');
|
|
||||||
}
|
|
||||||
item.vattrs.class += classes.join(' ');
|
|
||||||
if (!item.vattrs.style) {
|
|
||||||
item.vattrs.style = {};
|
|
||||||
}
|
|
||||||
item.vattrs.style['transform'] = `translate3d(0,${node.top}px,0)`;
|
|
||||||
return item;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const VirtualProxy: FunctionalComponent<{dom: VirtualNode[]}> = ({ dom }, children, utils) => {
|
||||||
|
return utils.map(children, (child, i) => {
|
||||||
|
const node = dom[i];
|
||||||
|
const vattrs = child.vattrs || {};
|
||||||
|
let classes = vattrs.class || '';
|
||||||
|
classes += 'virtual-item ';
|
||||||
|
if (!node.visible) {
|
||||||
|
classes += 'virtual-loading';
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
...child,
|
||||||
|
vattrs: {
|
||||||
|
...vattrs,
|
||||||
|
class: classes,
|
||||||
|
style: {
|
||||||
|
...vattrs.style,
|
||||||
|
transform: `translate3d(0,${node.top}px,0)`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user