Replace DummyUIManager with BridgelessUIManager. Log errors for deprecated methods in Bridgeless.

Summary:
Changelog: [Internal]

* Rename DummyUIManager to BridgelessUIManager
* Cleanup `RCTVirtualText` & `RCTShimmeringView` since the native changes from T107747313 are already in production, so these two will components always return a viewConfig in prod.

- `console.error` when deprecated Bridge UIManager method are being accessed.
- Make sure new BridgelessUIManager.js has the same method definition as [NativeUIManager.js](https://www.internalfb.com/code/fbsource/[e80c98b816183dcdfde1e81de01ba99aa6e30ed2]/xplat/js/react-native-github/Libraries/ReactNative/NativeUIManager.js?lines=15)

Reviewed By: RSNara

Differential Revision: D34203081

fbshipit-source-id: 99aafc2372b118d0c8cc41f7376e136dabae9bd5
This commit is contained in:
Paige Sun 2022-02-14 16:26:23 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 2b845d5585
Коммит f8158f8a03
4 изменённых файлов: 66 добавлений и 45 удалений

Просмотреть файл

@ -13,43 +13,51 @@
import type {RootTag} from 'react-native/Libraries/Types/RootTagTypes';
import {unstable_hasComponent} from 'react-native/Libraries/NativeComponent/NativeComponentRegistryUnstable';
const errorMessageForMethod = (methodName: string): string =>
"[ReactNative Architecture][JS] '" +
methodName +
"' is not available in the new React Native architecture.";
module.exports = {
getViewManagerConfig: (viewManagerName: string): mixed => {
console.warn(
'getViewManagerConfig is unavailable in Bridgeless, use hasViewManagerConfig instead. viewManagerName: ' +
console.error(
errorMessageForMethod('getViewManagerConfig') +
'Use hasViewManagerConfig instead. viewManagerName: ' +
viewManagerName,
);
if (
viewManagerName === 'RCTVirtualText' ||
viewManagerName === 'RCTShimmeringView'
) {
return {};
}
return null;
},
hasViewManagerConfig: (viewManagerName: string): boolean => {
if (global.__nativeComponentRegistry__hasComponent) {
return unstable_hasComponent(viewManagerName);
} else {
return (
viewManagerName === 'RCTVirtualText' ||
viewManagerName === 'RCTShimmeringView'
);
}
return unstable_hasComponent(viewManagerName);
},
getConstants: (): Object => {
console.error(errorMessageForMethod('getConstants'));
return {};
},
getConstantsForViewManager: (viewManagerName: string): Object => {
console.error(errorMessageForMethod('getConstantsForViewManager'));
return {};
},
getDefaultEventTypes: (): Array<string> => {
console.error(errorMessageForMethod('getDefaultEventTypes'));
return [];
},
lazilyLoadView: (name: string): Object => {
console.error(errorMessageForMethod('lazilyLoadView'));
return {};
},
getConstants: (): {...} => ({}),
getConstantsForViewManager: (viewManagerName: string) => {},
getDefaultEventTypes: (): Array<$FlowFixMe> => [],
lazilyLoadView: (name: string) => {},
createView: (
reactTag: ?number,
viewName: string,
rootTag: RootTag,
props: Object,
) => {},
updateView: (reactTag: number, viewName: string, props: Object) => {},
focus: (reactTag: ?number) => {},
blur: (reactTag: ?number) => {},
): void => console.error(errorMessageForMethod('createView')),
updateView: (reactTag: number, viewName: string, props: Object): void =>
console.error(errorMessageForMethod('updateView')),
focus: (reactTag: ?number): void =>
console.error(errorMessageForMethod('focus')),
blur: (reactTag: ?number): void =>
console.error(errorMessageForMethod('blur')),
findSubviewIn: (
reactTag: ?number,
point: Array<number>,
@ -60,12 +68,12 @@ module.exports = {
width: number,
height: number,
) => void,
) => {},
): void => console.error(errorMessageForMethod('findSubviewIn')),
dispatchViewManagerCommand: (
reactTag: ?number,
commandID: number,
commandArgs: ?Array<string | number | boolean>,
) => {},
): void => console.error(errorMessageForMethod('dispatchViewManagerCommand')),
measure: (
reactTag: ?number,
callback: (
@ -76,16 +84,16 @@ module.exports = {
pageX: number,
pageY: number,
) => void,
) => {},
): void => console.error(errorMessageForMethod('measure')),
measureInWindow: (
reactTag: ?number,
callback: (x: number, y: number, width: number, height: number) => void,
) => {},
): void => console.error(errorMessageForMethod('measureInWindow')),
viewIsDescendantOf: (
reactTag: ?number,
ancestorReactTag: ?number,
callback: (result: Array<boolean>) => void,
) => {},
): void => console.error(errorMessageForMethod('viewIsDescendantOf')),
measureLayout: (
reactTag: ?number,
ancestorReactTag: ?number,
@ -96,7 +104,7 @@ module.exports = {
width: number,
height: number,
) => void,
) => {},
): void => console.error(errorMessageForMethod('measureLayout')),
measureLayoutRelativeToParent: (
reactTag: ?number,
errorCallback: (error: Object) => void,
@ -106,17 +114,24 @@ module.exports = {
width: number,
height: number,
) => void,
) => {},
setJSResponder: (reactTag: ?number, blockNativeResponder: boolean) => {},
clearJSResponder: () => {},
): void =>
console.error(errorMessageForMethod('measureLayoutRelativeToParent')),
setJSResponder: (reactTag: ?number, blockNativeResponder: boolean): void =>
console.error(errorMessageForMethod('setJSResponder')),
clearJSResponder: (): void =>
console.error(errorMessageForMethod('clearJSResponder')),
configureNextLayoutAnimation: (
config: Object,
callback: () => void,
errorCallback: (error: Object) => void,
) => {},
removeSubviewsFromContainerWithID: (containerID: number) => {},
replaceExistingNonRootView: (reactTag: ?number, newReactTag: ?number) => {},
setChildren: (containerTag: ?number, reactTags: Array<number>) => {},
): void =>
console.error(errorMessageForMethod('configureNextLayoutAnimation')),
removeSubviewsFromContainerWithID: (containerID: number): void =>
console.error(errorMessageForMethod('removeSubviewsFromContainerWithID')),
replaceExistingNonRootView: (reactTag: ?number, newReactTag: ?number): void =>
console.error(errorMessageForMethod('replaceExistingNonRootView')),
setChildren: (containerTag: ?number, reactTags: Array<number>): void =>
console.error(errorMessageForMethod('setChildren')),
manageChildren: (
containerTag: ?number,
moveFromIndices: Array<number>,
@ -124,16 +139,22 @@ module.exports = {
addChildReactTags: Array<number>,
addAtIndices: Array<number>,
removeAtIndices: Array<number>,
) => {},
): void => console.error(errorMessageForMethod('manageChildren')),
// Android only
setLayoutAnimationEnabledExperimental: (enabled: boolean) => {},
sendAccessibilityEvent: (reactTag: ?number, eventType: number) => {},
setLayoutAnimationEnabledExperimental: (enabled: boolean): void => {
console.error(
errorMessageForMethod('setLayoutAnimationEnabledExperimental'),
);
},
sendAccessibilityEvent: (reactTag: ?number, eventType: number): void =>
console.error(errorMessageForMethod('sendAccessibilityEvent')),
showPopupMenu: (
reactTag: ?number,
items: Array<string>,
error: (error: Object) => void,
success: (event: string, selected?: number) => void,
) => {},
dismissPopupMenu: () => {},
): void => console.error(errorMessageForMethod('showPopupMenu')),
dismissPopupMenu: (): void =>
console.error(errorMessageForMethod('dismissPopupMenu')),
};

