PHP 7.4.33
Preview: codegenNativeComponent.js Size: 2.51 KB
/var/www/uibuilder.cmshelp.dk/httpdocs/node_modules/react-native/Libraries/Utilities/codegenNativeComponent.js
/**
 * 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.
 *
 * @format
 * @flow strict-local
 */

// TODO: move this file to shims/ReactNative (requires React update and sync)

import type {HostComponent} from '../../Libraries/Renderer/shims/ReactNativeTypes';

import requireNativeComponent from '../../Libraries/ReactNative/requireNativeComponent';
import UIManager from '../ReactNative/UIManager';

// TODO: import from CodegenSchema once workspaces are enabled
type Options = $ReadOnly<{|
  interfaceOnly?: boolean,
  paperComponentName?: string,
  paperComponentNameDeprecated?: string,
  excludedPlatforms?: $ReadOnlyArray<'iOS' | 'android'>,
|}>;

export type NativeComponentType<T> = HostComponent<T>;

// If this function runs then that means the view configs were not
// generated at build time using `GenerateViewConfigJs.js`. Thus
// we need to `requireNativeComponent` to get the view configs from view managers.
// `requireNativeComponent` is not available in Bridgeless mode.
// e.g. This function runs at runtime if `codegenNativeComponent` was not called
// from a file suffixed with NativeComponent.js.
function codegenNativeComponent<Props: {...}>(
  componentName: string,
  options?: Options,
): NativeComponentType<Props> {
  if (global.RN$Bridgeless === true && __DEV__) {
    console.warn(
      `Codegen didn't run for ${componentName}. This will be an error in the future. Make sure you are using @react-native/babel-preset when building your JavaScript code.`,
    );
  }

  let componentNameInUse =
    options && options.paperComponentName != null
      ? options.paperComponentName
      : componentName;

  if (options != null && options.paperComponentNameDeprecated != null) {
    if (UIManager.hasViewManagerConfig(componentName)) {
      componentNameInUse = componentName;
    } else if (
      options.paperComponentNameDeprecated != null &&
      UIManager.hasViewManagerConfig(options.paperComponentNameDeprecated)
    ) {
      // $FlowFixMe[incompatible-type]
      componentNameInUse = options.paperComponentNameDeprecated;
    } else {
      throw new Error(
        `Failed to find native component for either ${componentName} or ${
          options.paperComponentNameDeprecated ?? '(unknown)'
        }`,
      );
    }
  }

  return (requireNativeComponent<Props>(
    // $FlowFixMe[incompatible-call]
    componentNameInUse,
  ): HostComponent<Props>);
}

export default codegenNativeComponent;

Directory Contents

Dirs: 2 × Files: 53
Name Size Perms Modified Actions
differ DIR
- drwxr-xr-x 2025-03-28 11:04:42
Edit Download
__mocks__ DIR
- drwxr-xr-x 2025-03-28 11:04:42
Edit Download
1.69 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
4.16 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.67 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.06 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
769 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
503 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
902 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
830 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.51 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
6.89 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
441 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.67 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.73 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
315 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.48 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
897 B lrw-r--r-- 2025-03-28 11:04:43
Edit Download
2.35 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.54 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
4.08 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
521 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.01 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
824 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
10.51 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
742 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
443 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.42 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
1.42 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
760 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
721 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
407 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
402 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
418 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
458 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
442 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.04 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.09 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
4.21 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.24 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.31 KB lrw-r--r-- 2025-03-28 11:04:43
Edit Download
2.21 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
2.45 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
304 B lrw-r--r-- 2025-03-28 11:04:41
Edit Download
1.70 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.35 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
7.26 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
899 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
3.72 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
466 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
701 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.84 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.39 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
1.37 KB lrw-r--r-- 2025-03-28 11:04:42
Edit Download
732 B lrw-r--r-- 2025-03-28 11:04:42
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).