Deprecated scrollResponderScrollWithoutAnimationTo

Summary:
public

This diff deprecates `scrollResponderScrollWithoutAnimationTo` and replaces it with an optional `animated` param in `scrollResponderScrollTo`. This is more consistent with our other APIs.

Using the old `ScrollResponder.scrollResponderScrollWithoutAnimationTo` or  `ScrollView.scrollWithoutAnimationTo` functions will still work, but will trigger a warning.

Reviewed By: javache

Differential Revision: D2823479

fb-gh-sync-id: 259966512104ca7b3995c9586144812a91b8d3e9
This commit is contained in:
Nick Lockwood
2016-01-14 07:41:24 -08:00
committed by facebook-github-bot-0
parent 90d2787aef
commit ff6a2c3998
3 changed files with 38 additions and 49 deletions

View File

@@ -348,41 +348,31 @@ var ScrollResponderMixin = {
/**
* A helper function to scroll to a specific point in the scrollview.
* This is currently used to help focus on child textview's, but this
* This is currently used to help focus on child textviews, but this
* can also be used to quickly scroll to any element we want to focus
*/
scrollResponderScrollTo: function(offsetX: number, offsetY: number) {
scrollResponderScrollTo: function(offsetX: number, offsetY: number, animated: boolean = true) {
if (Platform.OS === 'android') {
UIManager.dispatchViewManagerCommand(
React.findNodeHandle(this),
UIManager.RCTScrollView.Commands.scrollTo,
UIManager.RCTScrollView.Commands[animated ? 'scrollTo' : 'scrollWithoutAnimationTo'],
[Math.round(offsetX), Math.round(offsetY)],
);
} else {
ScrollViewManager.scrollTo(
React.findNodeHandle(this),
{ x: offsetX, y: offsetY }
{ x: offsetX, y: offsetY },
animated
);
}
},
/**
* Like `scrollResponderScrollTo` but immediately scrolls to the given
* position
* Deprecated, do not use.
*/
scrollResponderScrollWithoutAnimationTo: function(offsetX: number, offsetY: number) {
if (Platform.OS === 'android') {
UIManager.dispatchViewManagerCommand(
React.findNodeHandle(this),
UIManager.RCTScrollView.Commands.scrollWithoutAnimationTo,
[offsetX, offsetY],
);
} else {
ScrollViewManager.scrollWithoutAnimationTo(
React.findNodeHandle(this),
{ x: offsetX, y: offsetY }
);
}
console.warn('`scrollResponderScrollWithoutAnimationTo` is deprecated. Use `scrollResponderScrollTo` instead');
self.scrollResponderScrollTo(offsetX, offsetY, false);
},
/**

View File

@@ -339,17 +339,17 @@ var ScrollView = React.createClass({
return React.findNodeHandle(this.refs[INNERVIEW]);
},
scrollTo: function(destY?: number, destX?: number) {
scrollTo: function(destY: number = 0, destX: number = 0, animated: boolean = true) {
// $FlowFixMe - Don't know how to pass Mixin correctly. Postpone for now
this.getScrollResponder().scrollResponderScrollTo(destX || 0, destY || 0);
this.getScrollResponder().scrollResponderScrollTo(destX, destY, animated);
},
scrollWithoutAnimationTo: function(destY?: number, destX?: number) {
// $FlowFixMe - Don't know how to pass Mixin correctly. Postpone for now
this.getScrollResponder().scrollResponderScrollWithoutAnimationTo(
destX || 0,
destY || 0,
);
/**
* Deprecated, do not use.
*/
scrollWithoutAnimationTo: function(destY: number = 0, destX: number = 0) {
console.warn('`scrollWithoutAnimationTo` is deprecated. Use `scrollTo` instead');
this.scrollTo(destX, destY, false);
},
handleScroll: function(e: Object) {