From 657f80ecffd78e0a2e68331ee5b92c66545fff23 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Fri, 23 Aug 2024 14:24:37 -0700 Subject: [PATCH] Allow apps to correct static view configs locally Summary: Right now, some third-party libraries may have invalid static view configs. (The infra is still experimental). And those validation warnings will block bridgeless adoption. It can take a long time to update those libraries. So, this diff introduces a deprecated api to NativeComponentRegistry that allows apps to override static view configs locally, to unblock bridgeless adoption. Changelog: [General][Added] Introduce deprecated svc api to unblock bridgeless adoption Differential Revision: D61717019 --- .../NativeComponentRegistry.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js b/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js index 68695660da1312..c568516d234e42 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 defaultStaticViewConfigModifier = (name: string, viewConfig: ViewConfig) => + viewConfig; +let modifyStaticViewConfig = defaultStaticViewConfigModifier; /** * Configures a function that is called to determine whether a given component @@ -42,6 +45,17 @@ export function setRuntimeConfigProvider( } } +export function setStaticViewConfigModifier_DEPRECATED( + staticViewConfigModifier: ( + name: string, + viewConfig: ViewConfig, + ) => ViewConfig, +) { + if (modifyStaticViewConfig === defaultStaticViewConfigModifier) { + modifyStaticViewConfig = staticViewConfigModifier; + } +} + /** * Gets a `NativeComponent` that can be rendered by React Native. * @@ -62,10 +76,10 @@ export function get( if (native) { viewConfig = getNativeComponentAttributes(name) ?? - createViewConfig(viewConfigProvider()); + modifyStaticViewConfig(name, createViewConfig(viewConfigProvider())); } else { viewConfig = - createViewConfig(viewConfigProvider()) ?? + modifyStaticViewConfig(name, createViewConfig(viewConfigProvider())) ?? getNativeComponentAttributes(name); } @@ -86,7 +100,7 @@ export function get( } const staticViewConfig: ViewConfig = native - ? createViewConfig(viewConfigProvider()) + ? modifyStaticViewConfig(name, createViewConfig(viewConfigProvider())) : viewConfig; const validationOutput = StaticViewConfigValidator.validate(