Skip to content

Commit

Permalink
Adding scrollWithoutAnimationTo method for ScrollViews
Browse files Browse the repository at this point in the history
Summary:
Implementing the consensus approach from the comments on
this PR:
facebook#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 facebook#509
Github Author: Charlie Cheever <ccheever@gmail.com>

Test Plan: Imported from GitHub, without a `Test Plan:` line.
  • Loading branch information
ccheever authored and oss sync committed Apr 12, 2015
1 parent ffd2570 commit 33fcd2e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,14 @@ var ScrollView = React.createClass({
);
},

scrollWithoutAnimationTo: function(destY?: number, destX?: number) {
RCTUIManager.scrollWithoutAnimationTo(
this.getNodeHandle(),
destX || 0,
destY || 0
);
},

render: function() {
var contentContainerStyle = [
this.props.horizontal && styles.contentContainerHorizontal,
Expand Down
16 changes: 15 additions & 1 deletion React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -1051,13 +1051,27 @@ - (void)scrollToOffsetWithView:(NSNumber *)reactTag scrollToOffsetX:(NSNumber *)
[self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){
UIView *view = viewRegistry[reactTag];
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
[(id<RCTScrollableProtocol>)view scrollToOffset:CGPointMake([offsetX floatValue], [offsetY floatValue])];
[(id<RCTScrollableProtocol>)view scrollToOffset:CGPointMake([offsetX floatValue], [offsetY floatValue]) animated:YES];
} else {
RCTLogError(@"tried to scrollToOffset: on non-RCTScrollableProtocol view %@ with tag %@", view, reactTag);
}
}];
}

- (void)scrollWithoutAnimationToOffsetWithView:(NSNumber *)reactTag scrollToOffsetX:(NSNumber *)offsetX offsetY:(NSNumber *)offsetY
{
RCT_EXPORT(scrollWithoutAnimationTo);

[self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){
UIView *view = viewRegistry[reactTag];
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
[(id<RCTScrollableProtocol>)view scrollToOffset:CGPointMake([offsetX floatValue], [offsetY floatValue]) animated:NO];
} else {
RCTLogError(@"tried to scrollToOffset: on non-RCTScrollableProtocol view %@ with tag %@", view, reactTag);
}
}];
}

- (void)zoomToRectWithView:(NSNumber *)reactTag rect:(NSDictionary *)rectDict
{
RCT_EXPORT(zoomToRect);
Expand Down

0 comments on commit 33fcd2e

Please sign in to comment.