diff --git a/Libraries/BatchedBridge/BatchedBridgedModules/NativeModules.js b/Libraries/BatchedBridge/BatchedBridgedModules/NativeModules.js index e781e4670..e374ddab9 100644 --- a/Libraries/BatchedBridge/BatchedBridgedModules/NativeModules.js +++ b/Libraries/BatchedBridge/BatchedBridgedModules/NativeModules.js @@ -13,7 +13,6 @@ const BatchedBridge = require('BatchedBridge'); const RemoteModules = BatchedBridge.RemoteModules; -const Platform = require('Platform'); function normalizePrefix(moduleName: string): string { return moduleName.replace(/^(RCT|RK)/, ''); @@ -57,65 +56,4 @@ Object.keys(RemoteModules).forEach((moduleName) => { }); }); -/** - * Copies the ViewManager constants and commands into UIManager. This is - * only needed for iOS, which puts the constants in the ViewManager - * namespace instead of UIManager, unlike Android. - * - * We'll eventually move this logic to UIManager.js, once all - * the call sites accessing NativeModules.UIManager directly have - * been removed #9344445 - */ -if (Platform.OS === 'ios') { - const UIManager = NativeModules.UIManager; - UIManager && Object.keys(UIManager).forEach(viewName => { - const viewConfig = UIManager[viewName]; - if (viewConfig.Manager) { - let constants; - /* $FlowFixMe - nice try. Flow doesn't like getters */ - Object.defineProperty(viewConfig, 'Constants', { - configurable: true, - enumerable: true, - get: () => { - if (constants) { - return constants; - } - constants = {}; - const viewManager = NativeModules[normalizePrefix(viewConfig.Manager)]; - viewManager && Object.keys(viewManager).forEach(key => { - const value = viewManager[key]; - if (typeof value !== 'function') { - constants[key] = value; - } - }); - return constants; - }, - }); - let commands; - /* $FlowFixMe - nice try. Flow doesn't like getters */ - Object.defineProperty(viewConfig, 'Commands', { - configurable: true, - enumerable: true, - get: () => { - if (commands) { - return commands; - } - commands = {}; - const viewManager = NativeModules[normalizePrefix(viewConfig.Manager)]; - // Note: we depend on the fact that the JS object holding the configuration - // retains key order. This will probably break at some point. - let index = 0; - viewManager && Object.keys(viewManager).forEach(key => { - const value = viewManager[key]; - if (typeof value === 'function') { - commands[key] = index++; - } - }); - return commands; - }, - }); - } - }); -} - module.exports = NativeModules; diff --git a/Libraries/Components/RefreshControl/RefreshControl.js b/Libraries/Components/RefreshControl/RefreshControl.js index 81cecb093..75396d7f0 100644 --- a/Libraries/Components/RefreshControl/RefreshControl.js +++ b/Libraries/Components/RefreshControl/RefreshControl.js @@ -20,7 +20,7 @@ const View = require('View'); const requireNativeComponent = require('requireNativeComponent'); if (Platform.OS === 'android') { - var RefreshLayoutConsts = require('NativeModules').UIManager.AndroidSwipeRefreshLayout.Constants; + var RefreshLayoutConsts = require('UIManager').AndroidSwipeRefreshLayout.Constants; } else { var RefreshLayoutConsts = {SIZE: {}}; } diff --git a/Libraries/Components/ScrollView/ScrollView.js b/Libraries/Components/ScrollView/ScrollView.js index 23cf01e99..362898e6c 100644 --- a/Libraries/Components/ScrollView/ScrollView.js +++ b/Libraries/Components/ScrollView/ScrollView.js @@ -15,7 +15,6 @@ var ColorPropType = require('ColorPropType'); var EdgeInsetsPropType = require('EdgeInsetsPropType'); var Platform = require('Platform'); var PointPropType = require('PointPropType'); -var RCTScrollView = require('NativeModules').UIManager.RCTScrollView; var RCTScrollViewManager = require('NativeModules').ScrollViewManager; var React = require('React'); var ReactNative = require('ReactNative'); diff --git a/Libraries/Inspector/Inspector.js b/Libraries/Inspector/Inspector.js index 620f13be0..a415f1f3b 100644 --- a/Libraries/Inspector/Inspector.js +++ b/Libraries/Inspector/Inspector.js @@ -21,7 +21,7 @@ var InspectorUtils = require('InspectorUtils'); var React = require('React'); var StyleSheet = require('StyleSheet'); var Touchable = require('Touchable'); -var UIManager = require('NativeModules').UIManager; +var UIManager = require('UIManager'); var View = require('View'); if (window.__REACT_DEVTOOLS_GLOBAL_HOOK__) { diff --git a/Libraries/Inspector/InspectorOverlay.js b/Libraries/Inspector/InspectorOverlay.js index 172a8c5fe..cacd84037 100644 --- a/Libraries/Inspector/InspectorOverlay.js +++ b/Libraries/Inspector/InspectorOverlay.js @@ -15,7 +15,7 @@ var Dimensions = require('Dimensions'); var InspectorUtils = require('InspectorUtils'); var React = require('React'); var StyleSheet = require('StyleSheet'); -var UIManager = require('NativeModules').UIManager; +var UIManager = require('UIManager'); var View = require('View'); var ElementBox = require('ElementBox'); diff --git a/Libraries/Utilities/UIManager.js b/Libraries/Utilities/UIManager.js index 6b94bfcb2..22d97004a 100644 --- a/Libraries/Utilities/UIManager.js +++ b/Libraries/Utilities/UIManager.js @@ -11,8 +11,11 @@ */ 'use strict'; -var UIManager = require('NativeModules').UIManager; -var findNodeHandle = require('findNodeHandle'); +const Platform = require('Platform'); +const NativeModules = require('NativeModules'); +const { UIManager } = NativeModules; + +const findNodeHandle = require('findNodeHandle'); const _takeSnapshot = UIManager.takeSnapshot; @@ -52,4 +55,63 @@ UIManager.takeSnapshot = async function( return _takeSnapshot(view, options); }; +/** + * Copies the ViewManager constants and commands into UIManager. This is + * only needed for iOS, which puts the constants in the ViewManager + * namespace instead of UIManager, unlike Android. + */ +if (Platform.OS === 'ios') { + // Copied from NativeModules + function normalizePrefix(moduleName: string): string { + return moduleName.replace(/^(RCT|RK)/, ''); + } + + Object.keys(UIManager).forEach(viewName => { + const viewConfig = UIManager[viewName]; + if (viewConfig.Manager) { + let constants; + /* $FlowFixMe - nice try. Flow doesn't like getters */ + Object.defineProperty(viewConfig, 'Constants', { + configurable: true, + enumerable: true, + get: () => { + if (constants) { + return constants; + } + constants = {}; + const viewManager = NativeModules[normalizePrefix(viewConfig.Manager)]; + viewManager && Object.keys(viewManager).forEach(key => { + const value = viewManager[key]; + if (typeof value !== 'function') { + constants[key] = value; + } + }); + return constants; + }, + }); + let commands; + /* $FlowFixMe - nice try. Flow doesn't like getters */ + Object.defineProperty(viewConfig, 'Commands', { + configurable: true, + enumerable: true, + get: () => { + if (commands) { + return commands; + } + commands = {}; + const viewManager = NativeModules[normalizePrefix(viewConfig.Manager)]; + let index = 0; + viewManager && Object.keys(viewManager).forEach(key => { + const value = viewManager[key]; + if (typeof value === 'function') { + commands[key] = index++; + } + }); + return commands; + }, + }); + } + }); +} + module.exports = UIManager;