Permalink
Browse files

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
  • Loading branch information...
nicklockwood authored and facebook-github-bot-0 committed Jan 14, 2016
1 parent 90d2787 commit ff6a2c39989121b8671ab7cf74a90d048fdc9acf
@@ -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);
},
/**
@@ -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) {
@@ -80,7 +80,8 @@ - (UIView *)view
RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag
callback:(RCTResponseSenderBlock)callback)
{
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
+ [self.bridge.uiManager addUIBlock:
+ ^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
RCTScrollView *view = viewRegistry[reactTag];
if (!view || ![view isKindOfClass:[RCTScrollView class]]) {
@@ -97,9 +98,10 @@ - (UIView *)view
}
RCT_EXPORT_METHOD(calculateChildFrames:(nonnull NSNumber *)reactTag
- callback:(RCTResponseSenderBlock)callback)
+ callback:(RCTResponseSenderBlock)callback)
{
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
+ [self.bridge.uiManager addUIBlock:
+ ^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
RCTScrollView *view = viewRegistry[reactTag];
if (!view || ![view isKindOfClass:[RCTScrollView class]]) {
@@ -116,7 +118,8 @@ - (UIView *)view
RCT_EXPORT_METHOD(endRefreshing:(nonnull NSNumber *)reactTag)
{
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
+ [self.bridge.uiManager addUIBlock:
+ ^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
RCTScrollView *view = viewRegistry[reactTag];
if (!view || ![view isKindOfClass:[RCTScrollView class]]) {
@@ -128,38 +131,34 @@ - (UIView *)view
}];
}
-RCT_EXPORT_METHOD(scrollTo:(nonnull NSNumber *)reactTag withOffset:(CGPoint)offset)
+RCT_EXPORT_METHOD(scrollTo:(nonnull NSNumber *)reactTag
+ withOffset:(CGPoint)offset
+ animated:(BOOL)animated)
{
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
+ [self.bridge.uiManager addUIBlock:
+ ^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
UIView *view = viewRegistry[reactTag];
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
- [(id<RCTScrollableProtocol>)view scrollToOffset:offset animated:YES];
+ [(id<RCTScrollableProtocol>)view scrollToOffset:offset animated:animated];
} else {
- RCTLogError(@"tried to scrollToOffset: on non-RCTScrollableProtocol view %@ with tag #%@", view, reactTag);
+ RCTLogError(@"tried to scrollTo: on non-RCTScrollableProtocol view %@ "
+ "with tag #%@", view, reactTag);
}
}];
}
-RCT_EXPORT_METHOD(scrollWithoutAnimationTo:(nonnull NSNumber *)reactTag withOffset:(CGPoint)offset)
-{
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
- UIView *view = viewRegistry[reactTag];
- if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
- [(id<RCTScrollableProtocol>)view scrollToOffset:offset animated:NO];
- } else {
- RCTLogError(@"tried to scrollToOffset: on non-RCTScrollableProtocol view %@ with tag #%@", view, reactTag);
- }
- }];
-}
-
-RCT_EXPORT_METHOD(zoomToRect:(nonnull NSNumber *)reactTag withRect:(CGRect)rect animated:(BOOL)animated)
+RCT_EXPORT_METHOD(zoomToRect:(nonnull NSNumber *)reactTag
+ withRect:(CGRect)rect
+ animated:(BOOL)animated)
{
- [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
+ [self.bridge.uiManager addUIBlock:
+ ^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
UIView *view = viewRegistry[reactTag];
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
[(id<RCTScrollableProtocol>)view zoomToRect:rect animated:animated];
} else {
- RCTLogError(@"tried to zoomToRect: on non-RCTScrollableProtocol view %@ with tag #%@", view, reactTag);
+ RCTLogError(@"tried to zoomToRect: on non-RCTScrollableProtocol view %@ "
+ "with tag #%@", view, reactTag);
}
}];
}

0 comments on commit ff6a2c3

Please sign in to comment.