Skip to content

Commit f4cb110

Browse files
author
ecorreia
committed
Merge branch 'master' into documentation
2 parents ca26e89 + 558c0dc commit f4cb110

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flatlist-react",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "A helpful utility component to handle lists in react like a champ",
55
"main": "./lib/index.js",
66
"scripts": {

src/___subComponents/PlainList.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ interface Props {
1111
renderItem: JSX.Element | renderFunc;
1212
renderWhenEmpty?: null | (() => JSX.Element);
1313
wrapperHtmlTag?: string;
14-
renderScroll?: boolean;
14+
renderOnScroll?: boolean;
1515
__forwarededRef?: Ref<HTMLElement>;
1616
[key: string]: any;
1717
}
1818

1919
const PlainList = (props: Props) => {
2020
const {
21-
list, renderItem, renderWhenEmpty, renderScroll, wrapperHtmlTag, __forwarededRef,
21+
list, renderItem, renderWhenEmpty, renderOnScroll, wrapperHtmlTag, __forwarededRef,
2222
...tagProps
2323
} = props;
2424
const dataList = convertListToArray(list);
@@ -31,7 +31,7 @@ const PlainList = (props: Props) => {
3131
const content = (
3232
<>
3333
{
34-
renderScroll
34+
renderOnScroll
3535
? <ScrollRenderer list={dataList} renderItem={renderItem}/>
3636
: dataList.map(handleRenderItem(renderItem))
3737
}
@@ -69,13 +69,13 @@ PlainList.propTypes = {
6969
wrapperHtmlTag: string,
7070
// eslint-disable-next-line react/forbid-prop-types
7171
__forwarededRef: object,
72-
renderScroll: bool
72+
renderOnScroll: bool
7373
};
7474

7575
PlainList.defaultProps = {
7676
wrapperHtmlTag: '',
7777
renderWhenEmpty: DefaultBlank,
78-
renderScroll: false,
78+
renderOnScroll: false,
7979
__forwarededRef: {current: null}
8080
};
8181

src/___subComponents/ScrollRenderer.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@ const ScrollRenderer = (props: Props) => {
3232
}
3333
};
3434

35-
const onScroll = () => {
36-
const span: any = containerRef.current;
37-
38-
if (span) {
39-
const startingPoint = span.parentNode.offsetTop + span.parentNode.offsetHeight;
40-
const anchorPos = span.offsetTop - span.parentNode.scrollTop;
35+
const onScroll = (span: any) => () => {
36+
const startingPoint = span.parentNode.offsetTop + span.parentNode.offsetHeight;
37+
const anchorPos = span.offsetTop - span.parentNode.scrollTop;
4138

42-
if (anchorPos <= (startingPoint + (span.parentNode.offsetHeight * 2))) {
43-
requestAnimationFrame(() => addItem(span.parentNode, span.parentNode.scrollTop));
44-
}
39+
if (anchorPos <= (startingPoint + (span.parentNode.offsetHeight * 2))) {
40+
requestAnimationFrame(() => addItem(span.parentNode, span.parentNode.scrollTop));
4541
}
4642
};
4743

@@ -68,25 +64,26 @@ const ScrollRenderer = (props: Props) => {
6864
useLayoutEffect(() => {
6965
const span: any = containerRef.current;
7066
let container: any = null;
67+
const handleScroll = onScroll(span);
7168
if (span) {
7269
container = span.parentNode;
7370
// populate double the container height of items
74-
if (span.parentNode.scrollHeight <= (container.offsetHeight * 2)) {
71+
if (render.index === 0 || container.scrollHeight <= (container.offsetHeight * 2)) {
7572
requestAnimationFrame(() => addItem(container));
7673
}
7774

7875
if (render.index > 0 && dataList.length === render.renderList.length) {
79-
container.removeEventListener('scroll', onScroll, true);
76+
container.removeEventListener('scroll', handleScroll, true);
8077
} else {
81-
container.addEventListener('scroll', onScroll, true);
78+
container.addEventListener('scroll', handleScroll, true);
8279
}
8380

8481
adding = false;
8582
}
8683

8784
return () => { // when unmounted
8885
if (span) {
89-
container.removeEventListener('scroll', onScroll, true);
86+
container.removeEventListener('scroll', handleScroll, true);
9087
}
9188
};
9289
}, [render.index]);

0 commit comments

Comments
 (0)