Skip to content

Commit

Permalink
Merge pull request #2 from tehandyb/master
Browse files Browse the repository at this point in the history
FIXED JITTER. must set child height state if children changed.
  • Loading branch information
jackcompton committed Jun 2, 2015
2 parents dfb2841 + c2f3dd9 commit e30e8ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 14 additions & 3 deletions dist/LazyRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ var LazyRender = React.createClass({displayName: "LazyRender",
},

componentDidMount: function() {
var firstChild = this.refs['child-0'];
var el = firstChild.getDOMNode();
var childHeight = this.getElementHeight(el);
var childHeight = this.getChildHeight();

var height = this.getHeight(
this.props.children.length,
Expand All @@ -116,6 +114,19 @@ var LazyRender = React.createClass({displayName: "LazyRender",
});
},

componentDidUpdate: function() {
//important to update the child height in the case that the children change(example: ajax call for data)
if(this.state.childHeight !== this.getChildHeight())
this.setState({childHeight: this.getChildHeight()});

},

getChildHeight: function() {
var firstChild = this.refs['child-0'];
var el = firstChild.getDOMNode();
return this.getElementHeight(el);
},

render: function() {
var start = this.state.childrenTop;
var end = this.state.childrenTop + this.state.childrenToRender;
Expand Down
17 changes: 14 additions & 3 deletions src/LazyRender.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ var LazyRender = React.createClass({
},

componentDidMount: function() {
var firstChild = this.refs['child-0'];
var el = firstChild.getDOMNode();
var childHeight = this.getElementHeight(el);
var childHeight = this.getChildHeight();

var height = this.getHeight(
this.props.children.length,
Expand All @@ -116,6 +114,19 @@ var LazyRender = React.createClass({
});
},

componentDidUpdate: function() {
//important to update the child height in the case that the children change(example: ajax call for data)
if(this.state.childHeight !== this.getChildHeight())
this.setState({childHeight: this.getChildHeight()});

},

getChildHeight: function() {
var firstChild = this.refs['child-0'];
var el = firstChild.getDOMNode();
return this.getElementHeight(el);
},

render: function() {
var start = this.state.childrenTop;
var end = this.state.childrenTop + this.state.childrenToRender;
Expand Down

0 comments on commit e30e8ec

Please sign in to comment.