diff --git a/Libraries/Components/ScrollResponder.js b/Libraries/Components/ScrollResponder.js index 088f7b2c9..eb1475ce8 100644 --- a/Libraries/Components/ScrollResponder.js +++ b/Libraries/Components/ScrollResponder.js @@ -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); }, /** diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index d2f54fa3e..7556e9c71 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -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) { diff --git a/React/Views/RCTScrollViewManager.m b/React/Views/RCTScrollViewManager.m index 7381e4223..549bc1fac 100644 --- a/React/Views/RCTScrollViewManager.m +++ b/React/Views/RCTScrollViewManager.m @@ -80,7 +80,8 @@ RCT_EXPORT_VIEW_PROPERTY(onRefreshStart, RCTDirectEventBlock) RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag callback:(RCTResponseSenderBlock)callback) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock: + ^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { RCTScrollView *view = viewRegistry[reactTag]; if (!view || ![view isKindOfClass:[RCTScrollView class]]) { @@ -97,9 +98,10 @@ RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag } RCT_EXPORT_METHOD(calculateChildFrames:(nonnull NSNumber *)reactTag - callback:(RCTResponseSenderBlock)callback) + callback:(RCTResponseSenderBlock)callback) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock: + ^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { RCTScrollView *view = viewRegistry[reactTag]; if (!view || ![view isKindOfClass:[RCTScrollView class]]) { @@ -116,7 +118,8 @@ RCT_EXPORT_METHOD(calculateChildFrames:(nonnull NSNumber *)reactTag RCT_EXPORT_METHOD(endRefreshing:(nonnull NSNumber *)reactTag) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { + [self.bridge.uiManager addUIBlock: + ^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry) { RCTScrollView *view = viewRegistry[reactTag]; if (!view || ![view isKindOfClass:[RCTScrollView class]]) { @@ -128,38 +131,34 @@ RCT_EXPORT_METHOD(endRefreshing:(nonnull NSNumber *)reactTag) }]; } -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 *viewRegistry){ + [self.bridge.uiManager addUIBlock: + ^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[reactTag]; if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) { - [(id)view scrollToOffset:offset animated:YES]; + [(id)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) +RCT_EXPORT_METHOD(zoomToRect:(nonnull NSNumber *)reactTag + withRect:(CGRect)rect + animated:(BOOL)animated) { - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry){ - UIView *view = viewRegistry[reactTag]; - if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) { - [(id)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) -{ - [self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry){ + [self.bridge.uiManager addUIBlock: + ^(__unused RCTUIManager *uiManager, NSDictionary *viewRegistry){ UIView *view = viewRegistry[reactTag]; if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) { [(id)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); } }]; }