diff --git a/Libraries/Components/RefreshControl/RefreshControl.js b/Libraries/Components/RefreshControl/RefreshControl.js index ee285a3c7..64e9a76ea 100644 --- a/Libraries/Components/RefreshControl/RefreshControl.js +++ b/Libraries/Components/RefreshControl/RefreshControl.js @@ -11,9 +11,10 @@ */ 'use strict'; -const React = require('React'); -const Platform = require('Platform'); const ColorPropType = require('ColorPropType'); +const NativeMethodsMixin = require('NativeMethodsMixin'); +const Platform = require('Platform'); +const React = require('React'); const View = require('View'); const requireNativeComponent = require('requireNativeComponent'); @@ -25,15 +26,57 @@ if (Platform.OS === 'android') { } /** - * This component is used inside a ScrollView to add pull to refresh + * This component is used inside a ScrollView or ListView to add pull to refresh * functionality. When the ScrollView is at `scrollY: 0`, swiping down * triggers an `onRefresh` event. + * + * ### Usage example + * + * ``` js + * class RefreshableList extends Component { + * constructor(props) { + * super(props); + * this.state = { + * refreshing: false, + * }; + * } + * + * _onRefresh() { + * this.setState({refreshing: true}); + * fetchData().then(() => { + * this.setState({refreshing: false}); + * }); + * } + * + * render() { + * return ( + * + * } + * ... + * > + * ... + * + * ); + * } + * ... + * } + * ``` + * + * __Note:__ `refreshing` is a controlled prop, this is why it needs to be set to true + * in the `onRefresh` function otherwise the refresh indicator will stop immediatly. */ const RefreshControl = React.createClass({ statics: { SIZE: RefreshLayoutConsts.SIZE, }, + mixins: [NativeMethodsMixin], + propTypes: { ...View.propTypes, /** @@ -76,8 +119,21 @@ const RefreshControl = React.createClass({ size: React.PropTypes.oneOf(RefreshLayoutConsts.SIZE.DEFAULT, RefreshLayoutConsts.SIZE.LARGE), }, + _nativeRef: {}, + render() { - return ; + return ( + this._nativeRef = ref} + onRefresh={this._onRefresh} + /> + ); + }, + + _onRefresh() { + this.props.onRefresh && this.props.onRefresh(); + this._nativeRef.setNativeProps({refreshing: this.props.refreshing}); }, }); diff --git a/website/layout/AutodocsLayout.js b/website/layout/AutodocsLayout.js index 269314cb1..e48212e58 100644 --- a/website/layout/AutodocsLayout.js +++ b/website/layout/AutodocsLayout.js @@ -41,12 +41,12 @@ function renderType(type) { return '{' + Object.keys(type.value).map((key => key + ': ' + renderType(type.value[key]))).join(', ') + '}'; } - if (type.name == 'union') { + if (type.name === 'union') { return type.value.map(renderType).join(', '); } if (type.name === 'arrayOf') { - return '[' + renderType(type.value) + ']'; + return [{renderType(type.value)}]; } if (type.name === 'instanceOf') { @@ -56,10 +56,10 @@ function renderType(type) { if (type.name === 'custom') { if (styleReferencePattern.test(type.raw)) { var name = type.raw.substring(0, type.raw.indexOf('.')); - return {name}#style + return {name}#style; } if (type.raw === 'ColorPropType') { - return color + return color; } if (type.raw === 'EdgeInsetsPropType') { return '{top: number, left: number, bottom: number, right: number}';