mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 22:38:59 +08:00
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:  After:  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:
committed by
Facebook Github Bot
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);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user