Skip to content

Commit

Permalink
2/4 Fix RNHostListComponentListRoute to validate SVCs with NVCs
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D33715385

fbshipit-source-id: d8d31e92dd934648f8431a508a78e2813c462f8f
  • Loading branch information
p-sun authored and facebook-github-bot committed Jan 25, 2022
1 parent 4f1f42b commit 6360532
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 95 deletions.
39 changes: 39 additions & 0 deletions Libraries/NativeComponent/StaticViewConfigValidator.js
Expand Up @@ -9,6 +9,10 @@
*/

import {type ViewConfig} from '../Renderer/shims/ReactNativeTypes';
// $FlowFixMe[nonstrict-import]
import getNativeComponentAttributes from '../ReactNative/getNativeComponentAttributes';
// $FlowFixMe[nonstrict-import]
import {createViewConfig} from './ViewConfig';

type Difference =
| {
Expand Down Expand Up @@ -37,6 +41,41 @@ type InvalidResult = {
differences: Array<Difference>,
};

type ViewConfigValidationResult = {
componentName: string,
nativeViewConfig?: ?ViewConfig,
staticViewConfig?: ?ViewConfig,
validationResult?: ?ValidationResult,
};

// e.g. require('MyNativeComponent') where MyNativeComponent.js exports a HostComponent
type JSModule = $FlowFixMe;

export function validateStaticViewConfigs(
nativeComponent: JSModule,
): ViewConfigValidationResult {
const nativeViewConfig = getNativeComponentAttributes(
nativeComponent.default || nativeComponent,
);

const generatedPartialViewConfig = nativeComponent.__INTERNAL_VIEW_CONFIG;
const staticViewConfig: ?ViewConfig =
generatedPartialViewConfig && createViewConfig(generatedPartialViewConfig);

const componentName: string = nativeComponent.default || nativeComponent;
const validationResult: ?ValidationResult =
nativeViewConfig &&
staticViewConfig &&
validate(componentName, nativeViewConfig, staticViewConfig);

return {
componentName,
nativeViewConfig,
staticViewConfig,
validationResult,
};
}

/**
* During the migration from native view configs to static view configs, this is
* used to validate that the two are equivalent.
Expand Down
Expand Up @@ -29,7 +29,7 @@ const {
} = require(\\"react-native/Libraries/Renderer/shims/ReactNative\\");
let nativeComponentName = 'RCTModule';
export default NativeComponentRegistry.get(nativeComponentName, () => ({
export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: 'RCTModule',
bubblingEventTypes: {
topBubblingEventDefinedInlineNull: {
Expand All @@ -47,7 +47,8 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
boolean_default_true_optional_both: true
}
}));
};
export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG);
export const Commands = {
hotspotUpdate(ref, x, y) {
dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]);
Expand Down Expand Up @@ -89,7 +90,7 @@ const {
} = require(\\"react-native/Libraries/Renderer/shims/ReactNative\\");
let nativeComponentName = 'RCTModule';
export default NativeComponentRegistry.get(nativeComponentName, () => ({
export const __INTERNAL_VIEW_CONFIG = {
uiViewClassName: 'RCTModule',
bubblingEventTypes: {
topBubblingEventDefinedInlineNull: {
Expand All @@ -107,7 +108,8 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
validAttributes: {
boolean_default_true_optional_both: true
}
}));
};
export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG);
export const Commands = {
hotspotUpdate(ref, x, y) {
dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]);
Expand Down

0 comments on commit 6360532

Please sign in to comment.