requireNativeComponent.js 1018 B

1234567891011121314151617181920212223242526272829303132
  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @flow
  8. * @format
  9. */
  10. 'use strict';
  11. const createReactNativeComponentClass = require('../Renderer/shims/createReactNativeComponentClass');
  12. const getNativeComponentAttributes = require('./getNativeComponentAttributes');
  13. import type {HostComponent} from '../Renderer/shims/ReactNativeTypes';
  14. /**
  15. * Creates values that can be used like React components which represent native
  16. * view managers. You should create JavaScript modules that wrap these values so
  17. * that the results are memoized. Example:
  18. *
  19. * const View = requireNativeComponent('RCTView');
  20. *
  21. */
  22. const requireNativeComponent = <T>(uiViewClassName: string): HostComponent<T> =>
  23. ((createReactNativeComponentClass(uiViewClassName, () =>
  24. getNativeComponentAttributes(uiViewClassName),
  25. ): any): HostComponent<T>);
  26. module.exports = requireNativeComponent;