Files
react-native/Libraries/Utilities/registerGeneratedViewConfig.js
T
Tim Yung 69b4611049 RN: Hoist Reflection from Verification
Summary:
Hoists the call to `getNativeComponentAttributes` out of the verification function so that it's easier to keep track of when this function is and is not called.

The purpose of this will become clearer in a future refactor.

Changelog:
[Internal]

Reviewed By: ejanzer

Differential Revision: D25072600

fbshipit-source-id: bc42461baae3476fa7ecb6186c4256dd23921ed5
2020-11-18 21:19:12 -08:00

89 lines
2.6 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
import ReactNativeViewConfigRegistry from '../Renderer/shims/ReactNativeViewConfigRegistry';
import ReactNativeViewViewConfig from '../Components/View/ReactNativeViewViewConfig';
import getNativeComponentAttributes from '../ReactNative/getNativeComponentAttributes';
import verifyComponentAttributeEquivalence from './verifyComponentAttributeEquivalence';
export type GeneratedViewConfig = {
uiViewClassName: string,
bubblingEventTypes?: $ReadOnly<{
[eventName: string]: $ReadOnly<{|
phasedRegistrationNames: $ReadOnly<{|
captured: string,
bubbled: string,
|}>,
|}>,
...,
}>,
directEventTypes?: $ReadOnly<{
[eventName: string]: $ReadOnly<{|
registrationName: string,
|}>,
...,
}>,
validAttributes?: {
[propName: string]:
| true
| $ReadOnly<{|
diff?: <T>(arg1: any, arg2: any) => boolean,
process?: (arg1: any) => any,
|}>,
...,
},
...
};
function registerGeneratedViewConfig(
componentName: string,
viewConfig: GeneratedViewConfig,
) {
const staticViewConfig = {
uiViewClassName: componentName,
Commands: {},
/* $FlowFixMe(>=0.122.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.122.0 was deployed. To see the error, delete
* this comment and run Flow. */
bubblingEventTypes: {
...ReactNativeViewViewConfig.bubblingEventTypes,
...(viewConfig.bubblingEventTypes || {}),
},
/* $FlowFixMe(>=0.122.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.122.0 was deployed. To see the error, delete
* this comment and run Flow. */
directEventTypes: {
...ReactNativeViewViewConfig.directEventTypes,
...(viewConfig.directEventTypes || {}),
},
/* $FlowFixMe(>=0.122.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.122.0 was deployed. To see the error, delete
* this comment and run Flow. */
validAttributes: {
...ReactNativeViewViewConfig.validAttributes,
...(viewConfig.validAttributes || {}),
},
};
ReactNativeViewConfigRegistry.register(componentName, () => {
if (!global.RN$Bridgeless) {
const nativeViewConfig = getNativeComponentAttributes(componentName);
verifyComponentAttributeEquivalence(nativeViewConfig, staticViewConfig);
}
return staticViewConfig;
});
}
module.exports = registerGeneratedViewConfig;