Skip to content

Commit

Permalink
ESM requireNativeComponent
Browse files Browse the repository at this point in the history
Summary: Changelog: [General][Changed] - ESM requireNativeComponent

Reviewed By: yungsters

Differential Revision: D42200329

fbshipit-source-id: f1120f06362dc25e48551b3f2421bbda7b68c571
  • Loading branch information
lunaleaps authored and facebook-github-bot committed Jan 4, 2023
1 parent aa8e69b commit 0aece02
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Libraries/ReactNative/requireNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ const requireNativeComponent = <T>(uiViewClassName: string): HostComponent<T> =>
getNativeComponentAttributes(uiViewClassName),
): any): HostComponent<T>);

module.exports = requireNativeComponent;
export default requireNativeComponent;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion jest/mockNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++;

Expand Down
2 changes: 1 addition & 1 deletion jest/mockScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';"
`;
Expand Down

0 comments on commit 0aece02

Please sign in to comment.