Skip to content

Commit 6360532

Browse files
p-sunfacebook-github-bot
authored andcommitted
2/4 Fix RNHostListComponentListRoute to validate SVCs with NVCs
Summary: Changelog: [Internal] Reviewed By: RSNara Differential Revision: D33715385 fbshipit-source-id: d8d31e92dd934648f8431a508a78e2813c462f8f
1 parent 4f1f42b commit 6360532

File tree

5 files changed

+274
-95
lines changed

5 files changed

+274
-95
lines changed

Libraries/NativeComponent/StaticViewConfigValidator.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
*/
1010

1111
import {type ViewConfig} from '../Renderer/shims/ReactNativeTypes';
12+
// $FlowFixMe[nonstrict-import]
13+
import getNativeComponentAttributes from '../ReactNative/getNativeComponentAttributes';
14+
// $FlowFixMe[nonstrict-import]
15+
import {createViewConfig} from './ViewConfig';
1216

1317
type Difference =
1418
| {
@@ -37,6 +41,41 @@ type InvalidResult = {
3741
differences: Array<Difference>,
3842
};
3943

44+
type ViewConfigValidationResult = {
45+
componentName: string,
46+
nativeViewConfig?: ?ViewConfig,
47+
staticViewConfig?: ?ViewConfig,
48+
validationResult?: ?ValidationResult,
49+
};
50+
51+
// e.g. require('MyNativeComponent') where MyNativeComponent.js exports a HostComponent
52+
type JSModule = $FlowFixMe;
53+
54+
export function validateStaticViewConfigs(
55+
nativeComponent: JSModule,
56+
): ViewConfigValidationResult {
57+
const nativeViewConfig = getNativeComponentAttributes(
58+
nativeComponent.default || nativeComponent,
59+
);
60+
61+
const generatedPartialViewConfig = nativeComponent.__INTERNAL_VIEW_CONFIG;
62+
const staticViewConfig: ?ViewConfig =
63+
generatedPartialViewConfig && createViewConfig(generatedPartialViewConfig);
64+
65+
const componentName: string = nativeComponent.default || nativeComponent;
66+
const validationResult: ?ValidationResult =
67+
nativeViewConfig &&
68+
staticViewConfig &&
69+
validate(componentName, nativeViewConfig, staticViewConfig);
70+
71+
return {
72+
componentName,
73+
nativeViewConfig,
74+
staticViewConfig,
75+
validationResult,
76+
};
77+
}
78+
4079
/**
4180
* During the migration from native view configs to static view configs, this is
4281
* used to validate that the two are equivalent.

packages/babel-plugin-codegen/__tests__/__snapshots__/index-test.js.snap

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const {
2929
} = require(\\"react-native/Libraries/Renderer/shims/ReactNative\\");
3030
3131
let nativeComponentName = 'RCTModule';
32-
export default NativeComponentRegistry.get(nativeComponentName, () => ({
32+
export const __INTERNAL_VIEW_CONFIG = {
3333
uiViewClassName: 'RCTModule',
3434
bubblingEventTypes: {
3535
topBubblingEventDefinedInlineNull: {
@@ -47,7 +47,8 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
4747
validAttributes: {
4848
boolean_default_true_optional_both: true
4949
}
50-
}));
50+
};
51+
export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG);
5152
export const Commands = {
5253
hotspotUpdate(ref, x, y) {
5354
dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]);
@@ -89,7 +90,7 @@ const {
8990
} = require(\\"react-native/Libraries/Renderer/shims/ReactNative\\");
9091
9192
let nativeComponentName = 'RCTModule';
92-
export default NativeComponentRegistry.get(nativeComponentName, () => ({
93+
export const __INTERNAL_VIEW_CONFIG = {
9394
uiViewClassName: 'RCTModule',
9495
bubblingEventTypes: {
9596
topBubblingEventDefinedInlineNull: {
@@ -107,7 +108,8 @@ export default NativeComponentRegistry.get(nativeComponentName, () => ({
107108
validAttributes: {
108109
boolean_default_true_optional_both: true
109110
}
110-
}));
111+
};
112+
export default NativeComponentRegistry.get(nativeComponentName, () => __INTERNAL_VIEW_CONFIG);
111113
export const Commands = {
112114
hotspotUpdate(ref, x, y) {
113115
dispatchCommand(ref, \\"hotspotUpdate\\", [x, y]);

0 commit comments

Comments
 (0)