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
This commit is contained in:
parent
82fd02a1e2
commit
074c3cef14
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue