mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Migrated components to export syntax (part 2) (#48767)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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
This commit is contained in:
1 parent
b200c7cb2f
commit
ce412746b1
16 files changed
+39
-33
No files matched your search
+1
-1
@@ -19,7 +19,7 @@ import * as React from 'react';
|
||||
|
||||
const PlatformActivityIndicator =
|
||||
Platform.OS === 'android'
|
||||
? require('../ProgressBarAndroid/ProgressBarAndroid')
|
||||
? require('../ProgressBarAndroid/ProgressBarAndroid').default
|
||||
: require('./ActivityIndicatorViewNativeComponent').default;
|
||||
|
||||
const GRAY = '#999999';
|
||||
|
||||
+4
-5
@@ -106,8 +106,7 @@ const ProgressBarAndroidWithForwardedRef: component(
|
||||
);
|
||||
});
|
||||
|
||||
module.exports =
|
||||
/* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an
|
||||
* error found when Flow v0.89 was deployed. To see the error, delete this
|
||||
* comment and run Flow. */
|
||||
(ProgressBarAndroidWithForwardedRef: typeof ProgressBarAndroidNativeComponent);
|
||||
export default /* $FlowFixMe(>=0.89.0 site=react_native_android_fb) This comment suppresses an
|
||||
* error found when Flow v0.89 was deployed. To see the error, delete this
|
||||
* comment and run Flow. */
|
||||
(ProgressBarAndroidWithForwardedRef: typeof ProgressBarAndroidNativeComponent);
|
||||
+1
-1
@@ -15,6 +15,6 @@ import typeof ProgressBarAndroidNativeComponentType from './ProgressBarAndroidNa
|
||||
|
||||
export type {ProgressBarAndroidProps} from './ProgressBarAndroid.android';
|
||||
|
||||
module.exports = (require('../UnimplementedViews/UnimplementedView'):
|
||||
export default (require('../UnimplementedViews/UnimplementedView'):
|
||||
| UnimplementedViewType
|
||||
| ProgressBarAndroidNativeComponentType);
|
||||
Vendored
+1
-1
@@ -16,7 +16,7 @@ const ReactNativeTestTools = require('../../../Utilities/ReactNativeTestTools');
|
||||
* comment suppresses an error found when Flow v0.99 was deployed. To see the
|
||||
* error, delete this comment and run Flow. */
|
||||
// $FlowFixMe[missing-platform-support]
|
||||
const ProgressBarAndroid = require('../ProgressBarAndroid.android');
|
||||
const ProgressBarAndroid = require('../ProgressBarAndroid.android').default;
|
||||
const React = require('react');
|
||||
|
||||
describe('<ProgressBarAndroid />', () => {
|
||||
|
||||
+1
-1
@@ -201,4 +201,4 @@ class RefreshControl extends React.Component<RefreshControlProps> {
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = RefreshControl;
|
||||
export default RefreshControl;
|
||||
@@ -1913,5 +1913,5 @@ Wrapper.displayName = 'ScrollView';
|
||||
// $FlowExpectedError[prop-missing]
|
||||
Wrapper.Context = ScrollViewContext;
|
||||
|
||||
module.exports = ((Wrapper: $FlowFixMe): typeof Wrapper &
|
||||
export default ((Wrapper: $FlowFixMe): typeof Wrapper &
|
||||
ScrollViewComponentStatics);
|
||||
+1
-1
@@ -15,7 +15,7 @@ const {create, unmount, update} = require('../../../../jest/renderer');
|
||||
const Text = require('../../../Text/Text');
|
||||
const ReactNativeTestTools = require('../../../Utilities/ReactNativeTestTools');
|
||||
const View = require('../../View/View');
|
||||
const ScrollView = require('../ScrollView');
|
||||
const ScrollView = require('../ScrollView').default;
|
||||
const React = require('react');
|
||||
|
||||
describe('ScrollView', () => {
|
||||
|
||||
+1
-1
@@ -27,4 +27,4 @@ function processDecelerationRate(
|
||||
return decelerationRate;
|
||||
}
|
||||
|
||||
module.exports = processDecelerationRate;
|
||||
export default processDecelerationRate;
|
||||
@@ -18,4 +18,4 @@ const SoundManager = {
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = SoundManager;
|
||||
export default SoundManager;
|
||||
@@ -493,4 +493,4 @@ class StatusBar extends React.Component<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StatusBar;
|
||||
export default StatusBar;
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
'use strict';
|
||||
|
||||
const {create} = require('../../../../jest/renderer');
|
||||
const StatusBar = require('../StatusBar');
|
||||
const StatusBar = require('../StatusBar').default;
|
||||
const React = require('react');
|
||||
|
||||
describe('StatusBar', () => {
|
||||
|
||||
@@ -15,7 +15,7 @@ import type {ElementsHierarchy, InspectedElement} from './Inspector';
|
||||
import SafeAreaView from '../Components/SafeAreaView/SafeAreaView';
|
||||
import React from 'react';
|
||||
|
||||
const ScrollView = require('../Components/ScrollView/ScrollView');
|
||||
const ScrollView = require('../Components/ScrollView/ScrollView').default;
|
||||
const TouchableHighlight = require('../Components/Touchable/TouchableHighlight');
|
||||
const View = require('../Components/View/View');
|
||||
const StyleSheet = require('../StyleSheet/StyleSheet');
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ import RCTModalHostView from './RCTModalHostViewNativeComponent';
|
||||
import {VirtualizedListContextResetter} from '@react-native/virtualized-lists';
|
||||
import React from 'react';
|
||||
|
||||
const ScrollView = require('../Components/ScrollView/ScrollView');
|
||||
const ScrollView = require('../Components/ScrollView/ScrollView').default;
|
||||
const View = require('../Components/View/View');
|
||||
const AppContainer = require('../ReactNative/AppContainer');
|
||||
const I18nManager = require('../ReactNative/I18nManager');
|
||||
|
||||
@@ -1936,7 +1936,7 @@ declare export default function useAndroidRippleForView(
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.js 1`] = `
|
||||
"export type { ProgressBarAndroidProps } from \\"./ProgressBarAndroid.android\\";
|
||||
declare module.exports:
|
||||
declare export default
|
||||
| UnimplementedViewType
|
||||
| ProgressBarAndroidNativeComponentType;
|
||||
"
|
||||
@@ -1993,7 +1993,7 @@ declare class RefreshControl extends React.Component<RefreshControlProps> {
|
||||
_onRefresh: $FlowFixMe;
|
||||
_setNativeRef: $FlowFixMe;
|
||||
}
|
||||
declare module.exports: RefreshControl;
|
||||
declare export default typeof RefreshControl;
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -2267,7 +2267,7 @@ declare const Wrapper: component(
|
||||
ref: React.RefSetter<PublicScrollViewInstance>,
|
||||
...props: Props
|
||||
);
|
||||
declare module.exports: typeof Wrapper & ScrollViewComponentStatics;
|
||||
declare export default typeof Wrapper & ScrollViewComponentStatics;
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -2413,7 +2413,7 @@ exports[`public API should not change unintentionally Libraries/Components/Scrol
|
||||
"declare function processDecelerationRate(
|
||||
decelerationRate: number | \\"normal\\" | \\"fast\\"
|
||||
): number;
|
||||
declare module.exports: processDecelerationRate;
|
||||
declare export default typeof processDecelerationRate;
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -2425,7 +2425,7 @@ declare export default typeof NativeSoundManager;
|
||||
|
||||
exports[`public API should not change unintentionally Libraries/Components/Sound/SoundManager.js 1`] = `
|
||||
"declare const SoundManager: { playTouchSound: () => void };
|
||||
declare module.exports: SoundManager;
|
||||
declare export default typeof SoundManager;
|
||||
"
|
||||
`;
|
||||
|
||||
@@ -2520,7 +2520,7 @@ declare class StatusBar extends React.Component<Props> {
|
||||
static _updatePropsStack: $FlowFixMe;
|
||||
render(): React.Node;
|
||||
}
|
||||
declare module.exports: StatusBar;
|
||||
declare export default typeof StatusBar;
|
||||
"
|
||||
`;
|
||||
|
||||
|
||||
Vendored
+6
-4
@@ -160,22 +160,24 @@ module.exports = {
|
||||
"It can now be installed and imported from '@react-native-community/progress-bar-android' instead of 'react-native'. " +
|
||||
'See https://github.com/react-native-progress-view/progress-bar-android',
|
||||
);
|
||||
return require('./Libraries/Components/ProgressBarAndroid/ProgressBarAndroid');
|
||||
return require('./Libraries/Components/ProgressBarAndroid/ProgressBarAndroid')
|
||||
.default;
|
||||
},
|
||||
get RefreshControl(): RefreshControl {
|
||||
return require('./Libraries/Components/RefreshControl/RefreshControl');
|
||||
return require('./Libraries/Components/RefreshControl/RefreshControl')
|
||||
.default;
|
||||
},
|
||||
get SafeAreaView(): SafeAreaView {
|
||||
return require('./Libraries/Components/SafeAreaView/SafeAreaView').default;
|
||||
},
|
||||
get ScrollView(): ScrollView {
|
||||
return require('./Libraries/Components/ScrollView/ScrollView');
|
||||
return require('./Libraries/Components/ScrollView/ScrollView').default;
|
||||
},
|
||||
get SectionList(): SectionList {
|
||||
return require('./Libraries/Lists/SectionList').default;
|
||||
},
|
||||
get StatusBar(): StatusBar {
|
||||
return require('./Libraries/Components/StatusBar/StatusBar');
|
||||
return require('./Libraries/Components/StatusBar/StatusBar').default;
|
||||
},
|
||||
get Switch(): Switch {
|
||||
return require('./Libraries/Components/Switch/Switch').default;
|
||||
|
||||
Vendored
+11
-6
@@ -169,11 +169,12 @@ jest
|
||||
setString: jest.fn(),
|
||||
},
|
||||
}))
|
||||
.mock('../Libraries/Components/RefreshControl/RefreshControl', () =>
|
||||
jest.requireActual(
|
||||
.mock('../Libraries/Components/RefreshControl/RefreshControl', () => ({
|
||||
__esModule: true,
|
||||
default: jest.requireActual(
|
||||
'../Libraries/Components/RefreshControl/__mocks__/RefreshControlMock',
|
||||
),
|
||||
)
|
||||
}))
|
||||
.mock('../Libraries/Components/ScrollView/ScrollView', () => {
|
||||
const baseComponent = mockComponent(
|
||||
'../Libraries/Components/ScrollView/ScrollView',
|
||||
@@ -190,16 +191,20 @@ jest
|
||||
scrollResponderZoomTo: jest.fn(),
|
||||
scrollResponderScrollNativeHandleToKeyboard: jest.fn(),
|
||||
},
|
||||
true, // isESModule
|
||||
);
|
||||
const mockScrollView = jest.requireActual('./mockScrollView');
|
||||
return mockScrollView(baseComponent);
|
||||
return {
|
||||
__esModule: true,
|
||||
default: mockScrollView(baseComponent),
|
||||
};
|
||||
})
|
||||
.mock('../Libraries/Components/ActivityIndicator/ActivityIndicator', () => ({
|
||||
__esModule: true,
|
||||
default: mockComponent(
|
||||
'../Libraries/Components/ActivityIndicator/ActivityIndicator',
|
||||
null,
|
||||
true,
|
||||
null, // instanceMethods
|
||||
true, // isESModule
|
||||
),
|
||||
}))
|
||||
.mock('../Libraries/AppState/AppState', () => ({
|
||||
|
||||
Reference in new issue
Block a user