From 729f1d139579c94e7c54bbd71543dffd1c5d164c Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 21 Sep 2022 10:54:37 -0700 Subject: [PATCH 1/3] Always generate the EventEmitters (#34750) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/34750 This Diff is the first step of enabling the CodeGen to parse and generate a NativeState for the components. The feature has been largely requested by the OSS community but it could be also helpful for people in Meta. To allow the generation of custom `NativeState`, we first have to always generate a `ViewEventEmitter`: that's because the `ConcreteShadowNode` template lists the Generics with this order: `Name`, `Props`, `EventEmitter`, Others... If we skip the `EventEmitters` and we put the `State`, React Native would think that the State is actually an `EventEmitter` and the build step will fail. ## Changelog [General][Added] - Always generate a ViewEventEmitter for Fabric Components Differential Revision: https://internalfb.com/D39509869 fbshipit-source-id: db5a466e7c810f0949631759dae67468f4cfe364 --- .../GenerateEventEmitterH-test.js.snap | 91 +++++++++ .../GenerateShadowNodeH-test.js.snap | 57 ++++-- .../components/GenerateEventEmitterH.js | 4 +- .../components/GenerateShadowNodeH.js | 14 +- .../GenerateEventEmitterH-test.js.snap | 185 ++++++++++++++++++ .../GenerateShadowNodeH-test.js.snap | 107 +++++++--- packages/rn-tester/Podfile.lock | 2 +- 7 files changed, 401 insertions(+), 59 deletions(-) diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap index 8ea473f15a6833..e7be3226bd8ca3 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap @@ -19,7 +19,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT ArrayPropsNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -46,7 +53,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT BooleanPropNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -73,7 +87,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT ColorPropNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -100,7 +121,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT EdgeInsetsPropNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -127,7 +155,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT EnumPropNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -281,7 +316,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT FloatPropsNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -308,7 +350,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT ImagePropNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -335,7 +384,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT IntegerPropNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -398,7 +454,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT MultiNativePropNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -425,7 +488,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT NoPropsNoEventsNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -452,7 +522,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT ObjectPropsNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -479,7 +556,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT PointPropNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -506,7 +590,14 @@ Object { namespace facebook { namespace react { +class JSI_EXPORT StringPropNativeComponentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap index 84724fbf4bd807..ae85fd7b694fda 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap @@ -14,6 +14,7 @@ Object { #pragma once +#include #include #include #include @@ -28,7 +29,8 @@ JSI_EXPORT extern const char ArrayPropsNativeComponentViewComponentName[]; */ using ArrayPropsNativeComponentViewShadowNode = ConcreteViewShadowNode< ArrayPropsNativeComponentViewComponentName, - ArrayPropsNativeComponentViewProps>; + ArrayPropsNativeComponentViewProps, + ArrayPropsNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -50,6 +52,7 @@ Object { #pragma once +#include #include #include #include @@ -64,7 +67,8 @@ JSI_EXPORT extern const char BooleanPropNativeComponentViewComponentName[]; */ using BooleanPropNativeComponentViewShadowNode = ConcreteViewShadowNode< BooleanPropNativeComponentViewComponentName, - BooleanPropNativeComponentViewProps>; + BooleanPropNativeComponentViewProps, + BooleanPropNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -86,6 +90,7 @@ Object { #pragma once +#include #include #include #include @@ -100,7 +105,8 @@ JSI_EXPORT extern const char ColorPropNativeComponentViewComponentName[]; */ using ColorPropNativeComponentViewShadowNode = ConcreteViewShadowNode< ColorPropNativeComponentViewComponentName, - ColorPropNativeComponentViewProps>; + ColorPropNativeComponentViewProps, + ColorPropNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -122,6 +128,7 @@ Object { #pragma once +#include #include #include #include @@ -136,7 +143,8 @@ JSI_EXPORT extern const char EdgeInsetsPropNativeComponentViewComponentName[]; */ using EdgeInsetsPropNativeComponentViewShadowNode = ConcreteViewShadowNode< EdgeInsetsPropNativeComponentViewComponentName, - EdgeInsetsPropNativeComponentViewProps>; + EdgeInsetsPropNativeComponentViewProps, + EdgeInsetsPropNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -158,6 +166,7 @@ Object { #pragma once +#include #include #include #include @@ -172,7 +181,8 @@ JSI_EXPORT extern const char EnumPropNativeComponentViewComponentName[]; */ using EnumPropNativeComponentViewShadowNode = ConcreteViewShadowNode< EnumPropNativeComponentViewComponentName, - EnumPropNativeComponentViewProps>; + EnumPropNativeComponentViewProps, + EnumPropNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -210,7 +220,7 @@ JSI_EXPORT extern const char EventNestedObjectPropsNativeComponentViewComponentN using EventNestedObjectPropsNativeComponentViewShadowNode = ConcreteViewShadowNode< EventNestedObjectPropsNativeComponentViewComponentName, EventNestedObjectPropsNativeComponentViewProps, -EventNestedObjectPropsNativeComponentViewEventEmitter>; + EventNestedObjectPropsNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -248,7 +258,7 @@ JSI_EXPORT extern const char EventPropsNativeComponentViewComponentName[]; using EventPropsNativeComponentViewShadowNode = ConcreteViewShadowNode< EventPropsNativeComponentViewComponentName, EventPropsNativeComponentViewProps, -EventPropsNativeComponentViewEventEmitter>; + EventPropsNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -270,6 +280,7 @@ Object { #pragma once +#include #include #include #include @@ -284,7 +295,8 @@ JSI_EXPORT extern const char FloatPropsNativeComponentViewComponentName[]; */ using FloatPropsNativeComponentViewShadowNode = ConcreteViewShadowNode< FloatPropsNativeComponentViewComponentName, - FloatPropsNativeComponentViewProps>; + FloatPropsNativeComponentViewProps, + FloatPropsNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -306,6 +318,7 @@ Object { #pragma once +#include #include #include #include @@ -320,7 +333,8 @@ JSI_EXPORT extern const char ImagePropNativeComponentViewComponentName[]; */ using ImagePropNativeComponentViewShadowNode = ConcreteViewShadowNode< ImagePropNativeComponentViewComponentName, - ImagePropNativeComponentViewProps>; + ImagePropNativeComponentViewProps, + ImagePropNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -342,6 +356,7 @@ Object { #pragma once +#include #include #include #include @@ -356,7 +371,8 @@ JSI_EXPORT extern const char IntegerPropNativeComponentViewComponentName[]; */ using IntegerPropNativeComponentViewShadowNode = ConcreteViewShadowNode< IntegerPropNativeComponentViewComponentName, - IntegerPropNativeComponentViewProps>; + IntegerPropNativeComponentViewProps, + IntegerPropNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -378,6 +394,7 @@ Object { #pragma once +#include #include #include #include @@ -407,6 +424,7 @@ Object { #pragma once +#include #include #include #include @@ -421,7 +439,8 @@ JSI_EXPORT extern const char MultiNativePropNativeComponentViewComponentName[]; */ using MultiNativePropNativeComponentViewShadowNode = ConcreteViewShadowNode< MultiNativePropNativeComponentViewComponentName, - MultiNativePropNativeComponentViewProps>; + MultiNativePropNativeComponentViewProps, + MultiNativePropNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -443,6 +462,7 @@ Object { #pragma once +#include #include #include #include @@ -457,7 +477,8 @@ JSI_EXPORT extern const char NoPropsNoEventsNativeComponentViewComponentName[]; */ using NoPropsNoEventsNativeComponentViewShadowNode = ConcreteViewShadowNode< NoPropsNoEventsNativeComponentViewComponentName, - NoPropsNoEventsNativeComponentViewProps>; + NoPropsNoEventsNativeComponentViewProps, + NoPropsNoEventsNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -479,6 +500,7 @@ Object { #pragma once +#include #include #include #include @@ -493,7 +515,8 @@ JSI_EXPORT extern const char ObjectPropsNativeComponentComponentName[]; */ using ObjectPropsNativeComponentShadowNode = ConcreteViewShadowNode< ObjectPropsNativeComponentComponentName, - ObjectPropsNativeComponentProps>; + ObjectPropsNativeComponentProps, + ObjectPropsNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -515,6 +538,7 @@ Object { #pragma once +#include #include #include #include @@ -529,7 +553,8 @@ JSI_EXPORT extern const char PointPropNativeComponentViewComponentName[]; */ using PointPropNativeComponentViewShadowNode = ConcreteViewShadowNode< PointPropNativeComponentViewComponentName, - PointPropNativeComponentViewProps>; + PointPropNativeComponentViewProps, + PointPropNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook @@ -551,6 +576,7 @@ Object { #pragma once +#include #include #include #include @@ -565,7 +591,8 @@ JSI_EXPORT extern const char StringPropNativeComponentViewComponentName[]; */ using StringPropNativeComponentViewShadowNode = ConcreteViewShadowNode< StringPropNativeComponentViewComponentName, - StringPropNativeComponentViewProps>; + StringPropNativeComponentViewProps, + StringPropNativeComponentViewEventEmitter>; } // namespace react } // namespace facebook diff --git a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js index 269567575c02f0..f61ca1ac091aa4 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateEventEmitterH.js @@ -285,9 +285,7 @@ module.exports = { .filter(Boolean) .reduce((acc, components) => Object.assign(acc, components), {}); - const moduleComponentsWithEvents = Object.keys(moduleComponents).filter( - componentName => moduleComponents[componentName].events.length > 0, - ); + const moduleComponentsWithEvents = Object.keys(moduleComponents); const fileName = 'EventEmitters.h'; diff --git a/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js b/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js index 5159bd6168568a..beb7b78a1adba9 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js @@ -75,8 +75,6 @@ module.exports = { ): FilesOutput { const fileName = 'ShadowNodes.h'; - let hasAnyEvents = false; - const moduleResults = Object.keys(schema.modules) .map(moduleName => { const module = schema.modules[moduleName]; @@ -97,15 +95,7 @@ module.exports = { return; } - const hasEvents = component.events.length > 0; - - if (hasEvents) { - hasAnyEvents = true; - } - - const eventEmitter = hasEvents - ? `,\n${componentName}EventEmitter` - : ''; + const eventEmitter = `,\n ${componentName}EventEmitter`; const replacedTemplate = ComponentTemplate({ className: componentName, @@ -124,7 +114,7 @@ module.exports = { const replacedTemplate = FileTemplate({ componentClasses: moduleResults, libraryName, - imports: hasAnyEvents ? eventEmitterImport : '', + imports: eventEmitterImport, }); return new Map([[fileName, replacedTemplate]]); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap index faacdff12be52a..fffed704338474 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateEventEmitterH-test.js.snap @@ -19,7 +19,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT ArrayPropsNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -46,7 +53,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT ArrayPropsNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -73,7 +87,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT BooleanPropNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -100,7 +121,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT ColorPropNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -127,7 +155,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT CommandNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -154,7 +189,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT CommandNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -181,7 +223,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT DoublePropNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -361,7 +410,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT ExcludedAndroidComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -388,7 +444,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT ExcludedAndroidIosComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -415,7 +478,22 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT ExcludedIosComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; +class JSI_EXPORT MultiFileIncludedNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; } // namespace react } // namespace facebook @@ -442,7 +520,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT FloatPropNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -469,7 +554,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT ImagePropNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -496,7 +588,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT InsetsPropNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -523,7 +622,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT Int32EnumPropsNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -550,7 +656,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT IntegerPropNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -613,7 +726,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT ImageColorPropNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -640,7 +760,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT NoPropsNoEventsComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -667,7 +794,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT ObjectPropsEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -694,7 +828,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT PointPropNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -721,7 +862,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT StringEnumPropsNativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -748,7 +896,14 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT StringPropComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -775,7 +930,22 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT MultiFile1NativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; +class JSI_EXPORT MultiFile2NativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; } // namespace react } // namespace facebook @@ -802,7 +972,22 @@ Map { namespace facebook { namespace react { +class JSI_EXPORT MultiComponent1NativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + +}; +class JSI_EXPORT MultiComponent2NativeComponentEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; } // namespace react } // namespace facebook diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap index fb4988800ad84b..13caa841d51f83 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap @@ -14,6 +14,7 @@ Map { #pragma once +#include #include #include #include @@ -28,7 +29,8 @@ JSI_EXPORT extern const char ArrayPropsNativeComponentComponentName[]; */ using ArrayPropsNativeComponentShadowNode = ConcreteViewShadowNode< ArrayPropsNativeComponentComponentName, - ArrayPropsNativeComponentProps>; + ArrayPropsNativeComponentProps, + ArrayPropsNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -50,6 +52,7 @@ Map { #pragma once +#include #include #include #include @@ -64,7 +67,8 @@ JSI_EXPORT extern const char ArrayPropsNativeComponentComponentName[]; */ using ArrayPropsNativeComponentShadowNode = ConcreteViewShadowNode< ArrayPropsNativeComponentComponentName, - ArrayPropsNativeComponentProps>; + ArrayPropsNativeComponentProps, + ArrayPropsNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -86,6 +90,7 @@ Map { #pragma once +#include #include #include #include @@ -100,7 +105,8 @@ JSI_EXPORT extern const char BooleanPropNativeComponentComponentName[]; */ using BooleanPropNativeComponentShadowNode = ConcreteViewShadowNode< BooleanPropNativeComponentComponentName, - BooleanPropNativeComponentProps>; + BooleanPropNativeComponentProps, + BooleanPropNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -122,6 +128,7 @@ Map { #pragma once +#include #include #include #include @@ -136,7 +143,8 @@ JSI_EXPORT extern const char ColorPropNativeComponentComponentName[]; */ using ColorPropNativeComponentShadowNode = ConcreteViewShadowNode< ColorPropNativeComponentComponentName, - ColorPropNativeComponentProps>; + ColorPropNativeComponentProps, + ColorPropNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -158,6 +166,7 @@ Map { #pragma once +#include #include #include #include @@ -172,7 +181,8 @@ JSI_EXPORT extern const char CommandNativeComponentComponentName[]; */ using CommandNativeComponentShadowNode = ConcreteViewShadowNode< CommandNativeComponentComponentName, - CommandNativeComponentProps>; + CommandNativeComponentProps, + CommandNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -194,6 +204,7 @@ Map { #pragma once +#include #include #include #include @@ -208,7 +219,8 @@ JSI_EXPORT extern const char CommandNativeComponentComponentName[]; */ using CommandNativeComponentShadowNode = ConcreteViewShadowNode< CommandNativeComponentComponentName, - CommandNativeComponentProps>; + CommandNativeComponentProps, + CommandNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -230,6 +242,7 @@ Map { #pragma once +#include #include #include #include @@ -244,7 +257,8 @@ JSI_EXPORT extern const char DoublePropNativeComponentComponentName[]; */ using DoublePropNativeComponentShadowNode = ConcreteViewShadowNode< DoublePropNativeComponentComponentName, - DoublePropNativeComponentProps>; + DoublePropNativeComponentProps, + DoublePropNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -282,7 +296,7 @@ JSI_EXPORT extern const char EventsNestedObjectNativeComponentComponentName[]; using EventsNestedObjectNativeComponentShadowNode = ConcreteViewShadowNode< EventsNestedObjectNativeComponentComponentName, EventsNestedObjectNativeComponentProps, -EventsNestedObjectNativeComponentEventEmitter>; + EventsNestedObjectNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -320,7 +334,7 @@ JSI_EXPORT extern const char EventsNativeComponentComponentName[]; using EventsNativeComponentShadowNode = ConcreteViewShadowNode< EventsNativeComponentComponentName, EventsNativeComponentProps, -EventsNativeComponentEventEmitter>; + EventsNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -342,6 +356,7 @@ Map { #pragma once +#include #include #include #include @@ -371,6 +386,7 @@ Map { #pragma once +#include #include #include #include @@ -385,7 +401,8 @@ JSI_EXPORT extern const char ExcludedAndroidComponentComponentName[]; */ using ExcludedAndroidComponentShadowNode = ConcreteViewShadowNode< ExcludedAndroidComponentComponentName, - ExcludedAndroidComponentProps>; + ExcludedAndroidComponentProps, + ExcludedAndroidComponentEventEmitter>; } // namespace react } // namespace facebook @@ -407,6 +424,7 @@ Map { #pragma once +#include #include #include #include @@ -421,7 +439,8 @@ JSI_EXPORT extern const char ExcludedAndroidIosComponentComponentName[]; */ using ExcludedAndroidIosComponentShadowNode = ConcreteViewShadowNode< ExcludedAndroidIosComponentComponentName, - ExcludedAndroidIosComponentProps>; + ExcludedAndroidIosComponentProps, + ExcludedAndroidIosComponentEventEmitter>; } // namespace react } // namespace facebook @@ -443,6 +462,7 @@ Map { #pragma once +#include #include #include #include @@ -457,7 +477,8 @@ JSI_EXPORT extern const char ExcludedIosComponentComponentName[]; */ using ExcludedIosComponentShadowNode = ConcreteViewShadowNode< ExcludedIosComponentComponentName, - ExcludedIosComponentProps>; + ExcludedIosComponentProps, + ExcludedIosComponentEventEmitter>; JSI_EXPORT extern const char MultiFileIncludedNativeComponentComponentName[]; @@ -466,7 +487,8 @@ JSI_EXPORT extern const char MultiFileIncludedNativeComponentComponentName[]; */ using MultiFileIncludedNativeComponentShadowNode = ConcreteViewShadowNode< MultiFileIncludedNativeComponentComponentName, - MultiFileIncludedNativeComponentProps>; + MultiFileIncludedNativeComponentProps, + MultiFileIncludedNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -488,6 +510,7 @@ Map { #pragma once +#include #include #include #include @@ -502,7 +525,8 @@ JSI_EXPORT extern const char FloatPropNativeComponentComponentName[]; */ using FloatPropNativeComponentShadowNode = ConcreteViewShadowNode< FloatPropNativeComponentComponentName, - FloatPropNativeComponentProps>; + FloatPropNativeComponentProps, + FloatPropNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -524,6 +548,7 @@ Map { #pragma once +#include #include #include #include @@ -538,7 +563,8 @@ JSI_EXPORT extern const char ImagePropNativeComponentComponentName[]; */ using ImagePropNativeComponentShadowNode = ConcreteViewShadowNode< ImagePropNativeComponentComponentName, - ImagePropNativeComponentProps>; + ImagePropNativeComponentProps, + ImagePropNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -560,6 +586,7 @@ Map { #pragma once +#include #include #include #include @@ -574,7 +601,8 @@ JSI_EXPORT extern const char InsetsPropNativeComponentComponentName[]; */ using InsetsPropNativeComponentShadowNode = ConcreteViewShadowNode< InsetsPropNativeComponentComponentName, - InsetsPropNativeComponentProps>; + InsetsPropNativeComponentProps, + InsetsPropNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -596,6 +624,7 @@ Map { #pragma once +#include #include #include #include @@ -610,7 +639,8 @@ JSI_EXPORT extern const char Int32EnumPropsNativeComponentComponentName[]; */ using Int32EnumPropsNativeComponentShadowNode = ConcreteViewShadowNode< Int32EnumPropsNativeComponentComponentName, - Int32EnumPropsNativeComponentProps>; + Int32EnumPropsNativeComponentProps, + Int32EnumPropsNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -632,6 +662,7 @@ Map { #pragma once +#include #include #include #include @@ -646,7 +677,8 @@ JSI_EXPORT extern const char IntegerPropNativeComponentComponentName[]; */ using IntegerPropNativeComponentShadowNode = ConcreteViewShadowNode< IntegerPropNativeComponentComponentName, - IntegerPropNativeComponentProps>; + IntegerPropNativeComponentProps, + IntegerPropNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -668,6 +700,7 @@ Map { #pragma once +#include #include #include #include @@ -697,6 +730,7 @@ Map { #pragma once +#include #include #include #include @@ -711,7 +745,8 @@ JSI_EXPORT extern const char ImageColorPropNativeComponentComponentName[]; */ using ImageColorPropNativeComponentShadowNode = ConcreteViewShadowNode< ImageColorPropNativeComponentComponentName, - ImageColorPropNativeComponentProps>; + ImageColorPropNativeComponentProps, + ImageColorPropNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -733,6 +768,7 @@ Map { #pragma once +#include #include #include #include @@ -747,7 +783,8 @@ JSI_EXPORT extern const char NoPropsNoEventsComponentComponentName[]; */ using NoPropsNoEventsComponentShadowNode = ConcreteViewShadowNode< NoPropsNoEventsComponentComponentName, - NoPropsNoEventsComponentProps>; + NoPropsNoEventsComponentProps, + NoPropsNoEventsComponentEventEmitter>; } // namespace react } // namespace facebook @@ -769,6 +806,7 @@ Map { #pragma once +#include #include #include #include @@ -783,7 +821,8 @@ JSI_EXPORT extern const char ObjectPropsComponentName[]; */ using ObjectPropsShadowNode = ConcreteViewShadowNode< ObjectPropsComponentName, - ObjectPropsProps>; + ObjectPropsProps, + ObjectPropsEventEmitter>; } // namespace react } // namespace facebook @@ -805,6 +844,7 @@ Map { #pragma once +#include #include #include #include @@ -819,7 +859,8 @@ JSI_EXPORT extern const char PointPropNativeComponentComponentName[]; */ using PointPropNativeComponentShadowNode = ConcreteViewShadowNode< PointPropNativeComponentComponentName, - PointPropNativeComponentProps>; + PointPropNativeComponentProps, + PointPropNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -841,6 +882,7 @@ Map { #pragma once +#include #include #include #include @@ -855,7 +897,8 @@ JSI_EXPORT extern const char StringEnumPropsNativeComponentComponentName[]; */ using StringEnumPropsNativeComponentShadowNode = ConcreteViewShadowNode< StringEnumPropsNativeComponentComponentName, - StringEnumPropsNativeComponentProps>; + StringEnumPropsNativeComponentProps, + StringEnumPropsNativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -877,6 +920,7 @@ Map { #pragma once +#include #include #include #include @@ -891,7 +935,8 @@ JSI_EXPORT extern const char StringPropComponentComponentName[]; */ using StringPropComponentShadowNode = ConcreteViewShadowNode< StringPropComponentComponentName, - StringPropComponentProps>; + StringPropComponentProps, + StringPropComponentEventEmitter>; } // namespace react } // namespace facebook @@ -913,6 +958,7 @@ Map { #pragma once +#include #include #include #include @@ -927,7 +973,8 @@ JSI_EXPORT extern const char MultiFile1NativeComponentComponentName[]; */ using MultiFile1NativeComponentShadowNode = ConcreteViewShadowNode< MultiFile1NativeComponentComponentName, - MultiFile1NativeComponentProps>; + MultiFile1NativeComponentProps, + MultiFile1NativeComponentEventEmitter>; JSI_EXPORT extern const char MultiFile2NativeComponentComponentName[]; @@ -936,7 +983,8 @@ JSI_EXPORT extern const char MultiFile2NativeComponentComponentName[]; */ using MultiFile2NativeComponentShadowNode = ConcreteViewShadowNode< MultiFile2NativeComponentComponentName, - MultiFile2NativeComponentProps>; + MultiFile2NativeComponentProps, + MultiFile2NativeComponentEventEmitter>; } // namespace react } // namespace facebook @@ -958,6 +1006,7 @@ Map { #pragma once +#include #include #include #include @@ -972,7 +1021,8 @@ JSI_EXPORT extern const char MultiComponent1NativeComponentComponentName[]; */ using MultiComponent1NativeComponentShadowNode = ConcreteViewShadowNode< MultiComponent1NativeComponentComponentName, - MultiComponent1NativeComponentProps>; + MultiComponent1NativeComponentProps, + MultiComponent1NativeComponentEventEmitter>; JSI_EXPORT extern const char MultiComponent2NativeComponentComponentName[]; @@ -981,7 +1031,8 @@ JSI_EXPORT extern const char MultiComponent2NativeComponentComponentName[]; */ using MultiComponent2NativeComponentShadowNode = ConcreteViewShadowNode< MultiComponent2NativeComponentComponentName, - MultiComponent2NativeComponentProps>; + MultiComponent2NativeComponentProps, + MultiComponent2NativeComponentEventEmitter>; } // namespace react } // namespace facebook diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index d0a218d9118bdb..05bbefbe17e07b 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -952,6 +952,6 @@ SPEC CHECKSUMS: Yoga: 1b1a12ff3d86a10565ea7cbe057d42f5e5fb2a07 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a -PODFILE CHECKSUM: c3d82494e47e0adce02921f2ed9dba2427f0a9ff +PODFILE CHECKSUM: e86c02825ce4e267e6fb3975bae791feb32a94a0 COCOAPODS: 1.11.3 From d75a02e965196660d0b0b90a7fbea8ac500dcfde Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 21 Sep 2022 10:54:37 -0700 Subject: [PATCH 2/3] Always generate an EmptyNativeState (#34754) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/34754 This Diff is the second step of enabling the CodeGen to parse and generate a NativeState for the components. The feature has been largely requested by the OSS community but it could be also helpful for people in Meta. ## Changelog [General][Added] - Always generate an empty NativeState for Fabric Components Differential Revision: https://internalfb.com/D39696435 fbshipit-source-id: fd27421151393352c7882b8a5bc737f136cbe3ea --- .../cmake-utils/ReactNative-application.cmake | 7 +- packages/react-native-codegen/DEFS.bzl | 19 + .../GenerateShadowNodeH-test.js.snap | 61 +- .../src/cli/generators/generate-all.js | 1 + .../src/generators/RNCodegen.js | 9 + .../generators/__tests__/RNCodegen-test.js | 2 + .../components/GenerateShadowNodeH.js | 4 +- .../generators/components/GenerateStateCpp.js | 90 ++ .../generators/components/GenerateStateH.js | 105 ++ .../__tests__/GenerateStateCpp-test.js | 27 + .../__tests__/GenerateStateH-test.js | 27 + .../GenerateShadowNodeH-test.js.snap | 111 +- .../GenerateStateCpp-test.js.snap | 649 +++++++++ .../__snapshots__/GenerateStateH-test.js.snap | 1237 +++++++++++++++++ .../generators/modules/GenerateModuleJniH.js | 1 + .../GenerateModuleJniH-test.js.snap | 16 +- packages/rn-tester/Podfile.lock | 2 +- scripts/react_native_pods.rb | 2 + 18 files changed, 2314 insertions(+), 56 deletions(-) create mode 100644 packages/react-native-codegen/src/generators/components/GenerateStateCpp.js create mode 100644 packages/react-native-codegen/src/generators/components/GenerateStateH.js create mode 100644 packages/react-native-codegen/src/generators/components/__tests__/GenerateStateCpp-test.js create mode 100644 packages/react-native-codegen/src/generators/components/__tests__/GenerateStateH-test.js create mode 100644 packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateCpp-test.js.snap create mode 100644 packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap diff --git a/ReactAndroid/cmake-utils/ReactNative-application.cmake b/ReactAndroid/cmake-utils/ReactNative-application.cmake index 2471db032a8031..51c0f734c24a8b 100644 --- a/ReactAndroid/cmake-utils/ReactNative-application.cmake +++ b/ReactAndroid/cmake-utils/ReactNative-application.cmake @@ -18,14 +18,14 @@ set(CMAKE_VERBOSE_MAKEFILE on) include(${REACT_ANDROID_DIR}/cmake-utils/Android-prebuilt.cmake) -file(GLOB input_SRC CONFIGURE_DEPENDS +file(GLOB input_SRC CONFIGURE_DEPENDS *.cpp ${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni/*.cpp) add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC}) -target_include_directories(${CMAKE_PROJECT_NAME} - PUBLIC +target_include_directories(${CMAKE_PROJECT_NAME} + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_BUILD_DIR}/generated/rncli/src/main/jni) @@ -45,6 +45,7 @@ target_link_libraries(${CMAKE_PROJECT_NAME} react_render_core react_render_debug react_render_graphics + react_render_mapbuffer rrc_view runtimeexecutor turbomodulejsijni diff --git a/packages/react-native-codegen/DEFS.bzl b/packages/react-native-codegen/DEFS.bzl index bd1ba845f035b5..ac56ecc43082c3 100644 --- a/packages/react-native-codegen/DEFS.bzl +++ b/packages/react-native-codegen/DEFS.bzl @@ -263,6 +263,8 @@ def rn_codegen_components( generate_event_emitter_h_name = "generate_event_emitter_h-{}".format(name) generate_props_cpp_name = "generate_props_cpp-{}".format(name) generate_props_h_name = "generated_props_h-{}".format(name) + generate_state_cpp_name = "generate_state_cpp-{}".format(name) + generate_state_h_name = "generated_state_h-{}".format(name) generate_tests_cpp_name = "generate_tests_cpp-{}".format(name) generate_shadow_node_cpp_name = "generated_shadow_node_cpp-{}".format(name) generate_shadow_node_h_name = "generated_shadow_node_h-{}".format(name) @@ -314,6 +316,13 @@ def rn_codegen_components( labels = ["codegen_rule"], ) + fb_native.genrule( + name = generate_state_cpp_name, + cmd = "cp $(location :{})/States.cpp $OUT".format(generate_fixtures_rule_name), + out = "States.cpp", + labels = ["codegen_rule"], + ) + fb_native.genrule( name = generate_tests_cpp_name, cmd = "cp $(location :{})/Tests.cpp $OUT".format(generate_fixtures_rule_name), @@ -328,6 +337,13 @@ def rn_codegen_components( labels = ["codegen_rule"], ) + fb_native.genrule( + name = generate_state_h_name, + cmd = "cp $(location :{})/States.h $OUT".format(generate_fixtures_rule_name), + out = "States.h", + labels = ["codegen_rule"], + ) + fb_native.genrule( name = copy_generated_java_files, # TODO: support different package name internally. @@ -388,12 +404,14 @@ def rn_codegen_components( srcs = [ ":{}".format(generate_event_emitter_cpp_name), ":{}".format(generate_props_cpp_name), + ":{}".format(generate_state_cpp_name), ":{}".format(generate_shadow_node_cpp_name), ], headers = [ ":{}".format(generate_component_descriptor_h_name), ":{}".format(generate_event_emitter_h_name), ":{}".format(generate_props_h_name), + ":{}".format(generate_state_h_name), ":{}".format(generate_shadow_node_h_name), ], header_namespace = "react/renderer/components/{}".format(name), @@ -403,6 +421,7 @@ def rn_codegen_components( "Props.h": ":{}".format(generate_props_h_name), "RCTComponentViewHelpers.h": ":{}".format(generate_component_hobjcpp_name), "ShadowNodes.h": ":{}".format(generate_shadow_node_h_name), + "States.h": ":{}".format(generate_state_h_name), }, fbobjc_compiler_flags = get_apple_compiler_flags(), fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(), diff --git a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap index ae85fd7b694fda..15357bb257178e 100644 --- a/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap +++ b/packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeH-test.js.snap @@ -16,6 +16,7 @@ Object { #include #include +#include #include #include @@ -30,7 +31,8 @@ JSI_EXPORT extern const char ArrayPropsNativeComponentViewComponentName[]; using ArrayPropsNativeComponentViewShadowNode = ConcreteViewShadowNode< ArrayPropsNativeComponentViewComponentName, ArrayPropsNativeComponentViewProps, - ArrayPropsNativeComponentViewEventEmitter>; + ArrayPropsNativeComponentViewEventEmitter, + ArrayPropsNativeComponentViewState>; } // namespace react } // namespace facebook @@ -54,6 +56,7 @@ Object { #include #include +#include #include #include @@ -68,7 +71,8 @@ JSI_EXPORT extern const char BooleanPropNativeComponentViewComponentName[]; using BooleanPropNativeComponentViewShadowNode = ConcreteViewShadowNode< BooleanPropNativeComponentViewComponentName, BooleanPropNativeComponentViewProps, - BooleanPropNativeComponentViewEventEmitter>; + BooleanPropNativeComponentViewEventEmitter, + BooleanPropNativeComponentViewState>; } // namespace react } // namespace facebook @@ -92,6 +96,7 @@ Object { #include #include +#include #include #include @@ -106,7 +111,8 @@ JSI_EXPORT extern const char ColorPropNativeComponentViewComponentName[]; using ColorPropNativeComponentViewShadowNode = ConcreteViewShadowNode< ColorPropNativeComponentViewComponentName, ColorPropNativeComponentViewProps, - ColorPropNativeComponentViewEventEmitter>; + ColorPropNativeComponentViewEventEmitter, + ColorPropNativeComponentViewState>; } // namespace react } // namespace facebook @@ -130,6 +136,7 @@ Object { #include #include +#include #include #include @@ -144,7 +151,8 @@ JSI_EXPORT extern const char EdgeInsetsPropNativeComponentViewComponentName[]; using EdgeInsetsPropNativeComponentViewShadowNode = ConcreteViewShadowNode< EdgeInsetsPropNativeComponentViewComponentName, EdgeInsetsPropNativeComponentViewProps, - EdgeInsetsPropNativeComponentViewEventEmitter>; + EdgeInsetsPropNativeComponentViewEventEmitter, + EdgeInsetsPropNativeComponentViewState>; } // namespace react } // namespace facebook @@ -168,6 +176,7 @@ Object { #include #include +#include #include #include @@ -182,7 +191,8 @@ JSI_EXPORT extern const char EnumPropNativeComponentViewComponentName[]; using EnumPropNativeComponentViewShadowNode = ConcreteViewShadowNode< EnumPropNativeComponentViewComponentName, EnumPropNativeComponentViewProps, - EnumPropNativeComponentViewEventEmitter>; + EnumPropNativeComponentViewEventEmitter, + EnumPropNativeComponentViewState>; } // namespace react } // namespace facebook @@ -206,6 +216,7 @@ Object { #include #include +#include #include #include @@ -220,7 +231,8 @@ JSI_EXPORT extern const char EventNestedObjectPropsNativeComponentViewComponentN using EventNestedObjectPropsNativeComponentViewShadowNode = ConcreteViewShadowNode< EventNestedObjectPropsNativeComponentViewComponentName, EventNestedObjectPropsNativeComponentViewProps, - EventNestedObjectPropsNativeComponentViewEventEmitter>; + EventNestedObjectPropsNativeComponentViewEventEmitter, + EventNestedObjectPropsNativeComponentViewState>; } // namespace react } // namespace facebook @@ -244,6 +256,7 @@ Object { #include #include +#include #include #include @@ -258,7 +271,8 @@ JSI_EXPORT extern const char EventPropsNativeComponentViewComponentName[]; using EventPropsNativeComponentViewShadowNode = ConcreteViewShadowNode< EventPropsNativeComponentViewComponentName, EventPropsNativeComponentViewProps, - EventPropsNativeComponentViewEventEmitter>; + EventPropsNativeComponentViewEventEmitter, + EventPropsNativeComponentViewState>; } // namespace react } // namespace facebook @@ -282,6 +296,7 @@ Object { #include #include +#include #include #include @@ -296,7 +311,8 @@ JSI_EXPORT extern const char FloatPropsNativeComponentViewComponentName[]; using FloatPropsNativeComponentViewShadowNode = ConcreteViewShadowNode< FloatPropsNativeComponentViewComponentName, FloatPropsNativeComponentViewProps, - FloatPropsNativeComponentViewEventEmitter>; + FloatPropsNativeComponentViewEventEmitter, + FloatPropsNativeComponentViewState>; } // namespace react } // namespace facebook @@ -320,6 +336,7 @@ Object { #include #include +#include #include #include @@ -334,7 +351,8 @@ JSI_EXPORT extern const char ImagePropNativeComponentViewComponentName[]; using ImagePropNativeComponentViewShadowNode = ConcreteViewShadowNode< ImagePropNativeComponentViewComponentName, ImagePropNativeComponentViewProps, - ImagePropNativeComponentViewEventEmitter>; + ImagePropNativeComponentViewEventEmitter, + ImagePropNativeComponentViewState>; } // namespace react } // namespace facebook @@ -358,6 +376,7 @@ Object { #include #include +#include #include #include @@ -372,7 +391,8 @@ JSI_EXPORT extern const char IntegerPropNativeComponentViewComponentName[]; using IntegerPropNativeComponentViewShadowNode = ConcreteViewShadowNode< IntegerPropNativeComponentViewComponentName, IntegerPropNativeComponentViewProps, - IntegerPropNativeComponentViewEventEmitter>; + IntegerPropNativeComponentViewEventEmitter, + IntegerPropNativeComponentViewState>; } // namespace react } // namespace facebook @@ -396,6 +416,7 @@ Object { #include #include +#include #include #include @@ -426,6 +447,7 @@ Object { #include #include +#include #include #include @@ -440,7 +462,8 @@ JSI_EXPORT extern const char MultiNativePropNativeComponentViewComponentName[]; using MultiNativePropNativeComponentViewShadowNode = ConcreteViewShadowNode< MultiNativePropNativeComponentViewComponentName, MultiNativePropNativeComponentViewProps, - MultiNativePropNativeComponentViewEventEmitter>; + MultiNativePropNativeComponentViewEventEmitter, + MultiNativePropNativeComponentViewState>; } // namespace react } // namespace facebook @@ -464,6 +487,7 @@ Object { #include #include +#include #include #include @@ -478,7 +502,8 @@ JSI_EXPORT extern const char NoPropsNoEventsNativeComponentViewComponentName[]; using NoPropsNoEventsNativeComponentViewShadowNode = ConcreteViewShadowNode< NoPropsNoEventsNativeComponentViewComponentName, NoPropsNoEventsNativeComponentViewProps, - NoPropsNoEventsNativeComponentViewEventEmitter>; + NoPropsNoEventsNativeComponentViewEventEmitter, + NoPropsNoEventsNativeComponentViewState>; } // namespace react } // namespace facebook @@ -502,6 +527,7 @@ Object { #include #include +#include #include #include @@ -516,7 +542,8 @@ JSI_EXPORT extern const char ObjectPropsNativeComponentComponentName[]; using ObjectPropsNativeComponentShadowNode = ConcreteViewShadowNode< ObjectPropsNativeComponentComponentName, ObjectPropsNativeComponentProps, - ObjectPropsNativeComponentEventEmitter>; + ObjectPropsNativeComponentEventEmitter, + ObjectPropsNativeComponentState>; } // namespace react } // namespace facebook @@ -540,6 +567,7 @@ Object { #include #include +#include #include #include @@ -554,7 +582,8 @@ JSI_EXPORT extern const char PointPropNativeComponentViewComponentName[]; using PointPropNativeComponentViewShadowNode = ConcreteViewShadowNode< PointPropNativeComponentViewComponentName, PointPropNativeComponentViewProps, - PointPropNativeComponentViewEventEmitter>; + PointPropNativeComponentViewEventEmitter, + PointPropNativeComponentViewState>; } // namespace react } // namespace facebook @@ -578,6 +607,7 @@ Object { #include #include +#include #include #include @@ -592,7 +622,8 @@ JSI_EXPORT extern const char StringPropNativeComponentViewComponentName[]; using StringPropNativeComponentViewShadowNode = ConcreteViewShadowNode< StringPropNativeComponentViewComponentName, StringPropNativeComponentViewProps, - StringPropNativeComponentViewEventEmitter>; + StringPropNativeComponentViewEventEmitter, + StringPropNativeComponentViewState>; } // namespace react } // namespace facebook diff --git a/packages/react-native-codegen/src/cli/generators/generate-all.js b/packages/react-native-codegen/src/cli/generators/generate-all.js index 6ceeedc9eb9b39..46d20751020885 100644 --- a/packages/react-native-codegen/src/cli/generators/generate-all.js +++ b/packages/react-native-codegen/src/cli/generators/generate-all.js @@ -55,6 +55,7 @@ RNCodegen.generate( 'descriptors', 'events', 'props', + 'states', 'tests', 'shadow-nodes', 'modulesAndroid', diff --git a/packages/react-native-codegen/src/generators/RNCodegen.js b/packages/react-native-codegen/src/generators/RNCodegen.js index 78004999db3a0b..b2648c626c1a54 100644 --- a/packages/react-native-codegen/src/generators/RNCodegen.js +++ b/packages/react-native-codegen/src/generators/RNCodegen.js @@ -23,6 +23,8 @@ const generateEventEmitterCpp = require('./components/GenerateEventEmitterCpp.js const generateEventEmitterH = require('./components/GenerateEventEmitterH.js'); const generatePropsCpp = require('./components/GeneratePropsCpp.js'); const generatePropsH = require('./components/GeneratePropsH.js'); +const generateStateCpp = require('./components/GenerateStateCpp.js'); +const generateStateH = require('./components/GenerateStateH.js'); const generateModuleH = require('./modules/GenerateModuleH.js'); const generateModuleCpp = require('./modules/GenerateModuleCpp.js'); const generateModuleObjCpp = require('./modules/GenerateModuleObjCpp'); @@ -61,6 +63,7 @@ type LibraryGenerators = | 'descriptors' | 'events' | 'props' + | 'states' | 'tests' | 'shadow-nodes' | 'modulesAndroid' @@ -82,6 +85,7 @@ type SchemasConfig = $ReadOnly<{ const LIBRARY_GENERATORS = { descriptors: [generateComponentDescriptorH.generate], events: [generateEventEmitterCpp.generate, generateEventEmitterH.generate], + states: [generateStateCpp.generate, generateStateH.generate], props: [ generateComponentHObjCpp.generate, generatePropsCpp.generate, @@ -97,6 +101,8 @@ const LIBRARY_GENERATORS = { generateEventEmitterH.generate, generatePropsCpp.generate, generatePropsH.generate, + generateStateCpp.generate, + generateStateH.generate, generateShadowNodeCpp.generate, generateShadowNodeH.generate, // Java files @@ -110,6 +116,8 @@ const LIBRARY_GENERATORS = { generateComponentHObjCpp.generate, generatePropsCpp.generate, generatePropsH.generate, + generateStateCpp.generate, + generateStateH.generate, generateShadowNodeCpp.generate, generateShadowNodeH.generate, ], @@ -211,6 +219,7 @@ module.exports = { descriptors: outputDirectory, events: outputDirectory, props: outputDirectory, + states: outputDirectory, componentsAndroid: outputDirectory, modulesAndroid: outputDirectory, modulesCxx: outputDirectory, diff --git a/packages/react-native-codegen/src/generators/__tests__/RNCodegen-test.js b/packages/react-native-codegen/src/generators/__tests__/RNCodegen-test.js index f4d59c0e09335e..864a0b06491967 100644 --- a/packages/react-native-codegen/src/generators/__tests__/RNCodegen-test.js +++ b/packages/react-native-codegen/src/generators/__tests__/RNCodegen-test.js @@ -39,6 +39,8 @@ describe('RNCodegen.generate', () => { 'ShadowNodes.cpp': componentsOutputDir, 'Props.h': componentsOutputDir, 'Props.cpp': componentsOutputDir, + 'States.h': componentsOutputDir, + 'States.cpp': componentsOutputDir, 'RCTComponentViewHelpers.h': componentsOutputDir, 'EventEmitters.h': componentsOutputDir, 'EventEmitters.cpp': componentsOutputDir, diff --git a/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js b/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js index beb7b78a1adba9..3e7cf71117ef22 100644 --- a/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js +++ b/packages/react-native-codegen/src/generators/components/GenerateShadowNodeH.js @@ -36,6 +36,7 @@ const FileTemplate = ({ #pragma once ${imports}#include +#include #include #include @@ -63,7 +64,8 @@ JSI_EXPORT extern const char ${className}ComponentName[]; */ using ${className}ShadowNode = ConcreteViewShadowNode< ${className}ComponentName, - ${className}Props${eventEmitter}>; + ${className}Props${eventEmitter}, + ${className}State>; `.trim(); module.exports = { diff --git a/packages/react-native-codegen/src/generators/components/GenerateStateCpp.js b/packages/react-native-codegen/src/generators/components/GenerateStateCpp.js new file mode 100644 index 00000000000000..1bbcc0e16e4dee --- /dev/null +++ b/packages/react-native-codegen/src/generators/components/GenerateStateCpp.js @@ -0,0 +1,90 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict + * @format + */ + +'use strict'; + +import type {SchemaType} from '../../CodegenSchema'; + +// File path -> contents +type FilesOutput = Map; + +const FileTemplate = ({ + libraryName, + stateClasses, +}: { + libraryName: string, + stateClasses: string, +}) => ` +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * ${'@'}generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + +${stateClasses} + +} // namespace react +} // namespace facebook +`; + +const StateTemplate = ({stateName}: {stateName: string}) => ''; + +module.exports = { + generate( + libraryName: string, + schema: SchemaType, + packageName?: string, + assumeNonnull: boolean = false, + ): FilesOutput { + const fileName = 'States.cpp'; + + const stateClasses = Object.keys(schema.modules) + .map(moduleName => { + const module = schema.modules[moduleName]; + if (module.type !== 'Component') { + return; + } + + const {components} = module; + // No components in this module + if (components == null) { + return null; + } + + return Object.keys(components) + .map(componentName => { + if (components[componentName].interfaceOnly === true) { + return null; + } + return StateTemplate({ + stateName: `${componentName}State`, + }); + }) + .filter(Boolean) + .join('\n'); + }) + .filter(Boolean) + .join('\n'); + + const replacedTemplate = FileTemplate({ + libraryName, + stateClasses, + }); + + return new Map([[fileName, replacedTemplate]]); + }, +}; diff --git a/packages/react-native-codegen/src/generators/components/GenerateStateH.js b/packages/react-native-codegen/src/generators/components/GenerateStateH.js new file mode 100644 index 00000000000000..76f46403d15d9b --- /dev/null +++ b/packages/react-native-codegen/src/generators/components/GenerateStateH.js @@ -0,0 +1,105 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict + * @format + */ + +'use strict'; + +import type {SchemaType} from '../../CodegenSchema'; + +// File path -> contents +type FilesOutput = Map; + +const FileTemplate = ({ + libraryName, + stateClasses, +}: { + libraryName: string, + stateClasses: string, +}) => ` +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * ${'@'}generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + +${stateClasses} + +} // namespace react +} // namespace facebook +`; + +const StateTemplate = ({stateName}: {stateName: string}) => ` +class ${stateName}State { + public: + ${stateName}State() = default; + +#ifdef ANDROID + ${stateName}State(${stateName}State const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; +`; + +module.exports = { + generate( + libraryName: string, + schema: SchemaType, + packageName?: string, + assumeNonnull: boolean = false, + ): FilesOutput { + const fileName = 'States.h'; + const stateClasses = Object.keys(schema.modules) + .map(moduleName => { + const module = schema.modules[moduleName]; + if (module.type !== 'Component') { + return; + } + + const {components} = module; + // No components in this module + if (components == null) { + return null; + } + + return Object.keys(components) + .map(componentName => { + if (components[componentName].interfaceOnly === true) { + return null; + } + + return StateTemplate({stateName: componentName}); + }) + .filter(Boolean) + .join('\n\n'); + }) + .filter(Boolean) + .join('\n\n'); + + const template = FileTemplate({libraryName, stateClasses}); + return new Map([[fileName, template]]); + }, +}; diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GenerateStateCpp-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GenerateStateCpp-test.js new file mode 100644 index 00000000000000..1ccba96ba02d9b --- /dev/null +++ b/packages/react-native-codegen/src/generators/components/__tests__/GenerateStateCpp-test.js @@ -0,0 +1,27 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + * @oncall react_native + */ + +'use strict'; + +const fixtures = require('../__test_fixtures__/fixtures.js'); +const generator = require('../GenerateStateCpp.js'); + +describe('GenerateStateCpp', () => { + Object.keys(fixtures) + .sort() + .forEach(fixtureName => { + const fixture = fixtures[fixtureName]; + + it(`can generate fixture ${fixtureName}`, () => { + expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + }); + }); +}); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/GenerateStateH-test.js b/packages/react-native-codegen/src/generators/components/__tests__/GenerateStateH-test.js new file mode 100644 index 00000000000000..30b6b184b0e51d --- /dev/null +++ b/packages/react-native-codegen/src/generators/components/__tests__/GenerateStateH-test.js @@ -0,0 +1,27 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + * @oncall react_native + */ + +'use strict'; + +const fixtures = require('../__test_fixtures__/fixtures.js'); +const generator = require('../GenerateStateH.js'); + +describe('GenerateStateH', () => { + Object.keys(fixtures) + .sort() + .forEach(fixtureName => { + const fixture = fixtures[fixtureName]; + + it(`can generate fixture ${fixtureName}`, () => { + expect(generator.generate(fixtureName, fixture)).toMatchSnapshot(); + }); + }); +}); diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap index 13caa841d51f83..86226abbbd7279 100644 --- a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateShadowNodeH-test.js.snap @@ -16,6 +16,7 @@ Map { #include #include +#include #include #include @@ -30,7 +31,8 @@ JSI_EXPORT extern const char ArrayPropsNativeComponentComponentName[]; using ArrayPropsNativeComponentShadowNode = ConcreteViewShadowNode< ArrayPropsNativeComponentComponentName, ArrayPropsNativeComponentProps, - ArrayPropsNativeComponentEventEmitter>; + ArrayPropsNativeComponentEventEmitter, + ArrayPropsNativeComponentState>; } // namespace react } // namespace facebook @@ -54,6 +56,7 @@ Map { #include #include +#include #include #include @@ -68,7 +71,8 @@ JSI_EXPORT extern const char ArrayPropsNativeComponentComponentName[]; using ArrayPropsNativeComponentShadowNode = ConcreteViewShadowNode< ArrayPropsNativeComponentComponentName, ArrayPropsNativeComponentProps, - ArrayPropsNativeComponentEventEmitter>; + ArrayPropsNativeComponentEventEmitter, + ArrayPropsNativeComponentState>; } // namespace react } // namespace facebook @@ -92,6 +96,7 @@ Map { #include #include +#include #include #include @@ -106,7 +111,8 @@ JSI_EXPORT extern const char BooleanPropNativeComponentComponentName[]; using BooleanPropNativeComponentShadowNode = ConcreteViewShadowNode< BooleanPropNativeComponentComponentName, BooleanPropNativeComponentProps, - BooleanPropNativeComponentEventEmitter>; + BooleanPropNativeComponentEventEmitter, + BooleanPropNativeComponentState>; } // namespace react } // namespace facebook @@ -130,6 +136,7 @@ Map { #include #include +#include #include #include @@ -144,7 +151,8 @@ JSI_EXPORT extern const char ColorPropNativeComponentComponentName[]; using ColorPropNativeComponentShadowNode = ConcreteViewShadowNode< ColorPropNativeComponentComponentName, ColorPropNativeComponentProps, - ColorPropNativeComponentEventEmitter>; + ColorPropNativeComponentEventEmitter, + ColorPropNativeComponentState>; } // namespace react } // namespace facebook @@ -168,6 +176,7 @@ Map { #include #include +#include #include #include @@ -182,7 +191,8 @@ JSI_EXPORT extern const char CommandNativeComponentComponentName[]; using CommandNativeComponentShadowNode = ConcreteViewShadowNode< CommandNativeComponentComponentName, CommandNativeComponentProps, - CommandNativeComponentEventEmitter>; + CommandNativeComponentEventEmitter, + CommandNativeComponentState>; } // namespace react } // namespace facebook @@ -206,6 +216,7 @@ Map { #include #include +#include #include #include @@ -220,7 +231,8 @@ JSI_EXPORT extern const char CommandNativeComponentComponentName[]; using CommandNativeComponentShadowNode = ConcreteViewShadowNode< CommandNativeComponentComponentName, CommandNativeComponentProps, - CommandNativeComponentEventEmitter>; + CommandNativeComponentEventEmitter, + CommandNativeComponentState>; } // namespace react } // namespace facebook @@ -244,6 +256,7 @@ Map { #include #include +#include #include #include @@ -258,7 +271,8 @@ JSI_EXPORT extern const char DoublePropNativeComponentComponentName[]; using DoublePropNativeComponentShadowNode = ConcreteViewShadowNode< DoublePropNativeComponentComponentName, DoublePropNativeComponentProps, - DoublePropNativeComponentEventEmitter>; + DoublePropNativeComponentEventEmitter, + DoublePropNativeComponentState>; } // namespace react } // namespace facebook @@ -282,6 +296,7 @@ Map { #include #include +#include #include #include @@ -296,7 +311,8 @@ JSI_EXPORT extern const char EventsNestedObjectNativeComponentComponentName[]; using EventsNestedObjectNativeComponentShadowNode = ConcreteViewShadowNode< EventsNestedObjectNativeComponentComponentName, EventsNestedObjectNativeComponentProps, - EventsNestedObjectNativeComponentEventEmitter>; + EventsNestedObjectNativeComponentEventEmitter, + EventsNestedObjectNativeComponentState>; } // namespace react } // namespace facebook @@ -320,6 +336,7 @@ Map { #include #include +#include #include #include @@ -334,7 +351,8 @@ JSI_EXPORT extern const char EventsNativeComponentComponentName[]; using EventsNativeComponentShadowNode = ConcreteViewShadowNode< EventsNativeComponentComponentName, EventsNativeComponentProps, - EventsNativeComponentEventEmitter>; + EventsNativeComponentEventEmitter, + EventsNativeComponentState>; } // namespace react } // namespace facebook @@ -358,6 +376,7 @@ Map { #include #include +#include #include #include @@ -388,6 +407,7 @@ Map { #include #include +#include #include #include @@ -402,7 +422,8 @@ JSI_EXPORT extern const char ExcludedAndroidComponentComponentName[]; using ExcludedAndroidComponentShadowNode = ConcreteViewShadowNode< ExcludedAndroidComponentComponentName, ExcludedAndroidComponentProps, - ExcludedAndroidComponentEventEmitter>; + ExcludedAndroidComponentEventEmitter, + ExcludedAndroidComponentState>; } // namespace react } // namespace facebook @@ -426,6 +447,7 @@ Map { #include #include +#include #include #include @@ -440,7 +462,8 @@ JSI_EXPORT extern const char ExcludedAndroidIosComponentComponentName[]; using ExcludedAndroidIosComponentShadowNode = ConcreteViewShadowNode< ExcludedAndroidIosComponentComponentName, ExcludedAndroidIosComponentProps, - ExcludedAndroidIosComponentEventEmitter>; + ExcludedAndroidIosComponentEventEmitter, + ExcludedAndroidIosComponentState>; } // namespace react } // namespace facebook @@ -464,6 +487,7 @@ Map { #include #include +#include #include #include @@ -478,7 +502,8 @@ JSI_EXPORT extern const char ExcludedIosComponentComponentName[]; using ExcludedIosComponentShadowNode = ConcreteViewShadowNode< ExcludedIosComponentComponentName, ExcludedIosComponentProps, - ExcludedIosComponentEventEmitter>; + ExcludedIosComponentEventEmitter, + ExcludedIosComponentState>; JSI_EXPORT extern const char MultiFileIncludedNativeComponentComponentName[]; @@ -488,7 +513,8 @@ JSI_EXPORT extern const char MultiFileIncludedNativeComponentComponentName[]; using MultiFileIncludedNativeComponentShadowNode = ConcreteViewShadowNode< MultiFileIncludedNativeComponentComponentName, MultiFileIncludedNativeComponentProps, - MultiFileIncludedNativeComponentEventEmitter>; + MultiFileIncludedNativeComponentEventEmitter, + MultiFileIncludedNativeComponentState>; } // namespace react } // namespace facebook @@ -512,6 +538,7 @@ Map { #include #include +#include #include #include @@ -526,7 +553,8 @@ JSI_EXPORT extern const char FloatPropNativeComponentComponentName[]; using FloatPropNativeComponentShadowNode = ConcreteViewShadowNode< FloatPropNativeComponentComponentName, FloatPropNativeComponentProps, - FloatPropNativeComponentEventEmitter>; + FloatPropNativeComponentEventEmitter, + FloatPropNativeComponentState>; } // namespace react } // namespace facebook @@ -550,6 +578,7 @@ Map { #include #include +#include #include #include @@ -564,7 +593,8 @@ JSI_EXPORT extern const char ImagePropNativeComponentComponentName[]; using ImagePropNativeComponentShadowNode = ConcreteViewShadowNode< ImagePropNativeComponentComponentName, ImagePropNativeComponentProps, - ImagePropNativeComponentEventEmitter>; + ImagePropNativeComponentEventEmitter, + ImagePropNativeComponentState>; } // namespace react } // namespace facebook @@ -588,6 +618,7 @@ Map { #include #include +#include #include #include @@ -602,7 +633,8 @@ JSI_EXPORT extern const char InsetsPropNativeComponentComponentName[]; using InsetsPropNativeComponentShadowNode = ConcreteViewShadowNode< InsetsPropNativeComponentComponentName, InsetsPropNativeComponentProps, - InsetsPropNativeComponentEventEmitter>; + InsetsPropNativeComponentEventEmitter, + InsetsPropNativeComponentState>; } // namespace react } // namespace facebook @@ -626,6 +658,7 @@ Map { #include #include +#include #include #include @@ -640,7 +673,8 @@ JSI_EXPORT extern const char Int32EnumPropsNativeComponentComponentName[]; using Int32EnumPropsNativeComponentShadowNode = ConcreteViewShadowNode< Int32EnumPropsNativeComponentComponentName, Int32EnumPropsNativeComponentProps, - Int32EnumPropsNativeComponentEventEmitter>; + Int32EnumPropsNativeComponentEventEmitter, + Int32EnumPropsNativeComponentState>; } // namespace react } // namespace facebook @@ -664,6 +698,7 @@ Map { #include #include +#include #include #include @@ -678,7 +713,8 @@ JSI_EXPORT extern const char IntegerPropNativeComponentComponentName[]; using IntegerPropNativeComponentShadowNode = ConcreteViewShadowNode< IntegerPropNativeComponentComponentName, IntegerPropNativeComponentProps, - IntegerPropNativeComponentEventEmitter>; + IntegerPropNativeComponentEventEmitter, + IntegerPropNativeComponentState>; } // namespace react } // namespace facebook @@ -702,6 +738,7 @@ Map { #include #include +#include #include #include @@ -732,6 +769,7 @@ Map { #include #include +#include #include #include @@ -746,7 +784,8 @@ JSI_EXPORT extern const char ImageColorPropNativeComponentComponentName[]; using ImageColorPropNativeComponentShadowNode = ConcreteViewShadowNode< ImageColorPropNativeComponentComponentName, ImageColorPropNativeComponentProps, - ImageColorPropNativeComponentEventEmitter>; + ImageColorPropNativeComponentEventEmitter, + ImageColorPropNativeComponentState>; } // namespace react } // namespace facebook @@ -770,6 +809,7 @@ Map { #include #include +#include #include #include @@ -784,7 +824,8 @@ JSI_EXPORT extern const char NoPropsNoEventsComponentComponentName[]; using NoPropsNoEventsComponentShadowNode = ConcreteViewShadowNode< NoPropsNoEventsComponentComponentName, NoPropsNoEventsComponentProps, - NoPropsNoEventsComponentEventEmitter>; + NoPropsNoEventsComponentEventEmitter, + NoPropsNoEventsComponentState>; } // namespace react } // namespace facebook @@ -808,6 +849,7 @@ Map { #include #include +#include #include #include @@ -822,7 +864,8 @@ JSI_EXPORT extern const char ObjectPropsComponentName[]; using ObjectPropsShadowNode = ConcreteViewShadowNode< ObjectPropsComponentName, ObjectPropsProps, - ObjectPropsEventEmitter>; + ObjectPropsEventEmitter, + ObjectPropsState>; } // namespace react } // namespace facebook @@ -846,6 +889,7 @@ Map { #include #include +#include #include #include @@ -860,7 +904,8 @@ JSI_EXPORT extern const char PointPropNativeComponentComponentName[]; using PointPropNativeComponentShadowNode = ConcreteViewShadowNode< PointPropNativeComponentComponentName, PointPropNativeComponentProps, - PointPropNativeComponentEventEmitter>; + PointPropNativeComponentEventEmitter, + PointPropNativeComponentState>; } // namespace react } // namespace facebook @@ -884,6 +929,7 @@ Map { #include #include +#include #include #include @@ -898,7 +944,8 @@ JSI_EXPORT extern const char StringEnumPropsNativeComponentComponentName[]; using StringEnumPropsNativeComponentShadowNode = ConcreteViewShadowNode< StringEnumPropsNativeComponentComponentName, StringEnumPropsNativeComponentProps, - StringEnumPropsNativeComponentEventEmitter>; + StringEnumPropsNativeComponentEventEmitter, + StringEnumPropsNativeComponentState>; } // namespace react } // namespace facebook @@ -922,6 +969,7 @@ Map { #include #include +#include #include #include @@ -936,7 +984,8 @@ JSI_EXPORT extern const char StringPropComponentComponentName[]; using StringPropComponentShadowNode = ConcreteViewShadowNode< StringPropComponentComponentName, StringPropComponentProps, - StringPropComponentEventEmitter>; + StringPropComponentEventEmitter, + StringPropComponentState>; } // namespace react } // namespace facebook @@ -960,6 +1009,7 @@ Map { #include #include +#include #include #include @@ -974,7 +1024,8 @@ JSI_EXPORT extern const char MultiFile1NativeComponentComponentName[]; using MultiFile1NativeComponentShadowNode = ConcreteViewShadowNode< MultiFile1NativeComponentComponentName, MultiFile1NativeComponentProps, - MultiFile1NativeComponentEventEmitter>; + MultiFile1NativeComponentEventEmitter, + MultiFile1NativeComponentState>; JSI_EXPORT extern const char MultiFile2NativeComponentComponentName[]; @@ -984,7 +1035,8 @@ JSI_EXPORT extern const char MultiFile2NativeComponentComponentName[]; using MultiFile2NativeComponentShadowNode = ConcreteViewShadowNode< MultiFile2NativeComponentComponentName, MultiFile2NativeComponentProps, - MultiFile2NativeComponentEventEmitter>; + MultiFile2NativeComponentEventEmitter, + MultiFile2NativeComponentState>; } // namespace react } // namespace facebook @@ -1008,6 +1060,7 @@ Map { #include #include +#include #include #include @@ -1022,7 +1075,8 @@ JSI_EXPORT extern const char MultiComponent1NativeComponentComponentName[]; using MultiComponent1NativeComponentShadowNode = ConcreteViewShadowNode< MultiComponent1NativeComponentComponentName, MultiComponent1NativeComponentProps, - MultiComponent1NativeComponentEventEmitter>; + MultiComponent1NativeComponentEventEmitter, + MultiComponent1NativeComponentState>; JSI_EXPORT extern const char MultiComponent2NativeComponentComponentName[]; @@ -1032,7 +1086,8 @@ JSI_EXPORT extern const char MultiComponent2NativeComponentComponentName[]; using MultiComponent2NativeComponentShadowNode = ConcreteViewShadowNode< MultiComponent2NativeComponentComponentName, MultiComponent2NativeComponentProps, - MultiComponent2NativeComponentEventEmitter>; + MultiComponent2NativeComponentEventEmitter, + MultiComponent2NativeComponentState>; } // namespace react } // namespace facebook diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateCpp-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateCpp-test.js.snap new file mode 100644 index 00000000000000..04084fb1b5a050 --- /dev/null +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateCpp-test.js.snap @@ -0,0 +1,649 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`GenerateStateCpp can generate fixture ARRAY_PROPS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture BOOLEAN_PROP 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture COLOR_PROP 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture COMMANDS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture COMMANDS_AND_PROPS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture DOUBLE_PROPS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture EVENT_NESTED_OBJECT_PROPS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture EVENT_PROPS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture EVENTS_WITH_PAPER_NAME 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture EXCLUDE_ANDROID 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture EXCLUDE_ANDROID_IOS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture FLOAT_PROPS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture IMAGE_PROP 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture INSETS_PROP 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture INT32_ENUM_PROP 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture INTEGER_PROPS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture INTERFACE_ONLY 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture MULTI_NATIVE_PROP 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture NO_PROPS_NO_EVENTS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture OBJECT_PROPS 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture POINT_PROP 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture STRING_ENUM_PROP 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture STRING_PROP 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateCpp can generate fixture TWO_COMPONENTS_SAME_FILE 1`] = ` +Map { + "States.cpp" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateCpp.js + */ +#include + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; diff --git a/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap new file mode 100644 index 00000000000000..d450b769097d1e --- /dev/null +++ b/packages/react-native-codegen/src/generators/components/__tests__/__snapshots__/GenerateStateH-test.js.snap @@ -0,0 +1,1237 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`GenerateStateH can generate fixture ARRAY_PROPS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class ArrayPropsNativeComponentState { + public: + ArrayPropsNativeComponentState() = default; + +#ifdef ANDROID + ArrayPropsNativeComponentState(ArrayPropsNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture ARRAY_PROPS_WITH_NESTED_OBJECT 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class ArrayPropsNativeComponentState { + public: + ArrayPropsNativeComponentState() = default; + +#ifdef ANDROID + ArrayPropsNativeComponentState(ArrayPropsNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture BOOLEAN_PROP 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class BooleanPropNativeComponentState { + public: + BooleanPropNativeComponentState() = default; + +#ifdef ANDROID + BooleanPropNativeComponentState(BooleanPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture COLOR_PROP 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class ColorPropNativeComponentState { + public: + ColorPropNativeComponentState() = default; + +#ifdef ANDROID + ColorPropNativeComponentState(ColorPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture COMMANDS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class CommandNativeComponentState { + public: + CommandNativeComponentState() = default; + +#ifdef ANDROID + CommandNativeComponentState(CommandNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture COMMANDS_AND_PROPS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class CommandNativeComponentState { + public: + CommandNativeComponentState() = default; + +#ifdef ANDROID + CommandNativeComponentState(CommandNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture DOUBLE_PROPS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class DoublePropNativeComponentState { + public: + DoublePropNativeComponentState() = default; + +#ifdef ANDROID + DoublePropNativeComponentState(DoublePropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture EVENT_NESTED_OBJECT_PROPS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class EventsNestedObjectNativeComponentState { + public: + EventsNestedObjectNativeComponentState() = default; + +#ifdef ANDROID + EventsNestedObjectNativeComponentState(EventsNestedObjectNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture EVENT_PROPS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class EventsNativeComponentState { + public: + EventsNativeComponentState() = default; + +#ifdef ANDROID + EventsNativeComponentState(EventsNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture EVENTS_WITH_PAPER_NAME 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture EXCLUDE_ANDROID 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class ExcludedAndroidComponentState { + public: + ExcludedAndroidComponentState() = default; + +#ifdef ANDROID + ExcludedAndroidComponentState(ExcludedAndroidComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture EXCLUDE_ANDROID_IOS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class ExcludedAndroidIosComponentState { + public: + ExcludedAndroidIosComponentState() = default; + +#ifdef ANDROID + ExcludedAndroidIosComponentState(ExcludedAndroidIosComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture EXCLUDE_IOS_TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class ExcludedIosComponentState { + public: + ExcludedIosComponentState() = default; + +#ifdef ANDROID + ExcludedIosComponentState(ExcludedIosComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + + +class MultiFileIncludedNativeComponentState { + public: + MultiFileIncludedNativeComponentState() = default; + +#ifdef ANDROID + MultiFileIncludedNativeComponentState(MultiFileIncludedNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture FLOAT_PROPS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class FloatPropNativeComponentState { + public: + FloatPropNativeComponentState() = default; + +#ifdef ANDROID + FloatPropNativeComponentState(FloatPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture IMAGE_PROP 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class ImagePropNativeComponentState { + public: + ImagePropNativeComponentState() = default; + +#ifdef ANDROID + ImagePropNativeComponentState(ImagePropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture INSETS_PROP 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class InsetsPropNativeComponentState { + public: + InsetsPropNativeComponentState() = default; + +#ifdef ANDROID + InsetsPropNativeComponentState(InsetsPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture INT32_ENUM_PROP 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class Int32EnumPropsNativeComponentState { + public: + Int32EnumPropsNativeComponentState() = default; + +#ifdef ANDROID + Int32EnumPropsNativeComponentState(Int32EnumPropsNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture INTEGER_PROPS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class IntegerPropNativeComponentState { + public: + IntegerPropNativeComponentState() = default; + +#ifdef ANDROID + IntegerPropNativeComponentState(IntegerPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture INTERFACE_ONLY 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture MULTI_NATIVE_PROP 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class ImageColorPropNativeComponentState { + public: + ImageColorPropNativeComponentState() = default; + +#ifdef ANDROID + ImageColorPropNativeComponentState(ImageColorPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture NO_PROPS_NO_EVENTS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class NoPropsNoEventsComponentState { + public: + NoPropsNoEventsComponentState() = default; + +#ifdef ANDROID + NoPropsNoEventsComponentState(NoPropsNoEventsComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture OBJECT_PROPS 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class ObjectPropsState { + public: + ObjectPropsState() = default; + +#ifdef ANDROID + ObjectPropsState(ObjectPropsState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture POINT_PROP 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class PointPropNativeComponentState { + public: + PointPropNativeComponentState() = default; + +#ifdef ANDROID + PointPropNativeComponentState(PointPropNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture STRING_ENUM_PROP 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class StringEnumPropsNativeComponentState { + public: + StringEnumPropsNativeComponentState() = default; + +#ifdef ANDROID + StringEnumPropsNativeComponentState(StringEnumPropsNativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture STRING_PROP 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class StringPropComponentState { + public: + StringPropComponentState() = default; + +#ifdef ANDROID + StringPropComponentState(StringPropComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture TWO_COMPONENTS_DIFFERENT_FILES 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class MultiFile1NativeComponentState { + public: + MultiFile1NativeComponentState() = default; + +#ifdef ANDROID + MultiFile1NativeComponentState(MultiFile1NativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + + +class MultiFile2NativeComponentState { + public: + MultiFile2NativeComponentState() = default; + +#ifdef ANDROID + MultiFile2NativeComponentState(MultiFile2NativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; + +exports[`GenerateStateH can generate fixture TWO_COMPONENTS_SAME_FILE 1`] = ` +Map { + "States.h" => " +/** + * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). + * + * Do not edit this file as changes may cause incorrect behavior and will be lost + * once the code is regenerated. + * + * @generated by codegen project: GenerateStateH.js + */ +#pragma once + +#ifdef ANDROID +#include +#include +#include +#endif + +namespace facebook { +namespace react { + + +class MultiComponent1NativeComponentState { + public: + MultiComponent1NativeComponentState() = default; + +#ifdef ANDROID + MultiComponent1NativeComponentState(MultiComponent1NativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + + +class MultiComponent2NativeComponentState { + public: + MultiComponent2NativeComponentState() = default; + +#ifdef ANDROID + MultiComponent2NativeComponentState(MultiComponent2NativeComponentState const &previousState, folly::dynamic data){}; + folly::dynamic getDynamic() const { + return {}; + }; + MapBuffer getMapBuffer() const { + return MapBufferBuilder::EMPTY(); + }; +#endif +}; + + +} // namespace react +} // namespace facebook +", +} +`; diff --git a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js index 146e39b46774a9..acfdde7f5bd6ae 100644 --- a/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js +++ b/packages/react-native-codegen/src/generators/modules/GenerateModuleJniH.js @@ -92,6 +92,7 @@ LOCAL_SHARED_LIBRARIES := libfbjni \ libreact_render_core \ libreact_render_debug \ libreact_render_graphics \ + libreact_render_mapbuffer \ librrc_view \ libturbomodulejsijni \ libyoga diff --git a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap index 0a84dc885c4fa7..25ebbd4c262032 100644 --- a/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap +++ b/packages/react-native-codegen/src/generators/modules/__tests__/__snapshots__/GenerateModuleJniH-test.js.snap @@ -54,7 +54,7 @@ LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/SampleWithUppercaseName -LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libturbomodulejsijni libyoga +LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics libreact_render_mapbuffer librrc_view libturbomodulejsijni libyoga LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -165,7 +165,7 @@ LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/complex_objects -LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libturbomodulejsijni libyoga +LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics libreact_render_mapbuffer librrc_view libturbomodulejsijni libyoga LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -269,7 +269,7 @@ LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/cxx_only_native_modules -LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libturbomodulejsijni libyoga +LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics libreact_render_mapbuffer librrc_view libturbomodulejsijni libyoga LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -380,7 +380,7 @@ LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/empty_native_modules -LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libturbomodulejsijni libyoga +LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics libreact_render_mapbuffer librrc_view libturbomodulejsijni libyoga LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -491,7 +491,7 @@ LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/native_modules_with_type_aliases -LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libturbomodulejsijni libyoga +LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics libreact_render_mapbuffer librrc_view libturbomodulejsijni libyoga LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -610,7 +610,7 @@ LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/real_module_example -LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libturbomodulejsijni libyoga +LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics libreact_render_mapbuffer librrc_view libturbomodulejsijni libyoga LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -721,7 +721,7 @@ LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/simple_native_modules -LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libturbomodulejsijni libyoga +LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics libreact_render_mapbuffer librrc_view libturbomodulejsijni libyoga LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" @@ -840,7 +840,7 @@ LOCAL_SRC_FILES := $(subst $(LOCAL_PATH)/,,$(LOCAL_SRC_FILES)) LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) $(LOCAL_PATH)/react/renderer/components/two_modules_different_files -LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics librrc_view libturbomodulejsijni libyoga +LOCAL_SHARED_LIBRARIES := libfbjni libfolly_runtime libglog libjsi libreact_codegen_rncore libreact_debug libreact_nativemodule_core libreact_render_core libreact_render_debug libreact_render_graphics libreact_render_mapbuffer librrc_view libturbomodulejsijni libyoga LOCAL_CFLAGS := \\\\ -DLOG_TAG=\\\\\\"ReactNative\\\\\\" diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index 05bbefbe17e07b..fc36e9a1a7ce40 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -944,7 +944,7 @@ SPEC CHECKSUMS: React-RCTTest: 06c388632dc7b30df17af01c8f9e89e641b4d31c React-RCTText: a861fbf2835299d3cc4189697cddd8bd8602afb9 React-RCTVibration: 0386f50996a153b3f39cecbe7d139763ac9a9fdf - React-rncore: 2a6ad37560e94cf7ff32e3f2ae1e708491b4c1f3 + React-rncore: 665c70690f404bbfa3948148de72689672a906d2 React-runtimeexecutor: 97dca9247f4d3cfe0733384b189c6930fbd402b7 ReactCommon: 8e39c4b24da570ea2b631accbf779b5891befe0c ScreenshotManager: 3fc534a218e7b8dde632158411d0f15b0ca8893c diff --git a/scripts/react_native_pods.rb b/scripts/react_native_pods.rb index 5922794f6d8123..25c2e2179fa69a 100644 --- a/scripts/react_native_pods.rb +++ b/scripts/react_native_pods.rb @@ -243,6 +243,8 @@ def use_react_native_codegen!(spec, options={}) "EventEmitters.h", "Props.cpp", "Props.h", + "States.cpp", + "States.h", "RCTComponentViewHelpers.h", "ShadowNodes.cpp", "ShadowNodes.h" From df3e57ca347c75c81d3be620e38e7904c522dcb9 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Wed, 21 Sep 2022 10:54:59 -0700 Subject: [PATCH 3/3] Parse custom NativeState in Flow (#34753) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/34753 This Diff introduce a the capability to parse custom NativeStates in Flow. To achieve this I also had to define the CodegenSchema. The parsing follows the exact same rules as props, as initial heuristic. This should allow enough customization for the developers who needs a custom state. There is only a case I was not able to make it work that is STATE_ALIASED_LOCALLY, from the fixtures. I don't know how diffuse it is and I think we can live with some workarounds for the time being. This diff also adds tests for the custom Native State Flow Parser. ## Changelog [General][Added] - Implement custom Native State parsing in Flow Differential Revision: D39686251 fbshipit-source-id: dbd288bc97adcc9352dac3377be35ee90669da68 --- .../react-native-codegen/src/CodegenSchema.js | 3 + .../__tests__/checkComponentSnaps-test.js | 13 +- .../components/__test_fixtures__/failures.js | 408 ++ .../components/__test_fixtures__/fixtures.js | 438 +- .../component-parser-test.js.snap | 3597 +++++++++++++---- .../src/parsers/flow/components/index.js | 39 +- .../src/parsers/flow/components/schema.js | 4 + .../src/parsers/flow/components/states.js | 493 +++ 8 files changed, 4160 insertions(+), 835 deletions(-) create mode 100644 packages/react-native-codegen/src/parsers/flow/components/states.js diff --git a/packages/react-native-codegen/src/CodegenSchema.js b/packages/react-native-codegen/src/CodegenSchema.js index 3e8857ec2be0a2..5f98933329e6fc 100644 --- a/packages/react-native-codegen/src/CodegenSchema.js +++ b/packages/react-native-codegen/src/CodegenSchema.js @@ -80,6 +80,7 @@ export type ComponentShape = $ReadOnly<{ events: $ReadOnlyArray, props: $ReadOnlyArray>, commands: $ReadOnlyArray>, + state?: $ReadOnlyArray>, }>; export type OptionsShape = $ReadOnly<{ @@ -185,6 +186,8 @@ export type ReservedPropTypeAnnotation = $ReadOnly<{ | 'EdgeInsetsPrimitive', }>; +export type StateTypeAnnotation = PropTypeAnnotation; + export type CommandTypeAnnotation = FunctionTypeAnnotation< CommandParamTypeAnnotation, VoidTypeAnnotation, diff --git a/packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js b/packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js index 367bd9df5b3cd2..bb54ecb30c4aa6 100644 --- a/packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js +++ b/packages/react-native-codegen/src/parsers/consistency/__tests__/checkComponentSnaps-test.js @@ -14,10 +14,19 @@ const {compareSnaps, compareTsArraySnaps} = require('../compareSnaps.js'); const flowFixtures = require('../../flow/components/__test_fixtures__/fixtures.js'); const flowSnaps = require('../../../../src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap'); -const flowExtraCases = []; +const flowExtraCases = [ + //TODO: remove these once we implement TypeScript parser for Custom State + 'ALL_STATE_TYPES', + 'ARRAY_STATE_TYPES', + 'COMMANDS_EVENTS_STATE_TYPES_EXPORTED', + 'OBJECT_STATE_TYPES', +]; const tsFixtures = require('../../typescript/components/__test_fixtures__/fixtures.js'); const tsSnaps = require('../../../../src/parsers/typescript/components/__tests__/__snapshots__/typescript-component-parser-test.js.snap'); -const tsExtraCases = ['ARRAY2_PROP_TYPES_NO_EVENTS']; +const tsExtraCases = ['ARRAY2_PROP_TYPES_NO_EVENTS'].concat([ + //TODO: remove these once we implement TypeScript parser for Custom State + 'COMMANDS_AND_EVENTS_TYPES_EXPORTED', +]); const ignoredCases = ['ARRAY_PROP_TYPES_NO_EVENTS']; compareSnaps( diff --git a/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/failures.js b/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/failures.js index 1d7072636a48a8..20d5b6044b6165 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/failures.js +++ b/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/failures.js @@ -579,6 +579,402 @@ export default (codegenNativeComponent( ): HostComponent); `; +// === STATE === +const NULLABLE_STATE_WITH_DEFAULT = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +import type {WithDefault, Float} from 'CodegenTypes'; +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, + +|}>; + +export type ModuleNativeState = $ReadOnly<{| + nullable_with_default: ?WithDefault, +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const NON_OPTIONAL_KEY_STATE_WITH_DEFAULT_VALUE = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +import type {WithDefault, Float} from 'CodegenTypes'; +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, + required_key_with_default: WithDefault, +|}>; + +export type ModuleNativeState = $ReadOnly<{| + required_key_with_default: WithDefault, +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const STATE_CONFLICT_NAMES = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, + isEnabled: string, + + isEnabled: boolean, +|}>; + +export type ModuleNativeState = $ReadOnly<{| + isEnabled: string, + + isEnabled: boolean, +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const STATE_CONFLICT_WITH_SPREAD_PROPS = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +type StateInFile = $ReadOnly<{| + isEnabled: boolean, +|}>; + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +export type ModuleNativeState = $ReadOnly<{| + ...StateInFile, + isEnabled: boolean, +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const STATE_SPREAD_CONFLICTS_WITH_PROPS = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +type StateInFile = $ReadOnly<{| + isEnabled: boolean, +|}>; + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +export type ModuleNativeState = $ReadOnly<{| + isEnabled: boolean, + ...StateInFile, +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const STATE_NUMBER_TYPE = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +export type ModuleNativeState = $ReadOnly<{| + someProp: number +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const STATE_MIXED_ENUM = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +export type ModuleNativeState = $ReadOnly<{| + someProp?: WithDefault<'foo' | 1, 1> +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const STATE_ENUM_BOOLEAN = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +export type ModuleNativeState = $ReadOnly<{| + someProp?: WithDefault +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const STATE_ARRAY_MIXED_ENUM = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +export type ModuleNativeState = $ReadOnly<{| + someProp?: WithDefault<$ReadOnlyArray<'foo' | 1>, 1> +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const STATE_ARRAY_ENUM_BOOLEAN = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +export type ModuleNativeState = $ReadOnly<{| + someProp?: WithDefault<$ReadOnlyArray, false> +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const STATE_ARRAY_ENUM_INT = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +export type ModuleNativeState = $ReadOnly<{| + someProp?: WithDefault<$ReadOnlyArray<0 | 1>, 0> +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const DOUBLE_STATE_IN_FILE = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +export type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +type SecondNativeState = $ReadOnly<{| + someProp: boolean +|}>; + +export type FirstNativeState = $ReadOnly<{| + someOtherProp: boolean +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + module.exports = { COMMANDS_DEFINED_INLINE, COMMANDS_DEFINED_MULTIPLE_TIMES, @@ -597,4 +993,16 @@ module.exports = { PROP_ARRAY_MIXED_ENUM, PROP_ARRAY_ENUM_BOOLEAN, PROP_ARRAY_ENUM_INT, + NULLABLE_STATE_WITH_DEFAULT, + NON_OPTIONAL_KEY_STATE_WITH_DEFAULT_VALUE, + STATE_CONFLICT_NAMES, + STATE_CONFLICT_WITH_SPREAD_PROPS, + STATE_SPREAD_CONFLICTS_WITH_PROPS, + STATE_NUMBER_TYPE, + STATE_MIXED_ENUM, + STATE_ENUM_BOOLEAN, + STATE_ARRAY_MIXED_ENUM, + STATE_ARRAY_ENUM_BOOLEAN, + STATE_ARRAY_ENUM_INT, + DOUBLE_STATE_IN_FILE, }; diff --git a/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/fixtures.js b/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/fixtures.js index 6c94f1065b0c24..41ac2e97093c73 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/fixtures.js +++ b/packages/react-native-codegen/src/parsers/flow/components/__test_fixtures__/fixtures.js @@ -939,7 +939,7 @@ export default (codegenNativeComponent( ): NativeType); `; -const COMMANDS_AND_EVENTS_TYPES_EXPORTED = ` +const COMMANDS_EVENTS_STATE_TYPES_EXPORTED = ` /** * Copyright (c) Meta Platforms, Inc. and affiliates. * @@ -981,6 +981,13 @@ export type ModuleProps = $ReadOnly<{| onDirectEventDefinedInlineWithPaperName: DirectEventHandler, |}>; +// Add state here +export type ModuleNativeState = $ReadOnly<{| + boolean_required: boolean, + boolean_optional_key?: WithDefault, + boolean_optional_both?: WithDefault, +|}> + type NativeType = HostComponent; export type ScrollTo = (viewRef: React.ElementRef, y: Int, animated: Boolean) => Void; @@ -998,6 +1005,429 @@ export default (codegenNativeComponent( ): NativeType); `; +// === STATE === // +const ALL_STATE_TYPES = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +import type {Int32, Double, Float, WithDefault} from 'CodegenTypes'; +import type {ImageSource} from 'ImageSource'; +import type {ColorValue, ColorArrayValue, PointValue, EdgeInsetsValue} from 'StyleSheetTypes'; +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +type ModuleNativeState = $ReadOnly<{| + // Boolean props + boolean_required: boolean, + boolean_optional_key?: WithDefault, + boolean_optional_both?: WithDefault, + + // Boolean props, null default + boolean_null_optional_key?: WithDefault, + boolean_null_optional_both?: WithDefault, + + // String props + string_required: string, + string_optional_key?: WithDefault, + string_optional_both?: WithDefault, + + // String props, null default + string_null_optional_key?: WithDefault, + string_null_optional_both?: WithDefault, + + // Stringish props + stringish_required: Stringish, + stringish_optional_key?: WithDefault, + stringish_optional_both?: WithDefault, + + // Stringish props, null default + stringish_null_optional_key?: WithDefault, + stringish_null_optional_both?: WithDefault, + + // Double props + double_required: Double, + double_optional_key?: WithDefault, + double_optional_both?: WithDefault, + + // Float props + float_required: Float, + float_optional_key?: WithDefault, + float_optional_both?: WithDefault, + + // Float props, null default + float_null_optional_key?: WithDefault, + float_null_optional_both?: WithDefault, + + // Int32 props + int32_required: Int32, + int32_optional_key?: WithDefault, + int32_optional_both?: WithDefault, + + // String enum props + enum_optional_key?: WithDefault<'small' | 'large', 'small'>, + enum_optional_both?: WithDefault<'small' | 'large', 'small'>, + + // Int enum props + int_enum_optional_key?: WithDefault<0 | 1, 0>, + + // Object props + object_optional_key?: $ReadOnly<{| prop: string |}>, + object_optional_both?: ?$ReadOnly<{| prop: string |}>, + object_optional_value: ?$ReadOnly<{| prop: string |}>, + + // ImageSource props + image_required: ImageSource, + image_optional_value: ?ImageSource, + image_optional_both?: ?ImageSource, + + // ColorValue props + color_required: ColorValue, + color_optional_key?: ColorValue, + color_optional_value: ?ColorValue, + color_optional_both?: ?ColorValue, + + // ColorArrayValue props + color_array_required: ColorArrayValue, + color_array_optional_key?: ColorArrayValue, + color_array_optional_value: ?ColorArrayValue, + color_array_optional_both?: ?ColorArrayValue, + + // ProcessedColorValue props + processed_color_required: ProcessedColorValue, + processed_color_optional_key?: ProcessedColorValue, + processed_color_optional_value: ?ProcessedColorValue, + processed_color_optional_both?: ?ProcessedColorValue, + + // PointValue props + point_required: PointValue, + point_optional_key?: PointValue, + point_optional_value: ?PointValue, + point_optional_both?: ?PointValue, + + // EdgeInsets props + insets_required: EdgeInsetsValue, + insets_optional_key?: EdgeInsetsValue, + insets_optional_value: ?EdgeInsetsValue, + insets_optional_both?: ?EdgeInsetsValue, +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const ARRAY_STATE_TYPES = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +import type {Int32, Double, Float, WithDefault} from 'CodegenTypes'; +import type {ImageSource} from 'ImageSource'; +import type {ColorValue, PointValue, ProcessColorValue, EdgeInsetsValue} from 'StyleSheetTypes'; +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +type ObjectType = $ReadOnly<{| prop: string |}>; +type ArrayObjectType = $ReadOnlyArray<$ReadOnly<{| prop: string |}>>; + +type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +type ModuleNativeState = $ReadOnly<{| + // Props + // Boolean props + array_boolean_required: $ReadOnlyArray, + array_boolean_optional_key?: $ReadOnlyArray, + array_boolean_optional_value: ?$ReadOnlyArray, + array_boolean_optional_both?: ?$ReadOnlyArray, + + // String props + array_string_required: $ReadOnlyArray, + array_string_optional_key?: $ReadOnlyArray, + array_string_optional_value: ?$ReadOnlyArray, + array_string_optional_both?: ?$ReadOnlyArray, + + // Double props + array_double_required: $ReadOnlyArray, + array_double_optional_key?: $ReadOnlyArray, + array_double_optional_value: ?$ReadOnlyArray, + array_double_optional_both?: ?$ReadOnlyArray, + + // Float props + array_float_required: $ReadOnlyArray, + array_float_optional_key?: $ReadOnlyArray, + array_float_optional_value: ?$ReadOnlyArray, + array_float_optional_both?: ?$ReadOnlyArray, + + // Int32 props + array_int32_required: $ReadOnlyArray, + array_int32_optional_key?: $ReadOnlyArray, + array_int32_optional_value: ?$ReadOnlyArray, + array_int32_optional_both?: ?$ReadOnlyArray, + + // String enum props + array_enum_optional_key?: WithDefault< + $ReadOnlyArray<'small' | 'large'>, + 'small', + >, + array_enum_optional_both?: WithDefault< + $ReadOnlyArray<'small' | 'large'>, + 'small', + >, + + // ImageSource props + array_image_required: $ReadOnlyArray, + array_image_optional_key?: $ReadOnlyArray, + array_image_optional_value: ?$ReadOnlyArray, + array_image_optional_both?: ?$ReadOnlyArray, + + // ColorValue props + array_color_required: $ReadOnlyArray, + array_color_optional_key?: $ReadOnlyArray, + array_color_optional_value: ?$ReadOnlyArray, + array_color_optional_both?: ?$ReadOnlyArray, + + // PointValue props + array_point_required: $ReadOnlyArray, + array_point_optional_key?: $ReadOnlyArray, + array_point_optional_value: ?$ReadOnlyArray, + array_point_optional_both?: ?$ReadOnlyArray, + + // EdgeInsetsValue props + array_insets_required: $ReadOnlyArray, + array_insets_optional_key?: $ReadOnlyArray, + array_insets_optional_value: ?$ReadOnlyArray, + array_insets_optional_both?: ?$ReadOnlyArray, + + // Object props + array_object_required: $ReadOnlyArray<$ReadOnly<{| prop: string |}>>, + array_object_optional_key?: $ReadOnlyArray<$ReadOnly<{| prop: string |}>>, + array_object_optional_value: ?ArrayObjectType, + array_object_optional_both?: ?$ReadOnlyArray, + + // Nested array object types + array_of_array_object_required: $ReadOnlyArray< + $ReadOnly<{| + // This needs to be the same name as the top level array above + array_object_required: $ReadOnlyArray<$ReadOnly<{| prop: string |}>>, + |}> + >, + array_of_array_object_optional_key?: $ReadOnlyArray< + $ReadOnly<{| + // This needs to be the same name as the top level array above + array_object_optional_key: $ReadOnlyArray<$ReadOnly<{| prop?: string |}>>, + |}> + >, + array_of_array_object_optional_value: ?$ReadOnlyArray< + $ReadOnly<{| + // This needs to be the same name as the top level array above + array_object_optional_value: $ReadOnlyArray<$ReadOnly<{| prop: ?string |}>>, + |}> + >, + array_of_array_object_optional_both?: ?$ReadOnlyArray< + $ReadOnly<{| + // This needs to be the same name as the top level array above + array_object_optional_both: $ReadOnlyArray<$ReadOnly<{| prop?: ?string |}>>, + |}> + >, + + // Nested array of array of object types + array_of_array_of_object_required: $ReadOnlyArray< + $ReadOnlyArray< + $ReadOnly<{| + prop: string, + |}>, + >, + >, + + // Nested array of array of object types (in file) + array_of_array_of_object_required_in_file: $ReadOnlyArray< + $ReadOnlyArray, + >, + + // Nested array of array of object types (with spread) + array_of_array_of_object_required_with_spread: $ReadOnlyArray< + $ReadOnlyArray< + $ReadOnly<{| + ...ObjectType + |}>, + >, + >, +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +const OBJECT_STATE_TYPES = ` +/** + * Copyright (c) Meta Platforms, Inc. and 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 strict-local + */ + +'use strict'; + +const codegenNativeComponent = require('codegenNativeComponent'); + +import type {Int32, Double, Float, WithDefault} from 'CodegenTypes'; +import type {ImageSource} from 'ImageSource'; +import type {ColorValue, PointValue, EdgeInsetsValue} from 'StyleSheetTypes'; +import type {ViewProps} from 'ViewPropTypes'; +import type {HostComponent} from 'react-native'; + +type ModuleProps = $ReadOnly<{| + ...ViewProps, +|}>; + +type ModuleNativeState = $ReadOnly<{| + // Props + // Boolean props + boolean_required: $ReadOnly<{|prop: boolean|}>, + boolean_optional: $ReadOnly<{|prop?: WithDefault|}>, + + // String props + string_required: $ReadOnly<{|prop: string|}>, + string_optional: $ReadOnly<{|prop?: WithDefault|}>, + + // Double props + double_required: $ReadOnly<{|prop: Double|}>, + double_optional: $ReadOnly<{|prop?: WithDefault|}>, + + // Float props + float_required: $ReadOnly<{|prop: Float|}>, + float_optional: $ReadOnly<{|prop?: WithDefault|}>, + + // Int32 props + int_required: $ReadOnly<{|prop: Int32|}>, + int_optional: $ReadOnly<{|prop?: WithDefault|}>, + + // String enum props + enum_optional: $ReadOnly<{| + prop?: WithDefault<$ReadOnlyArray<'small' | 'large'>, 'small'>, + |}>, + + // ImageSource props + image_required: $ReadOnly<{|prop: ImageSource|}>, + image_optional_key: $ReadOnly<{|prop?: ImageSource|}>, + image_optional_value: $ReadOnly<{|prop: ?ImageSource|}>, + image_optional_both: $ReadOnly<{|prop?: ?ImageSource|}>, + + // ColorValue props + color_required: $ReadOnly<{|prop: ColorValue|}>, + color_optional_key: $ReadOnly<{|prop?: ColorValue|}>, + color_optional_value: $ReadOnly<{|prop: ?ColorValue|}>, + color_optional_both: $ReadOnly<{|prop?: ?ColorValue|}>, + + // ProcessedColorValue props + processed_color_required: $ReadOnly<{|prop: ProcessedColorValue|}>, + processed_color_optional_key: $ReadOnly<{|prop?: ProcessedColorValue|}>, + processed_color_optional_value: $ReadOnly<{|prop: ?ProcessedColorValue|}>, + processed_color_optional_both: $ReadOnly<{|prop?: ?ProcessedColorValue|}>, + + // PointValue props + point_required: $ReadOnly<{|prop: PointValue|}>, + point_optional_key: $ReadOnly<{|prop?: PointValue|}>, + point_optional_value: $ReadOnly<{|prop: ?PointValue|}>, + point_optional_both: $ReadOnly<{|prop?: ?PointValue|}>, + + // EdgeInsetsValue props + insets_required: $ReadOnly<{|prop: EdgeInsetsValue|}>, + insets_optional_key: $ReadOnly<{|prop?: EdgeInsetsValue|}>, + insets_optional_value: $ReadOnly<{|prop: ?EdgeInsetsValue|}>, + insets_optional_both: $ReadOnly<{|prop?: ?EdgeInsetsValue|}>, + + // Nested object props + object_required: $ReadOnly<{|prop: $ReadOnly<{nestedProp: string}>|}>, + object_optional_key?: $ReadOnly<{|prop: $ReadOnly<{nestedProp: string}>|}>, + object_optional_value: ?$ReadOnly<{|prop: $ReadOnly<{nestedProp: string}>|}>, + object_optional_both?: ?$ReadOnly<{|prop: $ReadOnly<{nestedProp: string}>|}>, +|}>; + +export default (codegenNativeComponent( + 'Module', +): HostComponent); +`; + +//TODO: fix this. The code is the same as per the props, but it fails with the State. +// const STATE_ALIASED_LOCALLY = ` +// /** +// * Copyright (c) Meta Platforms, Inc. and 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 strict-local +// */ + +// 'use strict'; + +// import type {ViewProps} from 'ViewPropTypes'; +// import type {HostComponent} from 'react-native'; + +// const codegenNativeComponent = require('codegenNativeComponent'); + +// type DeepSpread = $ReadOnly<{| +// otherStringProp: string, +// |}>; + +// export type StateInFile = $ReadOnly<{| +// ...DeepSpread, +// isEnabled: boolean, +// label: string, +// |}>; + +// export type ModuleProps = $ReadOnly<{| +// ...ViewProps, +// |}>; + +// export type ModuleNativeState = $ReadOnly<{| +// ...StateInFile, + +// localType: $ReadOnly<{| +// ...StateInFile +// |}>, + +// localArr: $ReadOnlyArray +// ||}>; + +// export default (codegenNativeComponent( +// 'Module', +// ): HostComponent); +// `; + module.exports = { ALL_PROP_TYPES_NO_EVENTS, ARRAY_PROP_TYPES_NO_EVENTS, @@ -1009,8 +1439,12 @@ module.exports = { EVENTS_DEFINED_INLINE_WITH_ALL_TYPES, EVENTS_DEFINED_AS_NULL_INLINE, PROPS_AND_EVENTS_TYPES_EXPORTED, - COMMANDS_AND_EVENTS_TYPES_EXPORTED, + COMMANDS_EVENTS_STATE_TYPES_EXPORTED, COMMANDS_DEFINED_WITH_ALL_TYPES, PROPS_AS_EXTERNAL_TYPES, COMMANDS_WITH_EXTERNAL_TYPES, + ALL_STATE_TYPES, + ARRAY_STATE_TYPES, + OBJECT_STATE_TYPES, + // STATE_ALIASED_LOCALLY, }; diff --git a/packages/react-native-codegen/src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap b/packages/react-native-codegen/src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap index 5f52a06d543815..5dd86f7f66129a 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap +++ b/packages/react-native-codegen/src/parsers/flow/components/__tests__/__snapshots__/component-parser-test.js.snap @@ -12,8 +12,14 @@ exports[`RN Codegen Flow Parser Fails with error message COMMANDS_DEFINED_WITHOU exports[`RN Codegen Flow Parser Fails with error message COMMANDS_DEFINED_WITHOUT_REF 1`] = `"The first argument of method hotspotUpdate must be of type React.ElementRef<>"`; +exports[`RN Codegen Flow Parser Fails with error message DOUBLE_STATE_IN_FILE 1`] = `"Found 2 NativeStates for Module. Each component can have only 1 NativeState"`; + +exports[`RN Codegen Flow Parser Fails with error message NON_OPTIONAL_KEY_STATE_WITH_DEFAULT_VALUE 1`] = `"key required_key_with_default must be optional if used with WithDefault<> annotation"`; + exports[`RN Codegen Flow Parser Fails with error message NON_OPTIONAL_KEY_WITH_DEFAULT_VALUE 1`] = `"key required_key_with_default must be optional if used with WithDefault<> annotation"`; +exports[`RN Codegen Flow Parser Fails with error message NULLABLE_STATE_WITH_DEFAULT 1`] = `"WithDefault<> is optional and does not need to be marked as optional. Please remove the ? annotation in front of it."`; + exports[`RN Codegen Flow Parser Fails with error message NULLABLE_WITH_DEFAULT 1`] = `"WithDefault<> is optional and does not need to be marked as optional. Please remove the ? annotation in front of it."`; exports[`RN Codegen Flow Parser Fails with error message PROP_ARRAY_ENUM_BOOLEAN 1`] = `"Unsupported union type for \\"someProp\\", received \\"BooleanLiteralTypeAnnotation\\""`; @@ -34,6 +40,24 @@ exports[`RN Codegen Flow Parser Fails with error message PROPS_CONFLICT_WITH_SPR exports[`RN Codegen Flow Parser Fails with error message PROPS_SPREAD_CONFLICTS_WITH_PROPS 1`] = `"A prop was already defined with the name isEnabled"`; +exports[`RN Codegen Flow Parser Fails with error message STATE_ARRAY_ENUM_BOOLEAN 1`] = `"Unsupported union type for \\"someProp\\", received \\"BooleanLiteralTypeAnnotation\\""`; + +exports[`RN Codegen Flow Parser Fails with error message STATE_ARRAY_ENUM_INT 1`] = `"Arrays of int enums are not supported (see: \\"someProp\\")"`; + +exports[`RN Codegen Flow Parser Fails with error message STATE_ARRAY_MIXED_ENUM 1`] = `"Mixed types are not supported (see \\"someProp\\")."`; + +exports[`RN Codegen Flow Parser Fails with error message STATE_CONFLICT_NAMES 1`] = `"A prop was already defined with the name isEnabled"`; + +exports[`RN Codegen Flow Parser Fails with error message STATE_CONFLICT_WITH_SPREAD_PROPS 1`] = `"A property was already defined with the name isEnabled in the State"`; + +exports[`RN Codegen Flow Parser Fails with error message STATE_ENUM_BOOLEAN 1`] = `"Unsupported union type for \\"someProp\\", received \\"BooleanLiteralTypeAnnotation\\""`; + +exports[`RN Codegen Flow Parser Fails with error message STATE_MIXED_ENUM 1`] = `"Mixed types are not supported (see \\"someProp\\")."`; + +exports[`RN Codegen Flow Parser Fails with error message STATE_NUMBER_TYPE 1`] = `"Cannot use \\"NumberTypeAnnotation\\" type annotation for \\"someProp\\": must use a specific numeric type like Int32, Double, or Float"`; + +exports[`RN Codegen Flow Parser Fails with error message STATE_SPREAD_CONFLICTS_WITH_PROPS 1`] = `"A property was already defined with the name isEnabled in the State"`; + exports[`RN Codegen Flow Parser can generate fixture ALL_PROP_TYPES_NO_EVENTS 1`] = ` "{ 'modules': { @@ -549,7 +573,7 @@ exports[`RN Codegen Flow Parser can generate fixture ALL_PROP_TYPES_NO_EVENTS 1` }" `; -exports[`RN Codegen Flow Parser can generate fixture ARRAY_PROP_TYPES_NO_EVENTS 1`] = ` +exports[`RN Codegen Flow Parser can generate fixture ALL_STATE_TYPES 1`] = ` "{ 'modules': { 'Module': { @@ -563,692 +587,501 @@ exports[`RN Codegen Flow Parser can generate fixture ARRAY_PROP_TYPES_NO_EVENTS } ], 'events': [], - 'props': [ + 'props': [], + 'commands': [], + 'state': [ { - 'name': 'array_boolean_required', + 'name': 'boolean_required', 'optional': false, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'BooleanTypeAnnotation' - } + 'type': 'BooleanTypeAnnotation', + 'default': false } }, { - 'name': 'array_boolean_optional_key', + 'name': 'boolean_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'BooleanTypeAnnotation' - } + 'type': 'BooleanTypeAnnotation', + 'default': true } }, { - 'name': 'array_boolean_optional_value', + 'name': 'boolean_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'BooleanTypeAnnotation' - } + 'type': 'BooleanTypeAnnotation', + 'default': true } }, { - 'name': 'array_boolean_optional_both', + 'name': 'boolean_null_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'BooleanTypeAnnotation' - } + 'type': 'BooleanTypeAnnotation', + 'default': null } }, { - 'name': 'array_string_required', + 'name': 'boolean_null_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'BooleanTypeAnnotation', + 'default': null + } + }, + { + 'name': 'string_required', 'optional': false, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'StringTypeAnnotation' - } + 'type': 'StringTypeAnnotation', + 'default': null } }, { - 'name': 'array_string_optional_key', + 'name': 'string_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'StringTypeAnnotation' - } + 'type': 'StringTypeAnnotation', + 'default': '' } }, { - 'name': 'array_string_optional_value', + 'name': 'string_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'StringTypeAnnotation' - } + 'type': 'StringTypeAnnotation', + 'default': '' } }, { - 'name': 'array_string_optional_both', + 'name': 'string_null_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'StringTypeAnnotation' - } + 'type': 'StringTypeAnnotation', + 'default': null } }, { - 'name': 'array_double_required', - 'optional': false, + 'name': 'string_null_optional_both', + 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'DoubleTypeAnnotation' - } + 'type': 'StringTypeAnnotation', + 'default': null } }, { - 'name': 'array_double_optional_key', - 'optional': true, + 'name': 'stringish_required', + 'optional': false, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'DoubleTypeAnnotation' - } + 'type': 'StringTypeAnnotation', + 'default': null } }, { - 'name': 'array_double_optional_value', + 'name': 'stringish_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'DoubleTypeAnnotation' - } + 'type': 'StringTypeAnnotation', + 'default': '' } }, { - 'name': 'array_double_optional_both', + 'name': 'stringish_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'DoubleTypeAnnotation' - } + 'type': 'StringTypeAnnotation', + 'default': '' } }, { - 'name': 'array_float_required', - 'optional': false, + 'name': 'stringish_null_optional_key', + 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'FloatTypeAnnotation' - } + 'type': 'StringTypeAnnotation', + 'default': null } }, { - 'name': 'array_float_optional_key', + 'name': 'stringish_null_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'FloatTypeAnnotation' - } + 'type': 'StringTypeAnnotation', + 'default': null } }, { - 'name': 'array_float_optional_value', - 'optional': true, + 'name': 'double_required', + 'optional': false, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'FloatTypeAnnotation' - } + 'type': 'DoubleTypeAnnotation', + 'default': 0 } }, { - 'name': 'array_float_optional_both', + 'name': 'double_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'FloatTypeAnnotation' - } + 'type': 'DoubleTypeAnnotation', + 'default': 1.1 } }, { - 'name': 'array_int32_required', - 'optional': false, + 'name': 'double_optional_both', + 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'Int32TypeAnnotation' - } + 'type': 'DoubleTypeAnnotation', + 'default': 1.1 } }, { - 'name': 'array_int32_optional_key', - 'optional': true, + 'name': 'float_required', + 'optional': false, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'Int32TypeAnnotation' - } + 'type': 'FloatTypeAnnotation', + 'default': 0 } }, { - 'name': 'array_int32_optional_value', + 'name': 'float_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'Int32TypeAnnotation' - } + 'type': 'FloatTypeAnnotation', + 'default': 1.1 } }, { - 'name': 'array_int32_optional_both', + 'name': 'float_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'Int32TypeAnnotation' - } + 'type': 'FloatTypeAnnotation', + 'default': 1.1 } }, { - 'name': 'array_enum_optional_key', + 'name': 'float_null_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'StringEnumTypeAnnotation', - 'default': 'small', - 'options': [ - 'small', - 'large' - ] - } + 'type': 'FloatTypeAnnotation', + 'default': null } }, { - 'name': 'array_enum_optional_both', + 'name': 'float_null_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'StringEnumTypeAnnotation', - 'default': 'small', - 'options': [ - 'small', - 'large' - ] - } + 'type': 'FloatTypeAnnotation', + 'default': null } }, { - 'name': 'array_image_required', + 'name': 'int32_required', 'optional': false, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'ImageSourcePrimitive' - } + 'type': 'Int32TypeAnnotation', + 'default': 0 } }, { - 'name': 'array_image_optional_key', + 'name': 'int32_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'ImageSourcePrimitive' - } + 'type': 'Int32TypeAnnotation', + 'default': 1 } }, { - 'name': 'array_image_optional_value', + 'name': 'int32_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'ImageSourcePrimitive' - } + 'type': 'Int32TypeAnnotation', + 'default': 1 } }, { - 'name': 'array_image_optional_both', + 'name': 'enum_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'ImageSourcePrimitive' - } - } + 'type': 'StringEnumTypeAnnotation', + 'default': 'small', + 'options': [ + 'small', + 'large' + ] + } }, { - 'name': 'array_color_required', - 'optional': false, + 'name': 'enum_optional_both', + 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'ColorPrimitive' - } + 'type': 'StringEnumTypeAnnotation', + 'default': 'small', + 'options': [ + 'small', + 'large' + ] } }, { - 'name': 'array_color_optional_key', + 'name': 'int_enum_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'ColorPrimitive' - } + 'type': 'Int32EnumTypeAnnotation', + 'default': 0, + 'options': [ + 0, + 1 + ] } }, { - 'name': 'array_color_optional_value', + 'name': 'object_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'ColorPrimitive' - } + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] } }, { - 'name': 'array_color_optional_both', + 'name': 'object_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'ColorPrimitive' - } + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] } }, { - 'name': 'array_point_required', + 'name': 'object_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + }, + { + 'name': 'image_required', 'optional': false, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'PointPrimitive' - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' } }, { - 'name': 'array_point_optional_key', + 'name': 'image_optional_value', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'PointPrimitive' - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' } }, { - 'name': 'array_point_optional_value', + 'name': 'image_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'PointPrimitive' - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' } }, { - 'name': 'array_point_optional_both', + 'name': 'color_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + }, + { + 'name': 'color_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ReservedPropTypeAnnotation', - 'name': 'PointPrimitive' - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' } }, { - 'name': 'array_insets_required', + 'name': 'color_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + }, + { + 'name': 'color_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + }, + { + 'name': 'color_array_required', 'optional': false, 'typeAnnotation': { 'type': 'ArrayTypeAnnotation', 'elementType': { 'type': 'ReservedPropTypeAnnotation', - 'name': 'EdgeInsetsPrimitive' + 'name': 'ColorPrimitive' } } }, { - 'name': 'array_insets_optional_key', + 'name': 'color_array_optional_key', 'optional': true, 'typeAnnotation': { 'type': 'ArrayTypeAnnotation', 'elementType': { 'type': 'ReservedPropTypeAnnotation', - 'name': 'EdgeInsetsPrimitive' + 'name': 'ColorPrimitive' } } }, { - 'name': 'array_insets_optional_value', + 'name': 'color_array_optional_value', 'optional': true, 'typeAnnotation': { 'type': 'ArrayTypeAnnotation', 'elementType': { 'type': 'ReservedPropTypeAnnotation', - 'name': 'EdgeInsetsPrimitive' + 'name': 'ColorPrimitive' } } }, { - 'name': 'array_insets_optional_both', + 'name': 'color_array_optional_both', 'optional': true, 'typeAnnotation': { 'type': 'ArrayTypeAnnotation', 'elementType': { 'type': 'ReservedPropTypeAnnotation', - 'name': 'EdgeInsetsPrimitive' + 'name': 'ColorPrimitive' } } }, { - 'name': 'array_object_required', + 'name': 'processed_color_required', 'optional': false, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': false, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' } }, { - 'name': 'array_object_optional_key', + 'name': 'processed_color_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': false, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' } }, { - 'name': 'array_object_optional_value', + 'name': 'processed_color_optional_value', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': false, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' } }, { - 'name': 'array_object_optional_both', + 'name': 'processed_color_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': false, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' } }, { - 'name': 'array_of_array_object_required', + 'name': 'point_required', 'optional': false, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'array_object_required', - 'optional': false, - 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': false, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } - } - } - ] - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' } }, { - 'name': 'array_of_array_object_optional_key', + 'name': 'point_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'array_object_optional_key', - 'optional': false, - 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': true, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } - } - } - ] - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' } }, { - 'name': 'array_of_array_object_optional_value', + 'name': 'point_optional_value', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'array_object_optional_value', - 'optional': false, - 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': true, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } - } - } - ] - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' } }, { - 'name': 'array_of_array_object_optional_both', + 'name': 'point_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'array_object_optional_both', - 'optional': false, - 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': true, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } - } - } - ] - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' } }, { - 'name': 'array_of_array_of_object_required', + 'name': 'insets_required', 'optional': false, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': false, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' } }, { - 'name': 'array_of_array_of_object_required_in_file', - 'optional': false, + 'name': 'insets_optional_key', + 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': false, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' } }, { - 'name': 'array_of_array_of_object_required_with_spread', - 'optional': false, + 'name': 'insets_optional_value', + 'optional': true, 'typeAnnotation': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ArrayTypeAnnotation', - 'elementType': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'prop', - 'optional': false, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation', - 'default': null - } - } - ] - } - } + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + }, + { + 'name': 'insets_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' } } - ], - 'commands': [] + ] } } } @@ -1256,7 +1089,7 @@ exports[`RN Codegen Flow Parser can generate fixture ARRAY_PROP_TYPES_NO_EVENTS }" `; -exports[`RN Codegen Flow Parser can generate fixture COMMANDS_AND_EVENTS_TYPES_EXPORTED 1`] = ` +exports[`RN Codegen Flow Parser can generate fixture ARRAY_PROP_TYPES_NO_EVENTS 1`] = ` "{ 'modules': { 'Module': { @@ -1269,83 +1102,1601 @@ exports[`RN Codegen Flow Parser can generate fixture COMMANDS_AND_EVENTS_TYPES_E 'knownTypeName': 'ReactNativeCoreViewProps' } ], - 'events': [ + 'events': [], + 'props': [ { - 'name': 'onBubblingEventDefinedInline', + 'name': 'array_boolean_required', 'optional': false, - 'bubblingType': 'bubble', 'typeAnnotation': { - 'type': 'EventTypeAnnotation', - 'argument': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'boolean_required', - 'optional': false, - 'typeAnnotation': { - 'type': 'BooleanTypeAnnotation' - } - }, - { - 'name': 'boolean_optional_key', - 'optional': true, - 'typeAnnotation': { - 'type': 'BooleanTypeAnnotation' - } - }, - { - 'name': 'boolean_optional_value', - 'optional': true, - 'typeAnnotation': { - 'type': 'BooleanTypeAnnotation' - } - }, - { - 'name': 'boolean_optional_both', - 'optional': true, - 'typeAnnotation': { - 'type': 'BooleanTypeAnnotation' - } - }, - { - 'name': 'string_required', - 'optional': false, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation' - } - }, - { - 'name': 'string_optional_key', - 'optional': true, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation' - } - }, - { - 'name': 'string_optional_value', - 'optional': true, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation' - } - }, - { - 'name': 'string_optional_both', - 'optional': true, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation' - } - }, - { - 'name': 'double_required', - 'optional': false, - 'typeAnnotation': { - 'type': 'DoubleTypeAnnotation' - } - }, - { - 'name': 'double_optional_key', - 'optional': true, - 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'BooleanTypeAnnotation' + } + } + }, + { + 'name': 'array_boolean_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'BooleanTypeAnnotation' + } + } + }, + { + 'name': 'array_boolean_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'BooleanTypeAnnotation' + } + } + }, + { + 'name': 'array_boolean_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'BooleanTypeAnnotation' + } + } + }, + { + 'name': 'array_string_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringTypeAnnotation' + } + } + }, + { + 'name': 'array_string_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringTypeAnnotation' + } + } + }, + { + 'name': 'array_string_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringTypeAnnotation' + } + } + }, + { + 'name': 'array_string_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringTypeAnnotation' + } + } + }, + { + 'name': 'array_double_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'DoubleTypeAnnotation' + } + } + }, + { + 'name': 'array_double_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'DoubleTypeAnnotation' + } + } + }, + { + 'name': 'array_double_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'DoubleTypeAnnotation' + } + } + }, + { + 'name': 'array_double_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'DoubleTypeAnnotation' + } + } + }, + { + 'name': 'array_float_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'FloatTypeAnnotation' + } + } + }, + { + 'name': 'array_float_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'FloatTypeAnnotation' + } + } + }, + { + 'name': 'array_float_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'FloatTypeAnnotation' + } + } + }, + { + 'name': 'array_float_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'FloatTypeAnnotation' + } + } + }, + { + 'name': 'array_int32_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'Int32TypeAnnotation' + } + } + }, + { + 'name': 'array_int32_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'Int32TypeAnnotation' + } + } + }, + { + 'name': 'array_int32_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'Int32TypeAnnotation' + } + } + }, + { + 'name': 'array_int32_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'Int32TypeAnnotation' + } + } + }, + { + 'name': 'array_enum_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringEnumTypeAnnotation', + 'default': 'small', + 'options': [ + 'small', + 'large' + ] + } + } + }, + { + 'name': 'array_enum_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringEnumTypeAnnotation', + 'default': 'small', + 'options': [ + 'small', + 'large' + ] + } + } + }, + { + 'name': 'array_image_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + }, + { + 'name': 'array_image_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + }, + { + 'name': 'array_image_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + }, + { + 'name': 'array_image_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + }, + { + 'name': 'array_color_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + }, + { + 'name': 'array_color_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + }, + { + 'name': 'array_color_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + }, + { + 'name': 'array_color_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + }, + { + 'name': 'array_point_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + }, + { + 'name': 'array_point_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + }, + { + 'name': 'array_point_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + }, + { + 'name': 'array_point_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + }, + { + 'name': 'array_insets_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + }, + { + 'name': 'array_insets_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + }, + { + 'name': 'array_insets_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + }, + { + 'name': 'array_insets_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + }, + { + 'name': 'array_object_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + }, + { + 'name': 'array_object_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + }, + { + 'name': 'array_object_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + }, + { + 'name': 'array_object_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + }, + { + 'name': 'array_of_array_object_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'array_object_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + ] + } + } + }, + { + 'name': 'array_of_array_object_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'array_object_optional_key', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + ] + } + } + }, + { + 'name': 'array_of_array_object_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'array_object_optional_value', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + ] + } + } + }, + { + 'name': 'array_of_array_object_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'array_object_optional_both', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + ] + } + } + }, + { + 'name': 'array_of_array_of_object_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + }, + { + 'name': 'array_of_array_of_object_required_in_file', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + }, + { + 'name': 'array_of_array_of_object_required_with_spread', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + } + ], + 'commands': [] + } + } + } + } +}" +`; + +exports[`RN Codegen Flow Parser can generate fixture ARRAY_STATE_TYPES 1`] = ` +"{ + 'modules': { + 'Module': { + 'type': 'Component', + 'components': { + 'Module': { + 'extendsProps': [ + { + 'type': 'ReactNativeBuiltInType', + 'knownTypeName': 'ReactNativeCoreViewProps' + } + ], + 'events': [], + 'props': [], + 'commands': [], + 'state': [ + { + 'name': 'array_boolean_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'BooleanTypeAnnotation' + } + } + }, + { + 'name': 'array_boolean_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'BooleanTypeAnnotation' + } + } + }, + { + 'name': 'array_boolean_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'BooleanTypeAnnotation' + } + } + }, + { + 'name': 'array_boolean_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'BooleanTypeAnnotation' + } + } + }, + { + 'name': 'array_string_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringTypeAnnotation' + } + } + }, + { + 'name': 'array_string_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringTypeAnnotation' + } + } + }, + { + 'name': 'array_string_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringTypeAnnotation' + } + } + }, + { + 'name': 'array_string_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringTypeAnnotation' + } + } + }, + { + 'name': 'array_double_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'DoubleTypeAnnotation' + } + } + }, + { + 'name': 'array_double_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'DoubleTypeAnnotation' + } + } + }, + { + 'name': 'array_double_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'DoubleTypeAnnotation' + } + } + }, + { + 'name': 'array_double_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'DoubleTypeAnnotation' + } + } + }, + { + 'name': 'array_float_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'FloatTypeAnnotation' + } + } + }, + { + 'name': 'array_float_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'FloatTypeAnnotation' + } + } + }, + { + 'name': 'array_float_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'FloatTypeAnnotation' + } + } + }, + { + 'name': 'array_float_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'FloatTypeAnnotation' + } + } + }, + { + 'name': 'array_int32_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'Int32TypeAnnotation' + } + } + }, + { + 'name': 'array_int32_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'Int32TypeAnnotation' + } + } + }, + { + 'name': 'array_int32_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'Int32TypeAnnotation' + } + } + }, + { + 'name': 'array_int32_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'Int32TypeAnnotation' + } + } + }, + { + 'name': 'array_enum_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringEnumTypeAnnotation', + 'default': 'small', + 'options': [ + 'small', + 'large' + ] + } + } + }, + { + 'name': 'array_enum_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'StringEnumTypeAnnotation', + 'default': 'small', + 'options': [ + 'small', + 'large' + ] + } + } + }, + { + 'name': 'array_image_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + }, + { + 'name': 'array_image_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + }, + { + 'name': 'array_image_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + }, + { + 'name': 'array_image_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + }, + { + 'name': 'array_color_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + }, + { + 'name': 'array_color_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + }, + { + 'name': 'array_color_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + }, + { + 'name': 'array_color_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + }, + { + 'name': 'array_point_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + }, + { + 'name': 'array_point_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + }, + { + 'name': 'array_point_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + }, + { + 'name': 'array_point_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + }, + { + 'name': 'array_insets_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + }, + { + 'name': 'array_insets_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + }, + { + 'name': 'array_insets_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + }, + { + 'name': 'array_insets_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + }, + { + 'name': 'array_object_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + }, + { + 'name': 'array_object_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + }, + { + 'name': 'array_object_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + }, + { + 'name': 'array_object_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + }, + { + 'name': 'array_of_array_object_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'array_object_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + ] + } + } + }, + { + 'name': 'array_of_array_object_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'array_object_optional_key', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + ] + } + } + }, + { + 'name': 'array_of_array_object_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'array_object_optional_value', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + ] + } + } + }, + { + 'name': 'array_of_array_object_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'array_object_optional_both', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + ] + } + } + }, + { + 'name': 'array_of_array_of_object_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + }, + { + 'name': 'array_of_array_of_object_required_in_file', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + }, + { + 'name': 'array_of_array_of_object_required_with_spread', + 'optional': false, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + } + } + } + ] + } + } + } + } +}" +`; + +exports[`RN Codegen Flow Parser can generate fixture COMMANDS_DEFINED_WITH_ALL_TYPES 1`] = ` +"{ + 'modules': { + 'Module': { + 'type': 'Component', + 'components': { + 'Module': { + 'extendsProps': [ + { + 'type': 'ReactNativeBuiltInType', + 'knownTypeName': 'ReactNativeCoreViewProps' + } + ], + 'events': [], + 'props': [], + 'commands': [ + { + 'name': 'handleRootTag', + 'optional': false, + 'typeAnnotation': { + 'type': 'FunctionTypeAnnotation', + 'params': [ + { + 'name': 'rootTag', + 'typeAnnotation': { + 'type': 'ReservedTypeAnnotation', + 'name': 'RootTag' + } + } + ], + 'returnTypeAnnotation': { + 'type': 'VoidTypeAnnotation' + } + } + }, + { + 'name': 'hotspotUpdate', + 'optional': false, + 'typeAnnotation': { + 'type': 'FunctionTypeAnnotation', + 'params': [ + { + 'name': 'x', + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation' + } + }, + { + 'name': 'y', + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation' + } + } + ], + 'returnTypeAnnotation': { + 'type': 'VoidTypeAnnotation' + } + } + }, + { + 'name': 'scrollTo', + 'optional': false, + 'typeAnnotation': { + 'type': 'FunctionTypeAnnotation', + 'params': [ + { + 'name': 'x', + 'typeAnnotation': { + 'type': 'FloatTypeAnnotation' + } + }, + { + 'name': 'y', + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation' + } + }, + { + 'name': 'z', + 'typeAnnotation': { + 'type': 'DoubleTypeAnnotation' + } + }, + { + 'name': 'animated', + 'typeAnnotation': { + 'type': 'BooleanTypeAnnotation' + } + } + ], + 'returnTypeAnnotation': { + 'type': 'VoidTypeAnnotation' + } + } + } + ] + } + } + } + } +}" +`; + +exports[`RN Codegen Flow Parser can generate fixture COMMANDS_EVENTS_STATE_TYPES_EXPORTED 1`] = ` +"{ + 'modules': { + 'Module': { + 'type': 'Component', + 'components': { + 'Module': { + 'extendsProps': [ + { + 'type': 'ReactNativeBuiltInType', + 'knownTypeName': 'ReactNativeCoreViewProps' + } + ], + 'events': [ + { + 'name': 'onBubblingEventDefinedInline', + 'optional': false, + 'bubblingType': 'bubble', + 'typeAnnotation': { + 'type': 'EventTypeAnnotation', + 'argument': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'boolean_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'BooleanTypeAnnotation' + } + }, + { + 'name': 'boolean_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'BooleanTypeAnnotation' + } + }, + { + 'name': 'boolean_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'BooleanTypeAnnotation' + } + }, + { + 'name': 'boolean_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'BooleanTypeAnnotation' + } + }, + { + 'name': 'string_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation' + } + }, + { + 'name': 'string_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation' + } + }, + { + 'name': 'string_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation' + } + }, + { + 'name': 'string_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation' + } + }, + { + 'name': 'double_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'DoubleTypeAnnotation' + } + }, + { + 'name': 'double_optional_key', + 'optional': true, + 'typeAnnotation': { 'type': 'DoubleTypeAnnotation' } }, @@ -2811,107 +4162,30 @@ exports[`RN Codegen Flow Parser can generate fixture COMMANDS_AND_EVENTS_TYPES_E } } } - ] - } - } - } - } -}" -`; - -exports[`RN Codegen Flow Parser can generate fixture COMMANDS_DEFINED_WITH_ALL_TYPES 1`] = ` -"{ - 'modules': { - 'Module': { - 'type': 'Component', - 'components': { - 'Module': { - 'extendsProps': [ - { - 'type': 'ReactNativeBuiltInType', - 'knownTypeName': 'ReactNativeCoreViewProps' - } ], - 'events': [], - 'props': [], - 'commands': [ + 'state': [ { - 'name': 'handleRootTag', + 'name': 'boolean_required', 'optional': false, 'typeAnnotation': { - 'type': 'FunctionTypeAnnotation', - 'params': [ - { - 'name': 'rootTag', - 'typeAnnotation': { - 'type': 'ReservedTypeAnnotation', - 'name': 'RootTag' - } - } - ], - 'returnTypeAnnotation': { - 'type': 'VoidTypeAnnotation' - } + 'type': 'BooleanTypeAnnotation', + 'default': false } }, { - 'name': 'hotspotUpdate', - 'optional': false, + 'name': 'boolean_optional_key', + 'optional': true, 'typeAnnotation': { - 'type': 'FunctionTypeAnnotation', - 'params': [ - { - 'name': 'x', - 'typeAnnotation': { - 'type': 'Int32TypeAnnotation' - } - }, - { - 'name': 'y', - 'typeAnnotation': { - 'type': 'Int32TypeAnnotation' - } - } - ], - 'returnTypeAnnotation': { - 'type': 'VoidTypeAnnotation' - } + 'type': 'BooleanTypeAnnotation', + 'default': true } }, { - 'name': 'scrollTo', - 'optional': false, + 'name': 'boolean_optional_both', + 'optional': true, 'typeAnnotation': { - 'type': 'FunctionTypeAnnotation', - 'params': [ - { - 'name': 'x', - 'typeAnnotation': { - 'type': 'FloatTypeAnnotation' - } - }, - { - 'name': 'y', - 'typeAnnotation': { - 'type': 'Int32TypeAnnotation' - } - }, - { - 'name': 'z', - 'typeAnnotation': { - 'type': 'DoubleTypeAnnotation' - } - }, - { - 'name': 'animated', - 'typeAnnotation': { - 'type': 'BooleanTypeAnnotation' - } - } - ], - 'returnTypeAnnotation': { - 'type': 'VoidTypeAnnotation' - } + 'type': 'BooleanTypeAnnotation', + 'default': true } } ] @@ -6663,257 +7937,943 @@ exports[`RN Codegen Flow Parser can generate fixture EVENTS_DEFINED_INLINE_WITH_ } }, { - 'name': 'int32_optional_key', + 'name': 'int32_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation' + } + }, + { + 'name': 'int32_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation' + } + }, + { + 'name': 'int32_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation' + } + }, + { + 'name': 'enum_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringEnumTypeAnnotation', + 'options': [ + 'small', + 'large' + ] + } + }, + { + 'name': 'enum_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringEnumTypeAnnotation', + 'options': [ + 'small', + 'large' + ] + } + }, + { + 'name': 'enum_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringEnumTypeAnnotation', + 'options': [ + 'small', + 'large' + ] + } + }, + { + 'name': 'enum_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringEnumTypeAnnotation', + 'options': [ + 'small', + 'large' + ] + } + }, + { + 'name': 'object_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'boolean_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'BooleanTypeAnnotation' + } + } + ] + } + }, + { + 'name': 'object_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'string_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation' + } + } + ] + } + }, + { + 'name': 'object_optional_value', 'optional': true, 'typeAnnotation': { - 'type': 'Int32TypeAnnotation' + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'float_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'FloatTypeAnnotation' + } + } + ] } }, { - 'name': 'int32_optional_value', + 'name': 'object_optional_both', 'optional': true, 'typeAnnotation': { - 'type': 'Int32TypeAnnotation' + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'int32_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation' + } + } + ] } }, { - 'name': 'int32_optional_both', - 'optional': true, + 'name': 'object_required_nested_2_layers', + 'optional': false, 'typeAnnotation': { - 'type': 'Int32TypeAnnotation' + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'object_optional_nested_1_layer', + 'optional': true, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'boolean_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation' + } + }, + { + 'name': 'string_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation' + } + }, + { + 'name': 'double_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'DoubleTypeAnnotation' + } + }, + { + 'name': 'float_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'FloatTypeAnnotation' + } + }, + { + 'name': 'int32_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation' + } + } + ] + } + } + ] } }, { - 'name': 'enum_required', + 'name': 'object_readonly_required', 'optional': false, 'typeAnnotation': { - 'type': 'StringEnumTypeAnnotation', - 'options': [ - 'small', - 'large' + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'boolean_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'BooleanTypeAnnotation' + } + } ] } }, { - 'name': 'enum_optional_key', + 'name': 'object_readonly_optional_key', 'optional': true, 'typeAnnotation': { - 'type': 'StringEnumTypeAnnotation', - 'options': [ - 'small', - 'large' + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'string_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation' + } + } ] } }, { - 'name': 'enum_optional_value', + 'name': 'object_readonly_optional_value', 'optional': true, 'typeAnnotation': { - 'type': 'StringEnumTypeAnnotation', - 'options': [ - 'small', - 'large' + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'float_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'FloatTypeAnnotation' + } + } ] } }, { - 'name': 'enum_optional_both', + 'name': 'object_readonly_optional_both', 'optional': true, 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'int32_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation' + } + } + ] + } + } + ] + } + } + } + ], + 'props': [], + 'commands': [] + } + } + } + } +}" +`; + +exports[`RN Codegen Flow Parser can generate fixture NO_PROPS_EVENTS_ONLY_DEPRECATED_VIEW_CONFIG_NAME_OPTION 1`] = ` +"{ + 'modules': { + 'Module': { + 'type': 'Component', + 'components': { + 'Module': { + 'deprecatedViewConfigName': 'DeprecateModuleName', + 'extendsProps': [ + { + 'type': 'ReactNativeBuiltInType', + 'knownTypeName': 'ReactNativeCoreViewProps' + } + ], + 'events': [], + 'props': [], + 'commands': [] + } + } + } + } +}" +`; + +exports[`RN Codegen Flow Parser can generate fixture OBJECT_PROP_TYPES_NO_EVENTS 1`] = ` +"{ + 'modules': { + 'Module': { + 'type': 'Component', + 'components': { + 'Module': { + 'extendsProps': [ + { + 'type': 'ReactNativeBuiltInType', + 'knownTypeName': 'ReactNativeCoreViewProps' + } + ], + 'events': [], + 'props': [ + { + 'name': 'boolean_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'BooleanTypeAnnotation', + 'default': false + } + } + ] + } + }, + { + 'name': 'boolean_optional', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'BooleanTypeAnnotation', + 'default': false + } + } + ] + } + }, + { + 'name': 'string_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null + } + } + ] + } + }, + { + 'name': 'string_optional', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': '' + } + } + ] + } + }, + { + 'name': 'double_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'DoubleTypeAnnotation', + 'default': 0 + } + } + ] + } + }, + { + 'name': 'double_optional', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'DoubleTypeAnnotation', + 'default': 0 + } + } + ] + } + }, + { + 'name': 'float_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'FloatTypeAnnotation', + 'default': 0 + } + } + ] + } + }, + { + 'name': 'float_optional', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'FloatTypeAnnotation', + 'default': 0 + } + } + ] + } + }, + { + 'name': 'int_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation', + 'default': 0 + } + } + ] + } + }, + { + 'name': 'int_optional', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'Int32TypeAnnotation', + 'default': 0 + } + } + ] + } + }, + { + 'name': 'enum_optional', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ArrayTypeAnnotation', + 'elementType': { 'type': 'StringEnumTypeAnnotation', + 'default': 'small', 'options': [ 'small', 'large' ] } - }, - { - 'name': 'object_required', - 'optional': false, - 'typeAnnotation': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'boolean_required', - 'optional': false, - 'typeAnnotation': { - 'type': 'BooleanTypeAnnotation' - } - } - ] - } - }, - { - 'name': 'object_optional_key', - 'optional': true, - 'typeAnnotation': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'string_optional_key', - 'optional': true, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation' - } - } - ] - } - }, - { - 'name': 'object_optional_value', - 'optional': true, - 'typeAnnotation': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'float_optional_value', - 'optional': true, - 'typeAnnotation': { - 'type': 'FloatTypeAnnotation' - } - } - ] - } - }, - { - 'name': 'object_optional_both', - 'optional': true, - 'typeAnnotation': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'int32_optional_both', - 'optional': true, - 'typeAnnotation': { - 'type': 'Int32TypeAnnotation' - } - } - ] - } - }, - { - 'name': 'object_required_nested_2_layers', - 'optional': false, - 'typeAnnotation': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'object_optional_nested_1_layer', - 'optional': true, - 'typeAnnotation': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'boolean_required', - 'optional': false, - 'typeAnnotation': { - 'type': 'Int32TypeAnnotation' - } - }, - { - 'name': 'string_optional_key', - 'optional': true, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation' - } - }, - { - 'name': 'double_optional_value', - 'optional': true, - 'typeAnnotation': { - 'type': 'DoubleTypeAnnotation' - } - }, - { - 'name': 'float_optional_value', - 'optional': true, - 'typeAnnotation': { - 'type': 'FloatTypeAnnotation' - } - }, - { - 'name': 'int32_optional_both', - 'optional': true, - 'typeAnnotation': { - 'type': 'Int32TypeAnnotation' - } - } - ] - } - } - ] - } - }, - { - 'name': 'object_readonly_required', - 'optional': false, - 'typeAnnotation': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'boolean_required', - 'optional': false, - 'typeAnnotation': { - 'type': 'BooleanTypeAnnotation' - } + } + } + ] + } + }, + { + 'name': 'image_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + ] + } + }, + { + 'name': 'image_optional_key', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + ] + } + }, + { + 'name': 'image_optional_value', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + ] + } + }, + { + 'name': 'image_optional_both', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ImageSourcePrimitive' + } + } + ] + } + }, + { + 'name': 'color_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + ] + } + }, + { + 'name': 'color_optional_key', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + ] + } + }, + { + 'name': 'color_optional_value', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + ] + } + }, + { + 'name': 'color_optional_both', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + ] + } + }, + { + 'name': 'processed_color_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + ] + } + }, + { + 'name': 'processed_color_optional_key', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + ] + } + }, + { + 'name': 'processed_color_optional_value', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + ] + } + }, + { + 'name': 'processed_color_optional_both', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'ColorPrimitive' + } + } + ] + } + }, + { + 'name': 'point_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + ] + } + }, + { + 'name': 'point_optional_key', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + ] + } + }, + { + 'name': 'point_optional_value', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + ] + } + }, + { + 'name': 'point_optional_both', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'PointPrimitive' + } + } + ] + } + }, + { + 'name': 'insets_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + ] + } + }, + { + 'name': 'insets_optional_key', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + ] + } + }, + { + 'name': 'insets_optional_value', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + ] + } + }, + { + 'name': 'insets_optional_both', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': true, + 'typeAnnotation': { + 'type': 'ReservedPropTypeAnnotation', + 'name': 'EdgeInsetsPrimitive' + } + } + ] + } + }, + { + 'name': 'object_required', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'nestedProp', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null } - ] - } - }, - { - 'name': 'object_readonly_optional_key', - 'optional': true, - 'typeAnnotation': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'string_optional_key', - 'optional': true, - 'typeAnnotation': { - 'type': 'StringTypeAnnotation' - } + } + ] + } + } + ] + } + }, + { + 'name': 'object_optional_key', + 'optional': true, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'nestedProp', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null } - ] - } - }, - { - 'name': 'object_readonly_optional_value', - 'optional': true, - 'typeAnnotation': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'float_optional_value', - 'optional': true, - 'typeAnnotation': { - 'type': 'FloatTypeAnnotation' - } + } + ] + } + } + ] + } + }, + { + 'name': 'object_optional_value', + 'optional': true, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'nestedProp', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null } - ] - } - }, - { - 'name': 'object_readonly_optional_both', - 'optional': true, - 'typeAnnotation': { - 'type': 'ObjectTypeAnnotation', - 'properties': [ - { - 'name': 'int32_optional_both', - 'optional': true, - 'typeAnnotation': { - 'type': 'Int32TypeAnnotation' - } + } + ] + } + } + ] + } + }, + { + 'name': 'object_optional_both', + 'optional': true, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'prop', + 'optional': false, + 'typeAnnotation': { + 'type': 'ObjectTypeAnnotation', + 'properties': [ + { + 'name': 'nestedProp', + 'optional': false, + 'typeAnnotation': { + 'type': 'StringTypeAnnotation', + 'default': null } - ] - } + } + ] } - ] - } + } + ] } } ], - 'props': [], 'commands': [] } } @@ -6922,14 +8882,13 @@ exports[`RN Codegen Flow Parser can generate fixture EVENTS_DEFINED_INLINE_WITH_ }" `; -exports[`RN Codegen Flow Parser can generate fixture NO_PROPS_EVENTS_ONLY_DEPRECATED_VIEW_CONFIG_NAME_OPTION 1`] = ` +exports[`RN Codegen Flow Parser can generate fixture OBJECT_STATE_TYPES 1`] = ` "{ 'modules': { 'Module': { 'type': 'Component', 'components': { 'Module': { - 'deprecatedViewConfigName': 'DeprecateModuleName', 'extendsProps': [ { 'type': 'ReactNativeBuiltInType', @@ -6938,29 +8897,8 @@ exports[`RN Codegen Flow Parser can generate fixture NO_PROPS_EVENTS_ONLY_DEPREC ], 'events': [], 'props': [], - 'commands': [] - } - } - } - } -}" -`; - -exports[`RN Codegen Flow Parser can generate fixture OBJECT_PROP_TYPES_NO_EVENTS 1`] = ` -"{ - 'modules': { - 'Module': { - 'type': 'Component', - 'components': { - 'Module': { - 'extendsProps': [ - { - 'type': 'ReactNativeBuiltInType', - 'knownTypeName': 'ReactNativeCoreViewProps' - } - ], - 'events': [], - 'props': [ + 'commands': [], + 'state': [ { 'name': 'boolean_required', 'optional': false, @@ -7599,8 +9537,7 @@ exports[`RN Codegen Flow Parser can generate fixture OBJECT_PROP_TYPES_NO_EVENTS ] } } - ], - 'commands': [] + ] } } } diff --git a/packages/react-native-codegen/src/parsers/flow/components/index.js b/packages/react-native-codegen/src/parsers/flow/components/index.js index e488635d94300e..2b90a0a5bddce6 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/index.js +++ b/packages/react-native-codegen/src/parsers/flow/components/index.js @@ -16,6 +16,7 @@ import type {ComponentSchemaBuilderConfig} from './schema.js'; const {getTypes} = require('../utils'); const {getCommands} = require('./commands'); const {getEvents} = require('./events'); +const {getStateProperties, getState} = require('./states'); const {getExtendsProps, removeKnownExtends} = require('./extends'); const {getCommandOptions, getOptions} = require('./options'); const {getPropProperties, getProps} = require('./props'); @@ -111,8 +112,32 @@ function findComponentConfig(ast) { throw new Error('codegenNativeCommands may only be called once in a file'); } + const unexportedStateTypes: Array = ast.body + .filter( + node => + node.type === 'TypeAlias' && node.id.name.indexOf('NativeState') >= 0, + ) + .map(node => node.id.name); + + const exportedStateTypes: Array = namedExports + .filter( + node => + node.declaration.id && + node.declaration.id.name.indexOf('NativeState') >= 0, + ) + .map(node => node.declaration.id.name); + + const stateTypeName = exportedStateTypes.concat(unexportedStateTypes); + + if (Array.isArray(stateTypeName) && stateTypeName.length > 1) { + throw new Error( + `Found ${stateTypeName.length} NativeStates for ${foundConfig.componentName}. Each component can have only 1 NativeState`, + ); + } + return { ...foundConfig, + stateTypeName: stateTypeName[0], commandTypeName: commandsTypeNames[0] == null ? null @@ -185,6 +210,7 @@ function buildComponentSchema(ast): ComponentSchemaBuilderConfig { const { componentName, propsTypeName, + stateTypeName, commandTypeName, commandOptionsExpression, optionsExpression, @@ -209,7 +235,7 @@ function buildComponentSchema(ast): ComponentSchemaBuilderConfig { const events = getEvents(propProperties, types); const commands = getCommands(commandProperties, types); - return { + const toRet = { filename: componentName, componentName, options, @@ -218,6 +244,17 @@ function buildComponentSchema(ast): ComponentSchemaBuilderConfig { props, commands, }; + + if (stateTypeName) { + const stateProperties = getStateProperties(stateTypeName, types); + const state = getState(stateProperties, types); + return { + ...toRet, + state, + }; + } + + return toRet; } module.exports = { diff --git a/packages/react-native-codegen/src/parsers/flow/components/schema.js b/packages/react-native-codegen/src/parsers/flow/components/schema.js index ed6223c3347b50..e7bff107dbeba4 100644 --- a/packages/react-native-codegen/src/parsers/flow/components/schema.js +++ b/packages/react-native-codegen/src/parsers/flow/components/schema.js @@ -15,6 +15,7 @@ import type { NamedShape, CommandTypeAnnotation, PropTypeAnnotation, + StateTypeAnnotation, ExtendsPropsShape, SchemaType, OptionsShape, @@ -27,6 +28,7 @@ export type ComponentSchemaBuilderConfig = $ReadOnly<{ events: $ReadOnlyArray, props: $ReadOnlyArray>, commands: $ReadOnlyArray>, + state?: $ReadOnlyArray>, options?: ?OptionsShape, }>; @@ -36,6 +38,7 @@ function wrapComponentSchema({ extendsProps, events, props, + state, options, commands, }: ComponentSchemaBuilderConfig): SchemaType { @@ -50,6 +53,7 @@ function wrapComponentSchema({ events, props, commands, + state, }, }, }, diff --git a/packages/react-native-codegen/src/parsers/flow/components/states.js b/packages/react-native-codegen/src/parsers/flow/components/states.js new file mode 100644 index 00000000000000..987cc8a85adc31 --- /dev/null +++ b/packages/react-native-codegen/src/parsers/flow/components/states.js @@ -0,0 +1,493 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + */ + +'use strict'; +import type {ASTNode} from '../utils'; + +const {getValueFromTypes} = require('../utils.js'); + +import type {StateTypeAnnotation, NamedShape} from '../../../CodegenSchema.js'; +import type {TypeDeclarationMap} from '../utils.js'; + +function getStateProperties( + stateTypeName: string, + types: TypeDeclarationMap, +): $FlowFixMe { + const typeAlias = types[stateTypeName]; + try { + return typeAlias.right.typeParameters.params[0].properties; + } catch (e) { + throw new Error( + `Failed to find type definition for "${stateTypeName}", please check that you have a valid codegen flow file`, + ); + } +} + +function getTypeAnnotationForArray( + name: string, + typeAnnotation: $FlowFixMe, + defaultValue: $FlowFixMe | null, + types: TypeDeclarationMap, +) { + const extractedTypeAnnotation = getValueFromTypes(typeAnnotation, types); + if (extractedTypeAnnotation.type === 'NullableTypeAnnotation') { + throw new Error( + 'Nested optionals such as "$ReadOnlyArray" are not supported, please declare optionals at the top level of value definitions as in "?$ReadOnlyArray"', + ); + } + + if ( + extractedTypeAnnotation.type === 'GenericTypeAnnotation' && + extractedTypeAnnotation.id.name === 'WithDefault' + ) { + throw new Error( + 'Nested defaults such as "$ReadOnlyArray>" are not supported, please declare defaults at the top level of value definitions as in "WithDefault<$ReadOnlyArray, false>"', + ); + } + + if (extractedTypeAnnotation.type === 'GenericTypeAnnotation') { + // Resolve the type alias if it's not defined inline + const objectType = getValueFromTypes(extractedTypeAnnotation, types); + + if (objectType.id.name === '$ReadOnly') { + return { + type: 'ObjectTypeAnnotation', + properties: flattenProperties( + objectType.typeParameters.params[0].properties, + types, + ) + .map(prop => buildStateSchema(prop, types)) + .filter(Boolean), + }; + } + + if (objectType.id.name === '$ReadOnlyArray') { + // We need to go yet another level deeper to resolve + // types that may be defined in a type alias + const nestedObjectType = getValueFromTypes( + objectType.typeParameters.params[0], + types, + ); + + return { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ObjectTypeAnnotation', + properties: flattenProperties( + nestedObjectType.typeParameters.params[0].properties, + types, + ) + .map(prop => buildStateSchema(prop, types)) + .filter(Boolean), + }, + }; + } + } + + const type = + extractedTypeAnnotation.type === 'GenericTypeAnnotation' + ? extractedTypeAnnotation.id.name + : extractedTypeAnnotation.type; + + switch (type) { + case 'ImageSource': + return { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }; + case 'ColorValue': + case 'ProcessedColorValue': + return { + type: 'ReservedPropTypeAnnotation', + name: 'ColorPrimitive', + }; + case 'PointValue': + return { + type: 'ReservedPropTypeAnnotation', + name: 'PointPrimitive', + }; + case 'EdgeInsetsValue': + return { + type: 'ReservedPropTypeAnnotation', + name: 'EdgeInsetsPrimitive', + }; + case 'Stringish': + return { + type: 'StringTypeAnnotation', + }; + case 'Int32': + return { + type: 'Int32TypeAnnotation', + }; + case 'Double': + return { + type: 'DoubleTypeAnnotation', + }; + case 'Float': + return { + type: 'FloatTypeAnnotation', + }; + case 'BooleanTypeAnnotation': + return { + type: 'BooleanTypeAnnotation', + }; + case 'StringTypeAnnotation': + return { + type: 'StringTypeAnnotation', + }; + case 'UnionTypeAnnotation': + typeAnnotation.types.reduce((lastType, currType) => { + if (lastType && currType.type !== lastType.type) { + throw new Error(`Mixed types are not supported (see "${name}").`); + } + return currType; + }); + + if (defaultValue === null) { + throw new Error(`A default enum value is required for "${name}"`); + } + + const unionType = typeAnnotation.types[0].type; + if (unionType === 'StringLiteralTypeAnnotation') { + return { + type: 'StringEnumTypeAnnotation', + default: (defaultValue: string), + options: typeAnnotation.types.map(option => option.value), + }; + } else if (unionType === 'NumberLiteralTypeAnnotation') { + throw new Error( + `Arrays of int enums are not supported (see: "${name}")`, + ); + } else { + throw new Error( + `Unsupported union type for "${name}", received "${unionType}"`, + ); + } + default: + (type: empty); + throw new Error( + `Unknown property type for "${name}": ${type} in the State`, + ); + } +} + +function getTypeAnnotation( + name: string, + annotation: $FlowFixMe | ASTNode, + defaultValue: $FlowFixMe | null, + withNullDefault: boolean, + types: TypeDeclarationMap, +) { + const typeAnnotation = getValueFromTypes(annotation, types); + + if ( + typeAnnotation.type === 'GenericTypeAnnotation' && + typeAnnotation.id.name === '$ReadOnlyArray' + ) { + return { + type: 'ArrayTypeAnnotation', + elementType: getTypeAnnotationForArray( + name, + typeAnnotation.typeParameters.params[0], + defaultValue, + types, + ), + }; + } + + if ( + typeAnnotation.type === 'GenericTypeAnnotation' && + typeAnnotation.id.name === '$ReadOnly' + ) { + return { + type: 'ObjectTypeAnnotation', + properties: flattenProperties( + typeAnnotation.typeParameters.params[0].properties, + types, + ) + .map(prop => buildStateSchema(prop, types)) + .filter(Boolean), + }; + } + + const type = + typeAnnotation.type === 'GenericTypeAnnotation' + ? typeAnnotation.id.name + : typeAnnotation.type; + + switch (type) { + case 'ImageSource': + return { + type: 'ReservedPropTypeAnnotation', + name: 'ImageSourcePrimitive', + }; + case 'ColorValue': + case 'ProcessedColorValue': + return { + type: 'ReservedPropTypeAnnotation', + name: 'ColorPrimitive', + }; + case 'ColorArrayValue': + return { + type: 'ArrayTypeAnnotation', + elementType: { + type: 'ReservedPropTypeAnnotation', + name: 'ColorPrimitive', + }, + }; + case 'PointValue': + return { + type: 'ReservedPropTypeAnnotation', + name: 'PointPrimitive', + }; + case 'EdgeInsetsValue': + return { + type: 'ReservedPropTypeAnnotation', + name: 'EdgeInsetsPrimitive', + }; + case 'Int32': + return { + type: 'Int32TypeAnnotation', + default: ((defaultValue ? defaultValue : 0): number), + }; + case 'Double': + return { + type: 'DoubleTypeAnnotation', + default: ((defaultValue ? defaultValue : 0): number), + }; + case 'Float': + return { + type: 'FloatTypeAnnotation', + default: withNullDefault + ? (defaultValue: number | null) + : ((defaultValue ? defaultValue : 0): number), + }; + case 'BooleanTypeAnnotation': + return { + type: 'BooleanTypeAnnotation', + default: withNullDefault + ? (defaultValue: boolean | null) + : ((defaultValue == null ? false : defaultValue): boolean), + }; + case 'StringTypeAnnotation': + if (typeof defaultValue !== 'undefined') { + return { + type: 'StringTypeAnnotation', + default: (defaultValue: string | null), + }; + } + throw new Error(`A default string (or null) is required for "${name}"`); + case 'Stringish': + if (typeof defaultValue !== 'undefined') { + return { + type: 'StringTypeAnnotation', + default: (defaultValue: string | null), + }; + } + throw new Error(`A default string (or null) is required for "${name}"`); + case 'UnionTypeAnnotation': + typeAnnotation.types.reduce((lastType, currType) => { + if (lastType && currType.type !== lastType.type) { + throw new Error(`Mixed types are not supported (see "${name}").`); + } + return currType; + }); + + if (defaultValue === null) { + throw new Error(`A default enum value is required for "${name}"`); + } + + const unionType = typeAnnotation.types[0].type; + if (unionType === 'StringLiteralTypeAnnotation') { + return { + type: 'StringEnumTypeAnnotation', + default: (defaultValue: string), + options: typeAnnotation.types.map(option => option.value), + }; + } else if (unionType === 'NumberLiteralTypeAnnotation') { + return { + type: 'Int32EnumTypeAnnotation', + default: (defaultValue: number), + options: typeAnnotation.types.map(option => option.value), + }; + } else { + throw new Error( + `Unsupported union type for "${name}", received "${unionType}"`, + ); + } + case 'ObjectTypeAnnotation': + throw new Error( + `Cannot use "${type}" type annotation for "${name}": object types must be declared using $ReadOnly<>`, + ); + case 'NumberTypeAnnotation': + throw new Error( + `Cannot use "${type}" type annotation for "${name}": must use a specific numeric type like Int32, Double, or Float`, + ); + default: + (type: empty); + throw new Error( + `Unknown property type for "${name}": "${type}" in the State`, + ); + } +} + +function buildStateSchema( + property: PropAST, + types: TypeDeclarationMap, +): ?NamedShape { + const name = property.key.name; + + const value = getValueFromTypes(property.value, types); + let typeAnnotation = + value.type === 'NullableTypeAnnotation' ? value.typeAnnotation : value; + + const optional = + value.type === 'NullableTypeAnnotation' || + property.optional || + (value.type === 'GenericTypeAnnotation' && + typeAnnotation.id.name === 'WithDefault'); + + if ( + !property.optional && + value.type === 'GenericTypeAnnotation' && + typeAnnotation.id.name === 'WithDefault' + ) { + throw new Error( + `key ${name} must be optional if used with WithDefault<> annotation`, + ); + } + if ( + value.type === 'NullableTypeAnnotation' && + typeAnnotation.type === 'GenericTypeAnnotation' && + typeAnnotation.id.name === 'WithDefault' + ) { + throw new Error( + 'WithDefault<> is optional and does not need to be marked as optional. Please remove the ? annotation in front of it.', + ); + } + + // Discard events, they should not be managed in the state + let type = typeAnnotation.type; + if ( + type === 'GenericTypeAnnotation' && + (typeAnnotation.id.name === 'DirectEventHandler' || + typeAnnotation.id.name === 'BubblingEventHandler') + ) { + return null; + } + + // Discard style, they should not be managed in the state + if ( + name === 'style' && + type === 'GenericTypeAnnotation' && + typeAnnotation.id.name === 'ViewStyleProp' + ) { + return null; + } + + let defaultValue = null; + let withNullDefault = false; + if ( + type === 'GenericTypeAnnotation' && + typeAnnotation.id.name === 'WithDefault' + ) { + if (typeAnnotation.typeParameters.params.length === 1) { + throw new Error( + `WithDefault requires two parameters, did you forget to provide a default value for "${name}"?`, + ); + } + + defaultValue = typeAnnotation.typeParameters.params[1].value; + const defaultValueType = typeAnnotation.typeParameters.params[1].type; + + typeAnnotation = typeAnnotation.typeParameters.params[0]; + type = + typeAnnotation.type === 'GenericTypeAnnotation' + ? typeAnnotation.id.name + : typeAnnotation.type; + + if (defaultValueType === 'NullLiteralTypeAnnotation') { + defaultValue = null; + withNullDefault = true; + } + } + + return { + name, + optional, + typeAnnotation: getTypeAnnotation( + name, + typeAnnotation, + defaultValue, + withNullDefault, + types, + ), + }; +} + +// $FlowFixMe[unclear-type] there's no flowtype for ASTs +type PropAST = Object; + +function verifyStateNotAlreadyDefined( + props: $ReadOnlyArray, + needleProp: PropAST, +) { + const propName = needleProp.key.name; + const foundProp = props.some(prop => prop.key.name === propName); + if (foundProp) { + throw new Error( + `A property was already defined with the name ${propName} in the State`, + ); + } +} + +function flattenProperties( + typeDefinition: $ReadOnlyArray, + types: TypeDeclarationMap, +) { + return typeDefinition + .map(property => { + if (property.type === 'ObjectTypeProperty') { + return property; + } else if (property.type === 'ObjectTypeSpreadProperty') { + return flattenProperties( + getStateProperties(property.argument.id.name, types), + types, + ); + } + }) + .reduce((acc, item) => { + if (Array.isArray(item)) { + item.forEach(state => { + verifyStateNotAlreadyDefined(acc, state); + }); + return acc.concat(item); + } else { + verifyStateNotAlreadyDefined(acc, item); + acc.push(item); + return acc; + } + }, []) + .filter(Boolean); +} + +function getState( + typeDefinition: $ReadOnlyArray, + types: TypeDeclarationMap, +): $ReadOnlyArray> { + return flattenProperties(typeDefinition, types) + .map(property => buildStateSchema(property, types)) + .filter(Boolean); +} + +module.exports = { + getState, + getStateProperties, +};