mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add paperComponentName and paperComponentNameDeprecated
Summary: This diff removes an option from the codegen and replaces it with two new options Removes: - `isDeprecatedPaperComponentNameRCT` Adds: - `paperComponentName`: a better version of the removed option that allows more than just adding RCT - `paperComponentNameDeprecated`: a new option that allows migrating native code to a new name ``` // Use for components with no current paper rename in progress // Does not check for new name paperComponentName?: string, // Use for components currently being renamed in paper // Will use new name if it is available and fallback to this name paperComponentNameDeprecated?: string, ``` For example, Slider uses `paperComponentName: 'RCTSlider'` because it has a different name in fabric but is not currently being migrated to a new name. Because of other work in progress, we don't want to use UIManager check if we don't need to Reviewed By: shergin Differential Revision: D15857629 fbshipit-source-id: ca0d3b7dc4a75e00d136ae1f5c84f7423960399d
This commit is contained in:
committed by
Facebook Github Bot
parent
56f08fcf84
commit
ff5592cff4
@@ -51,5 +51,5 @@ type NativeProps = $ReadOnly<{|
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>('ActivityIndicatorView', {
|
||||
isDeprecatedPaperComponentNameRCT: true,
|
||||
paperComponentName: 'RCTActivityIndicatorView',
|
||||
});
|
||||
|
||||
@@ -17,7 +17,7 @@ const SwitchSchema: SchemaType = {
|
||||
ActivityIndicatorSchema: {
|
||||
components: {
|
||||
ActivityIndicatorView: {
|
||||
isDeprecatedPaperComponentNameRCT: true,
|
||||
paperComponentName: 'RCTActivityIndicatorView',
|
||||
extendsProps: [
|
||||
{
|
||||
type: 'ReactNativeBuiltInType',
|
||||
|
||||
@@ -55,5 +55,5 @@ type NativeProps = $ReadOnly<{|
|
||||
|
||||
export default codegenNativeComponent<NativeProps>('Slider', {
|
||||
interfaceOnly: true,
|
||||
isDeprecatedPaperComponentNameRCT: true,
|
||||
paperComponentName: 'RCTSlider',
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@ const SliderSchema: SchemaType = {
|
||||
components: {
|
||||
Slider: {
|
||||
interfaceOnly: true,
|
||||
isDeprecatedPaperComponentNameRCT: true,
|
||||
paperComponentName: 'RCTSlider',
|
||||
extendsProps: [
|
||||
{
|
||||
type: 'ReactNativeBuiltInType',
|
||||
|
||||
@@ -40,5 +40,5 @@ type NativeProps = $ReadOnly<{|
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<NativeProps>('Switch', {
|
||||
isDeprecatedPaperComponentNameRCT: true,
|
||||
paperComponentName: 'RCTSwitch',
|
||||
});
|
||||
|
||||
@@ -13,20 +13,37 @@
|
||||
|
||||
import type {NativeComponent} from '../../Libraries/Renderer/shims/ReactNative';
|
||||
import requireNativeComponent from '../../Libraries/ReactNative/requireNativeComponent';
|
||||
import {UIManager} from 'react-native';
|
||||
|
||||
// TODO: import from CodegenSchema once workspaces are enabled
|
||||
type Options = $ReadOnly<{|
|
||||
interfaceOnly?: boolean,
|
||||
isDeprecatedPaperComponentNameRCT?: boolean,
|
||||
paperComponentName?: string,
|
||||
paperComponentNameDeprecated?: string,
|
||||
|}>;
|
||||
|
||||
function codegenNativeComponent<Props>(
|
||||
componentName: string,
|
||||
options?: Options,
|
||||
): Class<NativeComponent<Props>> {
|
||||
let componentNameInUse = componentName;
|
||||
if (options && options.isDeprecatedPaperComponentNameRCT === true) {
|
||||
componentNameInUse = `RCT${componentName}`;
|
||||
let componentNameInUse =
|
||||
options && options.paperComponentName
|
||||
? options.paperComponentName
|
||||
: componentName;
|
||||
|
||||
if (options != null && options.paperComponentNameDeprecated != null) {
|
||||
if (UIManager.getViewManagerConfig(componentName)) {
|
||||
componentNameInUse = componentName;
|
||||
} else if (
|
||||
options.paperComponentNameDeprecated != null &&
|
||||
UIManager.getViewManagerConfig(options.paperComponentNameDeprecated)
|
||||
) {
|
||||
componentNameInUse = options.paperComponentNameDeprecated;
|
||||
} else {
|
||||
throw new Error(
|
||||
'Failed to find native component for either "::_COMPONENT_NAME_::" or "::_COMPONENT_NAME_DEPRECATED_::"',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// If this function is run at runtime then that means the view configs were not
|
||||
|
||||
@@ -44,7 +44,7 @@ function registerGeneratedViewConfig(
|
||||
viewConfig: GeneratedViewConfig,
|
||||
) {
|
||||
const mergedViewConfig = {
|
||||
uiViewClassName: viewConfig.uiViewClassName,
|
||||
uiViewClassName: componentName,
|
||||
Commands: {},
|
||||
bubblingEventTypes: {
|
||||
...ReactNativeViewViewConfig.bubblingEventTypes,
|
||||
|
||||
@@ -39,7 +39,7 @@ type ModuleProps = $ReadOnly<{|
|
||||
|
||||
export default codegenNativeComponent<ModuleProps>('Module', {
|
||||
interfaceOnly: true,
|
||||
isDeprecatedPaperComponentNameRCT: true,
|
||||
paperComponentName: 'RCTModule',
|
||||
});
|
||||
`;
|
||||
|
||||
|
||||
+3
-2
@@ -36,9 +36,10 @@ const ModuleViewConfig = {
|
||||
onBubblingEventDefinedInlineNull: true
|
||||
}
|
||||
};
|
||||
registerGeneratedViewConfig('RCTModule', ModuleViewConfig);
|
||||
let nativeComponentName = 'RCTModule';
|
||||
registerGeneratedViewConfig(nativeComponentName, ModuleViewConfig);
|
||||
export const __INTERNAL_VIEW_CONFIG = ModuleViewConfig;
|
||||
export default 'RCTModule'; // RCT prefix present for paper support"
|
||||
export default nativeComponentName;"
|
||||
`;
|
||||
|
||||
exports[`Babel plugin inline view configs can inline config for NotANativeComponent.js 1`] = `
|
||||
|
||||
@@ -18,7 +18,6 @@ function generateViewConfig(filename, code) {
|
||||
const libraryName = path
|
||||
.basename(filename)
|
||||
.replace(/NativeComponent\.js$/, '');
|
||||
|
||||
return RNCodegen.generateViewConfig({
|
||||
schema,
|
||||
libraryName,
|
||||
|
||||
+8
-1
@@ -123,7 +123,14 @@ export type EventTypeShape = $ReadOnly<{|
|
||||
|
||||
export type OptionsShape = $ReadOnly<{|
|
||||
interfaceOnly?: boolean,
|
||||
isDeprecatedPaperComponentNameRCT?: boolean,
|
||||
|
||||
// Use for components with no current paper rename in progress
|
||||
// Does not check for new name
|
||||
paperComponentName?: string,
|
||||
|
||||
// Use for components currently being renamed in paper
|
||||
// Will use new name if it is available and fallback to this name
|
||||
paperComponentNameDeprecated?: string,
|
||||
|}>;
|
||||
|
||||
export type ExtendsPropsShape = $ReadOnly<{|
|
||||
|
||||
@@ -87,11 +87,23 @@ function getReactDiffProcessValue(typeAnnotation) {
|
||||
const componentTemplate = `
|
||||
const ::_COMPONENT_NAME_::ViewConfig = VIEW_CONFIG;
|
||||
|
||||
registerGeneratedViewConfig('::_COMPONENT_NAME_WITH_COMPAT_SUPPORT_::', ::_COMPONENT_NAME_::ViewConfig);
|
||||
let nativeComponentName = '::_COMPONENT_NAME_WITH_COMPAT_SUPPORT_::';
|
||||
::_DEPRECATION_CHECK_::
|
||||
registerGeneratedViewConfig(nativeComponentName, ::_COMPONENT_NAME_::ViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = ::_COMPONENT_NAME_::ViewConfig;
|
||||
|
||||
export default '::_COMPONENT_NAME_WITH_COMPAT_SUPPORT_::';::_COMPAT_COMMENT_::
|
||||
export default nativeComponentName;
|
||||
`.trim();
|
||||
|
||||
const deprecatedComponentTemplate = `
|
||||
if (UIManager.getViewManagerConfig('::_COMPONENT_NAME_::')) {
|
||||
nativeComponentName = '::_COMPONENT_NAME_::';
|
||||
} else if (UIManager.getViewManagerConfig('::_COMPONENT_NAME_DEPRECATED_::')){
|
||||
nativeComponentName = '::_COMPONENT_NAME_DEPRECATED_::';
|
||||
} else {
|
||||
throw new Error('Failed to find native component for either "::_COMPONENT_NAME_::" or "::_COMPONENT_NAME_DEPRECATED_::"')
|
||||
}
|
||||
`.trim();
|
||||
|
||||
// Replicates the behavior of RCTNormalizeInputEventName in RCTEventDispatcher.m
|
||||
@@ -245,22 +257,30 @@ module.exports = {
|
||||
.map(componentName => {
|
||||
const component = components[componentName];
|
||||
|
||||
const compatabilityComponentName = `${
|
||||
component.isDeprecatedPaperComponentNameRCT ? 'RCT' : ''
|
||||
}${componentName}`;
|
||||
const paperComponentName = component.paperComponentName
|
||||
? component.paperComponentName
|
||||
: componentName;
|
||||
|
||||
if (component.paperComponentNameDeprecated) {
|
||||
imports.add('const {UIManager} = require("react-native")');
|
||||
}
|
||||
|
||||
const deprecatedCheckBlock = component.paperComponentNameDeprecated
|
||||
? deprecatedComponentTemplate
|
||||
.replace(/::_COMPONENT_NAME_::/g, componentName)
|
||||
.replace(
|
||||
/::_COMPONENT_NAME_DEPRECATED_::/g,
|
||||
component.paperComponentNameDeprecated || '',
|
||||
)
|
||||
: '';
|
||||
|
||||
const replacedTemplate = componentTemplate
|
||||
.replace(/::_COMPONENT_NAME_::/g, componentName)
|
||||
.replace(
|
||||
/::_COMPONENT_NAME_WITH_COMPAT_SUPPORT_::/g,
|
||||
compatabilityComponentName,
|
||||
paperComponentName,
|
||||
)
|
||||
.replace(
|
||||
/::_COMPAT_COMMENT_::/g,
|
||||
component.isDeprecatedPaperComponentNameRCT
|
||||
? ' // RCT prefix present for paper support'
|
||||
: '',
|
||||
);
|
||||
.replace(/::_DEPRECATION_CHECK_::/, deprecatedCheckBlock);
|
||||
|
||||
const replacedSource: string = j
|
||||
.withParser('flow')(replacedTemplate)
|
||||
@@ -270,7 +290,7 @@ module.exports = {
|
||||
.replaceWith(
|
||||
buildViewConfig(
|
||||
schema,
|
||||
compatabilityComponentName,
|
||||
paperComponentName,
|
||||
component,
|
||||
imports,
|
||||
),
|
||||
|
||||
@@ -18,7 +18,7 @@ const INTERFACE_ONLY: SchemaType = {
|
||||
components: {
|
||||
InterfaceOnlyComponent: {
|
||||
interfaceOnly: true,
|
||||
isDeprecatedPaperComponentNameRCT: true,
|
||||
paperComponentName: 'RCTInterfaceOnlyComponent',
|
||||
extendsProps: [
|
||||
{
|
||||
type: 'ReactNativeBuiltInType',
|
||||
|
||||
+24
@@ -24,4 +24,28 @@ describe('GenerateViewConfigJs', () => {
|
||||
expect(generator.generate(fixtureName, fixture)).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
it('can generate fixture with a deprecated view config name', () => {
|
||||
expect(
|
||||
generator.generate('DEPRECATED_VIEW_CONFIG_NAME', {
|
||||
modules: {
|
||||
Component: {
|
||||
components: {
|
||||
NativeComponentName: {
|
||||
paperComponentNameDeprecated: 'DeprecatedNativeComponentName',
|
||||
extendsProps: [
|
||||
{
|
||||
type: 'ReactNativeBuiltInType',
|
||||
knownTypeName: 'ReactNativeCoreViewProps',
|
||||
},
|
||||
],
|
||||
events: [],
|
||||
props: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
+107
-34
@@ -31,11 +31,13 @@ const ArrayPropsNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('ArrayPropsNativeComponent', ArrayPropsNativeComponentViewConfig);
|
||||
let nativeComponentName = 'ArrayPropsNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, ArrayPropsNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = ArrayPropsNativeComponentViewConfig;
|
||||
|
||||
export default 'ArrayPropsNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -64,11 +66,13 @@ const BooleanPropNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('BooleanPropNativeComponent', BooleanPropNativeComponentViewConfig);
|
||||
let nativeComponentName = 'BooleanPropNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, BooleanPropNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = BooleanPropNativeComponentViewConfig;
|
||||
|
||||
export default 'BooleanPropNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -97,11 +101,13 @@ const ColorPropNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('ColorPropNativeComponent', ColorPropNativeComponentViewConfig);
|
||||
let nativeComponentName = 'ColorPropNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, ColorPropNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = ColorPropNativeComponentViewConfig;
|
||||
|
||||
export default 'ColorPropNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -130,11 +136,13 @@ const EnumPropsNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('EnumPropsNativeComponent', EnumPropsNativeComponentViewConfig);
|
||||
let nativeComponentName = 'EnumPropsNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, EnumPropsNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = EnumPropsNativeComponentViewConfig;
|
||||
|
||||
export default 'EnumPropsNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -173,11 +181,13 @@ const EventsNestedObjectNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('EventsNestedObjectNativeComponent', EventsNestedObjectNativeComponentViewConfig);
|
||||
let nativeComponentName = 'EventsNestedObjectNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, EventsNestedObjectNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = EventsNestedObjectNativeComponentViewConfig;
|
||||
|
||||
export default 'EventsNestedObjectNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -236,11 +246,13 @@ const EventsNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('EventsNativeComponent', EventsNativeComponentViewConfig);
|
||||
let nativeComponentName = 'EventsNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, EventsNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = EventsNativeComponentViewConfig;
|
||||
|
||||
export default 'EventsNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -274,11 +286,13 @@ const FloatPropNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('FloatPropNativeComponent', FloatPropNativeComponentViewConfig);
|
||||
let nativeComponentName = 'FloatPropNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, FloatPropNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = FloatPropNativeComponentViewConfig;
|
||||
|
||||
export default 'FloatPropNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -307,11 +321,13 @@ const ImagePropNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('ImagePropNativeComponent', ImagePropNativeComponentViewConfig);
|
||||
let nativeComponentName = 'ImagePropNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, ImagePropNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = ImagePropNativeComponentViewConfig;
|
||||
|
||||
export default 'ImagePropNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -342,11 +358,13 @@ const IntegerPropNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('IntegerPropNativeComponent', IntegerPropNativeComponentViewConfig);
|
||||
let nativeComponentName = 'IntegerPropNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, IntegerPropNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = IntegerPropNativeComponentViewConfig;
|
||||
|
||||
export default 'IntegerPropNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -385,11 +403,13 @@ const InterfaceOnlyComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('RCTInterfaceOnlyComponent', InterfaceOnlyComponentViewConfig);
|
||||
let nativeComponentName = 'RCTInterfaceOnlyComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, InterfaceOnlyComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = InterfaceOnlyComponentViewConfig;
|
||||
|
||||
export default 'RCTInterfaceOnlyComponent'; // RCT prefix present for paper support
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -421,11 +441,13 @@ const ImageColorPropNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('ImageColorPropNativeComponent', ImageColorPropNativeComponentViewConfig);
|
||||
let nativeComponentName = 'ImageColorPropNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, ImageColorPropNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = ImageColorPropNativeComponentViewConfig;
|
||||
|
||||
export default 'ImageColorPropNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -454,11 +476,13 @@ const PointPropNativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('PointPropNativeComponent', PointPropNativeComponentViewConfig);
|
||||
let nativeComponentName = 'PointPropNativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, PointPropNativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = PointPropNativeComponentViewConfig;
|
||||
|
||||
export default 'PointPropNativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -488,11 +512,13 @@ const StringPropComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('StringPropComponent', StringPropComponentViewConfig);
|
||||
let nativeComponentName = 'StringPropComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, StringPropComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = StringPropComponentViewConfig;
|
||||
|
||||
export default 'StringPropComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -521,11 +547,13 @@ const MultiFile1NativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('MultiFile1NativeComponent', MultiFile1NativeComponentViewConfig);
|
||||
let nativeComponentName = 'MultiFile1NativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, MultiFile1NativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = MultiFile1NativeComponentViewConfig;
|
||||
|
||||
export default 'MultiFile1NativeComponent';
|
||||
export default nativeComponentName;
|
||||
|
||||
const MultiFile2NativeComponentViewConfig = {
|
||||
uiViewClassName: 'MultiFile2NativeComponent',
|
||||
@@ -535,11 +563,13 @@ const MultiFile2NativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('MultiFile2NativeComponent', MultiFile2NativeComponentViewConfig);
|
||||
let nativeComponentName = 'MultiFile2NativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, MultiFile2NativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = MultiFile2NativeComponentViewConfig;
|
||||
|
||||
export default 'MultiFile2NativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
@@ -568,11 +598,13 @@ const MultiComponent1NativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('MultiComponent1NativeComponent', MultiComponent1NativeComponentViewConfig);
|
||||
let nativeComponentName = 'MultiComponent1NativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, MultiComponent1NativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = MultiComponent1NativeComponentViewConfig;
|
||||
|
||||
export default 'MultiComponent1NativeComponent';
|
||||
export default nativeComponentName;
|
||||
|
||||
const MultiComponent2NativeComponentViewConfig = {
|
||||
uiViewClassName: 'MultiComponent2NativeComponent',
|
||||
@@ -582,11 +614,52 @@ const MultiComponent2NativeComponentViewConfig = {
|
||||
},
|
||||
};
|
||||
|
||||
registerGeneratedViewConfig('MultiComponent2NativeComponent', MultiComponent2NativeComponentViewConfig);
|
||||
let nativeComponentName = 'MultiComponent2NativeComponent';
|
||||
|
||||
registerGeneratedViewConfig(nativeComponentName, MultiComponent2NativeComponentViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = MultiComponent2NativeComponentViewConfig;
|
||||
|
||||
export default 'MultiComponent2NativeComponent';
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GenerateViewConfigJs can generate fixture with a deprecated view config name 1`] = `
|
||||
Map {
|
||||
"DEPRECATED_VIEW_CONFIG_NAMENativeViewConfig.js" => "
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const registerGeneratedViewConfig = require('registerGeneratedViewConfig');
|
||||
const {UIManager} = require(\\"react-native\\")
|
||||
|
||||
const NativeComponentNameViewConfig = {
|
||||
uiViewClassName: 'NativeComponentName',
|
||||
validAttributes: {},
|
||||
};
|
||||
|
||||
let nativeComponentName = 'NativeComponentName';
|
||||
if (UIManager.getViewManagerConfig('NativeComponentName')) {
|
||||
nativeComponentName = 'NativeComponentName';
|
||||
} else if (UIManager.getViewManagerConfig('DeprecatedNativeComponentName')){
|
||||
nativeComponentName = 'DeprecatedNativeComponentName';
|
||||
} else {
|
||||
throw new Error('Failed to find native component for either \\"NativeComponentName\\" or \\"DeprecatedNativeComponentName\\"')
|
||||
}
|
||||
registerGeneratedViewConfig(nativeComponentName, NativeComponentNameViewConfig);
|
||||
|
||||
export const __INTERNAL_VIEW_CONFIG = NativeComponentNameViewConfig;
|
||||
|
||||
export default nativeComponentName;
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
+28
-1
@@ -97,7 +97,33 @@ type ModuleProps = $ReadOnly<{|
|
||||
|
||||
export default codegenNativeComponent<ModuleProps>('Module', {
|
||||
interfaceOnly: true,
|
||||
isDeprecatedPaperComponentNameRCT: true,
|
||||
paperComponentName: 'RCTModule',
|
||||
});
|
||||
`;
|
||||
|
||||
const NO_PROPS_EVENTS_ONLY_DEPRECATED_VIEW_CONFIG_NAME_OPTION = `
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const codegenNativeComponent = require('codegenNativeComponent');
|
||||
|
||||
import type {ViewProps} from 'ViewPropTypes';
|
||||
|
||||
type ModuleProps = $ReadOnly<{|
|
||||
...ViewProps,
|
||||
|}>;
|
||||
|
||||
export default codegenNativeComponent<ModuleProps>('Module', {
|
||||
deprecatedViewConfigName: 'DeprecateModuleName',
|
||||
});
|
||||
`;
|
||||
|
||||
@@ -599,6 +625,7 @@ module.exports = {
|
||||
ALL_PROP_TYPES_NO_EVENTS,
|
||||
ARRAY_PROP_TYPES_NO_EVENTS,
|
||||
ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS,
|
||||
NO_PROPS_EVENTS_ONLY_DEPRECATED_VIEW_CONFIG_NAME_OPTION,
|
||||
EVENTS_DEFINED_INLINE_WITH_ALL_TYPES,
|
||||
EVENTS_DEFINED_IN_FILE_WITH_ALL_TYPES,
|
||||
EVENTS_DEFINED_AS_NULL_IN_FILE,
|
||||
|
||||
+23
-1
@@ -4744,6 +4744,28 @@ Object {
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`RN Codegen Flow Parser can generate fixture NO_PROPS_EVENTS_ONLY_DEPRECATED_VIEW_CONFIG_NAME_OPTION 1`] = `
|
||||
Object {
|
||||
"modules": Object {
|
||||
"Module": Object {
|
||||
"components": Object {
|
||||
"Module": Object {
|
||||
"deprecatedViewConfigName": "DeprecateModuleName",
|
||||
"events": Array [],
|
||||
"extendsProps": Array [
|
||||
Object {
|
||||
"knownTypeName": "ReactNativeCoreViewProps",
|
||||
"type": "ReactNativeBuiltInType",
|
||||
},
|
||||
],
|
||||
"props": Array [],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`RN Codegen Flow Parser can generate fixture ONE_OF_EACH_PROP_EVENT_DEFAULT_AND_OPTIONS 1`] = `
|
||||
Object {
|
||||
"modules": Object {
|
||||
@@ -4783,7 +4805,7 @@ Object {
|
||||
},
|
||||
],
|
||||
"interfaceOnly": true,
|
||||
"isDeprecatedPaperComponentNameRCT": true,
|
||||
"paperComponentName": "RCTModule",
|
||||
"props": Array [
|
||||
Object {
|
||||
"name": "boolean_default_true_optional_both",
|
||||
|
||||
+13
-1
@@ -19,8 +19,9 @@ function getOptions(optionsExpression: OptionsAST): ?OptionsShape {
|
||||
if (!optionsExpression) {
|
||||
return null;
|
||||
}
|
||||
let foundOptions;
|
||||
try {
|
||||
return optionsExpression.properties.reduce((options, prop) => {
|
||||
foundOptions = optionsExpression.properties.reduce((options, prop) => {
|
||||
options[prop.key.name] = prop.value.value;
|
||||
return options;
|
||||
}, {});
|
||||
@@ -29,6 +30,17 @@ function getOptions(optionsExpression: OptionsAST): ?OptionsShape {
|
||||
'Failed to parse codegen options, please check that they are defined correctly',
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
foundOptions.paperComponentName &&
|
||||
foundOptions.paperComponentNameDeprecated
|
||||
) {
|
||||
throw new Error(
|
||||
'Failed to parse codegen options, cannot use both paperComponentName and paperComponentNameDeprecated',
|
||||
);
|
||||
}
|
||||
|
||||
return foundOptions;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user