Skip to content

Commit

Permalink
Initial implementation of runRenderRowAfterInteractions
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne committed Sep 24, 2015
1 parent 4eecef1 commit 83c1b4e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Libraries/CustomComponents/ListView/ListView.js
Expand Up @@ -26,6 +26,7 @@
*/
'use strict';

var InteractionManager = require('InteractionManager');
var ListViewDataSource = require('ListViewDataSource');
var React = require('React');
var RCTUIManager = require('NativeModules').UIManager;
Expand Down Expand Up @@ -134,6 +135,11 @@ var ListView = React.createClass({
* a row can be reset by calling highlightRow(null).
*/
renderRow: PropTypes.func.isRequired,
/**
* If true, defer running renderRow until the current InteractionManager handle
* has cleared.
*/
runRenderRowAfterInteractions: PropTypes.bool,
/**
* How many rows to render on initial component mount. Use this to make
* it so that the first screen worth of data apears at one time instead of
Expand Down Expand Up @@ -239,6 +245,7 @@ var ListView = React.createClass({
initialListSize: DEFAULT_INITIAL_ROWS,
pageSize: DEFAULT_PAGE_SIZE,
renderScrollComponent: props => <ScrollView {...props} />,
runRenderRowAfterInteractions: false,
scrollRenderAheadDistance: DEFAULT_SCROLL_RENDER_AHEAD,
onEndReachedThreshold: DEFAULT_END_REACHED_THRESHOLD,
};
Expand Down Expand Up @@ -268,6 +275,8 @@ var ListView = React.createClass({
},

componentDidMount: function() {
this._mounted = true;

// do this in animation frame until componentDidMount actually runs after
// the component is laid out
this.requestAnimationFrame(() => {
Expand Down Expand Up @@ -296,6 +305,10 @@ var ListView = React.createClass({
});
},

componentWillUnmount() {
this._mounted = false;
},

onRowHighlighted: function(sectionID, rowID) {
this.setState({highlightedRow: {sectionID, rowID}});
},
Expand Down Expand Up @@ -461,7 +474,13 @@ var ListView = React.createClass({

var distanceFromEnd = this._getDistanceFromEnd(this.scrollProperties);
if (distanceFromEnd < this.props.scrollRenderAheadDistance) {
this._pageInNewRows();
if (this.props.runRenderRowAfterInteractions) {
InteractionManager.runAfterInteractions(() => {
this._mounted && this._pageInNewRows();
});
} else {
this._pageInNewRows();
}
}
},

Expand Down

0 comments on commit 83c1b4e

Please sign in to comment.