Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions packages/metro-react-native-babel-preset/src/configs/lazy-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* This is the set of modules that React Native publicly exports and that we
* want to require lazily. Keep this list in sync with
* Libraries/react-native/react-native-implementation.js (though having extra
* entries here is fairly harmless).
*/
module.exports = new Set([
'AccessibilityInfo',
'ActivityIndicator',
'ReactNativeART',
'Button',
'CheckBox',
'DatePickerIOS',
'DrawerLayoutAndroid',
'FlatList',
'Image',
'ImageBackground',
'ImageEditor',
'ImageStore',
'InputAccessoryView',
'KeyboardAvoidingView',
'ListView',
'MaskedViewIOS',
'Modal',
'Picker',
'PickerIOS',
'ProgressBarAndroid',
'ProgressViewIOS',
'SafeAreaView',
'ScrollView',
'SectionList',
'SegmentedControlIOS',
'Slider',
'Switch',
'RefreshControl',
'StatusBar',
'SwipeableFlatList',
'SwipeableListView',
'Text',
'TextInput',
'ToolbarAndroid',
'Touchable',
'TouchableHighlight',
'TouchableNativeFeedback',
'TouchableOpacity',
'TouchableWithoutFeedback',
'View',
'ViewPagerAndroid',
'VirtualizedList',
'WebView',

// APIs
'ActionSheetIOS',
'Alert',
'Animated',
'AppRegistry',
'AppState',
'AsyncStorage',
'BackHandler',
'CameraRoll',
'Clipboard',
'DatePickerAndroid',
'DeviceInfo',
'Dimensions',
'Easing',
'ReactNative',
'I18nManager',
'ImagePickerIOS',
'InteractionManager',
'Keyboard',
'LayoutAnimation',
'Linking',
'NativeEventEmitter',
'NetInfo',
'PanResponder',
'PermissionsAndroid',
'PixelRatio',
'PushNotificationIOS',
'Settings',
'Share',
'StatusBarIOS',
'StyleSheet',
'Systrace',
'TimePickerAndroid',
'ToastAndroid',
'TVEventHandler',
'UIManager',
'ReactNative',
'UTFSequence',
'Vibration',
'YellowBox',

// Plugins
'RCTDeviceEventEmitter',
'RCTNativeAppEventEmitter',
'NativeModules',
'Platform',
'processColor',
'requireNativeComponent',

// Prop Types
'DeprecatedColorPropType',
'DeprecatedEdgeInsetsPropType',
'DeprecatedPointPropType',
'DeprecatedViewPropTypes',
]);
7 changes: 6 additions & 1 deletion packages/metro-react-native-babel-preset/src/configs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

'use strict';

const lazyImports = require('./lazy-imports');

function isTypeScriptSource(fileName) {
return !!fileName && fileName.endsWith('.ts');
}
Expand Down Expand Up @@ -93,7 +95,10 @@ const getPreset = (src, options) => {
{
strict: false,
strictMode: false, // prevent "use strict" injections
lazy: !!(options && options.lazyImportExportTransform),
lazy:
options && options.lazyImportExportTransform !== undefined
? options.lazyImportExportTransform
: importSpecifier => lazyImports.has(importSpecifier),
allowTopLevelThis: true, // dont rewrite global `this` -> `undefined`
},
],
Expand Down