@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,327 @@
|
|
|
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
|
+
function getOrdinalNumber(num) {
|
|
14
|
+
switch (num) {
|
|
15
|
+
case 1:
|
|
16
|
+
return '1st';
|
|
17
|
+
case 2:
|
|
18
|
+
return '2nd';
|
|
19
|
+
case 3:
|
|
20
|
+
return '3rd';
|
|
21
|
+
}
|
|
22
|
+
if (num <= 20) {
|
|
23
|
+
return `${num}th`;
|
|
24
|
+
}
|
|
25
|
+
return 'unknown';
|
|
26
|
+
}
|
|
27
|
+
const ProtocolTemplate = ({componentName, methods}) =>
|
|
28
|
+
`
|
|
29
|
+
@protocol RCT${componentName}ViewProtocol <NSObject>
|
|
30
|
+
${methods}
|
|
31
|
+
@end
|
|
32
|
+
`.trim();
|
|
33
|
+
const CommandHandlerIfCaseConvertArgTemplate = ({
|
|
34
|
+
componentName,
|
|
35
|
+
expectedKind,
|
|
36
|
+
argNumber,
|
|
37
|
+
argNumberString,
|
|
38
|
+
expectedKindString,
|
|
39
|
+
argConversion,
|
|
40
|
+
}) =>
|
|
41
|
+
`
|
|
42
|
+
NSObject *arg${argNumber} = args[${argNumber}];
|
|
43
|
+
#if RCT_DEBUG
|
|
44
|
+
if (!RCTValidateTypeOfViewCommandArgument(arg${argNumber}, ${expectedKind}, @"${expectedKindString}", @"${componentName}", commandName, @"${argNumberString}")) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
#endif
|
|
48
|
+
${argConversion}
|
|
49
|
+
`.trim();
|
|
50
|
+
const CommandHandlerIfCaseTemplate = ({
|
|
51
|
+
componentName,
|
|
52
|
+
commandName,
|
|
53
|
+
numArgs,
|
|
54
|
+
convertArgs,
|
|
55
|
+
commandCall,
|
|
56
|
+
}) =>
|
|
57
|
+
`
|
|
58
|
+
if ([commandName isEqualToString:@"${commandName}"]) {
|
|
59
|
+
#if RCT_DEBUG
|
|
60
|
+
if ([args count] != ${numArgs}) {
|
|
61
|
+
RCTLogError(@"%@ command %@ received %d arguments, expected %d.", @"${componentName}", commandName, (int)[args count], ${numArgs});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
#endif
|
|
65
|
+
|
|
66
|
+
${convertArgs}
|
|
67
|
+
|
|
68
|
+
${commandCall}
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
`.trim();
|
|
72
|
+
const CommandHandlerTemplate = ({componentName, ifCases}) =>
|
|
73
|
+
`
|
|
74
|
+
RCT_EXTERN inline void RCT${componentName}HandleCommand(
|
|
75
|
+
id<RCT${componentName}ViewProtocol> componentView,
|
|
76
|
+
NSString const *commandName,
|
|
77
|
+
NSArray const *args)
|
|
78
|
+
{
|
|
79
|
+
${ifCases}
|
|
80
|
+
|
|
81
|
+
#if RCT_DEBUG
|
|
82
|
+
RCTLogError(@"%@ received command %@, which is not a supported command.", @"${componentName}", commandName);
|
|
83
|
+
#endif
|
|
84
|
+
}
|
|
85
|
+
`.trim();
|
|
86
|
+
const FileTemplate = ({componentContent}) =>
|
|
87
|
+
`
|
|
88
|
+
/**
|
|
89
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
90
|
+
*
|
|
91
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
92
|
+
* once the code is regenerated.
|
|
93
|
+
*
|
|
94
|
+
* ${'@'}generated by codegen project: GenerateComponentHObjCpp.js
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
#import <Foundation/Foundation.h>
|
|
98
|
+
#import <React/RCTDefines.h>
|
|
99
|
+
#import <React/RCTLog.h>
|
|
100
|
+
|
|
101
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
102
|
+
|
|
103
|
+
${componentContent}
|
|
104
|
+
|
|
105
|
+
NS_ASSUME_NONNULL_END
|
|
106
|
+
`.trim();
|
|
107
|
+
function getObjCParamType(param) {
|
|
108
|
+
const typeAnnotation = param.typeAnnotation;
|
|
109
|
+
switch (typeAnnotation.type) {
|
|
110
|
+
case 'ReservedTypeAnnotation':
|
|
111
|
+
switch (typeAnnotation.name) {
|
|
112
|
+
case 'RootTag':
|
|
113
|
+
return 'double';
|
|
114
|
+
default:
|
|
115
|
+
typeAnnotation.name;
|
|
116
|
+
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
|
117
|
+
}
|
|
118
|
+
case 'BooleanTypeAnnotation':
|
|
119
|
+
return 'BOOL';
|
|
120
|
+
case 'DoubleTypeAnnotation':
|
|
121
|
+
return 'double';
|
|
122
|
+
case 'FloatTypeAnnotation':
|
|
123
|
+
return 'float';
|
|
124
|
+
case 'Int32TypeAnnotation':
|
|
125
|
+
return 'NSInteger';
|
|
126
|
+
case 'StringTypeAnnotation':
|
|
127
|
+
return 'NSString *';
|
|
128
|
+
default:
|
|
129
|
+
typeAnnotation.type;
|
|
130
|
+
throw new Error('Received invalid param type annotation');
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function getObjCExpectedKindParamType(param) {
|
|
134
|
+
const typeAnnotation = param.typeAnnotation;
|
|
135
|
+
switch (typeAnnotation.type) {
|
|
136
|
+
case 'ReservedTypeAnnotation':
|
|
137
|
+
switch (typeAnnotation.name) {
|
|
138
|
+
case 'RootTag':
|
|
139
|
+
return '[NSNumber class]';
|
|
140
|
+
default:
|
|
141
|
+
typeAnnotation.name;
|
|
142
|
+
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
|
143
|
+
}
|
|
144
|
+
case 'BooleanTypeAnnotation':
|
|
145
|
+
return '[NSNumber class]';
|
|
146
|
+
case 'DoubleTypeAnnotation':
|
|
147
|
+
return '[NSNumber class]';
|
|
148
|
+
case 'FloatTypeAnnotation':
|
|
149
|
+
return '[NSNumber class]';
|
|
150
|
+
case 'Int32TypeAnnotation':
|
|
151
|
+
return '[NSNumber class]';
|
|
152
|
+
case 'StringTypeAnnotation':
|
|
153
|
+
return '[NSString class]';
|
|
154
|
+
default:
|
|
155
|
+
typeAnnotation.type;
|
|
156
|
+
throw new Error('Received invalid param type annotation');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function getReadableExpectedKindParamType(param) {
|
|
160
|
+
const typeAnnotation = param.typeAnnotation;
|
|
161
|
+
switch (typeAnnotation.type) {
|
|
162
|
+
case 'ReservedTypeAnnotation':
|
|
163
|
+
switch (typeAnnotation.name) {
|
|
164
|
+
case 'RootTag':
|
|
165
|
+
return 'double';
|
|
166
|
+
default:
|
|
167
|
+
typeAnnotation.name;
|
|
168
|
+
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
|
169
|
+
}
|
|
170
|
+
case 'BooleanTypeAnnotation':
|
|
171
|
+
return 'boolean';
|
|
172
|
+
case 'DoubleTypeAnnotation':
|
|
173
|
+
return 'double';
|
|
174
|
+
case 'FloatTypeAnnotation':
|
|
175
|
+
return 'float';
|
|
176
|
+
case 'Int32TypeAnnotation':
|
|
177
|
+
return 'number';
|
|
178
|
+
case 'StringTypeAnnotation':
|
|
179
|
+
return 'string';
|
|
180
|
+
default:
|
|
181
|
+
typeAnnotation.type;
|
|
182
|
+
throw new Error('Received invalid param type annotation');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function getObjCRightHandAssignmentParamType(param, index) {
|
|
186
|
+
const typeAnnotation = param.typeAnnotation;
|
|
187
|
+
switch (typeAnnotation.type) {
|
|
188
|
+
case 'ReservedTypeAnnotation':
|
|
189
|
+
switch (typeAnnotation.name) {
|
|
190
|
+
case 'RootTag':
|
|
191
|
+
return `[(NSNumber *)arg${index} doubleValue]`;
|
|
192
|
+
default:
|
|
193
|
+
typeAnnotation.name;
|
|
194
|
+
throw new Error(`Receieved invalid type: ${typeAnnotation.name}`);
|
|
195
|
+
}
|
|
196
|
+
case 'BooleanTypeAnnotation':
|
|
197
|
+
return `[(NSNumber *)arg${index} boolValue]`;
|
|
198
|
+
case 'DoubleTypeAnnotation':
|
|
199
|
+
return `[(NSNumber *)arg${index} doubleValue]`;
|
|
200
|
+
case 'FloatTypeAnnotation':
|
|
201
|
+
return `[(NSNumber *)arg${index} floatValue]`;
|
|
202
|
+
case 'Int32TypeAnnotation':
|
|
203
|
+
return `[(NSNumber *)arg${index} intValue]`;
|
|
204
|
+
case 'StringTypeAnnotation':
|
|
205
|
+
return `(NSString *)arg${index}`;
|
|
206
|
+
default:
|
|
207
|
+
typeAnnotation.type;
|
|
208
|
+
throw new Error('Received invalid param type annotation');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
function generateProtocol(component, componentName) {
|
|
212
|
+
const methods = component.commands
|
|
213
|
+
.map(command => {
|
|
214
|
+
const params = command.typeAnnotation.params;
|
|
215
|
+
const paramString =
|
|
216
|
+
params.length === 0
|
|
217
|
+
? ''
|
|
218
|
+
: params
|
|
219
|
+
.map((param, index) => {
|
|
220
|
+
const objCType = getObjCParamType(param);
|
|
221
|
+
return `${index === 0 ? '' : param.name}:(${objCType})${
|
|
222
|
+
param.name
|
|
223
|
+
}`;
|
|
224
|
+
})
|
|
225
|
+
.join(' ');
|
|
226
|
+
return `- (void)${command.name}${paramString};`;
|
|
227
|
+
})
|
|
228
|
+
.join('\n')
|
|
229
|
+
.trim();
|
|
230
|
+
return ProtocolTemplate({
|
|
231
|
+
componentName,
|
|
232
|
+
methods,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
function generateConvertAndValidateParam(param, index, componentName) {
|
|
236
|
+
const leftSideType = getObjCParamType(param);
|
|
237
|
+
const expectedKind = getObjCExpectedKindParamType(param);
|
|
238
|
+
const expectedKindString = getReadableExpectedKindParamType(param);
|
|
239
|
+
const argConversion = `${leftSideType} ${
|
|
240
|
+
param.name
|
|
241
|
+
} = ${getObjCRightHandAssignmentParamType(param, index)};`;
|
|
242
|
+
return CommandHandlerIfCaseConvertArgTemplate({
|
|
243
|
+
componentName,
|
|
244
|
+
argConversion,
|
|
245
|
+
argNumber: index,
|
|
246
|
+
argNumberString: getOrdinalNumber(index + 1),
|
|
247
|
+
expectedKind,
|
|
248
|
+
expectedKindString,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
function generateCommandIfCase(command, componentName) {
|
|
252
|
+
const params = command.typeAnnotation.params;
|
|
253
|
+
const convertArgs = params
|
|
254
|
+
.map((param, index) =>
|
|
255
|
+
generateConvertAndValidateParam(param, index, componentName),
|
|
256
|
+
)
|
|
257
|
+
.join('\n\n')
|
|
258
|
+
.trim();
|
|
259
|
+
const commandCallArgs =
|
|
260
|
+
params.length === 0
|
|
261
|
+
? ''
|
|
262
|
+
: params
|
|
263
|
+
.map((param, index) => {
|
|
264
|
+
return `${index === 0 ? '' : param.name}:${param.name}`;
|
|
265
|
+
})
|
|
266
|
+
.join(' ');
|
|
267
|
+
const commandCall = `[componentView ${command.name}${commandCallArgs}];`;
|
|
268
|
+
return CommandHandlerIfCaseTemplate({
|
|
269
|
+
componentName,
|
|
270
|
+
commandName: command.name,
|
|
271
|
+
numArgs: params.length,
|
|
272
|
+
convertArgs,
|
|
273
|
+
commandCall,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
function generateCommandHandler(component, componentName) {
|
|
277
|
+
if (component.commands.length === 0) {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
const ifCases = component.commands
|
|
281
|
+
.map(command => generateCommandIfCase(command, componentName))
|
|
282
|
+
.join('\n\n');
|
|
283
|
+
return CommandHandlerTemplate({
|
|
284
|
+
componentName,
|
|
285
|
+
ifCases,
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
module.exports = {
|
|
289
|
+
generate(libraryName, schema, packageName, assumeNonnull = false) {
|
|
290
|
+
const fileName = 'RCTComponentViewHelpers.h';
|
|
291
|
+
const componentContent = Object.keys(schema.modules)
|
|
292
|
+
.map(moduleName => {
|
|
293
|
+
const module = schema.modules[moduleName];
|
|
294
|
+
if (module.type !== 'Component') {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
const components = module.components;
|
|
298
|
+
// No components in this module
|
|
299
|
+
if (components == null) {
|
|
300
|
+
return null;
|
|
301
|
+
}
|
|
302
|
+
return Object.keys(components)
|
|
303
|
+
.filter(componentName => {
|
|
304
|
+
const component = components[componentName];
|
|
305
|
+
return !(
|
|
306
|
+
component.excludedPlatforms &&
|
|
307
|
+
component.excludedPlatforms.includes('iOS')
|
|
308
|
+
);
|
|
309
|
+
})
|
|
310
|
+
.map(componentName => {
|
|
311
|
+
return [
|
|
312
|
+
generateProtocol(components[componentName], componentName),
|
|
313
|
+
generateCommandHandler(components[componentName], componentName),
|
|
314
|
+
]
|
|
315
|
+
.join('\n\n')
|
|
316
|
+
.trim();
|
|
317
|
+
})
|
|
318
|
+
.join('\n\n');
|
|
319
|
+
})
|
|
320
|
+
.filter(Boolean)
|
|
321
|
+
.join('\n\n');
|
|
322
|
+
const replacedTemplate = FileTemplate({
|
|
323
|
+
componentContent,
|
|
324
|
+
});
|
|
325
|
+
return new Map([[fileName, replacedTemplate]]);
|
|
326
|
+
},
|
|
327
|
+
};
|