diff --git a/Libraries/Components/ActivityIndicator/ActivityIndicatorViewNativeComponent.js b/Libraries/Components/ActivityIndicator/ActivityIndicatorViewNativeComponent.js index 8781a230d4d..9cdb6f027e4 100644 --- a/Libraries/Components/ActivityIndicator/ActivityIndicatorViewNativeComponent.js +++ b/Libraries/Components/ActivityIndicator/ActivityIndicatorViewNativeComponent.js @@ -51,5 +51,5 @@ type NativeProps = $ReadOnly<{| |}>; export default codegenNativeComponent('ActivityIndicatorView', { - isDeprecatedPaperComponentNameRCT: true, + paperComponentName: 'RCTActivityIndicatorView', }); diff --git a/Libraries/Components/ActivityIndicator/ActivityIndicatorViewSchema.js b/Libraries/Components/ActivityIndicator/ActivityIndicatorViewSchema.js index d45f7590721..dba8225c903 100644 --- a/Libraries/Components/ActivityIndicator/ActivityIndicatorViewSchema.js +++ b/Libraries/Components/ActivityIndicator/ActivityIndicatorViewSchema.js @@ -17,7 +17,7 @@ const SwitchSchema: SchemaType = { ActivityIndicatorSchema: { components: { ActivityIndicatorView: { - isDeprecatedPaperComponentNameRCT: true, + paperComponentName: 'RCTActivityIndicatorView', extendsProps: [ { type: 'ReactNativeBuiltInType', diff --git a/Libraries/Components/Slider/SliderNativeComponent.js b/Libraries/Components/Slider/SliderNativeComponent.js index 4bfb5355abc..21f75f7dee9 100644 --- a/Libraries/Components/Slider/SliderNativeComponent.js +++ b/Libraries/Components/Slider/SliderNativeComponent.js @@ -55,5 +55,5 @@ type NativeProps = $ReadOnly<{| export default codegenNativeComponent('Slider', { interfaceOnly: true, - isDeprecatedPaperComponentNameRCT: true, + paperComponentName: 'RCTSlider', }); diff --git a/Libraries/Components/Slider/SliderSchema.js b/Libraries/Components/Slider/SliderSchema.js index 32d954ca9cc..423868e432d 100644 --- a/Libraries/Components/Slider/SliderSchema.js +++ b/Libraries/Components/Slider/SliderSchema.js @@ -18,7 +18,7 @@ const SliderSchema: SchemaType = { components: { Slider: { interfaceOnly: true, - isDeprecatedPaperComponentNameRCT: true, + paperComponentName: 'RCTSlider', extendsProps: [ { type: 'ReactNativeBuiltInType', diff --git a/Libraries/Components/Switch/SwitchNativeComponent.js b/Libraries/Components/Switch/SwitchNativeComponent.js index fe95c8237cb..cfb177aa481 100644 --- a/Libraries/Components/Switch/SwitchNativeComponent.js +++ b/Libraries/Components/Switch/SwitchNativeComponent.js @@ -40,5 +40,5 @@ type NativeProps = $ReadOnly<{| |}>; export default codegenNativeComponent('Switch', { - isDeprecatedPaperComponentNameRCT: true, + paperComponentName: 'RCTSwitch', }); diff --git a/Libraries/Utilities/codegenNativeComponent.js b/Libraries/Utilities/codegenNativeComponent.js index ad55cc84354..c38393b58af 100644 --- a/Libraries/Utilities/codegenNativeComponent.js +++ b/Libraries/Utilities/codegenNativeComponent.js @@ -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( componentName: string, options?: Options, ): Class> { - 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 diff --git a/Libraries/Utilities/registerGeneratedViewConfig.js b/Libraries/Utilities/registerGeneratedViewConfig.js index d0d5e7e1856..45f92adb3ce 100644 --- a/Libraries/Utilities/registerGeneratedViewConfig.js +++ b/Libraries/Utilities/registerGeneratedViewConfig.js @@ -44,7 +44,7 @@ function registerGeneratedViewConfig( viewConfig: GeneratedViewConfig, ) { const mergedViewConfig = { - uiViewClassName: viewConfig.uiViewClassName, + uiViewClassName: componentName, Commands: {}, bubblingEventTypes: { ...ReactNativeViewViewConfig.bubblingEventTypes, diff --git a/packages/babel-plugin-inline-view-configs/__test_fixtures__/fixtures.js b/packages/babel-plugin-inline-view-configs/__test_fixtures__/fixtures.js index 1a26fc15aef..b13aaa30a44 100644 --- a/packages/babel-plugin-inline-view-configs/__test_fixtures__/fixtures.js +++ b/packages/babel-plugin-inline-view-configs/__test_fixtures__/fixtures.js @@ -39,7 +39,7 @@ type ModuleProps = $ReadOnly<{| export default codegenNativeComponent('Module', { interfaceOnly: true, - isDeprecatedPaperComponentNameRCT: true, + paperComponentName: 'RCTModule', }); `; diff --git a/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap b/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap index eb655bb64a3..4ea15951844 100644 --- a/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap +++ b/packages/babel-plugin-inline-view-configs/__tests__/__snapshots__/index-test.js.snap @@ -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`] = ` diff --git a/packages/babel-plugin-inline-view-configs/index.js b/packages/babel-plugin-inline-view-configs/index.js index c7ea03798d9..992406c7eb3 100644 --- a/packages/babel-plugin-inline-view-configs/index.js +++ b/packages/babel-plugin-inline-view-configs/index.js @@ -18,7 +18,6 @@ function generateViewConfig(filename, code) { const libraryName = path .basename(filename) .replace(/NativeComponent\.js$/, ''); - return RNCodegen.generateViewConfig({ schema, libraryName, diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 60eccbc0149..7be78d78725 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -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<{| diff --git a/packages/react-native-codegen/src/generators/GenerateViewConfigJs.js b/packages/react-native-codegen/src/generators/GenerateViewConfigJs.js index 47e26446705..fa07f190ce8 100644 --- a/packages/react-native-codegen/src/generators/GenerateViewConfigJs.js +++ b/packages/react-native-codegen/src/generators/GenerateViewConfigJs.js @@ -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, ), diff --git a/packages/react-native-codegen/src/generators/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/generators/__test_fixtures__/fixtures.js index 60d0b93f517..28c4727090d 100644 --- a/packages/react-native-codegen/src/generators/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/generators/__test_fixtures__/fixtures.js @@ -18,7 +18,7 @@ const INTERFACE_ONLY: SchemaType = { components: { InterfaceOnlyComponent: { interfaceOnly: true, - isDeprecatedPaperComponentNameRCT: true, + paperComponentName: 'RCTInterfaceOnlyComponent', extendsProps: [ { type: 'ReactNativeBuiltInType', diff --git a/packages/react-native-codegen/src/generators/__tests__/GenerateViewConfigJs-test.js b/packages/react-native-codegen/src/generators/__tests__/GenerateViewConfigJs-test.js index 22fe2c7d3c9..e9bc944d453 100644 --- a/packages/react-native-codegen/src/generators/__tests__/GenerateViewConfigJs-test.js +++ b/packages/react-native-codegen/src/generators/__tests__/GenerateViewConfigJs-test.js @@ -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(); + }); }); diff --git a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap index 5edc66981b4..ebfce34d8ad 100644 --- a/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap +++ b/packages/react-native-codegen/src/generators/__tests__/__snapshots__/GenerateViewConfigJs-test.js.snap @@ -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; ", } `; diff --git a/packages/react-native-codegen/src/parsers/flow/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/parsers/flow/__test_fixtures__/fixtures.js index e5fec940091..eced8746b7f 100644 --- a/packages/react-native-codegen/src/parsers/flow/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/parsers/flow/__test_fixtures__/fixtures.js @@ -97,7 +97,33 @@ type ModuleProps = $ReadOnly<{| export default codegenNativeComponent('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('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, diff --git a/packages/react-native-codegen/src/parsers/flow/__tests__/__snapshots__/parser-test.js.snap b/packages/react-native-codegen/src/parsers/flow/__tests__/__snapshots__/parser-test.js.snap index 4c1195454ab..7919d2ffb82 100644 --- a/packages/react-native-codegen/src/parsers/flow/__tests__/__snapshots__/parser-test.js.snap +++ b/packages/react-native-codegen/src/parsers/flow/__tests__/__snapshots__/parser-test.js.snap @@ -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", diff --git a/packages/react-native-codegen/src/parsers/flow/options.js b/packages/react-native-codegen/src/parsers/flow/options.js index 1b42e25fa38..29613ea5e0e 100644 --- a/packages/react-native-codegen/src/parsers/flow/options.js +++ b/packages/react-native-codegen/src/parsers/flow/options.js @@ -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 = {