Skip to content

Commit 798eddb

Browse files
committed
Adding scrollWithoutAnimationTo method for ScrollViews
Summary: Implementing the consensus approach from the comments on this PR: react#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. Closes react#509 Github Author: Charlie Cheever <ccheever@gmail.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
1 parent 4365256 commit 798eddb

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

Libraries/Components/ScrollView/ScrollView.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,14 @@ var ScrollView = React.createClass({
202202
);
203203
},
204204

205+
scrollWithoutAnimationTo: function(destY?: number, destX?: number) {
206+
RCTUIManager.scrollWithoutAnimationTo(
207+
this.getNodeHandle(),
208+
destX || 0,
209+
destY || 0
210+
);
211+
},
212+
205213
render: function() {
206214
var contentContainerStyle = [
207215
this.props.horizontal && styles.contentContainerHorizontal,

React/Modules/RCTUIManager.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,13 +1051,27 @@ - (void)scrollToOffsetWithView:(NSNumber *)reactTag scrollToOffsetX:(NSNumber *)
10511051
[self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){
10521052
UIView *view = viewRegistry[reactTag];
10531053
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
1054-
[(id<RCTScrollableProtocol>)view scrollToOffset:CGPointMake([offsetX floatValue], [offsetY floatValue])];
1054+
[(id<RCTScrollableProtocol>)view scrollToOffset:CGPointMake([offsetX floatValue], [offsetY floatValue]) animated:YES];
10551055
} else {
10561056
RCTLogError(@"tried to scrollToOffset: on non-RCTScrollableProtocol view %@ with tag %@", view, reactTag);
10571057
}
10581058
}];
10591059
}
10601060

1061+
- (void)scrollWithoutAnimationToOffsetWithView:(NSNumber *)reactTag scrollToOffsetX:(NSNumber *)offsetX offsetY:(NSNumber *)offsetY
1062+
{
1063+
RCT_EXPORT(scrollWithoutAnimationTo);
1064+
1065+
[self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){
1066+
UIView *view = viewRegistry[reactTag];
1067+
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
1068+
[(id<RCTScrollableProtocol>)view scrollToOffset:CGPointMake([offsetX floatValue], [offsetY floatValue]) animated:NO];
1069+
} else {
1070+
RCTLogError(@"tried to scrollToOffset: on non-RCTScrollableProtocol view %@ with tag %@", view, reactTag);
1071+
}
1072+
}];
1073+
}
1074+
10611075
- (void)zoomToRectWithView:(NSNumber *)reactTag rect:(NSDictionary *)rectDict
10621076
{
10631077
RCT_EXPORT(zoomToRect);

0 commit comments

Comments
 (0)