@react-native/codegen 0.72.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +21 -0
  2. package/lib/CodegenSchema.js +11 -0
  3. package/lib/CodegenSchema.js.flow +351 -0
  4. package/lib/SchemaValidator.js +54 -0
  5. package/lib/SchemaValidator.js.flow +67 -0
  6. package/lib/cli/combine/combine-js-to-schema-cli.js +50 -0
  7. package/lib/cli/combine/combine-js-to-schema-cli.js.flow +49 -0
  8. package/lib/cli/combine/combine-js-to-schema.js +110 -0
  9. package/lib/cli/combine/combine-js-to-schema.js.flow +48 -0
  10. package/lib/cli/combine/combine-utils.js +118 -0
  11. package/lib/cli/combine/combine-utils.js.flow +85 -0
  12. package/lib/cli/generators/generate-all.js +65 -0
  13. package/lib/cli/generators/generate-all.js.flow +66 -0
  14. package/lib/cli/parser/parser-cli.js +55 -0
  15. package/lib/cli/parser/parser-cli.js.flow +18 -0
  16. package/lib/cli/parser/parser.js +35 -0
  17. package/lib/cli/parser/parser.js.flow +37 -0
  18. package/lib/cli/parser/parser.sh +15 -0
  19. package/lib/generators/RNCodegen.js +207 -0
  20. package/lib/generators/RNCodegen.js.flow +284 -0
  21. package/lib/generators/Utils.js +31 -0
  22. package/lib/generators/Utils.js.flow +33 -0
  23. package/lib/generators/__test_fixtures__/fixtures.js +79 -0
  24. package/lib/generators/__test_fixtures__/fixtures.js.flow +82 -0
  25. package/lib/generators/components/ComponentsGeneratorUtils.js +217 -0
  26. package/lib/generators/components/ComponentsGeneratorUtils.js.flow +304 -0
  27. package/lib/generators/components/CppHelpers.js +188 -0
  28. package/lib/generators/components/CppHelpers.js.flow +228 -0
  29. package/lib/generators/components/GenerateComponentDescriptorH.js +75 -0
  30. package/lib/generators/components/GenerateComponentDescriptorH.js.flow +95 -0
  31. package/lib/generators/components/GenerateComponentHObjCpp.js +327 -0
  32. package/lib/generators/components/GenerateComponentHObjCpp.js.flow +418 -0
  33. package/lib/generators/components/GenerateEventEmitterCpp.js +199 -0
  34. package/lib/generators/components/GenerateEventEmitterCpp.js.flow +273 -0
  35. package/lib/generators/components/GenerateEventEmitterH.js +224 -0
  36. package/lib/generators/components/GenerateEventEmitterH.js.flow +315 -0
  37. package/lib/generators/components/GeneratePropsCpp.js +126 -0
  38. package/lib/generators/components/GeneratePropsCpp.js.flow +161 -0
  39. package/lib/generators/components/GeneratePropsH.js +606 -0
  40. package/lib/generators/components/GeneratePropsH.js.flow +778 -0
  41. package/lib/generators/components/GeneratePropsJavaDelegate.js +287 -0
  42. package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +348 -0
  43. package/lib/generators/components/GeneratePropsJavaInterface.js +237 -0
  44. package/lib/generators/components/GeneratePropsJavaInterface.js.flow +288 -0
  45. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +157 -0
  46. package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +187 -0
  47. package/lib/generators/components/GeneratePropsJavaPojo/index.js +66 -0
  48. package/lib/generators/components/GeneratePropsJavaPojo/index.js.flow +80 -0
  49. package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +273 -0
  50. package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +296 -0
  51. package/lib/generators/components/GenerateShadowNodeCpp.js +73 -0
  52. package/lib/generators/components/GenerateShadowNodeCpp.js.flow +95 -0
  53. package/lib/generators/components/GenerateShadowNodeH.js +91 -0
  54. package/lib/generators/components/GenerateShadowNodeH.js.flow +124 -0
  55. package/lib/generators/components/GenerateStateCpp.js +70 -0
  56. package/lib/generators/components/GenerateStateCpp.js.flow +92 -0
  57. package/lib/generators/components/GenerateStateH.js +93 -0
  58. package/lib/generators/components/GenerateStateH.js.flow +111 -0
  59. package/lib/generators/components/GenerateTests.js +165 -0
  60. package/lib/generators/components/GenerateTests.js.flow +219 -0
  61. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +91 -0
  62. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +107 -0
  63. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +89 -0
  64. package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +105 -0
  65. package/lib/generators/components/GenerateViewConfigJs.js +410 -0
  66. package/lib/generators/components/GenerateViewConfigJs.js.flow +484 -0
  67. package/lib/generators/components/JavaHelpers.js +87 -0
  68. package/lib/generators/components/JavaHelpers.js.flow +119 -0
  69. package/lib/generators/components/__test_fixtures__/fixtures.js +1641 -0
  70. package/lib/generators/components/__test_fixtures__/fixtures.js.flow +1672 -0
  71. package/lib/generators/modules/GenerateModuleCpp.js +299 -0
  72. package/lib/generators/modules/GenerateModuleCpp.js.flow +278 -0
  73. package/lib/generators/modules/GenerateModuleH.js +373 -0
  74. package/lib/generators/modules/GenerateModuleH.js.flow +355 -0
  75. package/lib/generators/modules/GenerateModuleJavaSpec.js +571 -0
  76. package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +553 -0
  77. package/lib/generators/modules/GenerateModuleJniCpp.js +505 -0
  78. package/lib/generators/modules/GenerateModuleJniCpp.js.flow +523 -0
  79. package/lib/generators/modules/GenerateModuleJniH.js +138 -0
  80. package/lib/generators/modules/GenerateModuleJniH.js.flow +148 -0
  81. package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js +262 -0
  82. package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js.flow +208 -0
  83. package/lib/generators/modules/GenerateModuleObjCpp/Utils.js +25 -0
  84. package/lib/generators/modules/GenerateModuleObjCpp/Utils.js.flow +32 -0
  85. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +337 -0
  86. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js.flow +288 -0
  87. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +330 -0
  88. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js.flow +279 -0
  89. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js +25 -0
  90. package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js.flow +35 -0
  91. package/lib/generators/modules/GenerateModuleObjCpp/index.js +185 -0
  92. package/lib/generators/modules/GenerateModuleObjCpp/index.js.flow +219 -0
  93. package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +529 -0
  94. package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +510 -0
  95. package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js +96 -0
  96. package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js.flow +121 -0
  97. package/lib/generators/modules/Utils.js +34 -0
  98. package/lib/generators/modules/Utils.js.flow +53 -0
  99. package/lib/generators/modules/__test_fixtures__/fixtures.js +1658 -0
  100. package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +1669 -0
  101. package/lib/parsers/consistency/compareSnaps.js +84 -0
  102. package/lib/parsers/error-utils.js +284 -0
  103. package/lib/parsers/error-utils.js.flow +295 -0
  104. package/lib/parsers/errors.js +350 -0
  105. package/lib/parsers/errors.js.flow +439 -0
  106. package/lib/parsers/flow/components/__test_fixtures__/failures.js +583 -0
  107. package/lib/parsers/flow/components/__test_fixtures__/failures.js.flow +600 -0
  108. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +1001 -0
  109. package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +1016 -0
  110. package/lib/parsers/flow/components/commands.js +104 -0
  111. package/lib/parsers/flow/components/commands.js.flow +123 -0
  112. package/lib/parsers/flow/components/componentsUtils.js +446 -0
  113. package/lib/parsers/flow/components/componentsUtils.js.flow +496 -0
  114. package/lib/parsers/flow/components/events.js +233 -0
  115. package/lib/parsers/flow/components/events.js.flow +262 -0
  116. package/lib/parsers/flow/components/extends.js +52 -0
  117. package/lib/parsers/flow/components/extends.js.flow +66 -0
  118. package/lib/parsers/flow/components/index.js +267 -0
  119. package/lib/parsers/flow/components/index.js.flow +226 -0
  120. package/lib/parsers/flow/components/options.js +72 -0
  121. package/lib/parsers/flow/components/options.js.flow +87 -0
  122. package/lib/parsers/flow/components/props.js +47 -0
  123. package/lib/parsers/flow/components/props.js.flow +60 -0
  124. package/lib/parsers/flow/components/schema.js +106 -0
  125. package/lib/parsers/flow/components/schema.js.flow +62 -0
  126. package/lib/parsers/flow/index.js +80 -0
  127. package/lib/parsers/flow/index.js.flow +85 -0
  128. package/lib/parsers/flow/modules/__test_fixtures__/failures.js +215 -0
  129. package/lib/parsers/flow/modules/__test_fixtures__/failures.js.flow +223 -0
  130. package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +724 -0
  131. package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +747 -0
  132. package/lib/parsers/flow/modules/index.js +528 -0
  133. package/lib/parsers/flow/modules/index.js.flow +420 -0
  134. package/lib/parsers/flow/parser.js +109 -0
  135. package/lib/parsers/flow/parser.js.flow +83 -0
  136. package/lib/parsers/flow/utils.js +108 -0
  137. package/lib/parsers/flow/utils.js.flow +123 -0
  138. package/lib/parsers/parser.js +11 -0
  139. package/lib/parsers/parser.js.flow +70 -0
  140. package/lib/parsers/parserMock.js +96 -0
  141. package/lib/parsers/parserMock.js.flow +68 -0
  142. package/lib/parsers/parsers-commons.js +448 -0
  143. package/lib/parsers/parsers-commons.js.flow +447 -0
  144. package/lib/parsers/parsers-primitives.js +387 -0
  145. package/lib/parsers/parsers-primitives.js.flow +383 -0
  146. package/lib/parsers/parsers-utils.js +18 -0
  147. package/lib/parsers/parsers-utils.js.flow +19 -0
  148. package/lib/parsers/schema/index.js +23 -0
  149. package/lib/parsers/schema/index.js.flow +26 -0
  150. package/lib/parsers/typescript/components/__test_fixtures__/failures.js +489 -0
  151. package/lib/parsers/typescript/components/__test_fixtures__/failures.js.flow +505 -0
  152. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +1151 -0
  153. package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +1168 -0
  154. package/lib/parsers/typescript/components/commands.js +132 -0
  155. package/lib/parsers/typescript/components/commands.js.flow +151 -0
  156. package/lib/parsers/typescript/components/componentsUtils.js +471 -0
  157. package/lib/parsers/typescript/components/componentsUtils.js.flow +521 -0
  158. package/lib/parsers/typescript/components/events.js +240 -0
  159. package/lib/parsers/typescript/components/events.js.flow +262 -0
  160. package/lib/parsers/typescript/components/extends.js +88 -0
  161. package/lib/parsers/typescript/components/extends.js.flow +103 -0
  162. package/lib/parsers/typescript/components/index.js +277 -0
  163. package/lib/parsers/typescript/components/index.js.flow +239 -0
  164. package/lib/parsers/typescript/components/options.js +72 -0
  165. package/lib/parsers/typescript/components/options.js.flow +87 -0
  166. package/lib/parsers/typescript/components/props.js +39 -0
  167. package/lib/parsers/typescript/components/props.js.flow +48 -0
  168. package/lib/parsers/typescript/components/schema.js +106 -0
  169. package/lib/parsers/typescript/components/schema.js.flow +62 -0
  170. package/lib/parsers/typescript/index.js +85 -0
  171. package/lib/parsers/typescript/index.js.flow +94 -0
  172. package/lib/parsers/typescript/modules/__test_fixtures__/failures.js +160 -0
  173. package/lib/parsers/typescript/modules/__test_fixtures__/failures.js.flow +167 -0
  174. package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +701 -0
  175. package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +727 -0
  176. package/lib/parsers/typescript/modules/index.js +543 -0
  177. package/lib/parsers/typescript/modules/index.js.flow +435 -0
  178. package/lib/parsers/typescript/parseTopLevelType.js +203 -0
  179. package/lib/parsers/typescript/parseTopLevelType.js.flow +243 -0
  180. package/lib/parsers/typescript/parser.js +105 -0
  181. package/lib/parsers/typescript/parser.js.flow +87 -0
  182. package/lib/parsers/typescript/utils.js +101 -0
  183. package/lib/parsers/typescript/utils.js.flow +115 -0
  184. package/lib/parsers/utils.js +273 -0
  185. package/lib/parsers/utils.js.flow +266 -0
  186. package/package.json +45 -0
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+ import type {ComponentShape, PropTypeAnnotation} from '../../CodegenSchema';
13
+ import type {SchemaType} from '../../CodegenSchema';
14
+
15
+ const {getImports, toSafeCppString} = require('./CppHelpers');
16
+
17
+ type FilesOutput = Map<string, string>;
18
+ type PropValueType = string | number | boolean;
19
+
20
+ type TestCase = $ReadOnly<{
21
+ propName: string,
22
+ propValue: ?PropValueType,
23
+ testName?: string,
24
+ raw?: boolean,
25
+ }>;
26
+
27
+ const FileTemplate = ({
28
+ libraryName,
29
+ imports,
30
+ componentTests,
31
+ }: {
32
+ libraryName: string,
33
+ imports: string,
34
+ componentTests: string,
35
+ }) =>
36
+ `
37
+ /**
38
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
39
+ *
40
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
41
+ * once the code is regenerated.
42
+ *
43
+ * ${'@'}generated by codegen project: GenerateTests.js
44
+ * */
45
+
46
+ #include <gtest/gtest.h>
47
+ #include <react/renderer/core/PropsParserContext.h>
48
+ #include <react/renderer/components/${libraryName}/Props.h>
49
+ ${imports}
50
+
51
+ using namespace facebook::react;
52
+ ${componentTests}
53
+ `.trim();
54
+
55
+ const TestTemplate = ({
56
+ componentName,
57
+ testName,
58
+ propName,
59
+ propValue,
60
+ }: {
61
+ componentName: string,
62
+ testName: string,
63
+ propName: string,
64
+ propValue: string,
65
+ }) => `
66
+ TEST(${componentName}_${testName}, etc) {
67
+ auto propParser = RawPropsParser();
68
+ propParser.prepare<${componentName}>();
69
+ auto const &sourceProps = ${componentName}();
70
+ auto const &rawProps = RawProps(folly::dynamic::object("${propName}", ${propValue}));
71
+
72
+ ContextContainer contextContainer{};
73
+ PropsParserContext parserContext{-1, contextContainer};
74
+
75
+ rawProps.parse(propParser, parserContext);
76
+ ${componentName}(parserContext, sourceProps, rawProps);
77
+ }
78
+ `;
79
+
80
+ function getTestCasesForProp(
81
+ propName: string,
82
+ typeAnnotation: PropTypeAnnotation,
83
+ ) {
84
+ const cases = [];
85
+ if (typeAnnotation.type === 'StringEnumTypeAnnotation') {
86
+ typeAnnotation.options.forEach(option =>
87
+ cases.push({
88
+ propName,
89
+ testName: `${propName}_${toSafeCppString(option)}`,
90
+ propValue: option,
91
+ }),
92
+ );
93
+ } else if (typeAnnotation.type === 'StringTypeAnnotation') {
94
+ cases.push({
95
+ propName,
96
+ propValue:
97
+ typeAnnotation.default != null && typeAnnotation.default !== ''
98
+ ? typeAnnotation.default
99
+ : 'foo',
100
+ });
101
+ } else if (typeAnnotation.type === 'BooleanTypeAnnotation') {
102
+ cases.push({
103
+ propName: propName,
104
+ propValue: typeAnnotation.default != null ? typeAnnotation.default : true,
105
+ });
106
+ // $FlowFixMe[incompatible-type]
107
+ } else if (typeAnnotation.type === 'IntegerTypeAnnotation') {
108
+ cases.push({
109
+ propName,
110
+ propValue: typeAnnotation.default || 10,
111
+ });
112
+ } else if (typeAnnotation.type === 'FloatTypeAnnotation') {
113
+ cases.push({
114
+ propName,
115
+ propValue: typeAnnotation.default != null ? typeAnnotation.default : 0.1,
116
+ });
117
+ } else if (typeAnnotation.type === 'ReservedPropTypeAnnotation') {
118
+ if (typeAnnotation.name === 'ColorPrimitive') {
119
+ cases.push({
120
+ propName,
121
+ propValue: 1,
122
+ });
123
+ } else if (typeAnnotation.name === 'PointPrimitive') {
124
+ cases.push({
125
+ propName,
126
+ propValue: 'folly::dynamic::object("x", 1)("y", 1)',
127
+ raw: true,
128
+ });
129
+ } else if (typeAnnotation.name === 'ImageSourcePrimitive') {
130
+ cases.push({
131
+ propName,
132
+ propValue: 'folly::dynamic::object("url", "testurl")',
133
+ raw: true,
134
+ });
135
+ }
136
+ }
137
+
138
+ return cases;
139
+ }
140
+
141
+ function generateTestsString(name: string, component: ComponentShape) {
142
+ function createTest({testName, propName, propValue, raw = false}: TestCase) {
143
+ const value =
144
+ !raw && typeof propValue === 'string' ? `"${propValue}"` : propValue;
145
+
146
+ return TestTemplate({
147
+ componentName: name,
148
+ testName: testName != null ? testName : propName,
149
+ propName,
150
+ propValue: String(value),
151
+ });
152
+ }
153
+
154
+ const testCases = component.props.reduce((cases: Array<TestCase>, prop) => {
155
+ return cases.concat(getTestCasesForProp(prop.name, prop.typeAnnotation));
156
+ }, []);
157
+
158
+ const baseTest = {
159
+ testName: 'DoesNotDie',
160
+ propName: 'xx_invalid_xx',
161
+ propValue: 'xx_invalid_xx',
162
+ };
163
+
164
+ return [baseTest, ...testCases].map(createTest).join('');
165
+ }
166
+
167
+ module.exports = {
168
+ generate(
169
+ libraryName: string,
170
+ schema: SchemaType,
171
+ packageName?: string,
172
+ assumeNonnull: boolean = false,
173
+ ): FilesOutput {
174
+ const fileName = 'Tests.cpp';
175
+ const allImports = new Set([
176
+ '#include <react/renderer/core/propsConversions.h>',
177
+ '#include <react/renderer/core/RawProps.h>',
178
+ '#include <react/renderer/core/RawPropsParser.h>',
179
+ ]);
180
+
181
+ const componentTests = Object.keys(schema.modules)
182
+ .map(moduleName => {
183
+ const module = schema.modules[moduleName];
184
+ if (module.type !== 'Component') {
185
+ return;
186
+ }
187
+
188
+ const {components} = module;
189
+ if (components == null) {
190
+ return null;
191
+ }
192
+
193
+ return Object.keys(components)
194
+ .map(componentName => {
195
+ const component = components[componentName];
196
+ const name = `${componentName}Props`;
197
+
198
+ const imports = getImports(component.props);
199
+ // $FlowFixMe[method-unbinding] added when improving typing for this parameters
200
+ imports.forEach(allImports.add, allImports);
201
+
202
+ return generateTestsString(name, component);
203
+ })
204
+ .join('');
205
+ })
206
+ .filter(Boolean)
207
+ .join('');
208
+
209
+ const imports = Array.from(allImports).sort().join('\n').trim();
210
+
211
+ const replacedTemplate = FileTemplate({
212
+ imports,
213
+ libraryName,
214
+ componentTests,
215
+ });
216
+
217
+ return new Map([[fileName, replacedTemplate]]);
218
+ },
219
+ };
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ // File path -> contents
14
+
15
+ const FileTemplate = ({lookupFuncs}) => `
16
+ /*
17
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
18
+ *
19
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
20
+ * once the code is regenerated.
21
+ *
22
+ * ${'@'}generated by GenerateRCTThirdPartyFabricComponentsProviderH
23
+ */
24
+
25
+ #pragma GCC diagnostic push
26
+ #pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"
27
+
28
+ #import <React/RCTComponentViewProtocol.h>
29
+
30
+ #ifdef __cplusplus
31
+ extern "C" {
32
+ #endif
33
+
34
+ Class<RCTComponentViewProtocol> RCTThirdPartyFabricComponentsProvider(const char *name);
35
+
36
+ ${lookupFuncs}
37
+
38
+ #ifdef __cplusplus
39
+ }
40
+ #endif
41
+
42
+ #pragma GCC diagnostic pop
43
+
44
+ `;
45
+ const LookupFuncTemplate = ({className, libraryName}) =>
46
+ `
47
+ Class<RCTComponentViewProtocol> ${className}Cls(void) __attribute__((used)); // ${libraryName}
48
+ `.trim();
49
+ module.exports = {
50
+ generate(schemas) {
51
+ const fileName = 'RCTThirdPartyFabricComponentsProvider.h';
52
+ const lookupFuncs = Object.keys(schemas)
53
+ .map(libraryName => {
54
+ const schema = schemas[libraryName];
55
+ return Object.keys(schema.modules)
56
+ .map(moduleName => {
57
+ const module = schema.modules[moduleName];
58
+ if (module.type !== 'Component') {
59
+ return;
60
+ }
61
+ const components = module.components;
62
+ // No components in this module
63
+ if (components == null) {
64
+ return null;
65
+ }
66
+ return Object.keys(components)
67
+ .filter(componentName => {
68
+ const component = components[componentName];
69
+ return !(
70
+ component.excludedPlatforms &&
71
+ component.excludedPlatforms.includes('iOS')
72
+ );
73
+ })
74
+ .map(componentName => {
75
+ return LookupFuncTemplate({
76
+ className: componentName,
77
+ libraryName,
78
+ });
79
+ })
80
+ .join('\n');
81
+ })
82
+ .filter(Boolean)
83
+ .join('\n');
84
+ })
85
+ .join('\n');
86
+ const replacedTemplate = FileTemplate({
87
+ lookupFuncs,
88
+ });
89
+ return new Map([[fileName, replacedTemplate]]);
90
+ },
91
+ };
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ import type {SchemaType} from '../../CodegenSchema';
14
+
15
+ // File path -> contents
16
+ type FilesOutput = Map<string, string>;
17
+
18
+ const FileTemplate = ({lookupFuncs}: {lookupFuncs: string}) => `
19
+ /*
20
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
21
+ *
22
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
23
+ * once the code is regenerated.
24
+ *
25
+ * ${'@'}generated by GenerateRCTThirdPartyFabricComponentsProviderH
26
+ */
27
+
28
+ #pragma GCC diagnostic push
29
+ #pragma GCC diagnostic ignored "-Wreturn-type-c-linkage"
30
+
31
+ #import <React/RCTComponentViewProtocol.h>
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ Class<RCTComponentViewProtocol> RCTThirdPartyFabricComponentsProvider(const char *name);
38
+
39
+ ${lookupFuncs}
40
+
41
+ #ifdef __cplusplus
42
+ }
43
+ #endif
44
+
45
+ #pragma GCC diagnostic pop
46
+
47
+ `;
48
+
49
+ const LookupFuncTemplate = ({
50
+ className,
51
+ libraryName,
52
+ }: {
53
+ className: string,
54
+ libraryName: string,
55
+ }) =>
56
+ `
57
+ Class<RCTComponentViewProtocol> ${className}Cls(void) __attribute__((used)); // ${libraryName}
58
+ `.trim();
59
+
60
+ module.exports = {
61
+ generate(schemas: {[string]: SchemaType}): FilesOutput {
62
+ const fileName = 'RCTThirdPartyFabricComponentsProvider.h';
63
+
64
+ const lookupFuncs = Object.keys(schemas)
65
+ .map(libraryName => {
66
+ const schema = schemas[libraryName];
67
+ return Object.keys(schema.modules)
68
+ .map(moduleName => {
69
+ const module = schema.modules[moduleName];
70
+ if (module.type !== 'Component') {
71
+ return;
72
+ }
73
+
74
+ const {components} = module;
75
+ // No components in this module
76
+ if (components == null) {
77
+ return null;
78
+ }
79
+
80
+ return Object.keys(components)
81
+ .filter(componentName => {
82
+ const component = components[componentName];
83
+ return !(
84
+ component.excludedPlatforms &&
85
+ component.excludedPlatforms.includes('iOS')
86
+ );
87
+ })
88
+ .map(componentName => {
89
+ return LookupFuncTemplate({
90
+ className: componentName,
91
+ libraryName,
92
+ });
93
+ })
94
+ .join('\n');
95
+ })
96
+ .filter(Boolean)
97
+ .join('\n');
98
+ })
99
+ .join('\n');
100
+
101
+ const replacedTemplate = FileTemplate({
102
+ lookupFuncs,
103
+ });
104
+
105
+ return new Map([[fileName, replacedTemplate]]);
106
+ },
107
+ };
@@ -0,0 +1,89 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ *
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ // File path -> contents
14
+
15
+ const FileTemplate = ({lookupMap}) => `
16
+ /**
17
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
18
+ *
19
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
20
+ * once the code is regenerated.
21
+ *
22
+ * ${'@'}generated by GenerateRCTThirdPartyFabricComponentsProviderCpp
23
+ */
24
+
25
+ // OSS-compatibility layer
26
+
27
+ #import "RCTThirdPartyFabricComponentsProvider.h"
28
+
29
+ #import <string>
30
+ #import <unordered_map>
31
+
32
+ Class<RCTComponentViewProtocol> RCTThirdPartyFabricComponentsProvider(const char *name) {
33
+ static std::unordered_map<std::string, Class (*)(void)> sFabricComponentsClassMap = {
34
+ ${lookupMap}
35
+ };
36
+
37
+ auto p = sFabricComponentsClassMap.find(name);
38
+ if (p != sFabricComponentsClassMap.end()) {
39
+ auto classFunc = p->second;
40
+ return classFunc();
41
+ }
42
+ return nil;
43
+ }
44
+ `;
45
+ const LookupMapTemplate = ({className, libraryName}) => `
46
+ {"${className}", ${className}Cls}, // ${libraryName}`;
47
+ module.exports = {
48
+ generate(schemas) {
49
+ const fileName = 'RCTThirdPartyFabricComponentsProvider.mm';
50
+ const lookupMap = Object.keys(schemas)
51
+ .map(libraryName => {
52
+ const schema = schemas[libraryName];
53
+ return Object.keys(schema.modules)
54
+ .map(moduleName => {
55
+ const module = schema.modules[moduleName];
56
+ if (module.type !== 'Component') {
57
+ return;
58
+ }
59
+ const components = module.components;
60
+ // No components in this module
61
+ if (components == null) {
62
+ return null;
63
+ }
64
+ const componentTemplates = Object.keys(components)
65
+ .filter(componentName => {
66
+ const component = components[componentName];
67
+ return !(
68
+ component.excludedPlatforms &&
69
+ component.excludedPlatforms.includes('iOS')
70
+ );
71
+ })
72
+ .map(componentName => {
73
+ const replacedTemplate = LookupMapTemplate({
74
+ className: componentName,
75
+ libraryName,
76
+ });
77
+ return replacedTemplate;
78
+ });
79
+ return componentTemplates.length > 0 ? componentTemplates : null;
80
+ })
81
+ .filter(Boolean);
82
+ })
83
+ .join('\n');
84
+ const replacedTemplate = FileTemplate({
85
+ lookupMap,
86
+ });
87
+ return new Map([[fileName, replacedTemplate]]);
88
+ },
89
+ };
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ * @format
9
+ */
10
+
11
+ 'use strict';
12
+
13
+ import type {SchemaType} from '../../CodegenSchema';
14
+
15
+ // File path -> contents
16
+ type FilesOutput = Map<string, string>;
17
+
18
+ const FileTemplate = ({lookupMap}: {lookupMap: string}) => `
19
+ /**
20
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
21
+ *
22
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
23
+ * once the code is regenerated.
24
+ *
25
+ * ${'@'}generated by GenerateRCTThirdPartyFabricComponentsProviderCpp
26
+ */
27
+
28
+ // OSS-compatibility layer
29
+
30
+ #import "RCTThirdPartyFabricComponentsProvider.h"
31
+
32
+ #import <string>
33
+ #import <unordered_map>
34
+
35
+ Class<RCTComponentViewProtocol> RCTThirdPartyFabricComponentsProvider(const char *name) {
36
+ static std::unordered_map<std::string, Class (*)(void)> sFabricComponentsClassMap = {
37
+ ${lookupMap}
38
+ };
39
+
40
+ auto p = sFabricComponentsClassMap.find(name);
41
+ if (p != sFabricComponentsClassMap.end()) {
42
+ auto classFunc = p->second;
43
+ return classFunc();
44
+ }
45
+ return nil;
46
+ }
47
+ `;
48
+
49
+ const LookupMapTemplate = ({
50
+ className,
51
+ libraryName,
52
+ }: {
53
+ className: string,
54
+ libraryName: string,
55
+ }) => `
56
+ {"${className}", ${className}Cls}, // ${libraryName}`;
57
+
58
+ module.exports = {
59
+ generate(schemas: {[string]: SchemaType}): FilesOutput {
60
+ const fileName = 'RCTThirdPartyFabricComponentsProvider.mm';
61
+
62
+ const lookupMap = Object.keys(schemas)
63
+ .map(libraryName => {
64
+ const schema = schemas[libraryName];
65
+ return Object.keys(schema.modules)
66
+ .map(moduleName => {
67
+ const module = schema.modules[moduleName];
68
+ if (module.type !== 'Component') {
69
+ return;
70
+ }
71
+
72
+ const {components} = module;
73
+ // No components in this module
74
+ if (components == null) {
75
+ return null;
76
+ }
77
+
78
+ const componentTemplates = Object.keys(components)
79
+ .filter(componentName => {
80
+ const component = components[componentName];
81
+ return !(
82
+ component.excludedPlatforms &&
83
+ component.excludedPlatforms.includes('iOS')
84
+ );
85
+ })
86
+ .map(componentName => {
87
+ const replacedTemplate = LookupMapTemplate({
88
+ className: componentName,
89
+ libraryName,
90
+ });
91
+
92
+ return replacedTemplate;
93
+ });
94
+
95
+ return componentTemplates.length > 0 ? componentTemplates : null;
96
+ })
97
+ .filter(Boolean);
98
+ })
99
+ .join('\n');
100
+
101
+ const replacedTemplate = FileTemplate({lookupMap});
102
+
103
+ return new Map([[fileName, replacedTemplate]]);
104
+ },
105
+ };