2015-11-24 16:50:39 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
2015-12-07 16:28:45 +00:00
|
|
|
* @providesModule PullToRefreshViewAndroid
|
2015-11-24 16:50:39 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-12-23 03:29:01 +00:00
|
|
|
var ColorPropType = require('ColorPropType');
|
2015-11-24 16:50:39 +00:00
|
|
|
var React = require('React');
|
2015-12-23 03:29:01 +00:00
|
|
|
var RefreshLayoutConsts = require('UIManager').AndroidSwipeRefreshLayout.Constants;
|
2015-11-24 16:50:39 +00:00
|
|
|
var View = require('View');
|
|
|
|
|
|
|
|
var onlyChild = require('onlyChild');
|
|
|
|
var processColor = require('processColor');
|
|
|
|
var requireNativeComponent = require('requireNativeComponent');
|
|
|
|
|
|
|
|
var NATIVE_REF = 'native_swiperefreshlayout';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* React view that supports a single scrollable child view (e.g. `ScrollView`). When this child
|
|
|
|
* view is at `scrollY: 0`, swiping down triggers an `onRefresh` event.
|
2015-12-16 13:16:15 +00:00
|
|
|
*
|
|
|
|
* The style `{flex: 1}` might be required to ensure the expected behavior of the child component
|
|
|
|
* (e.g. when the child is expected to scroll with `ScrollView` or `ListView`).
|
2015-11-24 16:50:39 +00:00
|
|
|
*/
|
2015-12-07 16:28:45 +00:00
|
|
|
var PullToRefreshViewAndroid = React.createClass({
|
2015-11-24 16:50:39 +00:00
|
|
|
statics: {
|
|
|
|
SIZE: RefreshLayoutConsts.SIZE,
|
|
|
|
},
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
...View.propTypes,
|
|
|
|
/**
|
|
|
|
* Whether the pull to refresh functionality is enabled
|
|
|
|
*/
|
|
|
|
enabled: React.PropTypes.bool,
|
|
|
|
/**
|
|
|
|
* The colors (at least one) that will be used to draw the refresh indicator
|
|
|
|
*/
|
2015-12-23 03:29:01 +00:00
|
|
|
colors: React.PropTypes.arrayOf(ColorPropType),
|
2015-11-24 16:50:39 +00:00
|
|
|
/**
|
|
|
|
* The background color of the refresh indicator
|
|
|
|
*/
|
2015-12-23 03:29:01 +00:00
|
|
|
progressBackgroundColor: ColorPropType,
|
2015-11-24 16:50:39 +00:00
|
|
|
/**
|
|
|
|
* Whether the view should be indicating an active refresh
|
|
|
|
*/
|
|
|
|
refreshing: React.PropTypes.bool,
|
|
|
|
/**
|
2015-12-07 16:28:45 +00:00
|
|
|
* Size of the refresh indicator, see PullToRefreshViewAndroid.SIZE
|
2015-11-24 16:50:39 +00:00
|
|
|
*/
|
|
|
|
size: React.PropTypes.oneOf(RefreshLayoutConsts.SIZE.DEFAULT, RefreshLayoutConsts.SIZE.LARGE),
|
|
|
|
},
|
|
|
|
|
|
|
|
getInnerViewNode: function() {
|
|
|
|
return this.refs[NATIVE_REF];
|
|
|
|
},
|
|
|
|
|
2015-12-14 20:53:22 +00:00
|
|
|
setNativeProps: function(props) {
|
|
|
|
return this.refs[NATIVE_REF].setNativeProps(props);
|
|
|
|
},
|
|
|
|
|
2015-11-24 16:50:39 +00:00
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<NativePullToRefresh
|
|
|
|
colors={this.props.colors && this.props.colors.map(processColor)}
|
|
|
|
enabled={this.props.enabled}
|
|
|
|
onRefresh={this._onRefresh}
|
|
|
|
progressBackgroundColor={this.props.progressBackgroundColor}
|
|
|
|
ref={NATIVE_REF}
|
|
|
|
refreshing={this.props.refreshing}
|
|
|
|
size={this.props.size}
|
|
|
|
style={this.props.style}>
|
|
|
|
{onlyChild(this.props.children)}
|
|
|
|
</NativePullToRefresh>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onRefresh: function() {
|
|
|
|
this.props.onRefresh && this.props.onRefresh();
|
|
|
|
this.refs[NATIVE_REF].setNativeProps({refreshing: !!this.props.refreshing});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var NativePullToRefresh = requireNativeComponent(
|
|
|
|
'AndroidSwipeRefreshLayout',
|
2015-12-07 16:28:45 +00:00
|
|
|
PullToRefreshViewAndroid
|
2015-11-24 16:50:39 +00:00
|
|
|
);
|
|
|
|
|
2015-12-07 16:28:45 +00:00
|
|
|
module.exports = PullToRefreshViewAndroid;
|