From e68cf7cee9d36271a1d3899fecff817304bb8bdc Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 26 Jan 2021 14:01:50 -0800 Subject: [PATCH] Avoid the call to getViewManagerConfig on deprecatedPropType method Summary: This diff removes the call to UIManager.getViewManagerConfig into the deprecatedPropType method when static view configs are enabled This was necessary to avoid innecessary calls to UIManager.getViewManagerConfig and to avoid loading UIManagerModule classes when static view configs are enabled changelog: [internal] internal Reviewed By: fkgozali, yungsters Differential Revision: D26040855 fbshipit-source-id: 82cad9f4abe9898e781fd989ebaa03497dad926b --- Libraries/ReactNative/DummyUIManager.js | 3 +++ Libraries/ReactNative/PaperUIManager.js | 3 +++ Libraries/ReactNative/UIManager.js | 1 + Libraries/ReactNative/UIManagerProperties.js | 1 + Libraries/Utilities/deprecatedPropType.js | 4 ++-- jest/setup.js | 3 +++ 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Libraries/ReactNative/DummyUIManager.js b/Libraries/ReactNative/DummyUIManager.js index 1947640e0a8..0d380f0a276 100644 --- a/Libraries/ReactNative/DummyUIManager.js +++ b/Libraries/ReactNative/DummyUIManager.js @@ -20,6 +20,9 @@ module.exports = { } return null; }, + hasViewManagerConfig: (viewManagerName: string): boolean => { + return viewManagerName === 'RCTVirtualText'; + }, getConstants: (): {...} => ({}), getConstantsForViewManager: (viewManagerName: string) => {}, getDefaultEventTypes: (): Array<$FlowFixMe> => [], diff --git a/Libraries/ReactNative/PaperUIManager.js b/Libraries/ReactNative/PaperUIManager.js index 3ee17c5d807..92f59e0a208 100644 --- a/Libraries/ReactNative/PaperUIManager.js +++ b/Libraries/ReactNative/PaperUIManager.js @@ -97,6 +97,9 @@ const UIManagerJS = { getViewManagerConfig(viewManagerName: string): any { return getViewManagerConfig(viewManagerName); }, + hasViewManagerConfig(viewManagerName: string): boolean { + return getViewManagerConfig(viewManagerName) != null; + }, }; // TODO (T45220498): Remove this. diff --git a/Libraries/ReactNative/UIManager.js b/Libraries/ReactNative/UIManager.js index 84b280dce9d..d25d3040d45 100644 --- a/Libraries/ReactNative/UIManager.js +++ b/Libraries/ReactNative/UIManager.js @@ -15,6 +15,7 @@ import type {Spec} from './NativeUIManager'; interface UIManagerJSInterface extends Spec { +getViewManagerConfig: (viewManagerName: string) => Object; + +hasViewManagerConfig: (viewManagerName: string) => boolean; +createView: ( reactTag: ?number, viewName: string, diff --git a/Libraries/ReactNative/UIManagerProperties.js b/Libraries/ReactNative/UIManagerProperties.js index 77e67267e57..f8f9f6b7ea8 100644 --- a/Libraries/ReactNative/UIManagerProperties.js +++ b/Libraries/ReactNative/UIManagerProperties.js @@ -57,6 +57,7 @@ module.exports = [ 'AccessibilityEventTypes', 'UIView', 'getViewManagerConfig', + 'hasViewManagerConfig', 'blur', 'focus', 'genericBubblingEventTypes', diff --git a/Libraries/Utilities/deprecatedPropType.js b/Libraries/Utilities/deprecatedPropType.js index 480cf4cbeda..4fc73c836fe 100644 --- a/Libraries/Utilities/deprecatedPropType.js +++ b/Libraries/Utilities/deprecatedPropType.js @@ -10,7 +10,7 @@ 'use strict'; -const UIManager = require('../ReactNative/UIManager'); +import UIManager from '../ReactNative/UIManager'; /** * Adds a deprecation warning when the prop is used. @@ -23,7 +23,7 @@ function deprecatedPropType( // Don't warn for native components. if ( !global.RN$Bridgeless && - !UIManager.getViewManagerConfig(componentName) && + UIManager.hasViewManagerConfig(componentName) && props[propName] !== undefined ) { console.warn( diff --git a/jest/setup.js b/jest/setup.js index 514e76c5242..504ff379363 100644 --- a/jest/setup.js +++ b/jest/setup.js @@ -69,6 +69,9 @@ jest }; } }), + hasViewManagerConfig: jest.fn(name => { + return true; + }), measure: jest.fn(), manageChildren: jest.fn(), removeSubviewsFromContainerWithID: jest.fn(),