Skip to content

Commit

Permalink
Merge branch 'pull-to-refresh-2' of github.com:janicduplessis/react-n…
Browse files Browse the repository at this point in the history
…ative into pull-to-refresh-2
  • Loading branch information
janicduplessis committed Jan 1, 2016
2 parents e9cb690 + 836e388 commit 12fece7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
5 changes: 2 additions & 3 deletions Libraries/Components/RefreshControl/RefreshControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ const RefreshControl = React.createClass({
tintColor={this.props.tintColor}
title={this.props.title}
refreshing={this.props.refreshing}
onRefresh={this._onRefreshIOS}
/>
onRefresh={this._onRefreshIOS}/>
);
},

Expand All @@ -114,7 +113,7 @@ const RefreshControl = React.createClass({
ref={NATIVE_REF}
refreshing={this.props.refreshing}
size={this.props.size}
style={[{flex: 1}, this.props.style]}>
style={this.props.style}>
{onlyChild(this.props.children)}
</NativeRefreshControl>
);
Expand Down
36 changes: 24 additions & 12 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ var ScrollView = React.createClass({
this.props.contentContainerStyle,
];
if (__DEV__ && this.props.style) {
var style = flattenStyle(this.props.style);
var childLayoutProps = ['alignItems', 'justifyContent']
const style = flattenStyle(this.props.style);
const childLayoutProps = ['alignItems', 'justifyContent']
.filter((prop) => style && style[prop] !== undefined);
invariant(
childLayoutProps.length === 0,
Expand All @@ -402,13 +402,18 @@ var ScrollView = React.createClass({

// Extract the RefreshControl from the children if there is one.
var refreshControl = null;
var children = this.props.children.filter(c => {
if (c && c.type && c.type.displayName === 'RefreshControl') {
refreshControl = c;
return false;
}
return true;
});
var children;
if (Array.isArray(this.props.children)) {
children = this.props.children.filter(c => {
if (c && c.type && c.type.displayName === 'RefreshControl') {
refreshControl = c;
return false;
}
return true;
});
} else {
children = this.props.children;
}

var contentContainer =
<View
Expand Down Expand Up @@ -487,10 +492,17 @@ var ScrollView = React.createClass({
);
} else if (Platform.OS === 'android') {
// On Android we need to wrap the ScrollView with the RefreshControl.
// Since we are wrapping the ScrollView add the style props to the
// RefreshControl and use flex: 1 for the ScrollView.
const {
style,
...others,
} = props;
return React.cloneElement(
refreshControl,
{},
<ScrollViewClass {...props} ref={SCROLLVIEW}>
refreshControl, {
style,
},
<ScrollViewClass {...others} style={styles.base} ref={SCROLLVIEW}>
{contentContainer}
</ScrollViewClass>
);
Expand Down

0 comments on commit 12fece7

Please sign in to comment.