Skip to content
This repository has been archived by the owner on Jun 10, 2020. It is now read-only.

Loading items on container height dynamically changed #192

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions __tests__/infinite_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,37 @@ describe("React Infinite's Infinite Scroll Capabilities", function() {
expect(infiniteSpy).not.toHaveBeenCalled();
});

it('triggers the onInfiniteLoad function when containerHeight changes', function() {
Copy link

@DevSide DevSide May 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may provide the case where useWindowAsScrollContainer is true so when containerHeight changes, onInfiniteLoad is not called

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

var infiniteSpy = jasmine.createSpy('infiniteSpy');
var elementHeight = 200;

var rootNode = document.createElement('div');

ReactDOM.render(
<Infinite elementHeight={elementHeight}
containerHeight={400}
onInfiniteLoad={infiniteSpy}
infiniteLoadBeginEdgeOffset={100}
className={"correct-class-name"}>
{renderHelpers.divGenerator(2, elementHeight)}
</Infinite>,
rootNode
);

ReactDOM.render(
<Infinite elementHeight={elementHeight}
containerHeight={1000}
onInfiniteLoad={infiniteSpy}
infiniteLoadBeginEdgeOffset={100}
className={"correct-class-name"}>
{renderHelpers.divGenerator(2, elementHeight)}
</Infinite>,
rootNode
);

expect(infiniteSpy).toHaveBeenCalled();
});

it('triggers the onInfiniteLoad function when scrolling past infiniteLoadBeginEdgeOffset', function() {
var infiniteSpy = jasmine.createSpy('infiniteSpy');
var elementHeight = 200;
Expand Down
9 changes: 9 additions & 0 deletions src/react-infinite.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,15 @@ var Infinite = React.createClass({
if (isMissingVisibleRows) {
this.onInfiniteLoad();
}

if (this.props.containerHeight !== prevProps.containerHeight) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ containerHeight is computed in generateComputedProps so you can't get the previous value by this way

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

const scrollTop = this.utils.getScrollTop();
const newApertureState = infiniteHelpers.recomputeApertureStateFromOptionsAndScrollTop(this.state, scrollTop);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may rely on handleScroll for the rest ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks, it is much simpler now

if (this.passedEdgeForInfiniteScroll(scrollTop) && !this.state.isInfiniteLoading) {
this.setState({...newApertureState});
this.onInfiniteLoad();
}
}
},

componentDidMount() {
Expand Down