ESM requireNativeComponent

Summary: Changelog: [General][Changed] - ESM requireNativeComponent

Reviewed By: yungsters

Differential Revision: D42200329

fbshipit-source-id: f1120f06362dc25e48551b3f2421bbda7b68c571
This commit is contained in:
Luna Wei 2023-01-03 18:09:06 -08:00 committed by Facebook GitHub Bot
parent aa8e69b696
commit 0aece02cb0
7 changed files with 8 additions and 8 deletions

View File

@ -29,4 +29,4 @@ const requireNativeComponent = <T>(uiViewClassName: string): HostComponent<T> =>
getNativeComponentAttributes(uiViewClassName),
): any): HostComponent<T>);
module.exports = requireNativeComponent;
export default requireNativeComponent;

View File

@ -387,7 +387,7 @@ module.exports = {
get requireNativeComponent(): <T>(
uiViewClassName: string,
) => HostComponent<T> {
return require('./Libraries/ReactNative/requireNativeComponent');
return require('./Libraries/ReactNative/requireNativeComponent').default;
},
get RootTagContext(): RootTagContext {
return require('./Libraries/ReactNative/RootTag').RootTagContext;

View File

@ -13,7 +13,7 @@ const React = require('react');
let nativeTag = 1;
module.exports = viewName => {
export default viewName => {
const Component = class extends React.Component {
_nativeTag = nativeTag++;

View File

@ -15,7 +15,7 @@
const React = require('react');
const View = require('../Libraries/Components/View/View');
const requireNativeComponent = require('../Libraries/ReactNative/requireNativeComponent');
import requireNativeComponent from '../Libraries/ReactNative/requireNativeComponent';
const RCTScrollView: $FlowFixMe = requireNativeComponent('RCTScrollView');
function mockScrollView(BaseComponent: $FlowFixMe) {

View File

@ -338,10 +338,10 @@ jest
.mock('../Libraries/NativeComponent/NativeComponentRegistry', () => {
return {
get: jest.fn((name, viewConfigProvider) => {
return jest.requireActual('./mockNativeComponent')(name);
return jest.requireActual('./mockNativeComponent').default(name);
}),
getWithFallback_DEPRECATED: jest.fn((name, viewConfigProvider) => {
return jest.requireActual('./mockNativeComponent')(name);
return jest.requireActual('./mockNativeComponent').default(name);
}),
setRuntimeConfigProvider: jest.fn(),
};

View File

@ -10,7 +10,7 @@
'use strict';
const NOT_A_NATIVE_COMPONENT = `
const requireNativeComponent = require('requireNativeComponent');
import requireNativeComponent from 'requireNativeComponent';
export default 'Not a view config'
`;

View File

@ -127,7 +127,7 @@ export const Commands = {
`;
exports[`Babel plugin inline view configs can inline config for NotANativeComponent.js 1`] = `
"const requireNativeComponent = require('requireNativeComponent');
"import requireNativeComponent from 'requireNativeComponent';
export default 'Not a view config';"
`;