Adding `scrollWithoutAnimationTo` method for ScrollViews
Summary: 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. Closes https://github.com/facebook/react-native/pull/509 Github Author: Charlie Cheever <ccheever@gmail.com> Test Plan: Imported from GitHub, without a `Test Plan:` line.
This commit is contained in:
Родитель
2f00cb05bd
Коммит
774442efd2
|
@ -202,6 +202,14 @@ var ScrollView = React.createClass({
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
scrollWithoutAnimationTo: function(destY?: number, destX?: number) {
|
||||||
|
RCTUIManager.scrollWithoutAnimationTo(
|
||||||
|
this.getNodeHandle(),
|
||||||
|
destX || 0,
|
||||||
|
destY || 0
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var contentContainerStyle = [
|
var contentContainerStyle = [
|
||||||
this.props.horizontal && styles.contentContainerHorizontal,
|
this.props.horizontal && styles.contentContainerHorizontal,
|
||||||
|
|
|
@ -1051,13 +1051,27 @@ static void RCTMeasureLayout(RCTShadowView *view,
|
||||||
[self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){
|
[self addUIBlock:^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry){
|
||||||
UIView *view = viewRegistry[reactTag];
|
UIView *view = viewRegistry[reactTag];
|
||||||
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
|
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 {
|
} else {
|
||||||
RCTLogError(@"tried to scrollToOffset: on non-RCTScrollableProtocol view %@ with tag %@", view, reactTag);
|
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
|
- (void)zoomToRectWithView:(NSNumber *)reactTag rect:(NSDictionary *)rectDict
|
||||||
{
|
{
|
||||||
RCT_EXPORT(zoomToRect);
|
RCT_EXPORT(zoomToRect);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче