Skip to content

Commit ce41274

Browse files
iwoplazafacebook-github-bot
authored andcommitted
Migrated components to export syntax (part 2) (#48767)
Summary: Pull Request resolved: #48767 ## Motivation Modernising the react-native codebase to allow for ingestion by modern Flow tooling. ## This diff - Updates a handful of components in `Libraries/Components` to use `export` syntax - `export default` for qualified objects, many `export` statements for collections (determined by how it's imported) - Appends `.default` to requires of the changed files. - Updates test files. - Updates the public API snapshot (intented breaking change) Changelog: [General][Breaking] - Files inside `Libraries/Components` use `export` syntax, which requires the addition of `.default` when imported with the CJS `require` syntax. Reviewed By: yungsters Differential Revision: D68335872 fbshipit-source-id: eb0c67039edfe92e9e133726f6b01900dd2c2322
1 parent b200c7c commit ce41274

File tree

16 files changed

+39
-33
lines changed

16 files changed

+39
-33
lines changed

packages/react-native/Libraries/Components/ActivityIndicator/ActivityIndicator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import * as React from 'react';
1919

2020
const PlatformActivityIndicator =
2121
Platform.OS === 'android'
22-
? require('../ProgressBarAndroid/ProgressBarAndroid')
22+
? require('../ProgressBarAndroid/ProgressBarAndroid').default
2323
: require('./ActivityIndicatorViewNativeComponent').default;
2424

2525
const GRAY = '#999999';

packages/react-native/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.android.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ const ProgressBarAndroidWithForwardedRef: component(
106106
);
107107
});
108108

109-
module.exports =
110-
/* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an
111-
* error found when Flow v0.89 was deployed. To see the error, delete this
112-
* comment and run Flow. */
113-
(ProgressBarAndroidWithForwardedRef: typeof ProgressBarAndroidNativeComponent);
109+
export default /* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an
110+
* error found when Flow v0.89 was deployed. To see the error, delete this
111+
* comment and run Flow. */
112+
(ProgressBarAndroidWithForwardedRef: typeof ProgressBarAndroidNativeComponent);

packages/react-native/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ import typeof ProgressBarAndroidNativeComponentType from './ProgressBarAndroidNa
1515

1616
export type {ProgressBarAndroidProps} from './ProgressBarAndroid.android';
1717

