diff --git a/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js b/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js index 68695660da1312..3c826b6eeee4ac 100644 --- a/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js +++ b/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js @@ -23,6 +23,9 @@ import invariant from 'invariant'; import * as React from 'react'; let getRuntimeConfig; +let defaultStaticViewConfigPatcher = (name: string, viewConfig: ViewConfig) => + viewConfig; +let patchStaticViewConfig = defaultStaticViewConfigPatcher; /** * Configures a function that is called to determine whether a given component @@ -42,6 +45,14 @@ export function setRuntimeConfigProvider( } } +export function setStaticViewConfigPatcher_EXPERIMENTAL( + staticViewConfigPatcher: (name: string, viewConfig: ViewConfig) => ViewConfig, +) { + if (patchStaticViewConfig === defaultStaticViewConfigPatcher) { + patchStaticViewConfig = staticViewConfigPatcher; + } +} + /** * Gets a `NativeComponent` that can be rendered by React Native. * @@ -62,10 +73,10 @@ export function get( if (native) { viewConfig = getNativeComponentAttributes(name) ?? - createViewConfig(viewConfigProvider()); + patchStaticViewConfig(name, createViewConfig(viewConfigProvider())); } else { viewConfig = - createViewConfig(viewConfigProvider()) ?? + patchStaticViewConfig(name, createViewConfig(viewConfigProvider())) ?? getNativeComponentAttributes(name); } @@ -86,7 +97,7 @@ export function get( } const staticViewConfig: ViewConfig = native - ? createViewConfig(viewConfigProvider()) + ? patchStaticViewConfig(name, createViewConfig(viewConfigProvider())) : viewConfig; const validationOutput = StaticViewConfigValidator.validate( diff --git a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap index 5eb59f565101e2..13c39e4b17e499 100644 --- a/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap +++ b/packages/react-native/Libraries/__tests__/__snapshots__/public-api-test.js.snap @@ -6382,6 +6382,9 @@ exports[`public API should not change unintentionally Libraries/NativeComponent/ verify: boolean, } ): void; +declare export function setStaticViewConfigPatcher_DEPRECATED( + staticViewConfigPatcher: (name: string, viewConfig: ViewConfig) => ViewConfig +): void; declare export function get( name: string, viewConfigProvider: () => PartialViewConfig