Skip to content

Commit 8cdc328

Browse files
committed
add addtional props with render children for IE
1 parent 26019df commit 8cdc328

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,15 @@ import List from 'rc-virtual-list';
4747

4848
## List
4949

50-
| Prop | Description | Type | Default |
51-
| ---------- | ------------------------------------------------------- | -------------------- | ------- |
52-
| children | Render props of item | item => ReactElement | - |
53-
| component | Customize List dom element | string \| Component | div |
54-
| data | Data list | Array | - |
55-
| disabled | Disable scroll check. Usually used on animation control | boolean | false |
56-
| height | List height | number | - |
57-
| itemHeight | Item minium height | number | - |
58-
| itemKey | Match key with item | string | - |
50+
| Prop | Description | Type | Default |
51+
| ---------- | ------------------------------------------------------- | ------------------------------------ | ------- |
52+
| children | Render props of item | (item, index, props) => ReactElement | - |
53+
| component | Customize List dom element | string \| Component | div |
54+
| data | Data list | Array | - |
55+
| disabled | Disable scroll check. Usually used on animation control | boolean | false |
56+
| height | List height | number | - |
57+
| itemHeight | Item minium height | number | - |
58+
| itemKey | Match key with item | string | - |
59+
60+
`children` provides additional `props` argument to support IE 11 scroll shaking.
61+
It will set `style` to `visibility: hidden` when measuring. You can ignore this if no requirement on IE.

examples/basic.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ const Demo = () => {
7474
boxSizing: 'border-box',
7575
}}
7676
>
77-
{item => (type === 'dom' ? <ForwardMyItem {...item} /> : <TestItem {...item} />)}
77+
{(item, _, props) =>
78+
type === 'dom' ? (
79+
<ForwardMyItem {...item} {...props} />
80+
) : (
81+
<TestItem {...item} {...props} />
82+
)
83+
}
7884
</List>
7985
</div>
8086
</React.StrictMode>

src/List.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import {
1313
} from './utils/itemUtil';
1414
import { getIndexByStartLoc, findListDiffIndex } from './utils/algorithmUtil';
1515

16-
type RenderFunc<T> = (item: T, index: number) => React.ReactNode;
16+
type RenderFunc<T> = (
17+
item: T,
18+
index: number,
19+
props: { style: React.CSSProperties },
20+
) => React.ReactNode;
1721

1822
const ITEM_SCALE_RATE = 1;
1923

@@ -401,11 +405,14 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
401405
/**
402406
* Phase 4: Render item and get all the visible items height
403407
*/
404-
public renderChildren = (list: T[], startIndex: number, renderFunc: RenderFunc<T>) =>
408+
public renderChildren = (list: T[], startIndex: number, renderFunc: RenderFunc<T>) => {
409+
const { status } = this.state;
405410
// We should measure rendered item height
406-
list.map((item, index) => {
411+
return list.map((item, index) => {
407412
const eleIndex = startIndex + index;
408-
const node = renderFunc(item, eleIndex) as React.ReactElement;
413+
const node = renderFunc(item, eleIndex, {
414+
style: status === 'MEASURE_START' ? { visibility: 'hidden' } : {},
415+
}) as React.ReactElement;
409416
const eleKey = this.getIndexKey(eleIndex);
410417

411418
// Pass `key` and `ref` for internal measure
@@ -416,6 +423,7 @@ class List<T> extends React.Component<ListProps<T>, ListState<T>> {
416423
},
417424
});
418425
});
426+
};
419427

420428
public render() {
421429
const {

0 commit comments

Comments
 (0)