mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
UIRefreshControl added to scroll view
Summary: **What:** adds `onRefreshStart` property to `ScrollView.js` for displaying and activating pull to refresh. **Why:** Javascript implementations seemed a little flakey and inconsistent. As you can see in the issues below: https://github.com/facebook/react-native/issues/2356 https://github.com/facebook/react-native/issues/745 So this is an attempt a completely native implementation. What do you think?  Closes https://github.com/facebook/react-native/pull/4205 Reviewed By: svcscm Differential Revision: D2674945 Pulled By: nicklockwood fb-gh-sync-id: 65113a5db9785df5a95c68323c2cdf19f3b217b1
This commit is contained in:
committed by
facebook-github-bot-4
parent
5950f8cf15
commit
2faf8632d3
@@ -15,6 +15,7 @@ var EdgeInsetsPropType = require('EdgeInsetsPropType');
|
||||
var Platform = require('Platform');
|
||||
var PointPropType = require('PointPropType');
|
||||
var RCTScrollView = require('NativeModules').UIManager.RCTScrollView;
|
||||
var RCTScrollViewManager = require('NativeModules').ScrollViewManager;
|
||||
var React = require('React');
|
||||
var ReactNativeViewAttributes = require('ReactNativeViewAttributes');
|
||||
var RCTUIManager = require('NativeModules').UIManager;
|
||||
@@ -279,6 +280,21 @@ var ScrollView = React.createClass({
|
||||
* @platform ios
|
||||
*/
|
||||
zoomScale: PropTypes.number,
|
||||
|
||||
/**
|
||||
* When defined, displays a UIRefreshControl.
|
||||
* Invoked with a function to stop refreshing when the UIRefreshControl is animating.
|
||||
*
|
||||
* ```
|
||||
* (endRefreshing) => {
|
||||
* endRefreshing();
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @platform ios
|
||||
*/
|
||||
onRefreshStart: PropTypes.func,
|
||||
|
||||
},
|
||||
|
||||
mixins: [ScrollResponder.Mixin],
|
||||
@@ -291,6 +307,12 @@ var ScrollView = React.createClass({
|
||||
this.refs[SCROLLVIEW].setNativeProps(props);
|
||||
},
|
||||
|
||||
endRefreshing: function() {
|
||||
RCTScrollViewManager.endRefreshing(
|
||||
React.findNodeHandle(this)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a reference to the underlying scroll responder, which supports
|
||||
* operations like `scrollTo`. All ScrollView-like components should
|
||||
@@ -396,6 +418,13 @@ var ScrollView = React.createClass({
|
||||
onResponderReject: this.scrollResponderHandleResponderReject,
|
||||
};
|
||||
|
||||
var onRefreshStart = this.props.onRefreshStart;
|
||||
// this is necessary because if we set it on props, even when empty,
|
||||
// it'll trigger the default pull-to-refresh behaviour on native.
|
||||
props.onRefreshStart = onRefreshStart
|
||||
? function() { onRefreshStart && onRefreshStart(this.endRefreshing); }.bind(this)
|
||||
: null;
|
||||
|
||||
var ScrollViewClass;
|
||||
if (Platform.OS === 'ios') {
|
||||
ScrollViewClass = RCTScrollView;
|
||||
|
||||
Reference in New Issue
Block a user