Просмотреть файл

@ -33,7 +33,7 @@ export interface UIManagerJSInterface extends Spec {
const UIManager: UIManagerJSInterface =
global.RN$Bridgeless === true
? require('./DummyUIManager')
? require('./BridgelessUIManager')
: require('./PaperUIManager');
module.exports = UIManager;

Просмотреть файл

@ -141,7 +141,7 @@ const DeprecatedComponentNameCheckTemplate = ({
paperComponentNameDeprecated: string,
}) =>
`
if (global.__nativeComponentRegistry__hasComponent) {
if (global.RN$Bridgeless) {
if (UIManager.hasViewManagerConfig('${componentName}')) {
nativeComponentName = '${componentName}';
} else if (UIManager.hasViewManagerConfig('${paperComponentNameDeprecated}')) {

Просмотреть файл

@ -1070,7 +1070,7 @@ const NativeComponentRegistry = require('react-native/Libraries/NativeComponent/
const {UIManager} = require(\\"react-native\\")
let nativeComponentName = 'NativeComponentName';
if (global.__nativeComponentRegistry__hasComponent) {
if (global.RN$Bridgeless) {
if (UIManager.hasViewManagerConfig('NativeComponentName')) {
nativeComponentName = 'NativeComponentName';
} else if (UIManager.hasViewManagerConfig('DeprecatedNativeComponentName')) {