Skip to content

Commit

Permalink
Use RN$LegacyInterop_UIManager_getConstants in BridgelessUIManager (#…
Browse files Browse the repository at this point in the history
…37730)

Summary:
Pull Request resolved: #37730

This diff makes unschematized native components available in bridgeless mode. In case there is no static view config, `BridgelessUIManager` calls `RN$LegacyInterop_UIManager_getConstants`, and gets native view config form the constants.

Changelog: [Internal] - Use RN$LegacyInterop_UIManager_getConstants in BridgelessUIManager

Reviewed By: sammy-SC

Differential Revision: D45154396

fbshipit-source-id: 32b3718841b59a8b6fb22022c9d9edc17dad877f
  • Loading branch information
dmytrorykun authored and facebook-github-bot committed Jul 20, 2023
1 parent 2d3348e commit a6b49a1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
34 changes: 26 additions & 8 deletions packages/react-native/Libraries/ReactNative/BridgelessUIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,45 @@
import type {RootTag} from '../Types/RootTagTypes';

import {unstable_hasComponent} from '../NativeComponent/NativeComponentRegistryUnstable';
import ReactNativeFeatureFlags from './ReactNativeFeatureFlags';

let cachedConstants = null;

const errorMessageForMethod = (methodName: string): string =>
"[ReactNative Architecture][JS] '" +
methodName +
"' is not available in the new React Native architecture.";

function getCachedConstants(): Object {
if (!cachedConstants) {
cachedConstants = global.RN$LegacyInterop_UIManager_getConstants();
}
return cachedConstants;
}

module.exports = {
getViewManagerConfig: (viewManagerName: string): mixed => {
console.error(
errorMessageForMethod('getViewManagerConfig') +
'Use hasViewManagerConfig instead. viewManagerName: ' +
viewManagerName,
);
return null;
if (ReactNativeFeatureFlags.enableNativeViewConfigsInBridgelessMode) {
return getCachedConstants()[viewManagerName];
} else {
console.error(
errorMessageForMethod('getViewManagerConfig') +
'Use hasViewManagerConfig instead. viewManagerName: ' +
viewManagerName,
);
return null;
}
},
hasViewManagerConfig: (viewManagerName: string): boolean => {
return unstable_hasComponent(viewManagerName);
},
getConstants: (): Object => {
console.error(errorMessageForMethod('getConstants'));
return {};
if (ReactNativeFeatureFlags.enableNativeViewConfigsInBridgelessMode) {
return getCachedConstants();
} else {
console.error(errorMessageForMethod('getConstants'));
return null;
}
},
getConstantsForViewManager: (viewManagerName: string): Object => {
console.error(errorMessageForMethod('getConstantsForViewManager'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export type FeatureFlags = {|
* Enables use of setNativeProps in JS driven animations.
*/
shouldUseSetNativePropsInFabric: () => boolean,
/**
* Enables native view configs in brdgeless mode.
*/
enableNativeViewConfigsInBridgelessMode: () => boolean,
|};

const ReactNativeFeatureFlags: FeatureFlags = {
Expand All @@ -65,6 +69,7 @@ const ReactNativeFeatureFlags: FeatureFlags = {
enableAccessToHostTreeInFabric: () => false,
shouldUseAnimatedObjectForTransform: () => false,
shouldUseSetNativePropsInFabric: () => false,
enableNativeViewConfigsInBridgelessMode: () => false,
};

module.exports = ReactNativeFeatureFlags;

0 comments on commit a6b49a1

Please sign in to comment.