Skip to content

Commit

Permalink
Allow apps to correct 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

Differential Revision: D61717019
  • Loading branch information
RSNara authored and facebook-github-bot committed Aug 23, 2024
1 parent 8d3c4fb commit 657f80e
Showing 1 changed file 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 defaultStaticViewConfigModifier = (name: string, viewConfig: ViewConfig) =>
viewConfig;
let modifyStaticViewConfig = defaultStaticViewConfigModifier;

/**
* Configures a function that is called to determine whether a given component
Expand All @@ -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.
*
Expand All @@ -62,10 +76,10 @@ export function get<Config>(
if (native) {
viewConfig =
getNativeComponentAttributes(name) ??
createViewConfig(viewConfigProvider());
modifyStaticViewConfig(name, createViewConfig(viewConfigProvider()));
} else {
viewConfig =
createViewConfig(viewConfigProvider()) ??
modifyStaticViewConfig(name, createViewConfig(viewConfigProvider())) ??
getNativeComponentAttributes(name);
}

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

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

const validationOutput = StaticViewConfigValidator.validate(
Expand Down

0 comments on commit 657f80e

Please sign in to comment.