@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.
- package/README.md +21 -0
- package/lib/CodegenSchema.js +11 -0
- package/lib/CodegenSchema.js.flow +351 -0
- package/lib/SchemaValidator.js +54 -0
- package/lib/SchemaValidator.js.flow +67 -0
- package/lib/cli/combine/combine-js-to-schema-cli.js +50 -0
- package/lib/cli/combine/combine-js-to-schema-cli.js.flow +49 -0
- package/lib/cli/combine/combine-js-to-schema.js +110 -0
- package/lib/cli/combine/combine-js-to-schema.js.flow +48 -0
- package/lib/cli/combine/combine-utils.js +118 -0
- package/lib/cli/combine/combine-utils.js.flow +85 -0
- package/lib/cli/generators/generate-all.js +65 -0
- package/lib/cli/generators/generate-all.js.flow +66 -0
- package/lib/cli/parser/parser-cli.js +55 -0
- package/lib/cli/parser/parser-cli.js.flow +18 -0
- package/lib/cli/parser/parser.js +35 -0
- package/lib/cli/parser/parser.js.flow +37 -0
- package/lib/cli/parser/parser.sh +15 -0
- package/lib/generators/RNCodegen.js +207 -0
- package/lib/generators/RNCodegen.js.flow +284 -0
- package/lib/generators/Utils.js +31 -0
- package/lib/generators/Utils.js.flow +33 -0
- package/lib/generators/__test_fixtures__/fixtures.js +79 -0
- package/lib/generators/__test_fixtures__/fixtures.js.flow +82 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js +217 -0
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +304 -0
- package/lib/generators/components/CppHelpers.js +188 -0
- package/lib/generators/components/CppHelpers.js.flow +228 -0
- package/lib/generators/components/GenerateComponentDescriptorH.js +75 -0
- package/lib/generators/components/GenerateComponentDescriptorH.js.flow +95 -0
- package/lib/generators/components/GenerateComponentHObjCpp.js +327 -0
- package/lib/generators/components/GenerateComponentHObjCpp.js.flow +418 -0
- package/lib/generators/components/GenerateEventEmitterCpp.js +199 -0
- package/lib/generators/components/GenerateEventEmitterCpp.js.flow +273 -0
- package/lib/generators/components/GenerateEventEmitterH.js +224 -0
- package/lib/generators/components/GenerateEventEmitterH.js.flow +315 -0
- package/lib/generators/components/GeneratePropsCpp.js +126 -0
- package/lib/generators/components/GeneratePropsCpp.js.flow +161 -0
- package/lib/generators/components/GeneratePropsH.js +606 -0
- package/lib/generators/components/GeneratePropsH.js.flow +778 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js +287 -0
- package/lib/generators/components/GeneratePropsJavaDelegate.js.flow +348 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js +237 -0
- package/lib/generators/components/GeneratePropsJavaInterface.js.flow +288 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js +157 -0
- package/lib/generators/components/GeneratePropsJavaPojo/PojoCollector.js.flow +187 -0
- package/lib/generators/components/GeneratePropsJavaPojo/index.js +66 -0
- package/lib/generators/components/GeneratePropsJavaPojo/index.js.flow +80 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js +273 -0
- package/lib/generators/components/GeneratePropsJavaPojo/serializePojo.js.flow +296 -0
- package/lib/generators/components/GenerateShadowNodeCpp.js +73 -0
- package/lib/generators/components/GenerateShadowNodeCpp.js.flow +95 -0
- package/lib/generators/components/GenerateShadowNodeH.js +91 -0
- package/lib/generators/components/GenerateShadowNodeH.js.flow +124 -0
- package/lib/generators/components/GenerateStateCpp.js +70 -0
- package/lib/generators/components/GenerateStateCpp.js.flow +92 -0
- package/lib/generators/components/GenerateStateH.js +93 -0
- package/lib/generators/components/GenerateStateH.js.flow +111 -0
- package/lib/generators/components/GenerateTests.js +165 -0
- package/lib/generators/components/GenerateTests.js.flow +219 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js +91 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderH.js.flow +107 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js +89 -0
- package/lib/generators/components/GenerateThirdPartyFabricComponentsProviderObjCpp.js.flow +105 -0
- package/lib/generators/components/GenerateViewConfigJs.js +410 -0
- package/lib/generators/components/GenerateViewConfigJs.js.flow +484 -0
- package/lib/generators/components/JavaHelpers.js +87 -0
- package/lib/generators/components/JavaHelpers.js.flow +119 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js +1641 -0
- package/lib/generators/components/__test_fixtures__/fixtures.js.flow +1672 -0
- package/lib/generators/modules/GenerateModuleCpp.js +299 -0
- package/lib/generators/modules/GenerateModuleCpp.js.flow +278 -0
- package/lib/generators/modules/GenerateModuleH.js +373 -0
- package/lib/generators/modules/GenerateModuleH.js.flow +355 -0
- package/lib/generators/modules/GenerateModuleJavaSpec.js +571 -0
- package/lib/generators/modules/GenerateModuleJavaSpec.js.flow +553 -0
- package/lib/generators/modules/GenerateModuleJniCpp.js +505 -0
- package/lib/generators/modules/GenerateModuleJniCpp.js.flow +523 -0
- package/lib/generators/modules/GenerateModuleJniH.js +138 -0
- package/lib/generators/modules/GenerateModuleJniH.js.flow +148 -0
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js +262 -0
- package/lib/generators/modules/GenerateModuleObjCpp/StructCollector.js.flow +208 -0
- package/lib/generators/modules/GenerateModuleObjCpp/Utils.js +25 -0
- package/lib/generators/modules/GenerateModuleObjCpp/Utils.js.flow +32 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js +337 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeConstantsStruct.js.flow +288 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js +330 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeRegularStruct.js.flow +279 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js +25 -0
- package/lib/generators/modules/GenerateModuleObjCpp/header/serializeStruct.js.flow +35 -0
- package/lib/generators/modules/GenerateModuleObjCpp/index.js +185 -0
- package/lib/generators/modules/GenerateModuleObjCpp/index.js.flow +219 -0
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js +529 -0
- package/lib/generators/modules/GenerateModuleObjCpp/serializeMethod.js.flow +510 -0
- package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js +96 -0
- package/lib/generators/modules/GenerateModuleObjCpp/source/serializeModule.js.flow +121 -0
- package/lib/generators/modules/Utils.js +34 -0
- package/lib/generators/modules/Utils.js.flow +53 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js +1658 -0
- package/lib/generators/modules/__test_fixtures__/fixtures.js.flow +1669 -0
- package/lib/parsers/consistency/compareSnaps.js +84 -0
- package/lib/parsers/error-utils.js +284 -0
- package/lib/parsers/error-utils.js.flow +295 -0
- package/lib/parsers/errors.js +350 -0
- package/lib/parsers/errors.js.flow +439 -0
- package/lib/parsers/flow/components/__test_fixtures__/failures.js +583 -0
- package/lib/parsers/flow/components/__test_fixtures__/failures.js.flow +600 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js +1001 -0
- package/lib/parsers/flow/components/__test_fixtures__/fixtures.js.flow +1016 -0
- package/lib/parsers/flow/components/commands.js +104 -0
- package/lib/parsers/flow/components/commands.js.flow +123 -0
- package/lib/parsers/flow/components/componentsUtils.js +446 -0
- package/lib/parsers/flow/components/componentsUtils.js.flow +496 -0
- package/lib/parsers/flow/components/events.js +233 -0
- package/lib/parsers/flow/components/events.js.flow +262 -0
- package/lib/parsers/flow/components/extends.js +52 -0
- package/lib/parsers/flow/components/extends.js.flow +66 -0
- package/lib/parsers/flow/components/index.js +267 -0
- package/lib/parsers/flow/components/index.js.flow +226 -0
- package/lib/parsers/flow/components/options.js +72 -0
- package/lib/parsers/flow/components/options.js.flow +87 -0
- package/lib/parsers/flow/components/props.js +47 -0
- package/lib/parsers/flow/components/props.js.flow +60 -0
- package/lib/parsers/flow/components/schema.js +106 -0
- package/lib/parsers/flow/components/schema.js.flow +62 -0
- package/lib/parsers/flow/index.js +80 -0
- package/lib/parsers/flow/index.js.flow +85 -0
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js +215 -0
- package/lib/parsers/flow/modules/__test_fixtures__/failures.js.flow +223 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js +724 -0
- package/lib/parsers/flow/modules/__test_fixtures__/fixtures.js.flow +747 -0
- package/lib/parsers/flow/modules/index.js +528 -0
- package/lib/parsers/flow/modules/index.js.flow +420 -0
- package/lib/parsers/flow/parser.js +109 -0
- package/lib/parsers/flow/parser.js.flow +83 -0
- package/lib/parsers/flow/utils.js +108 -0
- package/lib/parsers/flow/utils.js.flow +123 -0
- package/lib/parsers/parser.js +11 -0
- package/lib/parsers/parser.js.flow +70 -0
- package/lib/parsers/parserMock.js +96 -0
- package/lib/parsers/parserMock.js.flow +68 -0
- package/lib/parsers/parsers-commons.js +448 -0
- package/lib/parsers/parsers-commons.js.flow +447 -0
- package/lib/parsers/parsers-primitives.js +387 -0
- package/lib/parsers/parsers-primitives.js.flow +383 -0
- package/lib/parsers/parsers-utils.js +18 -0
- package/lib/parsers/parsers-utils.js.flow +19 -0
- package/lib/parsers/schema/index.js +23 -0
- package/lib/parsers/schema/index.js.flow +26 -0
- package/lib/parsers/typescript/components/__test_fixtures__/failures.js +489 -0
- package/lib/parsers/typescript/components/__test_fixtures__/failures.js.flow +505 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js +1151 -0
- package/lib/parsers/typescript/components/__test_fixtures__/fixtures.js.flow +1168 -0
- package/lib/parsers/typescript/components/commands.js +132 -0
- package/lib/parsers/typescript/components/commands.js.flow +151 -0
- package/lib/parsers/typescript/components/componentsUtils.js +471 -0
- package/lib/parsers/typescript/components/componentsUtils.js.flow +521 -0
- package/lib/parsers/typescript/components/events.js +240 -0
- package/lib/parsers/typescript/components/events.js.flow +262 -0
- package/lib/parsers/typescript/components/extends.js +88 -0
- package/lib/parsers/typescript/components/extends.js.flow +103 -0
- package/lib/parsers/typescript/components/index.js +277 -0
- package/lib/parsers/typescript/components/index.js.flow +239 -0
- package/lib/parsers/typescript/components/options.js +72 -0
- package/lib/parsers/typescript/components/options.js.flow +87 -0
- package/lib/parsers/typescript/components/props.js +39 -0
- package/lib/parsers/typescript/components/props.js.flow +48 -0
- package/lib/parsers/typescript/components/schema.js +106 -0
- package/lib/parsers/typescript/components/schema.js.flow +62 -0
- package/lib/parsers/typescript/index.js +85 -0
- package/lib/parsers/typescript/index.js.flow +94 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js +160 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/failures.js.flow +167 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js +701 -0
- package/lib/parsers/typescript/modules/__test_fixtures__/fixtures.js.flow +727 -0
- package/lib/parsers/typescript/modules/index.js +543 -0
- package/lib/parsers/typescript/modules/index.js.flow +435 -0
- package/lib/parsers/typescript/parseTopLevelType.js +203 -0
- package/lib/parsers/typescript/parseTopLevelType.js.flow +243 -0
- package/lib/parsers/typescript/parser.js +105 -0
- package/lib/parsers/typescript/parser.js.flow +87 -0
- package/lib/parsers/typescript/utils.js +101 -0
- package/lib/parsers/typescript/utils.js.flow +115 -0
- package/lib/parsers/utils.js +273 -0
- package/lib/parsers/utils.js.flow +266 -0
- package/package.json +45 -0
|
@@ -0,0 +1,296 @@
|
|
|
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 {Pojo, PojoProperty, PojoTypeAnnotation} from './PojoCollector';
|
|
14
|
+
const {capitalize} = require('../../Utils');
|
|
15
|
+
|
|
16
|
+
type ImportCollector = ($import: string) => void;
|
|
17
|
+
|
|
18
|
+
function toJavaType(
|
|
19
|
+
typeAnnotation: PojoTypeAnnotation,
|
|
20
|
+
addImport: ImportCollector,
|
|
21
|
+
): string {
|
|
22
|
+
const importNullable = () => addImport('androidx.annotation.Nullable');
|
|
23
|
+
const importReadableMap = () =>
|
|
24
|
+
addImport('com.facebook.react.bridge.ReadableMap');
|
|
25
|
+
const importArrayList = () => addImport('java.util.ArrayList');
|
|
26
|
+
switch (typeAnnotation.type) {
|
|
27
|
+
/**
|
|
28
|
+
* Primitives
|
|
29
|
+
*/
|
|
30
|
+
case 'BooleanTypeAnnotation': {
|
|
31
|
+
if (typeAnnotation.default === null) {
|
|
32
|
+
importNullable();
|
|
33
|
+
return '@Nullable Boolean';
|
|
34
|
+
} else {
|
|
35
|
+
return 'boolean';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
case 'StringTypeAnnotation': {
|
|
39
|
+
importNullable();
|
|
40
|
+
return '@Nullable String';
|
|
41
|
+
}
|
|
42
|
+
case 'DoubleTypeAnnotation': {
|
|
43
|
+
return 'double';
|
|
44
|
+
}
|
|
45
|
+
case 'FloatTypeAnnotation': {
|
|
46
|
+
if (typeAnnotation.default === null) {
|
|
47
|
+
importNullable();
|
|
48
|
+
return '@Nullable Float';
|
|
49
|
+
} else {
|
|
50
|
+
return 'float';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
case 'Int32TypeAnnotation': {
|
|
54
|
+
return 'int';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Enums
|
|
59
|
+
*/
|
|
60
|
+
// TODO: Make StringEnumTypeAnnotation type-safe?
|
|
61
|
+
case 'StringEnumTypeAnnotation':
|
|
62
|
+
importNullable();
|
|
63
|
+
return '@Nullable String';
|
|
64
|
+
// TODO: Make Int32EnumTypeAnnotation type-safe?
|
|
65
|
+
case 'Int32EnumTypeAnnotation':
|
|
66
|
+
importNullable();
|
|
67
|
+
return '@Nullable Integer';
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Reserved types
|
|
71
|
+
*/
|
|
72
|
+
case 'ReservedPropTypeAnnotation': {
|
|
73
|
+
switch (typeAnnotation.name) {
|
|
74
|
+
case 'ColorPrimitive':
|
|
75
|
+
importNullable();
|
|
76
|
+
return '@Nullable Integer';
|
|
77
|
+
|
|
78
|
+
// TODO: Make ImageSourcePrimitive type-safe
|
|
79
|
+
case 'ImageSourcePrimitive':
|
|
80
|
+
importNullable();
|
|
81
|
+
importReadableMap();
|
|
82
|
+
return '@Nullable ReadableMap';
|
|
83
|
+
|
|
84
|
+
// TODO: Make ImageRequestPrimitive type-safe
|
|
85
|
+
case 'ImageRequestPrimitive':
|
|
86
|
+
importNullable();
|
|
87
|
+
importReadableMap();
|
|
88
|
+
return '@Nullable ReadableMap';
|
|
89
|
+
|
|
90
|
+
// TODO: Make PointPrimitive type-safe
|
|
91
|
+
case 'PointPrimitive':
|
|
92
|
+
importNullable();
|
|
93
|
+
importReadableMap();
|
|
94
|
+
return '@Nullable ReadableMap';
|
|
95
|
+
|
|
96
|
+
// TODO: Make EdgeInsetsPrimitive type-safe
|
|
97
|
+
case 'EdgeInsetsPrimitive':
|
|
98
|
+
importNullable();
|
|
99
|
+
importReadableMap();
|
|
100
|
+
return '@Nullable ReadableMap';
|
|
101
|
+
default:
|
|
102
|
+
(typeAnnotation.name: empty);
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Received unknown ReservedPropTypeAnnotation ${typeAnnotation.name}`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Other Pojo objects
|
|
111
|
+
*/
|
|
112
|
+
case 'PojoTypeAliasTypeAnnotation': {
|
|
113
|
+
return typeAnnotation.name;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Arrays
|
|
118
|
+
*/
|
|
119
|
+
case 'ArrayTypeAnnotation': {
|
|
120
|
+
const {elementType} = typeAnnotation;
|
|
121
|
+
|
|
122
|
+
const elementTypeString = (() => {
|
|
123
|
+
switch (elementType.type) {
|
|
124
|
+
/**
|
|
125
|
+
* Primitives
|
|
126
|
+
*/
|
|
127
|
+
case 'BooleanTypeAnnotation': {
|
|
128
|
+
return 'Boolean';
|
|
129
|
+
}
|
|
130
|
+
case 'StringTypeAnnotation': {
|
|
131
|
+
return 'String';
|
|
132
|
+
}
|
|
133
|
+
case 'DoubleTypeAnnotation': {
|
|
134
|
+
return 'Double';
|
|
135
|
+
}
|
|
136
|
+
case 'FloatTypeAnnotation': {
|
|
137
|
+
return 'Float';
|
|
138
|
+
}
|
|
139
|
+
case 'Int32TypeAnnotation': {
|
|
140
|
+
return 'Integer';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Enums
|
|
145
|
+
*/
|
|
146
|
+
// TODO: Make StringEnums type-safe in Pojos
|
|
147
|
+
case 'StringEnumTypeAnnotation': {
|
|
148
|
+
return 'String';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Other Pojo objects
|
|
153
|
+
*/
|
|
154
|
+
case 'PojoTypeAliasTypeAnnotation': {
|
|
155
|
+
return elementType.name;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Reserved types
|
|
160
|
+
*/
|
|
161
|
+
case 'ReservedPropTypeAnnotation': {
|
|
162
|
+
switch (elementType.name) {
|
|
163
|
+
case 'ColorPrimitive':
|
|
164
|
+
return 'Integer';
|
|
165
|
+
|
|
166
|
+
// TODO: Make ImageSourcePrimitive type-safe
|
|
167
|
+
case 'ImageSourcePrimitive':
|
|
168
|
+
importReadableMap();
|
|
169
|
+
return 'ReadableMap';
|
|
170
|
+
|
|
171
|
+
// TODO: Make ImageRequestPrimitive type-safe
|
|
172
|
+
case 'ImageRequestPrimitive':
|
|
173
|
+
importReadableMap();
|
|
174
|
+
return 'ReadableMap';
|
|
175
|
+
|
|
176
|
+
// TODO: Make PointPrimitive type-safe
|
|
177
|
+
case 'PointPrimitive':
|
|
178
|
+
importReadableMap();
|
|
179
|
+
return 'ReadableMap';
|
|
180
|
+
|
|
181
|
+
// TODO: Make EdgeInsetsPrimitive type-safe
|
|
182
|
+
case 'EdgeInsetsPrimitive':
|
|
183
|
+
importReadableMap();
|
|
184
|
+
return 'ReadableMap';
|
|
185
|
+
default:
|
|
186
|
+
(elementType.name: empty);
|
|
187
|
+
throw new Error(
|
|
188
|
+
`Received unknown ReservedPropTypeAnnotation ${elementType.name}`,
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Arrays
|
|
194
|
+
case 'ArrayTypeAnnotation': {
|
|
195
|
+
const {elementType: pojoTypeAliasTypeAnnotation} = elementType;
|
|
196
|
+
|
|
197
|
+
importArrayList();
|
|
198
|
+
return `ArrayList<${pojoTypeAliasTypeAnnotation.name}>`;
|
|
199
|
+
}
|
|
200
|
+
default: {
|
|
201
|
+
(elementType.type: empty);
|
|
202
|
+
throw new Error(
|
|
203
|
+
`Unrecognized PojoTypeAnnotation Array element type annotation '${typeAnnotation.type}'`,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
})();
|
|
208
|
+
|
|
209
|
+
importArrayList();
|
|
210
|
+
return `ArrayList<${elementTypeString}>`;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
default: {
|
|
214
|
+
(typeAnnotation.type: empty);
|
|
215
|
+
throw new Error(
|
|
216
|
+
`Unrecognized PojoTypeAnnotation '${typeAnnotation.type}'`,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function toJavaMemberName(property: PojoProperty): string {
|
|
223
|
+
return `m${capitalize(property.name)}`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function toJavaMemberDeclaration(
|
|
227
|
+
property: PojoProperty,
|
|
228
|
+
addImport: ImportCollector,
|
|
229
|
+
): string {
|
|
230
|
+
const type = toJavaType(property.typeAnnotation, addImport);
|
|
231
|
+
const memberName = toJavaMemberName(property);
|
|
232
|
+
return `private ${type} ${memberName};`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function toJavaGetter(property: PojoProperty, addImport: ImportCollector) {
|
|
236
|
+
const type = toJavaType(property.typeAnnotation, addImport);
|
|
237
|
+
const getterName = `get${capitalize(property.name)}`;
|
|
238
|
+
const memberName = toJavaMemberName(property);
|
|
239
|
+
|
|
240
|
+
addImport('com.facebook.proguard.annotations.DoNotStrip');
|
|
241
|
+
return `@DoNotStrip
|
|
242
|
+
public ${type} ${getterName}() {
|
|
243
|
+
return ${memberName};
|
|
244
|
+
}`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function serializePojo(pojo: Pojo, basePackageName: string): string {
|
|
248
|
+
const importSet: Set<string> = new Set();
|
|
249
|
+
const addImport = ($import: string) => {
|
|
250
|
+
importSet.add($import);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
addImport('com.facebook.proguard.annotations.DoNotStrip');
|
|
254
|
+
|
|
255
|
+
const indent = ' '.repeat(2);
|
|
256
|
+
|
|
257
|
+
const members = pojo.properties
|
|
258
|
+
.map(property => toJavaMemberDeclaration(property, addImport))
|
|
259
|
+
.map(member => `${indent}${member}`)
|
|
260
|
+
.join('\n');
|
|
261
|
+
|
|
262
|
+
const getters = pojo.properties
|
|
263
|
+
.map(property => toJavaGetter(property, addImport))
|
|
264
|
+
.map(getter =>
|
|
265
|
+
getter
|
|
266
|
+
.split('\n')
|
|
267
|
+
.map(line => `${indent}${line}`)
|
|
268
|
+
.join('\n'),
|
|
269
|
+
)
|
|
270
|
+
.join('\n');
|
|
271
|
+
|
|
272
|
+
const imports = [...importSet]
|
|
273
|
+
.map($import => `import ${$import};`)
|
|
274
|
+
.sort()
|
|
275
|
+
.join('\n');
|
|
276
|
+
|
|
277
|
+
return `/**
|
|
278
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
279
|
+
*
|
|
280
|
+
* This source code is licensed under the MIT license found in the
|
|
281
|
+
* LICENSE file in the root directory of this source tree.
|
|
282
|
+
*
|
|
283
|
+
* ${'@'}generated by codegen project: GeneratePropsJavaPojo.js
|
|
284
|
+
*/
|
|
285
|
+
|
|
286
|
+
package ${basePackageName}.${pojo.namespace};
|
|
287
|
+
${imports === '' ? '' : `\n${imports}\n`}
|
|
288
|
+
@DoNotStrip
|
|
289
|
+
public class ${pojo.name} {
|
|
290
|
+
${members}
|
|
291
|
+
${getters}
|
|
292
|
+
}
|
|
293
|
+
`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
module.exports = {serializePojo};
|
|
@@ -0,0 +1,73 @@
|
|
|
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 = ({libraryName, componentNames}) => `
|
|
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 codegen project: GenerateShadowNodeCpp.js
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#include <react/renderer/components/${libraryName}/ShadowNodes.h>
|
|
26
|
+
|
|
27
|
+
namespace facebook {
|
|
28
|
+
namespace react {
|
|
29
|
+
|
|
30
|
+
${componentNames}
|
|
31
|
+
|
|
32
|
+
} // namespace react
|
|
33
|
+
} // namespace facebook
|
|
34
|
+
`;
|
|
35
|
+
const ComponentTemplate = ({className}) =>
|
|
36
|
+
`
|
|
37
|
+
extern const char ${className}ComponentName[] = "${className}";
|
|
38
|
+
`.trim();
|
|
39
|
+
module.exports = {
|
|
40
|
+
generate(libraryName, schema, packageName, assumeNonnull = false) {
|
|
41
|
+
const fileName = 'ShadowNodes.cpp';
|
|
42
|
+
const componentNames = Object.keys(schema.modules)
|
|
43
|
+
.map(moduleName => {
|
|
44
|
+
const module = schema.modules[moduleName];
|
|
45
|
+
if (module.type !== 'Component') {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const components = module.components;
|
|
49
|
+
// No components in this module
|
|
50
|
+
if (components == null) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
return Object.keys(components)
|
|
54
|
+
.map(componentName => {
|
|
55
|
+
if (components[componentName].interfaceOnly === true) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const replacedTemplate = ComponentTemplate({
|
|
59
|
+
className: componentName,
|
|
60
|
+
});
|
|
61
|
+
return replacedTemplate;
|
|
62
|
+
})
|
|
63
|
+
.join('\n');
|
|
64
|
+
})
|
|
65
|
+
.filter(Boolean)
|
|
66
|
+
.join('\n');
|
|
67
|
+
const replacedTemplate = FileTemplate({
|
|
68
|
+
componentNames,
|
|
69
|
+
libraryName,
|
|
70
|
+
});
|
|
71
|
+
return new Map([[fileName, replacedTemplate]]);
|
|
72
|
+
},
|
|
73
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
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 = ({
|
|
19
|
+
libraryName,
|
|
20
|
+
componentNames,
|
|
21
|
+
}: {
|
|
22
|
+
libraryName: string,
|
|
23
|
+
componentNames: string,
|
|
24
|
+
}) => `
|
|
25
|
+
/**
|
|
26
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
27
|
+
*
|
|
28
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
29
|
+
* once the code is regenerated.
|
|
30
|
+
*
|
|
31
|
+
* ${'@'}generated by codegen project: GenerateShadowNodeCpp.js
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
#include <react/renderer/components/${libraryName}/ShadowNodes.h>
|
|
35
|
+
|
|
36
|
+
namespace facebook {
|
|
37
|
+
namespace react {
|
|
38
|
+
|
|
39
|
+
${componentNames}
|
|
40
|
+
|
|
41
|
+
} // namespace react
|
|
42
|
+
} // namespace facebook
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
const ComponentTemplate = ({className}: {className: string}) =>
|
|
46
|
+
`
|
|
47
|
+
extern const char ${className}ComponentName[] = "${className}";
|
|
48
|
+
`.trim();
|
|
49
|
+
|
|
50
|
+
module.exports = {
|
|
51
|
+
generate(
|
|
52
|
+
libraryName: string,
|
|
53
|
+
schema: SchemaType,
|
|
54
|
+
packageName?: string,
|
|
55
|
+
assumeNonnull: boolean = false,
|
|
56
|
+
): FilesOutput {
|
|
57
|
+
const fileName = 'ShadowNodes.cpp';
|
|
58
|
+
|
|
59
|
+
const componentNames = Object.keys(schema.modules)
|
|
60
|
+
.map(moduleName => {
|
|
61
|
+
const module = schema.modules[moduleName];
|
|
62
|
+
if (module.type !== 'Component') {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const {components} = module;
|
|
67
|
+
// No components in this module
|
|
68
|
+
if (components == null) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return Object.keys(components)
|
|
73
|
+
.map(componentName => {
|
|
74
|
+
if (components[componentName].interfaceOnly === true) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const replacedTemplate = ComponentTemplate({
|
|
78
|
+
className: componentName,
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
return replacedTemplate;
|
|
82
|
+
})
|
|
83
|
+
.join('\n');
|
|
84
|
+
})
|
|
85
|
+
.filter(Boolean)
|
|
86
|
+
.join('\n');
|
|
87
|
+
|
|
88
|
+
const replacedTemplate = FileTemplate({
|
|
89
|
+
componentNames,
|
|
90
|
+
libraryName,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return new Map([[fileName, replacedTemplate]]);
|
|
94
|
+
},
|
|
95
|
+
};
|
|
@@ -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 = ({imports, libraryName, componentClasses}) => `
|
|
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 codegen project: GenerateShadowNodeH.js
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
#pragma once
|
|
26
|
+
|
|
27
|
+
${imports}#include <react/renderer/components/${libraryName}/Props.h>
|
|
28
|
+
#include <react/renderer/components/${libraryName}/States.h>
|
|
29
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
30
|
+
#include <jsi/jsi.h>
|
|
31
|
+
|
|
32
|
+
namespace facebook {
|
|
33
|
+
namespace react {
|
|
34
|
+
|
|
35
|
+
${componentClasses}
|
|
36
|
+
|
|
37
|
+
} // namespace react
|
|
38
|
+
} // namespace facebook
|
|
39
|
+
`;
|
|
40
|
+
const ComponentTemplate = ({className, eventEmitter}) =>
|
|
41
|
+
`
|
|
42
|
+
JSI_EXPORT extern const char ${className}ComponentName[];
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* \`ShadowNode\` for <${className}> component.
|
|
46
|
+
*/
|
|
47
|
+
using ${className}ShadowNode = ConcreteViewShadowNode<
|
|
48
|
+
${className}ComponentName,
|
|
49
|
+
${className}Props${eventEmitter},
|
|
50
|
+
${className}State>;
|
|
51
|
+
`.trim();
|
|
52
|
+
module.exports = {
|
|
53
|
+
generate(libraryName, schema, packageName, assumeNonnull = false) {
|
|
54
|
+
const fileName = 'ShadowNodes.h';
|
|
55
|
+
const moduleResults = 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
|
+
.map(componentName => {
|
|
68
|
+
const component = components[componentName];
|
|
69
|
+
if (component.interfaceOnly === true) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const eventEmitter = `,\n ${componentName}EventEmitter`;
|
|
73
|
+
const replacedTemplate = ComponentTemplate({
|
|
74
|
+
className: componentName,
|
|
75
|
+
eventEmitter,
|
|
76
|
+
});
|
|
77
|
+
return replacedTemplate;
|
|
78
|
+
})
|
|
79
|
+
.join('\n\n');
|
|
80
|
+
})
|
|
81
|
+
.filter(Boolean)
|
|
82
|
+
.join('\n\n');
|
|
83
|
+
const eventEmitterImport = `#include <react/renderer/components/${libraryName}/EventEmitters.h>\n`;
|
|
84
|
+
const replacedTemplate = FileTemplate({
|
|
85
|
+
componentClasses: moduleResults,
|
|
86
|
+
libraryName,
|
|
87
|
+
imports: eventEmitterImport,
|
|
88
|
+
});
|
|
89
|
+
return new Map([[fileName, replacedTemplate]]);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
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 = ({
|
|
19
|
+
imports,
|
|
20
|
+
libraryName,
|
|
21
|
+
componentClasses,
|
|
22
|
+
}: {
|
|
23
|
+
imports: string,
|
|
24
|
+
libraryName: string,
|
|
25
|
+
componentClasses: string,
|
|
26
|
+
}) => `
|
|
27
|
+
/**
|
|
28
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
29
|
+
*
|
|
30
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
31
|
+
* once the code is regenerated.
|
|
32
|
+
*
|
|
33
|
+
* ${'@'}generated by codegen project: GenerateShadowNodeH.js
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
#pragma once
|
|
37
|
+
|
|
38
|
+
${imports}#include <react/renderer/components/${libraryName}/Props.h>
|
|
39
|
+
#include <react/renderer/components/${libraryName}/States.h>
|
|
40
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
41
|
+
#include <jsi/jsi.h>
|
|
42
|
+
|
|
43
|
+
namespace facebook {
|
|
44
|
+
namespace react {
|
|
45
|
+
|
|
46
|
+
${componentClasses}
|
|
47
|
+
|
|
48
|
+
} // namespace react
|
|
49
|
+
} // namespace facebook
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
const ComponentTemplate = ({
|
|
53
|
+
className,
|
|
54
|
+
eventEmitter,
|
|
55
|
+
}: {
|
|
56
|
+
className: string,
|
|
57
|
+
eventEmitter: string,
|
|
58
|
+
}) =>
|
|
59
|
+
`
|
|
60
|
+
JSI_EXPORT extern const char ${className}ComponentName[];
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
* \`ShadowNode\` for <${className}> component.
|
|
64
|
+
*/
|
|
65
|
+
using ${className}ShadowNode = ConcreteViewShadowNode<
|
|
66
|
+
${className}ComponentName,
|
|
67
|
+
${className}Props${eventEmitter},
|
|
68
|
+
${className}State>;
|
|
69
|
+
`.trim();
|
|
70
|
+
|
|
71
|
+
module.exports = {
|
|
72
|
+
generate(
|
|
73
|
+
libraryName: string,
|
|
74
|
+
schema: SchemaType,
|
|
75
|
+
packageName?: string,
|
|
76
|
+
assumeNonnull: boolean = false,
|
|
77
|
+
): FilesOutput {
|
|
78
|
+
const fileName = 'ShadowNodes.h';
|
|
79
|
+
|
|
80
|
+
const moduleResults = Object.keys(schema.modules)
|
|
81
|
+
.map(moduleName => {
|
|
82
|
+
const module = schema.modules[moduleName];
|
|
83
|
+
if (module.type !== 'Component') {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const {components} = module;
|
|
88
|
+
// No components in this module
|
|
89
|
+
if (components == null) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return Object.keys(components)
|
|
94
|
+
.map(componentName => {
|
|
95
|
+
const component = components[componentName];
|
|
96
|
+
if (component.interfaceOnly === true) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const eventEmitter = `,\n ${componentName}EventEmitter`;
|
|
101
|
+
|
|
102
|
+
const replacedTemplate = ComponentTemplate({
|
|
103
|
+
className: componentName,
|
|
104
|
+
eventEmitter,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return replacedTemplate;
|
|
108
|
+
})
|
|
109
|
+
.join('\n\n');
|
|
110
|
+
})
|
|
111
|
+
.filter(Boolean)
|
|
112
|
+
.join('\n\n');
|
|
113
|
+
|
|
114
|
+
const eventEmitterImport = `#include <react/renderer/components/${libraryName}/EventEmitters.h>\n`;
|
|
115
|
+
|
|
116
|
+
const replacedTemplate = FileTemplate({
|
|
117
|
+
componentClasses: moduleResults,
|
|
118
|
+
libraryName,
|
|
119
|
+
imports: eventEmitterImport,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
return new Map([[fileName, replacedTemplate]]);
|
|
123
|
+
},
|
|
124
|
+
};
|