Try static view config if native view config is not available (#44065)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44065

React Native will try to use static view config if native view config is not available.
This will allow Fabric-only native components in Bridge mode.

Changelog: [General][Added] - Add support for Fabric-only native components in Bridge mode.

Reviewed By: cortinico

Differential Revision: D56062759

fbshipit-source-id: e562700695c14c88d11056aec1e66f8aa10a3957
This commit is contained in:
Dmitry Rykun
2024-04-17 06:14:35 -07:00
committed by Facebook GitHub Bot
parent 3426591bbe
commit 2f1cd04073
2 changed files with 15 additions and 11 deletions
@@ -62,14 +62,21 @@ export function get<Config>(
let viewConfig;
if (native) {
viewConfig = getNativeComponentAttributes(name);
viewConfig =
getNativeComponentAttributes(name) ??
createViewConfig(viewConfigProvider());
} else {
viewConfig = createViewConfig(viewConfigProvider());
if (viewConfig == null) {
viewConfig = getNativeComponentAttributes(name);
}
viewConfig =
createViewConfig(viewConfigProvider()) ??
getNativeComponentAttributes(name);
}
invariant(
viewConfig != null,
'NativeComponentRegistry.get: both static and native view config are missing for native component "%s".',
name,
);
if (verify) {
const nativeViewConfig = native
? viewConfig
@@ -19,17 +19,14 @@ const matricesDiffer = require('../Utilities/differ/matricesDiffer');
const pointsDiffer = require('../Utilities/differ/pointsDiffer');
const sizesDiffer = require('../Utilities/differ/sizesDiffer');
const UIManager = require('./UIManager');
const invariant = require('invariant');
const nullthrows = require('nullthrows');
function getNativeComponentAttributes(uiViewClassName: string): any {
const viewConfig = UIManager.getViewManagerConfig(uiViewClassName);
invariant(
viewConfig != null && viewConfig.NativeProps != null,
'requireNativeComponent: "%s" was not found in the UIManager.',
uiViewClassName,
);
if (viewConfig == null) {
return null;
}
// TODO: This seems like a whole lot of runtime initialization for every
// native component that can be either avoided or simplified.