Skip to content

Commit

Permalink
Initial implementation of runRenderRowAfterInteractions
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvatne authored and machard committed Mar 2, 2016
1 parent 74bb504 commit 47b413e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Libraries/CustomComponents/ListView/ListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
'use strict';

var InteractionManager = require('InteractionManager');
var ListViewDataSource = require('ListViewDataSource');
var React = require('React');
var RCTScrollViewManager = require('NativeModules').ScrollViewManager;
Expand Down Expand Up @@ -135,6 +136,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 appears at one time instead of
Expand Down Expand Up @@ -250,6 +256,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,
stickyHeaderIndices: [],
Expand Down Expand Up @@ -281,6 +288,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 @@ -318,6 +327,10 @@ var ListView = React.createClass({
});
},

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

onRowHighlighted: function(sectionID, rowID) {
this.setState({highlightedRow: {sectionID, rowID}});
},
Expand Down Expand Up @@ -495,7 +508,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

2 comments on commit 47b413e

@btoueg
Copy link

@btoueg btoueg commented on 47b413e Jul 19, 2016

Choose a reason for hiding this comment

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

Pour améliorer les listes (rendu des rows au fur et à mesure). Ce commit fait en sorte que les rows supplémentaires ne se rendent pas s'il y a des modifications en cours.

@btoueg
Copy link

@btoueg btoueg commented on 47b413e Aug 29, 2016

Choose a reason for hiding this comment

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

See facebook#3011 for original PR
and facebook#2990 for more recent discussion about the subject

Please sign in to comment.