mirror of
https://github.com/status-im/react-native.git
synced 2025-01-27 01:40:08 +00:00
Remove deprecated PullToRefreshViewAndroid and onRefreshStart / endRefreshing
Summary: Removes the deprecated APIs that were replaced by `RefreshControl`. Those API have been deprecated for a while already so I think it's fine to remove them at this point. Also ported the `SwipeRefreshLayoutTestModule` test to use `RefreshControl` instead of `PullToRefreshViewAndroid`. **Test plan (required)** Made sure no references are left in the codebase to `PullToRefreshViewAndroid`, `onRefreshStart` and `endRefreshing`. Tested that `ScrollView` examples in UIExplorer still work properly. Check that the `SwipeRefreshLayoutTestModule` passes on CI. Closes https://github.com/facebook/react-native/pull/7447 Reviewed By: mkonicek Differential Revision: D3292391 Pulled By: bestander fbshipit-source-id: 27eb2443861e04a9f7319586ce2ada381b714d47
This commit is contained in:
parent
18d6d85320
commit
a71a9efe96
@ -24,7 +24,6 @@ const StyleSheetPropType = require('StyleSheetPropType');
|
||||
const View = require('View');
|
||||
const ViewStylePropTypes = require('ViewStylePropTypes');
|
||||
|
||||
const deprecatedPropType = require('deprecatedPropType');
|
||||
const dismissKeyboard = require('dismissKeyboard');
|
||||
const flattenStyle = require('flattenStyle');
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
@ -311,14 +310,6 @@ const ScrollView = React.createClass({
|
||||
*/
|
||||
refreshControl: PropTypes.element,
|
||||
|
||||
/**
|
||||
* @platform ios
|
||||
*/
|
||||
onRefreshStart: deprecatedPropType(
|
||||
PropTypes.func,
|
||||
'Use the `refreshControl` prop instead.'
|
||||
),
|
||||
|
||||
/**
|
||||
* Sometimes a scrollview takes up more space than its content fills. When this is
|
||||
* the case, this prop will fill the rest of the scrollview with a color to avoid setting
|
||||
@ -348,15 +339,6 @@ const ScrollView = React.createClass({
|
||||
this._scrollViewRef && this._scrollViewRef.setNativeProps(props);
|
||||
},
|
||||
|
||||
/**
|
||||
* Deprecated. Use `RefreshControl` instead.
|
||||
*/
|
||||
endRefreshing: function() {
|
||||
RCTScrollViewManager.endRefreshing(
|
||||
ReactNative.findNodeHandle(this)
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns a reference to the underlying scroll responder, which supports
|
||||
* operations like `scrollTo`. All ScrollView-like components should
|
||||
@ -510,14 +492,6 @@ const ScrollView = React.createClass({
|
||||
sendMomentumEvents: (this.props.onMomentumScrollBegin || this.props.onMomentumScrollEnd) ? true : false,
|
||||
};
|
||||
|
||||
const onRefreshStart = this.props.onRefreshStart;
|
||||
if (onRefreshStart) {
|
||||
// this is necessary because if we set it on props, even when empty,
|
||||
// it'll trigger the default pull-to-refresh behavior on native.
|
||||
props.onRefreshStart =
|
||||
function() { onRefreshStart && onRefreshStart(this.endRefreshing); }.bind(this);
|
||||
}
|
||||
|
||||
const { decelerationRate } = this.props;
|
||||
if (decelerationRate) {
|
||||
props.decelerationRate = processDecelerationRate(decelerationRate);
|
||||
|
@ -1,107 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @providesModule PullToRefreshViewAndroid
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var ColorPropType = require('ColorPropType');
|
||||
var React = require('React');
|
||||
var RefreshLayoutConsts = require('UIManager').AndroidSwipeRefreshLayout.Constants;
|
||||
var View = require('View');
|
||||
|
||||
var onlyChild = require('onlyChild');
|
||||
var requireNativeComponent = require('requireNativeComponent');
|
||||
|
||||
var NATIVE_REF = 'native_swiperefreshlayout';
|
||||
|
||||
/**
|
||||
* Deprecated. Use `RefreshControl` instead.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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`).
|
||||
*/
|
||||
var PullToRefreshViewAndroid = React.createClass({
|
||||
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
|
||||
*/
|
||||
colors: React.PropTypes.arrayOf(ColorPropType),
|
||||
/**
|
||||
* The background color of the refresh indicator
|
||||
*/
|
||||
progressBackgroundColor: ColorPropType,
|
||||
/**
|
||||
* Progress view top offset
|
||||
* @platform android
|
||||
*/
|
||||
progressViewOffset: React.PropTypes.number,
|
||||
/**
|
||||
* Whether the view should be indicating an active refresh
|
||||
*/
|
||||
refreshing: React.PropTypes.bool,
|
||||
/**
|
||||
* Size of the refresh indicator, see PullToRefreshViewAndroid.SIZE
|
||||
*/
|
||||
size: React.PropTypes.oneOf(RefreshLayoutConsts.SIZE.DEFAULT, RefreshLayoutConsts.SIZE.LARGE),
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
console.warn('`PullToRefreshViewAndroid` is deprecated. Use `RefreshControl` instead.');
|
||||
},
|
||||
|
||||
getInnerViewNode: function() {
|
||||
return this.refs[NATIVE_REF];
|
||||
},
|
||||
|
||||
setNativeProps: function(props) {
|
||||
let innerViewNode = this.getInnerViewNode();
|
||||
return innerViewNode && innerViewNode.setNativeProps(props);
|
||||
},
|
||||
|
||||
render: function() {
|
||||
return (
|
||||
<NativePullToRefresh
|
||||
colors={this.props.colors}
|
||||
enabled={this.props.enabled}
|
||||
onRefresh={this._onRefresh}
|
||||
progressBackgroundColor={this.props.progressBackgroundColor}
|
||||
ref={NATIVE_REF}
|
||||
refreshing={this.props.refreshing}
|
||||
progressViewOffset={this.props.progressViewOffset}
|
||||
size={this.props.size}
|
||||
style={this.props.style}>
|
||||
{onlyChild(this.props.children)}
|
||||
</NativePullToRefresh>
|
||||
);
|
||||
},
|
||||
|
||||
_onRefresh: function() {
|
||||
this.props.onRefresh && this.props.onRefresh();
|
||||
this.setNativeProps({refreshing: !!this.props.refreshing});
|
||||
}
|
||||
});
|
||||
|
||||
var NativePullToRefresh = requireNativeComponent(
|
||||
'AndroidSwipeRefreshLayout',
|
||||
PullToRefreshViewAndroid
|
||||
);
|
||||
|
||||
module.exports = PullToRefreshViewAndroid;
|
@ -1,13 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @providesModule PullToRefreshViewAndroid
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
module.exports = require('UnimplementedView');
|
1
Libraries/react-native/react-native.js
vendored
1
Libraries/react-native/react-native.js
vendored
@ -49,7 +49,6 @@ var ReactNative = {
|
||||
get SliderIOS() { return require('SliderIOS'); },
|
||||
get SnapshotViewIOS() { return require('SnapshotViewIOS'); },
|
||||
get Switch() { return require('Switch'); },
|
||||
get PullToRefreshViewAndroid() { return require('PullToRefreshViewAndroid'); },
|
||||
get RecyclerViewBackedScrollView() { return require('RecyclerViewBackedScrollView'); },
|
||||
get RefreshControl() { return require('RefreshControl'); },
|
||||
get StatusBar() { return require('StatusBar'); },
|
||||
|
@ -48,7 +48,6 @@ var ReactNative = Object.assign(Object.create(require('ReactNative')), {
|
||||
SnapshotViewIOS: require('SnapshotViewIOS'),
|
||||
StatusBar: require('StatusBar'),
|
||||
Switch: require('Switch'),
|
||||
PullToRefreshViewAndroid: require('PullToRefreshViewAndroid'),
|
||||
RecyclerViewBackedScrollView: require('RecyclerViewBackedScrollView'),
|
||||
RefreshControl: require('RefreshControl'),
|
||||
SwitchAndroid: require('SwitchAndroid'),
|
||||
|
@ -58,10 +58,6 @@
|
||||
@property (nonatomic, copy) RCTDirectEventBlock onMomentumScrollEnd;
|
||||
@property (nonatomic, copy) RCTDirectEventBlock onScrollAnimationEnd;
|
||||
|
||||
// Pull-to-refresh support (deprecated - use RCTPullToRefreshControl instead)
|
||||
@property (nonatomic, copy) RCTDirectEventBlock onRefreshStart;
|
||||
- (void)endRefreshing;
|
||||
|
||||
@end
|
||||
|
||||
@interface RCTEventDispatcher (RCTScrollView)
|
||||
|
@ -934,34 +934,6 @@ RCT_SET_AND_PRESERVE_OFFSET(setShowsVerticalScrollIndicator, showsVerticalScroll
|
||||
RCT_SET_AND_PRESERVE_OFFSET(setZoomScale, zoomScale, CGFloat);
|
||||
RCT_SET_AND_PRESERVE_OFFSET(setScrollIndicatorInsets, scrollIndicatorInsets, UIEdgeInsets);
|
||||
|
||||
- (void)setOnRefreshStart:(RCTDirectEventBlock)onRefreshStart
|
||||
{
|
||||
if (!onRefreshStart) {
|
||||
_onRefreshStart = nil;
|
||||
_scrollView.refreshControl = nil;
|
||||
return;
|
||||
}
|
||||
_onRefreshStart = [onRefreshStart copy];
|
||||
|
||||
if (!_scrollView.refreshControl) {
|
||||
RCTRefreshControl *refreshControl = [RCTRefreshControl new];
|
||||
[refreshControl addTarget:self action:@selector(refreshControlValueChanged) forControlEvents:UIControlEventValueChanged];
|
||||
_scrollView.refreshControl = refreshControl;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)refreshControlValueChanged
|
||||
{
|
||||
if (self.onRefreshStart) {
|
||||
self.onRefreshStart(nil);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)endRefreshing
|
||||
{
|
||||
[_scrollView.refreshControl endRefreshing];
|
||||
}
|
||||
|
||||
- (void)sendScrollEventWithName:(NSString *)eventName
|
||||
scrollView:(UIScrollView *)scrollView
|
||||
userData:(NSDictionary *)userData
|
||||
|
@ -72,7 +72,6 @@ RCT_EXPORT_VIEW_PROPERTY(scrollIndicatorInsets, UIEdgeInsets)
|
||||
RCT_EXPORT_VIEW_PROPERTY(snapToInterval, int)
|
||||
RCT_EXPORT_VIEW_PROPERTY(snapToAlignment, NSString)
|
||||
RCT_REMAP_VIEW_PROPERTY(contentOffset, scrollView.contentOffset, CGPoint)
|
||||
RCT_EXPORT_VIEW_PROPERTY(onRefreshStart, RCTDirectEventBlock)
|
||||
RCT_EXPORT_VIEW_PROPERTY(onScrollBeginDrag, RCTDirectEventBlock)
|
||||
RCT_EXPORT_VIEW_PROPERTY(onScroll, RCTDirectEventBlock)
|
||||
RCT_EXPORT_VIEW_PROPERTY(onScrollEndDrag, RCTDirectEventBlock)
|
||||
@ -119,21 +118,6 @@ RCT_EXPORT_METHOD(calculateChildFrames:(nonnull NSNumber *)reactTag
|
||||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(endRefreshing:(nonnull NSNumber *)reactTag)
|
||||
{
|
||||
[self.bridge.uiManager addUIBlock:
|
||||
^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
|
||||
|
||||
RCTScrollView *view = viewRegistry[reactTag];
|
||||
if (!view || ![view isKindOfClass:[RCTScrollView class]]) {
|
||||
RCTLogError(@"Cannot find RCTScrollView with tag #%@", reactTag);
|
||||
return;
|
||||
}
|
||||
|
||||
[view endRefreshing];
|
||||
}];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(scrollTo:(nonnull NSNumber *)reactTag
|
||||
offsetX:(CGFloat)x
|
||||
offsetY:(CGFloat)y
|
||||
|
@ -15,7 +15,7 @@ var BatchedBridge = require('BatchedBridge');
|
||||
var React = require('React');
|
||||
var RecordingModule = require('NativeModules').SwipeRefreshLayoutRecordingModule;
|
||||
var ScrollView = require('ScrollView');
|
||||
var PullToRefreshViewAndroid = require('PullToRefreshViewAndroid');
|
||||
var RefreshControl = require('RefreshControl');
|
||||
var Text = require('Text');
|
||||
var TouchableWithoutFeedback = require('TouchableWithoutFeedback');
|
||||
var View = require('View');
|
||||
@ -62,13 +62,17 @@ var SwipeRefreshLayoutTestApp = React.createClass({
|
||||
rows.push(<Row key={i} />);
|
||||
}
|
||||
return (
|
||||
<PullToRefreshViewAndroid
|
||||
<ScrollView
|
||||
style={{flex: 1}}
|
||||
onRefresh={() => RecordingModule.onRefresh()}>
|
||||
<ScrollView style={{flex: 1}}>
|
||||
{rows}
|
||||
</ScrollView>
|
||||
</PullToRefreshViewAndroid>
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
style={{flex: 1}}
|
||||
refreshing={false}
|
||||
onRefresh={() => RecordingModule.onRefresh()}
|
||||
/>
|
||||
}>
|
||||
{rows}
|
||||
</ScrollView>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user