Skip to content

Commit

Permalink
[ListView] Allow different types of ScrollView to be composed
Browse files Browse the repository at this point in the history
This enables code like:
```js
<ListView renderScrollView={(props) => <CustomScrollView {...props} />} />
```

where CustomScrollView might be inverted or support pull-to-refresh, etc.
  • Loading branch information
ide committed May 16, 2015
1 parent 4fd009f commit afdb6be
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions Libraries/CustomComponents/ListView/ListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ var ScrollResponder = require('ScrollResponder');
var StaticRenderer = require('StaticRenderer');
var TimerMixin = require('react-timer-mixin');

var isEmpty = require('isEmpty');
var logError = require('logError');
var merge = require('merge');
var isEmpty = require('isEmpty');

var PropTypes = React.PropTypes;

Expand Down Expand Up @@ -163,6 +163,13 @@ var ListView = React.createClass({
* header.
*/
renderSectionHeader: PropTypes.func,
/**
* (props) => renderable
*
* A function that returns the scroll view in which the list rows are
* rendered. Defaults to returning a ScrollView with the given props.
*/
renderScrollView: React.PropTypes.func.isRequired,
/**
* How early to start rendering rows before they come on screen, in
* pixels.
Expand Down Expand Up @@ -218,6 +225,7 @@ var ListView = React.createClass({
return {
initialListSize: DEFAULT_INITIAL_ROWS,
pageSize: DEFAULT_PAGE_SIZE,
renderScrollView: (props) => <ScrollView {...props} />,
scrollRenderAheadDistance: DEFAULT_SCROLL_RENDER_AHEAD,
onEndReachedThreshold: DEFAULT_END_REACHED_THRESHOLD,
};
Expand Down Expand Up @@ -319,24 +327,22 @@ var ListView = React.createClass({
}
}

var props = merge(
this.props, {
onScroll: this._onScroll,
stickyHeaderIndices: sectionHeaderIndices,
}
);
var {
renderScrollView,
...props,
} = this.props;
if (!props.scrollEventThrottle) {
props.scrollEventThrottle = DEFAULT_SCROLL_CALLBACK_THROTTLE;
}
Object.assign(props, {
onScroll: this._onScroll,
stickyHeaderIndices: sectionHeaderIndices,
children: [header, bodyComponents, footer],
});

return (
<ScrollView {...props}
ref={SCROLLVIEW_REF}>
{header}
{bodyComponents}
{footer}
</ScrollView>
);
return React.cloneElement(renderScrollView(props), {
ref: SCROLLVIEW_REF,
});
},

/**
Expand Down

0 comments on commit afdb6be

Please sign in to comment.