From 074c3cef145635bf647a6a1552305bb66916ef08 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Tue, 9 May 2017 12:21:24 -0700 Subject: [PATCH] Work around a false positive warning Summary: This works around a false positive `isMounted()` deprecation warning when using latest React DevTools and selecting components in the hierarchy. Before: ![screen shot 2017-05-09 at 7 03 39 pm 1](https://cloud.githubusercontent.com/assets/810438/25865249/3a5cc9e2-34ea-11e7-9930-6d0d8436b390.png) After: ![screen shot 2017-05-09 at 7 02 54 pm](https://cloud.githubusercontent.com/assets/810438/25865274/4d2d573a-34ea-11e7-8bdd-807e32c54594.png) Closes https://github.com/facebook/react-native/pull/13873 Reviewed By: bvaughn Differential Revision: D5029550 Pulled By: gaearon fbshipit-source-id: cbe941368e8204a335de17ad3d444580aef9d833 --- .../native/NativeMethodsMixinUtils.js | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Libraries/Renderer/src/renderers/native/NativeMethodsMixinUtils.js b/Libraries/Renderer/src/renderers/native/NativeMethodsMixinUtils.js index a30e115bc..81a0c55ca 100644 --- a/Libraries/Renderer/src/renderers/native/NativeMethodsMixinUtils.js +++ b/Libraries/Renderer/src/renderers/native/NativeMethodsMixinUtils.js @@ -57,12 +57,24 @@ export interface NativeMethodsInterface { */ function mountSafeCallback(context: any, callback: ?Function): any { return function() { - if ( - !callback || - (typeof context.isMounted === 'function' && !context.isMounted()) - ) { + if (!callback) { return undefined; } + if (typeof context.__isMounted === 'boolean') { + // TODO(gaearon): this is gross and should be removed. + // It is currently necessary because View uses createClass, + // and so any measure() calls on View (which are done by React + // DevTools) trigger the isMounted() deprecation warning. + if (!context.__isMounted) { + return undefined; + } + // The else branch is important so that we don't + // trigger the deprecation warning by calling isMounted. + } else if (typeof context.isMounted === 'function') { + if (!context.isMounted()) { + return undefined; + } + } return callback.apply(context, arguments); }; }