From a2ed8091f7e95e2adfb09f399bb3062cb04df58d Mon Sep 17 00:00:00 2001 From: Charlie Cheever Date: Mon, 30 Mar 2015 13:11:06 -0700 Subject: [PATCH] Adding `scrollWithoutAnimationTo` method for ScrollViews Implementing the consensus approach from the comments on this PR: https://github.com/facebook/react-native/pull/486 We use a boolean flag in the Obj-C code to determine whether to animate or not, and then provide two public JS functions that call the Obj-C with or without the flag. --- Libraries/Components/ScrollView/ScrollView.js | 12 +++++++++++- React/Modules/RCTUIManager.m | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 92cdab05ac0bc1..4f8efce54abd4e 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -191,7 +191,17 @@ var ScrollView = React.createClass({ RCTUIManager.scrollTo( this.getNodeHandle(), destX || 0, - destY || 0 + destY || 0, + true + ); + }, + + scrollWithoutAnimationTo: function(destY?: number, destX?: number) { + RCTUIManager.scrollTo( + this.getNodeHandle(), + destX || 0, + destY || 0, + false ); }, diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index a0e7285c6b0dfb..3e55af98956494 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -1034,14 +1034,14 @@ - (void)setMainScrollViewTag:(NSNumber *)reactTag }]; } -- (void)scrollToOffsetWithView:(NSNumber *)reactTag scrollToOffsetX:(NSNumber *)offsetX offsetY:(NSNumber *)offsetY +- (void)scrollToOffsetWithView:(NSNumber *)reactTag scrollToOffsetX:(NSNumber *)offsetX offsetY:(NSNumber *)offsetY animated:(BOOL)animated { RCT_EXPORT(scrollTo); [self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){ UIView *view = viewRegistry[reactTag]; if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) { - [(id)view scrollToOffset:CGPointMake([offsetX floatValue], [offsetY floatValue])]; + [(id)view scrollToOffset:CGPointMake([offsetX floatValue], [offsetY floatValue]) animated:animated]; } else { RCTLogError(@"tried to scrollToOffset: on non-RCTScrollableProtocol view %@ with tag %@", view, reactTag); }