Allow customized refreshControl in ScrollView for Android

Summary:
Original Android's refreshControl in ScrollView is tightly coupled with AndroidSwipeRefreshLayout. If someone use `ref=` for RefreshControl in ScrollView, it does nothing since RefreshControl in Android return null.

This change allows customized  RefreshControl especially for `ref=` as well as making ScrollView's code clearer.
Closes https://github.com/facebook/react-native/pull/5623

Reviewed By: svcscm

Differential Revision: D2890072

Pulled By: nicklockwood

fb-gh-sync-id: a8fc7746bcc050a6e46fedf3583979f4cb9021b6
This commit is contained in:
Kudo Chien
2016-02-02 07:11:41 -08:00
committed by facebook-github-bot-1
parent a0bed63f13
commit 6d65a90017
5 changed files with 17 additions and 24 deletions

View File

@@ -13,6 +13,7 @@
const React = require('React');
const Platform = require('Platform');
const ColorPropType = require('ColorPropType');
const View = require('View');
const requireNativeComponent = require('requireNativeComponent');
@@ -33,6 +34,7 @@ const RefreshControl = React.createClass({
},
propTypes: {
...View.propTypes,
/**
* Called when the view starts refreshing.
*/
@@ -74,15 +76,7 @@ const RefreshControl = React.createClass({
},
render() {
if (Platform.OS === 'ios') {
return <NativeRefreshControl {...this.props}/>;
} else {
// On Android the ScrollView is wrapped so this component doesn't render
// anything and only acts as a way to configure the wrapper view.
// ScrollView will wrap itself in a AndroidSwipeRefreshLayout using props
// from this.
return null;
}
return <NativeRefreshControl {...this.props} />;
},
});
@@ -91,6 +85,11 @@ if (Platform.OS === 'ios') {
'RCTRefreshControl',
RefreshControl
);
} else if (Platform.OS === 'android') {
var NativeRefreshControl = requireNativeComponent(
'AndroidSwipeRefreshLayout',
RefreshControl
);
}
module.exports = RefreshControl;