Revert D9930713: Avoid view manager class loads

Differential Revision:
D9930713

Original commit changeset: 4aa013f8398d

fbshipit-source-id: 1fed02b41fa9d91f54d1a19f710bdb666701a4a0
This commit is contained in:
Andrew Chen (Eng)
2018-09-28 14:50:37 -07:00
committed by Facebook Github Bot
parent 5ce2c0144b
commit e082a61324
5 changed files with 5 additions and 107 deletions

View File

@@ -11,13 +11,11 @@
const NativeModules = require('NativeModules');
const Platform = require('Platform');
const UIManagerProperties = require('UIManagerProperties');
const defineLazyObjectProperty = require('defineLazyObjectProperty');
const invariant = require('fbjs/lib/invariant');
const {UIManager} = NativeModules;
const viewManagerConfigs = {};
invariant(
UIManager,
@@ -38,20 +36,7 @@ UIManager.takeSnapshot = function() {
);
};
UIManager.getViewManagerConfig = function(viewManagerName: string) {
if (
viewManagerConfigs[viewManagerName] === undefined &&
UIManager.getConstantsForViewManager
) {
try {
viewManagerConfigs[
viewManagerName
] = UIManager.getConstantsForViewManager(viewManagerName);
} catch (e) {
viewManagerConfigs[viewManagerName] = null;
}
}
return viewManagerConfigs[viewManagerName];
return UIManager[viewManagerName];
};
/**
@@ -63,7 +48,6 @@ if (Platform.OS === 'ios') {
Object.keys(UIManager).forEach(viewName => {
const viewConfig = UIManager[viewName];
if (viewConfig.Manager) {
viewManagerConfigs[viewName] = viewConfig;
defineLazyObjectProperty(viewConfig, 'Constants', {
get: () => {
const viewManager = NativeModules[viewConfig.Manager];
@@ -123,20 +107,4 @@ if (Platform.OS === 'ios') {
if (global.__makePartial) global.__makePartial(UIManager);
}
if (__DEV__) {
Object.keys(UIManager).forEach(viewManagerName => {
if (!UIManagerProperties.includes(viewManagerName)) {
defineLazyObjectProperty(UIManager, viewManagerName, {
get: () => {
console.warn(
`Accessing view manager configs directly off UIManager via UIManager['${viewManagerName}'] ` +
`is no longer supported. Use UIManager.getViewManager('${viewManagerName}') instead.`,
);
return UIManager.getViewManagerConfig(viewManagerName);
},
});
}
});
}
module.exports = UIManager;

View File

@@ -1,67 +0,0 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
/**
* The list of non-ViewManager related UIManager properties.
*
* In an effort to improve startup performance by lazily loading view managers,
* the interface to access view managers will change from
* UIManager['viewManagerName'] to UIManager.getViewManager('viewManagerName').
* By using a function call instead of a property access, the UIManager will
* be able to initialize and load the required view manager from native
* synchronously. All of React Native's core components have been updated to
* use getViewManager(). For the next few releases, any usage of
* UIManager['viewManagerName'] will result in a warning. Because React Native
* does not support Proxy objects, a view manager access is implied if any of
* UIManager's properties that are not one of the properties below is being
* accessed. Once UIManager property accesses for view managers has been fully
* deprecated, this file will also be removed.
*/
module.exports = [
'clearJSResponder',
'configureNextLayoutAnimation',
'createView',
'dismissPopupMenu',
'dispatchViewManagerCommand',
'findSubviewIn',
'getConstantsForViewManager',
'getDefaultEventTypes',
'manageChildren',
'measure',
'measureInWindow',
'measureLayout',
'measureLayoutRelativeToParent',
'playTouchSound',
'removeRootView',
'removeSubviewsFromContainerWithID',
'replaceExistingNonRootView',
'sendAccessibilityEvent',
'setChildren',
'setJSResponder',
'setLayoutAnimationEnabledExperimental',
'showPopupMenu',
'updateView',
'viewIsDescendantOf',
'PopupMenu',
'LazyViewManagersEnabled',
'ViewManagerNames',
'StyleConstants',
'AccessibilityEventTypes',
'UIView',
'__takeSnapshot',
'takeSnapshot',
'getViewManagerConfig',
'measureViewsInRect',
'blur',
'focus',
'genericBubblingEventTypes',
'genericDirectEventTypes',
];

View File

@@ -96,7 +96,7 @@ function attachDefaultEventTypes(viewConfig: any) {
// This is supported on UIManager platforms (ex: Android),
// as lazy view managers are not implemented for all platforms.
// See [UIManager] for details on constants and implementations.
if (UIManager.ViewManagerNames || UIManager.LazyViewManagersEnabled) {
if (UIManager.ViewManagerNames) {
// Lazy view managers enabled.
viewConfig = merge(viewConfig, UIManager.getDefaultEventTypes());
} else {