Fix invariant in scrollResponderZoomTo

Summary:
This fixes a cryptic bug to appear when you try to use scrollResponderZoomTo in Android.
before this PR it would break with a `Error: TaskQueue: Error with task : invariant requires an error message argument` because the invariant() was not properly used..

Also, instead of detecting the platform, I think it's better practice to duck type.
Closes https://github.com/facebook/react-native/pull/11186

Differential Revision: D4246674

fbshipit-source-id: 47002a85d8252e5abbd1cd9ecef3d7676fa8615a
This commit is contained in:
Gaëtan Renaudeau 2016-11-29 14:29:53 -08:00 committed by Facebook Github Bot
parent aac8daf378
commit 20e99f5b93
1 changed files with 6 additions and 9 deletions

View File

@ -410,16 +410,13 @@ var ScrollResponderMixin = {
rect: { x: number, y: number, width: number, height: number, animated?: boolean },
animated?: boolean // deprecated, put this inside the rect argument instead
) {
if (Platform.OS === 'android') {
invariant('zoomToRect is not implemented');
} else {
if ('animated' in rect) {
var { animated, ...rect } = rect;
} else if (typeof animated !== 'undefined') {
console.warn('`scrollResponderZoomTo` `animated` argument is deprecated. Use `options.animated` instead');
}
ScrollViewManager.zoomToRect(this.scrollResponderGetScrollableNode(), rect, animated !== false);
invariant(ScrollViewManager && ScrollViewManager.zoomToRect, 'zoomToRect is not implemented');
if ('animated' in rect) {
var { animated, ...rect } = rect;
} else if (typeof animated !== 'undefined') {
console.warn('`scrollResponderZoomTo` `animated` argument is deprecated. Use `options.animated` instead');
}
ScrollViewManager.zoomToRect(this.scrollResponderGetScrollableNode(), rect, animated !== false);
},
/**