Home / File/ NativeMethodsMixinUtils.js — react Source File

NativeMethodsMixinUtils.js — react Source File

Architecture documentation for NativeMethodsMixinUtils.js, a javascript file in the react codebase. 0 imports, 1 dependents.

File javascript BabelCompiler Validation 1 dependents 2 functions

Entity Profile

Dependency Diagram

graph LR
  78f5be05_fc7e_f09a_e92e_c046356e87a8["NativeMethodsMixinUtils.js"]
  f6a368ec_c652_2004_0c12_4c53a053a27c["ReactNativeFiberHostComponent.js"]
  f6a368ec_c652_2004_0c12_4c53a053a27c --> 78f5be05_fc7e_f09a_e92e_c046356e87a8
  style 78f5be05_fc7e_f09a_e92e_c046356e87a8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

/**
 * In the future, we should cleanup callbacks by cancelling them instead of
 * using this.
 */
export function mountSafeCallback_NOT_REALLY_SAFE(
  context: any,
  callback: ?Function,
): any {
  return function () {
    if (!callback) {
      return undefined;
    }
    // This protects against createClass() components.
    // We don't know if there is code depending on it.
    // We intentionally don't use isMounted() because even accessing
    // isMounted property on a React ES6 class will trigger a warning.
    if (typeof context.__isMounted === 'boolean') {
      if (!context.__isMounted) {
        return undefined;
      }
    }

    // FIXME: there used to be other branches that protected
    // against unmounted host components. But RN host components don't
    // define isMounted() anymore, so those checks didn't do anything.

    // They caused false positive warning noise so we removed them:
    // https://github.com/facebook/react-native/issues/18868#issuecomment-413579095

    // However, this means that the callback is NOT guaranteed to be safe
    // for host components. The solution we should implement is to make
    // UIManager.measure() and similar calls truly cancelable. Then we
    // can change our own code calling them to cancel when something unmounts.

    return callback.apply(context, arguments);
  };
}

export function warnForStyleProps(props: any, validAttributes: any) {
  if (__DEV__) {
    for (const key in validAttributes.style) {
      if (!(validAttributes[key] || props[key] === undefined)) {
        console.error(
          'You are setting the style `{ %s' +
            ': ... }` as a prop. You ' +
            'should nest it in a style object. ' +
            'E.g. `{ style: { %s' +
            ': ... } }`',
          key,
          key,
        );
      }
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does NativeMethodsMixinUtils.js do?
NativeMethodsMixinUtils.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in NativeMethodsMixinUtils.js?
NativeMethodsMixinUtils.js defines 2 function(s): mountSafeCallback_NOT_REALLY_SAFE, warnForStyleProps.
What files import NativeMethodsMixinUtils.js?
NativeMethodsMixinUtils.js is imported by 1 file(s): ReactNativeFiberHostComponent.js.
Where is NativeMethodsMixinUtils.js in the architecture?
NativeMethodsMixinUtils.js is located at packages/react-native-renderer/src/NativeMethodsMixinUtils.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-native-renderer/src).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free