18-
module.exports = (require('../UnimplementedViews/UnimplementedView'):
18+
export default (require('../UnimplementedViews/UnimplementedView'):
1919
| UnimplementedViewType
2020
| ProgressBarAndroidNativeComponentType);

packages/react-native/Libraries/Components/ProgressBarAndroid/__tests__/ProgressBarAndroid-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const ReactNativeTestTools = require('../../../Utilities/ReactNativeTestTools');
1616
* comment suppresses an error found when Flow v0.99 was deployed. To see the
1717
* error, delete this comment and run Flow. */
1818
// $FlowFixMe[missing-platform-support]
19-
const ProgressBarAndroid = require('../ProgressBarAndroid.android');
19+
const ProgressBarAndroid = require('../ProgressBarAndroid.android').default;
2020
const React = require('react');
2121

2222
describe('<ProgressBarAndroid />', () => {

packages/react-native/Libraries/Components/RefreshControl/RefreshControl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,4 @@ class RefreshControl extends React.Component<RefreshControlProps> {
201201
};
202202
}
203203

204-
module.exports = RefreshControl;
204+
export default RefreshControl;

packages/react-native/Libraries/Components/ScrollView/ScrollView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1913,5 +1913,5 @@ Wrapper.displayName = 'ScrollView';
19131913
// $FlowExpectedError[prop-missing]
19141914
Wrapper.Context = ScrollViewContext;
19151915

1916-
module.exports = ((Wrapper: $FlowFixMe): typeof Wrapper &
1916+
export default ((Wrapper: $FlowFixMe): typeof Wrapper &
19171917
ScrollViewComponentStatics);

packages/react-native/Libraries/Components/ScrollView/__tests__/ScrollView-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const {create, unmount, update} = require('../../../../jest/renderer');
1515
const Text = require('../../../Text/Text');
1616
const ReactNativeTestTools = require('../../../Utilities/ReactNativeTestTools');
1717
const View = require('../../View/View');
18-
const ScrollView = require('../ScrollView');
18+
const ScrollView = require('../ScrollView').default;
1919
const React = require('react');
2020

2121
describe('ScrollView', () => {

packages/react-native/Libraries/Components/ScrollView/processDecelerationRate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ function processDecelerationRate(
2727
return decelerationRate;
2828
}
2929

30-
module.exports = processDecelerationRate;
30+
export default processDecelerationRate;

packages/react-native/Libraries/Components/Sound/SoundManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ const SoundManager = {
1818
},
1919
};
2020

21-
module.exports = SoundManager;
21+
export default SoundManager;

packages/react-native/Libraries/Components/StatusBar/StatusBar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,4 +493,4 @@ class StatusBar extends React.Component<Props> {
493493
}
494494
}
495495

496-
module.exports = StatusBar;
496+
export default StatusBar;

packages/react-native/Libraries/Components/StatusBar/__tests__/StatusBar-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'use strict';
1212

1313
const {create} = require('../../../../jest/renderer');
14-
const StatusBar = require('../StatusBar');
14+
const StatusBar = require('../StatusBar').default;
1515
const React = require('react');
1616

1717
describe('StatusBar', () => {

packages/react-native/Libraries/Inspector/InspectorPanel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {ElementsHierarchy, InspectedElement} from './Inspector';
1515
import SafeAreaView from '../Components/SafeAreaView/SafeAreaView';
1616
import React from 'react';
1717

18-
const ScrollView = require('../Components/ScrollView/ScrollView');
18+
const ScrollView = require('../Components/ScrollView/ScrollView').default;
1919
const TouchableHighlight = require('../Components/Touchable/TouchableHighlight');
2020
const View = require('../Components/View/View');
2121
const StyleSheet = require('../StyleSheet/StyleSheet');

packages/react-native/Libraries/Modal/Modal.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import RCTModalHostView from './RCTModalHostViewNativeComponent';
2020
import {VirtualizedListContextResetter} from '@react-native/virtualized-lists';
2121
import React from 'react';
2222

23-
const ScrollView = require('../Components/ScrollView/ScrollView');
23+
const ScrollView = require('../Components/ScrollView/ScrollView').default;
2424
const View = require('../Components/View/View');
2525
const AppContainer = require('../ReactNative/AppContainer');
2626
const I18nManager = require('../ReactNative/I18nManager');

packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ declare export default function useAndroidRippleForView(
19361936

19371937
exports[`public API should not change unintentionally Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.js 1`] = `
19381938
"export type { ProgressBarAndroidProps } from \\"./ProgressBarAndroid.android\\";
1939-
declare module.exports:
1939+
declare export default
19401940
| UnimplementedViewType
19411941
| ProgressBarAndroidNativeComponentType;
19421942
"
@@ -1993,7 +1993,7 @@ declare class RefreshControl extends React.Component<RefreshControlProps> {
19931993
_onRefresh: $FlowFixMe;
19941994
_setNativeRef: $FlowFixMe;
19951995
}
1996-
declare module.exports: RefreshControl;
1996+
declare export default typeof RefreshControl;
19971997
"
19981998
`;
19991999

@@ -2267,7 +2267,7 @@ declare const Wrapper: component(
22672267
ref: React.RefSetter<PublicScrollViewInstance>,
22682268
...props: Props
22692269
);
2270-
declare module.exports: typeof Wrapper & ScrollViewComponentStatics;
2270+
declare export default typeof Wrapper & ScrollViewComponentStatics;
22712271
"
22722272
`;
22732273

@@ -2413,7 +2413,7 @@ exports[`public API should not change unintentionally Libraries/Components/Scrol
24132413
"declare function processDecelerationRate(
24142414
decelerationRate: number | \\"normal\\" | \\"fast\\"
24152415
): number;
2416-
declare module.exports: processDecelerationRate;
2416+
declare export default typeof processDecelerationRate;
24172417
"
24182418
`;
24192419

@@ -2425,7 +2425,7 @@ declare export default typeof NativeSoundManager;
24252425

24262426
exports[`public API should not change unintentionally Libraries/Components/Sound/SoundManager.js 1`] = `
24272427
"declare const SoundManager: { playTouchSound: () => void };
2428-
declare module.exports: SoundManager;
2428+
declare export default typeof SoundManager;
24292429
"
24302430
`;
24312431

@@ -2520,7 +2520,7 @@ declare class StatusBar extends React.Component<Props> {
25202520
static _updatePropsStack: $FlowFixMe;
25212521
render(): React.Node;
25222522
}
2523-
declare module.exports: StatusBar;
2523+
declare export default typeof StatusBar;
25242524
"
25252525
`;
25262526

packages/react-native/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,24 @@ module.exports = {
160160
"It can now be installed and imported from '@react-native-community/progress-bar-android' instead of 'react-native'. " +
161161
'See https://github.com/react-native-progress-view/progress-bar-android',
162162
);
163-
return require('./Libraries/Components/ProgressBarAndroid/ProgressBarAndroid');
163+
return require('./Libraries/Components/ProgressBarAndroid/ProgressBarAndroid')
164+
.default;
164165
},
165166
get RefreshControl(): RefreshControl {
166-
return require('./Libraries/Components/RefreshControl/RefreshControl');
167+
return require('./Libraries/Components/RefreshControl/RefreshControl')
168+
.default;
167169
},
168170
get SafeAreaView(): SafeAreaView {
169171
return require('./Libraries/Components/SafeAreaView/SafeAreaView').default;
170172
},
171173
get ScrollView(): ScrollView {
172-
return require('./Libraries/Components/ScrollView/ScrollView');
174+
return require('./Libraries/Components/ScrollView/ScrollView').default;
173175
},
174176
get SectionList(): SectionList {
175177
return require('./Libraries/Lists/SectionList').default;
176178
},
177179
get StatusBar(): StatusBar {
178-
return require('./Libraries/Components/StatusBar/StatusBar');
180+
return require('./Libraries/Components/StatusBar/StatusBar').default;
179181
},
180182
get Switch(): Switch {
181183
return require('./Libraries/Components/Switch/Switch').default;

packages/react-native/jest/setup.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,12 @@ jest
169169
setString: jest.fn(),
170170
},
171171
}))
172-
.mock('../Libraries/Components/RefreshControl/RefreshControl', () =>
173-
jest.requireActual(
172+
.mock('../Libraries/Components/RefreshControl/RefreshControl', () => ({
173+
__esModule: true,
174+
default: jest.requireActual(
174175
'../Libraries/Components/RefreshControl/__mocks__/RefreshControlMock',
175176
),
176-
)
177+
}))
177178
.mock('../Libraries/Components/ScrollView/ScrollView', () => {
178179
const baseComponent = mockComponent(
179180
'../Libraries/Components/ScrollView/ScrollView',
@@ -190,16 +191,20 @@ jest
190191
scrollResponderZoomTo: jest.fn(),
191192
scrollResponderScrollNativeHandleToKeyboard: jest.fn(),
192193
},
194+
true, // isESModule
193195
);
194196
const mockScrollView = jest.requireActual('./mockScrollView');
195-
return mockScrollView(baseComponent);
197+
return {
198+
__esModule: true,
199+
default: mockScrollView(baseComponent),
200+
};
196201
})
197202
.mock('../Libraries/Components/ActivityIndicator/ActivityIndicator', () => ({
198203
__esModule: true,
199204
default: mockComponent(
200205
'../Libraries/Components/ActivityIndicator/ActivityIndicator',
201-
null,
202-
true,
206+
null, // instanceMethods
207+
true, // isESModule
203208
),
204209
}))
205210
.mock('../Libraries/AppState/AppState', () => ({

0 commit comments

Comments
 (0)