Deprecated `scrollResponderScrollWithoutAnimationTo`
Summary: public This diff deprecates `scrollResponderScrollWithoutAnimationTo` and replaces it with an optional `animated` param in `scrollResponderScrollTo`. This is more consistent with our other APIs. Using the old `ScrollResponder.scrollResponderScrollWithoutAnimationTo` or `ScrollView.scrollWithoutAnimationTo` functions will still work, but will trigger a warning. Reviewed By: javache Differential Revision: D2823479 fb-gh-sync-id: 259966512104ca7b3995c9586144812a91b8d3e9
This commit is contained in:
parent
90d2787aef
commit
ff6a2c3998
|
@ -348,41 +348,31 @@ var ScrollResponderMixin = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper function to scroll to a specific point in the scrollview.
|
* 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
|
* 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') {
|
if (Platform.OS === 'android') {
|
||||||
UIManager.dispatchViewManagerCommand(
|
UIManager.dispatchViewManagerCommand(
|
||||||
React.findNodeHandle(this),
|
React.findNodeHandle(this),
|
||||||
UIManager.RCTScrollView.Commands.scrollTo,
|
UIManager.RCTScrollView.Commands[animated ? 'scrollTo' : 'scrollWithoutAnimationTo'],
|
||||||
[Math.round(offsetX), Math.round(offsetY)],
|
[Math.round(offsetX), Math.round(offsetY)],
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
ScrollViewManager.scrollTo(
|
ScrollViewManager.scrollTo(
|
||||||
React.findNodeHandle(this),
|
React.findNodeHandle(this),
|
||||||
{ x: offsetX, y: offsetY }
|
{ x: offsetX, y: offsetY },
|
||||||
|
animated
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like `scrollResponderScrollTo` but immediately scrolls to the given
|
* Deprecated, do not use.
|
||||||
* position
|
|
||||||
*/
|
*/
|
||||||
scrollResponderScrollWithoutAnimationTo: function(offsetX: number, offsetY: number) {
|
scrollResponderScrollWithoutAnimationTo: function(offsetX: number, offsetY: number) {
|
||||||
if (Platform.OS === 'android') {
|
console.warn('`scrollResponderScrollWithoutAnimationTo` is deprecated. Use `scrollResponderScrollTo` instead');
|
||||||
UIManager.dispatchViewManagerCommand(
|
self.scrollResponderScrollTo(offsetX, offsetY, false);
|
||||||
React.findNodeHandle(this),
|
|
||||||
UIManager.RCTScrollView.Commands.scrollWithoutAnimationTo,
|
|
||||||
[offsetX, offsetY],
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
ScrollViewManager.scrollWithoutAnimationTo(
|
|
||||||
React.findNodeHandle(this),
|
|
||||||
{ x: offsetX, y: offsetY }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -339,17 +339,17 @@ var ScrollView = React.createClass({
|
||||||
return React.findNodeHandle(this.refs[INNERVIEW]);
|
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
|
// $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
|
* Deprecated, do not use.
|
||||||
this.getScrollResponder().scrollResponderScrollWithoutAnimationTo(
|
*/
|
||||||
destX || 0,
|
scrollWithoutAnimationTo: function(destY: number = 0, destX: number = 0) {
|
||||||
destY || 0,
|
console.warn('`scrollWithoutAnimationTo` is deprecated. Use `scrollTo` instead');
|
||||||
);
|
this.scrollTo(destX, destY, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleScroll: function(e: Object) {
|
handleScroll: function(e: Object) {
|
||||||
|
|
|
@ -80,7 +80,8 @@ RCT_EXPORT_VIEW_PROPERTY(onRefreshStart, RCTDirectEventBlock)
|
||||||
RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag
|
RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag
|
||||||
callback:(RCTResponseSenderBlock)callback)
|
callback:(RCTResponseSenderBlock)callback)
|
||||||
{
|
{
|
||||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
|
[self.bridge.uiManager addUIBlock:
|
||||||
|
^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
|
||||||
|
|
||||||
RCTScrollView *view = viewRegistry[reactTag];
|
RCTScrollView *view = viewRegistry[reactTag];
|
||||||
if (!view || ![view isKindOfClass:[RCTScrollView class]]) {
|
if (!view || ![view isKindOfClass:[RCTScrollView class]]) {
|
||||||
|
@ -99,7 +100,8 @@ RCT_EXPORT_METHOD(getContentSize:(nonnull NSNumber *)reactTag
|
||||||
RCT_EXPORT_METHOD(calculateChildFrames:(nonnull NSNumber *)reactTag
|
RCT_EXPORT_METHOD(calculateChildFrames:(nonnull NSNumber *)reactTag
|
||||||
callback:(RCTResponseSenderBlock)callback)
|
callback:(RCTResponseSenderBlock)callback)
|
||||||
{
|
{
|
||||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
|
[self.bridge.uiManager addUIBlock:
|
||||||
|
^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
|
||||||
|
|
||||||
RCTScrollView *view = viewRegistry[reactTag];
|
RCTScrollView *view = viewRegistry[reactTag];
|
||||||
if (!view || ![view isKindOfClass:[RCTScrollView class]]) {
|
if (!view || ![view isKindOfClass:[RCTScrollView class]]) {
|
||||||
|
@ -116,7 +118,8 @@ RCT_EXPORT_METHOD(calculateChildFrames:(nonnull NSNumber *)reactTag
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(endRefreshing:(nonnull NSNumber *)reactTag)
|
RCT_EXPORT_METHOD(endRefreshing:(nonnull NSNumber *)reactTag)
|
||||||
{
|
{
|
||||||
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
|
[self.bridge.uiManager addUIBlock:
|
||||||
|
^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTScrollView *> *viewRegistry) {
|
||||||
|
|
||||||
RCTScrollView *view = viewRegistry[reactTag];
|
RCTScrollView *view = viewRegistry[reactTag];
|
||||||
if (!view || ![view isKindOfClass:[RCTScrollView class]]) {
|
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<NSNumber *, UIView *> *viewRegistry){
|
[self.bridge.uiManager addUIBlock:
|
||||||
|
^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
|
||||||
UIView *view = viewRegistry[reactTag];
|
UIView *view = viewRegistry[reactTag];
|
||||||
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
|
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
|
||||||
[(id<RCTScrollableProtocol>)view scrollToOffset:offset animated:YES];
|
[(id<RCTScrollableProtocol>)view scrollToOffset:offset animated:animated];
|
||||||
} else {
|
} 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<NSNumber *, UIView *> *viewRegistry){
|
[self.bridge.uiManager addUIBlock:
|
||||||
UIView *view = viewRegistry[reactTag];
|
^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry){
|
||||||
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
|
|
||||||
[(id<RCTScrollableProtocol>)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<NSNumber *, UIView *> *viewRegistry){
|
|
||||||
UIView *view = viewRegistry[reactTag];
|
UIView *view = viewRegistry[reactTag];
|
||||||
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
|
if ([view conformsToProtocol:@protocol(RCTScrollableProtocol)]) {
|
||||||
[(id<RCTScrollableProtocol>)view zoomToRect:rect animated:animated];
|
[(id<RCTScrollableProtocol>)view zoomToRect:rect animated:animated];
|
||||||
} else {
|
} 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);
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue