Skip to content

Commit

Permalink
Allow apps to patch static view configs locally
Browse files Browse the repository at this point in the history
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

Reviewed By: javache

Differential Revision: D61717019
  • Loading branch information
RSNara authored and facebook-github-bot committed Sep 5, 2024
1 parent b371014 commit 5e5a31e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
*
Expand All @@ -62,10 +73,10 @@ export function get<Config>(
if (native) {
viewConfig =
getNativeComponentAttributes(name) ??
createViewConfig(viewConfigProvider());
patchStaticViewConfig(name, createViewConfig(viewConfigProvider()));
} else {
viewConfig =
createViewConfig(viewConfigProvider()) ??
patchStaticViewConfig(name, createViewConfig(viewConfigProvider())) ??
getNativeComponentAttributes(name);
}

Expand All @@ -86,7 +97,7 @@ export function get<Config>(
}

const staticViewConfig: ViewConfig = native
? createViewConfig(viewConfigProvider())
? patchStaticViewConfig(name, createViewConfig(viewConfigProvider()))
: viewConfig;

const validationOutput = StaticViewConfigValidator.validate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Config>(
name: string,
viewConfigProvider: () => PartialViewConfig
Expand Down

0 comments on commit 5e5a31e

Please sign in to comment.