@react-native/codegen 0.86.0-nightly-20260319-941ace990 → 0.86.0-nightly-20260322-56908a74c
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/lib/generators/RNCodegen.js.flow +0 -6
- package/lib/generators/ReservedPrimitiveTypes.js +90 -0
- package/lib/generators/ReservedPrimitiveTypes.js.flow +155 -0
- package/lib/generators/Utils.js +10 -2
- package/lib/generators/Utils.js.flow +11 -2
- package/lib/generators/components/ComponentsGeneratorUtils.js +14 -65
- package/lib/generators/components/ComponentsGeneratorUtils.js.flow +21 -72
- package/lib/generators/components/CppHelpers.js +5 -18
- package/lib/generators/components/CppHelpers.js.flow +5 -18
- package/lib/generators/components/JavaHelpers.js +9 -33
- package/lib/generators/components/JavaHelpers.js.flow +7 -37
- package/lib/generators/modules/GenerateModuleH.js.flow +0 -1
- package/lib/parsers/flow/parser.js.flow +1 -9
- package/lib/parsers/typescript/parser.js.flow +1 -3
- package/package.json +1 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const RESERVED_TYPES = {
|
|
4
|
+
ColorPrimitive: {
|
|
5
|
+
cpp: {
|
|
6
|
+
typeName: 'SharedColor',
|
|
7
|
+
localIncludes: ['#include <react/renderer/graphics/Color.h>'],
|
|
8
|
+
conversionIncludes: []
|
|
9
|
+
},
|
|
10
|
+
java: {
|
|
11
|
+
interfaceImports: [],
|
|
12
|
+
delegateImports: ['import com.facebook.react.bridge.ColorPropConverter;']
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
ImageSourcePrimitive: {
|
|
16
|
+
cpp: {
|
|
17
|
+
typeName: 'ImageSource',
|
|
18
|
+
localIncludes: ['#include <react/renderer/imagemanager/primitives.h>'],
|
|
19
|
+
conversionIncludes: ['#include <react/renderer/components/image/conversions.h>']
|
|
20
|
+
},
|
|
21
|
+
java: {
|
|
22
|
+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
23
|
+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;']
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
ImageRequestPrimitive: {
|
|
27
|
+
cpp: {
|
|
28
|
+
typeName: 'ImageRequest',
|
|
29
|
+
localIncludes: ['#include <react/renderer/imagemanager/ImageRequest.h>'],
|
|
30
|
+
conversionIncludes: []
|
|
31
|
+
},
|
|
32
|
+
java: {
|
|
33
|
+
interfaceImports: [],
|
|
34
|
+
delegateImports: []
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
PointPrimitive: {
|
|
38
|
+
cpp: {
|
|
39
|
+
typeName: 'Point',
|
|
40
|
+
localIncludes: ['#include <react/renderer/graphics/Point.h>'],
|
|
41
|
+
conversionIncludes: []
|
|
42
|
+
},
|
|
43
|
+
java: {
|
|
44
|
+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
45
|
+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;']
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
EdgeInsetsPrimitive: {
|
|
49
|
+
cpp: {
|
|
50
|
+
typeName: 'EdgeInsets',
|
|
51
|
+
localIncludes: ['#include <react/renderer/graphics/RectangleEdges.h>'],
|
|
52
|
+
conversionIncludes: []
|
|
53
|
+
},
|
|
54
|
+
java: {
|
|
55
|
+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
56
|
+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;']
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
DimensionPrimitive: {
|
|
60
|
+
cpp: {
|
|
61
|
+
typeName: 'YGValue',
|
|
62
|
+
localIncludes: ['#include <yoga/Yoga.h>', '#include <react/renderer/core/graphicsConversions.h>'],
|
|
63
|
+
conversionIncludes: ['#include <react/renderer/components/view/conversions.h>']
|
|
64
|
+
},
|
|
65
|
+
java: {
|
|
66
|
+
interfaceImports: ['import com.facebook.yoga.YogaValue;'],
|
|
67
|
+
delegateImports: ['import com.facebook.react.bridge.DimensionPropConverter;']
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
function getCppTypeForReservedPrimitive(name) {
|
|
72
|
+
return RESERVED_TYPES[name].cpp.typeName;
|
|
73
|
+
}
|
|
74
|
+
function getCppLocalIncludesForReservedPrimitive(name) {
|
|
75
|
+
return RESERVED_TYPES[name].cpp.localIncludes;
|
|
76
|
+
}
|
|
77
|
+
function getCppConversionIncludesForReservedPrimitive(name) {
|
|
78
|
+
return RESERVED_TYPES[name].cpp.conversionIncludes;
|
|
79
|
+
}
|
|
80
|
+
function getJavaImportsForReservedPrimitive(name, type) {
|
|
81
|
+
const info = RESERVED_TYPES[name].java;
|
|
82
|
+
return type === 'interface' ? info.interfaceImports : info.delegateImports;
|
|
83
|
+
}
|
|
84
|
+
module.exports = {
|
|
85
|
+
RESERVED_TYPES,
|
|
86
|
+
getCppTypeForReservedPrimitive,
|
|
87
|
+
getCppLocalIncludesForReservedPrimitive,
|
|
88
|
+
getCppConversionIncludesForReservedPrimitive,
|
|
89
|
+
getJavaImportsForReservedPrimitive
|
|
90
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* Single source of truth for the 6 reserved primitive types used in
|
|
15
|
+
* React Native component props. Each type maps to its per-language
|
|
16
|
+
* representation (C++ type name, C++ includes, Java imports).
|
|
17
|
+
*
|
|
18
|
+
* Previously these mappings were scattered across CppHelpers.js,
|
|
19
|
+
* ComponentsGeneratorUtils.js, and JavaHelpers.js.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
export type ReservedPrimitiveName =
|
|
23
|
+
| 'ColorPrimitive'
|
|
24
|
+
| 'EdgeInsetsPrimitive'
|
|
25
|
+
| 'ImageRequestPrimitive'
|
|
26
|
+
| 'ImageSourcePrimitive'
|
|
27
|
+
| 'PointPrimitive'
|
|
28
|
+
| 'DimensionPrimitive';
|
|
29
|
+
|
|
30
|
+
type CppTypeInfo = {
|
|
31
|
+
+typeName: string,
|
|
32
|
+
+localIncludes: ReadonlyArray<string>,
|
|
33
|
+
+conversionIncludes: ReadonlyArray<string>,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
type JavaImportInfo = {
|
|
37
|
+
+interfaceImports: ReadonlyArray<string>,
|
|
38
|
+
+delegateImports: ReadonlyArray<string>,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
type ReservedTypeMapping = {
|
|
42
|
+
+cpp: CppTypeInfo,
|
|
43
|
+
+java: JavaImportInfo,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const RESERVED_TYPES: {+[ReservedPrimitiveName]: ReservedTypeMapping} = {
|
|
47
|
+
ColorPrimitive: {
|
|
48
|
+
cpp: {
|
|
49
|
+
typeName: 'SharedColor',
|
|
50
|
+
localIncludes: ['#include <react/renderer/graphics/Color.h>'],
|
|
51
|
+
conversionIncludes: [],
|
|
52
|
+
},
|
|
53
|
+
java: {
|
|
54
|
+
interfaceImports: [],
|
|
55
|
+
delegateImports: ['import com.facebook.react.bridge.ColorPropConverter;'],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
ImageSourcePrimitive: {
|
|
59
|
+
cpp: {
|
|
60
|
+
typeName: 'ImageSource',
|
|
61
|
+
localIncludes: ['#include <react/renderer/imagemanager/primitives.h>'],
|
|
62
|
+
conversionIncludes: [
|
|
63
|
+
'#include <react/renderer/components/image/conversions.h>',
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
java: {
|
|
67
|
+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
68
|
+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
ImageRequestPrimitive: {
|
|
72
|
+
cpp: {
|
|
73
|
+
typeName: 'ImageRequest',
|
|
74
|
+
localIncludes: ['#include <react/renderer/imagemanager/ImageRequest.h>'],
|
|
75
|
+
conversionIncludes: [],
|
|
76
|
+
},
|
|
77
|
+
java: {
|
|
78
|
+
// ImageRequestPrimitive is not used in Java component props
|
|
79
|
+
interfaceImports: [],
|
|
80
|
+
delegateImports: [],
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
PointPrimitive: {
|
|
84
|
+
cpp: {
|
|
85
|
+
typeName: 'Point',
|
|
86
|
+
localIncludes: ['#include <react/renderer/graphics/Point.h>'],
|
|
87
|
+
conversionIncludes: [],
|
|
88
|
+
},
|
|
89
|
+
java: {
|
|
90
|
+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
91
|
+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
EdgeInsetsPrimitive: {
|
|
95
|
+
cpp: {
|
|
96
|
+
typeName: 'EdgeInsets',
|
|
97
|
+
localIncludes: ['#include <react/renderer/graphics/RectangleEdges.h>'],
|
|
98
|
+
conversionIncludes: [],
|
|
99
|
+
},
|
|
100
|
+
java: {
|
|
101
|
+
interfaceImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
102
|
+
delegateImports: ['import com.facebook.react.bridge.ReadableMap;'],
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
DimensionPrimitive: {
|
|
106
|
+
cpp: {
|
|
107
|
+
typeName: 'YGValue',
|
|
108
|
+
localIncludes: [
|
|
109
|
+
'#include <yoga/Yoga.h>',
|
|
110
|
+
'#include <react/renderer/core/graphicsConversions.h>',
|
|
111
|
+
],
|
|
112
|
+
conversionIncludes: [
|
|
113
|
+
'#include <react/renderer/components/view/conversions.h>',
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
java: {
|
|
117
|
+
interfaceImports: ['import com.facebook.yoga.YogaValue;'],
|
|
118
|
+
delegateImports: [
|
|
119
|
+
'import com.facebook.react.bridge.DimensionPropConverter;',
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
function getCppTypeForReservedPrimitive(name: ReservedPrimitiveName): string {
|
|
126
|
+
return RESERVED_TYPES[name].cpp.typeName;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getCppLocalIncludesForReservedPrimitive(
|
|
130
|
+
name: ReservedPrimitiveName,
|
|
131
|
+
): ReadonlyArray<string> {
|
|
132
|
+
return RESERVED_TYPES[name].cpp.localIncludes;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getCppConversionIncludesForReservedPrimitive(
|
|
136
|
+
name: ReservedPrimitiveName,
|
|
137
|
+
): ReadonlyArray<string> {
|
|
138
|
+
return RESERVED_TYPES[name].cpp.conversionIncludes;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function getJavaImportsForReservedPrimitive(
|
|
142
|
+
name: ReservedPrimitiveName,
|
|
143
|
+
type: 'interface' | 'delegate',
|
|
144
|
+
): ReadonlyArray<string> {
|
|
145
|
+
const info = RESERVED_TYPES[name].java;
|
|
146
|
+
return type === 'interface' ? info.interfaceImports : info.delegateImports;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
module.exports = {
|
|
150
|
+
RESERVED_TYPES,
|
|
151
|
+
getCppTypeForReservedPrimitive,
|
|
152
|
+
getCppLocalIncludesForReservedPrimitive,
|
|
153
|
+
getCppConversionIncludesForReservedPrimitive,
|
|
154
|
+
getJavaImportsForReservedPrimitive,
|
|
155
|
+
};
|
package/lib/generators/Utils.js
CHANGED
|
@@ -16,10 +16,17 @@ function toPascalCase(inString) {
|
|
|
16
16
|
if (inString.length === 0) {
|
|
17
17
|
return inString;
|
|
18
18
|
}
|
|
19
|
-
return
|
|
19
|
+
return capitalize(inString);
|
|
20
|
+
}
|
|
21
|
+
function toSafeIdentifier(input, shouldCapitalize) {
|
|
22
|
+
const parts = input.split('-');
|
|
23
|
+
if (!shouldCapitalize) {
|
|
24
|
+
return parts.join('');
|
|
25
|
+
}
|
|
26
|
+
return parts.map(toPascalCase).join('');
|
|
20
27
|
}
|
|
21
28
|
function toSafeCppString(input) {
|
|
22
|
-
return input
|
|
29
|
+
return toSafeIdentifier(input, true);
|
|
23
30
|
}
|
|
24
31
|
function getEnumName(moduleName, origEnumName) {
|
|
25
32
|
const uppercasedPropName = toSafeCppString(origEnumName);
|
|
@@ -65,6 +72,7 @@ module.exports = {
|
|
|
65
72
|
indent,
|
|
66
73
|
parseValidUnionType,
|
|
67
74
|
toPascalCase,
|
|
75
|
+
toSafeIdentifier,
|
|
68
76
|
toSafeCppString,
|
|
69
77
|
getEnumName,
|
|
70
78
|
HeterogeneousUnionError
|
|
@@ -34,11 +34,19 @@ function toPascalCase(inString: string): string {
|
|
|
34
34
|
return inString;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
return
|
|
37
|
+
return capitalize(inString);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function toSafeIdentifier(input: string, shouldCapitalize: boolean): string {
|
|
41
|
+
const parts = input.split('-');
|
|
42
|
+
if (!shouldCapitalize) {
|
|
43
|
+
return parts.join('');
|
|
44
|
+
}
|
|
45
|
+
return parts.map(toPascalCase).join('');
|
|
38
46
|
}
|
|
39
47
|
|
|
40
48
|
function toSafeCppString(input: string): string {
|
|
41
|
-
return input
|
|
49
|
+
return toSafeIdentifier(input, true);
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
function getEnumName(moduleName: string, origEnumName: string): string {
|
|
@@ -105,6 +113,7 @@ module.exports = {
|
|
|
105
113
|
indent,
|
|
106
114
|
parseValidUnionType,
|
|
107
115
|
toPascalCase,
|
|
116
|
+
toSafeIdentifier,
|
|
108
117
|
toSafeCppString,
|
|
109
118
|
getEnumName,
|
|
110
119
|
HeterogeneousUnionError,
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {
|
|
4
|
+
getCppLocalIncludesForReservedPrimitive,
|
|
5
|
+
getCppTypeForReservedPrimitive
|
|
6
|
+
} = require('../ReservedPrimitiveTypes');
|
|
3
7
|
const {
|
|
4
8
|
getEnumName
|
|
5
9
|
} = require('../Utils');
|
|
@@ -19,23 +23,7 @@ function getNativeTypeFromAnnotation(componentName, prop, nameParts) {
|
|
|
19
23
|
case 'FloatTypeAnnotation':
|
|
20
24
|
return getCppTypeForAnnotation(typeAnnotation.type);
|
|
21
25
|
case 'ReservedPropTypeAnnotation':
|
|
22
|
-
|
|
23
|
-
case 'ColorPrimitive':
|
|
24
|
-
return 'SharedColor';
|
|
25
|
-
case 'ImageSourcePrimitive':
|
|
26
|
-
return 'ImageSource';
|
|
27
|
-
case 'ImageRequestPrimitive':
|
|
28
|
-
return 'ImageRequest';
|
|
29
|
-
case 'PointPrimitive':
|
|
30
|
-
return 'Point';
|
|
31
|
-
case 'EdgeInsetsPrimitive':
|
|
32
|
-
return 'EdgeInsets';
|
|
33
|
-
case 'DimensionPrimitive':
|
|
34
|
-
return 'YGValue';
|
|
35
|
-
default:
|
|
36
|
-
typeAnnotation.name;
|
|
37
|
-
throw new Error('Received unknown ReservedPropTypeAnnotation');
|
|
38
|
-
}
|
|
26
|
+
return getCppTypeForReservedPrimitive(typeAnnotation.name);
|
|
39
27
|
case 'ArrayTypeAnnotation':
|
|
40
28
|
{
|
|
41
29
|
const arrayType = typeAnnotation.elementType.type;
|
|
@@ -98,57 +86,18 @@ function convertVariableToPointer(type, value, convertibleTypes) {
|
|
|
98
86
|
}
|
|
99
87
|
return value;
|
|
100
88
|
}
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
typesToConvert.add('ImageRequest');
|
|
109
|
-
return convertValueToSharedPointerWithMove(type, value, typesToConvert);
|
|
110
|
-
};
|
|
111
|
-
const convertGettersReturnTypeToAddressType = type => {
|
|
112
|
-
const typesToConvert = new Set();
|
|
113
|
-
typesToConvert.add('ImageRequest');
|
|
114
|
-
return convertTypesToConstAddressIfNeeded(type, typesToConvert);
|
|
115
|
-
};
|
|
116
|
-
const convertVarTypeToSharedPointer = type => {
|
|
117
|
-
const typesToConvert = new Set();
|
|
118
|
-
typesToConvert.add('ImageRequest');
|
|
119
|
-
return convertVariableToSharedPointer(type, typesToConvert);
|
|
120
|
-
};
|
|
121
|
-
const convertVarValueToPointer = (type, value) => {
|
|
122
|
-
const typesToConvert = new Set();
|
|
123
|
-
typesToConvert.add('ImageRequest');
|
|
124
|
-
return convertVariableToPointer(type, value, typesToConvert);
|
|
125
|
-
};
|
|
89
|
+
const CTOR_PARAM_ADDRESS_TYPES = new Set(['ImageSource']);
|
|
90
|
+
const SHARED_POINTER_TYPES = new Set(['ImageRequest']);
|
|
91
|
+
const convertCtorParamToAddressType = type => convertTypesToConstAddressIfNeeded(type, CTOR_PARAM_ADDRESS_TYPES);
|
|
92
|
+
const convertCtorInitToSharedPointers = (type, value) => convertValueToSharedPointerWithMove(type, value, SHARED_POINTER_TYPES);
|
|
93
|
+
const convertGettersReturnTypeToAddressType = type => convertTypesToConstAddressIfNeeded(type, SHARED_POINTER_TYPES);
|
|
94
|
+
const convertVarTypeToSharedPointer = type => convertVariableToSharedPointer(type, SHARED_POINTER_TYPES);
|
|
95
|
+
const convertVarValueToPointer = (type, value) => convertVariableToPointer(type, value, SHARED_POINTER_TYPES);
|
|
126
96
|
function getLocalImports(properties) {
|
|
127
97
|
const imports = new Set();
|
|
128
98
|
function addImportsForNativeName(name) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
imports.add('#include <react/renderer/graphics/Color.h>');
|
|
132
|
-
return;
|
|
133
|
-
case 'ImageSourcePrimitive':
|
|
134
|
-
imports.add('#include <react/renderer/imagemanager/primitives.h>');
|
|
135
|
-
return;
|
|
136
|
-
case 'ImageRequestPrimitive':
|
|
137
|
-
imports.add('#include <react/renderer/imagemanager/ImageRequest.h>');
|
|
138
|
-
return;
|
|
139
|
-
case 'PointPrimitive':
|
|
140
|
-
imports.add('#include <react/renderer/graphics/Point.h>');
|
|
141
|
-
return;
|
|
142
|
-
case 'EdgeInsetsPrimitive':
|
|
143
|
-
imports.add('#include <react/renderer/graphics/RectangleEdges.h>');
|
|
144
|
-
return;
|
|
145
|
-
case 'DimensionPrimitive':
|
|
146
|
-
imports.add('#include <yoga/Yoga.h>');
|
|
147
|
-
imports.add('#include <react/renderer/core/graphicsConversions.h>');
|
|
148
|
-
return;
|
|
149
|
-
default:
|
|
150
|
-
name;
|
|
151
|
-
throw new Error(`Invalid ReservedPropTypeAnnotation name, got ${name}`);
|
|
99
|
+
for (const include of getCppLocalIncludesForReservedPrimitive(name)) {
|
|
100
|
+
imports.add(include);
|
|
152
101
|
}
|
|
153
102
|
}
|
|
154
103
|
properties.forEach(prop => {
|
|
@@ -21,6 +21,10 @@ import type {
|
|
|
21
21
|
StringTypeAnnotation,
|
|
22
22
|
} from '../../CodegenSchema';
|
|
23
23
|
|
|
24
|
+
const {
|
|
25
|
+
getCppLocalIncludesForReservedPrimitive,
|
|
26
|
+
getCppTypeForReservedPrimitive,
|
|
27
|
+
} = require('../ReservedPrimitiveTypes');
|
|
24
28
|
const {getEnumName} = require('../Utils');
|
|
25
29
|
const {
|
|
26
30
|
generateStructName,
|
|
@@ -66,23 +70,7 @@ function getNativeTypeFromAnnotation(
|
|
|
66
70
|
case 'FloatTypeAnnotation':
|
|
67
71
|
return getCppTypeForAnnotation(typeAnnotation.type);
|
|
68
72
|
case 'ReservedPropTypeAnnotation':
|
|
69
|
-
|
|
70
|
-
case 'ColorPrimitive':
|
|
71
|
-
return 'SharedColor';
|
|
72
|
-
case 'ImageSourcePrimitive':
|
|
73
|
-
return 'ImageSource';
|
|
74
|
-
case 'ImageRequestPrimitive':
|
|
75
|
-
return 'ImageRequest';
|
|
76
|
-
case 'PointPrimitive':
|
|
77
|
-
return 'Point';
|
|
78
|
-
case 'EdgeInsetsPrimitive':
|
|
79
|
-
return 'EdgeInsets';
|
|
80
|
-
case 'DimensionPrimitive':
|
|
81
|
-
return 'YGValue';
|
|
82
|
-
default:
|
|
83
|
-
(typeAnnotation.name: empty);
|
|
84
|
-
throw new Error('Received unknown ReservedPropTypeAnnotation');
|
|
85
|
-
}
|
|
73
|
+
return getCppTypeForReservedPrimitive(typeAnnotation.name);
|
|
86
74
|
case 'ArrayTypeAnnotation': {
|
|
87
75
|
const arrayType = typeAnnotation.elementType.type;
|
|
88
76
|
if (arrayType === 'ArrayTypeAnnotation') {
|
|
@@ -175,43 +163,25 @@ function convertVariableToPointer(
|
|
|
175
163
|
return value;
|
|
176
164
|
}
|
|
177
165
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
166
|
+
// Configuration for C++ type conversions of reserved types.
|
|
167
|
+
// Centralizes the knowledge of which types need special pointer/address handling.
|
|
168
|
+
const CTOR_PARAM_ADDRESS_TYPES: Set<string> = new Set(['ImageSource']);
|
|
169
|
+
const SHARED_POINTER_TYPES: Set<string> = new Set(['ImageRequest']);
|
|
181
170
|
|
|
182
|
-
|
|
183
|
-
|
|
171
|
+
const convertCtorParamToAddressType = (type: string): string =>
|
|
172
|
+
convertTypesToConstAddressIfNeeded(type, CTOR_PARAM_ADDRESS_TYPES);
|
|
184
173
|
|
|
185
|
-
const convertCtorInitToSharedPointers = (
|
|
186
|
-
type
|
|
187
|
-
value: string,
|
|
188
|
-
): string => {
|
|
189
|
-
const typesToConvert: Set<string> = new Set();
|
|
190
|
-
typesToConvert.add('ImageRequest');
|
|
174
|
+
const convertCtorInitToSharedPointers = (type: string, value: string): string =>
|
|
175
|
+
convertValueToSharedPointerWithMove(type, value, SHARED_POINTER_TYPES);
|
|
191
176
|
|
|
192
|
-
|
|
193
|
-
|
|
177
|
+
const convertGettersReturnTypeToAddressType = (type: string): string =>
|
|
178
|
+
convertTypesToConstAddressIfNeeded(type, SHARED_POINTER_TYPES);
|
|
194
179
|
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
typesToConvert.add('ImageRequest');
|
|
180
|
+
const convertVarTypeToSharedPointer = (type: string): string =>
|
|
181
|
+
convertVariableToSharedPointer(type, SHARED_POINTER_TYPES);
|
|
198
182
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const convertVarTypeToSharedPointer = (type: string): string => {
|
|
203
|
-
const typesToConvert: Set<string> = new Set();
|
|
204
|
-
typesToConvert.add('ImageRequest');
|
|
205
|
-
|
|
206
|
-
return convertVariableToSharedPointer(type, typesToConvert);
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const convertVarValueToPointer = (type: string, value: string): string => {
|
|
210
|
-
const typesToConvert: Set<string> = new Set();
|
|
211
|
-
typesToConvert.add('ImageRequest');
|
|
212
|
-
|
|
213
|
-
return convertVariableToPointer(type, value, typesToConvert);
|
|
214
|
-
};
|
|
183
|
+
const convertVarValueToPointer = (type: string, value: string): string =>
|
|
184
|
+
convertVariableToPointer(type, value, SHARED_POINTER_TYPES);
|
|
215
185
|
|
|
216
186
|
function getLocalImports(
|
|
217
187
|
properties: ReadonlyArray<NamedShape<PropTypeAnnotation>>,
|
|
@@ -227,29 +197,8 @@ function getLocalImports(
|
|
|
227
197
|
| 'ImageRequestPrimitive'
|
|
228
198
|
| 'DimensionPrimitive',
|
|
229
199
|
) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
imports.add('#include <react/renderer/graphics/Color.h>');
|
|
233
|
-
return;
|
|
234
|
-
case 'ImageSourcePrimitive':
|
|
235
|
-
imports.add('#include <react/renderer/imagemanager/primitives.h>');
|
|
236
|
-
return;
|
|
237
|
-
case 'ImageRequestPrimitive':
|
|
238
|
-
imports.add('#include <react/renderer/imagemanager/ImageRequest.h>');
|
|
239
|
-
return;
|
|
240
|
-
case 'PointPrimitive':
|
|
241
|
-
imports.add('#include <react/renderer/graphics/Point.h>');
|
|
242
|
-
return;
|
|
243
|
-
case 'EdgeInsetsPrimitive':
|
|
244
|
-
imports.add('#include <react/renderer/graphics/RectangleEdges.h>');
|
|
245
|
-
return;
|
|
246
|
-
case 'DimensionPrimitive':
|
|
247
|
-
imports.add('#include <yoga/Yoga.h>');
|
|
248
|
-
imports.add('#include <react/renderer/core/graphicsConversions.h>');
|
|
249
|
-
return;
|
|
250
|
-
default:
|
|
251
|
-
(name: empty);
|
|
252
|
-
throw new Error(`Invalid ReservedPropTypeAnnotation name, got ${name}`);
|
|
200
|
+
for (const include of getCppLocalIncludesForReservedPrimitive(name)) {
|
|
201
|
+
imports.add(include);
|
|
253
202
|
}
|
|
254
203
|
}
|
|
255
204
|
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {
|
|
4
|
+
getCppConversionIncludesForReservedPrimitive
|
|
5
|
+
} = require('../ReservedPrimitiveTypes');
|
|
3
6
|
const {
|
|
4
7
|
getEnumName,
|
|
5
8
|
parseValidUnionType,
|
|
@@ -76,24 +79,8 @@ function getCppArrayTypeForAnnotation(typeElement, structParts) {
|
|
|
76
79
|
function getImports(properties) {
|
|
77
80
|
const imports = new Set();
|
|
78
81
|
function addImportsForNativeName(name) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return;
|
|
82
|
-
case 'PointPrimitive':
|
|
83
|
-
return;
|
|
84
|
-
case 'EdgeInsetsPrimitive':
|
|
85
|
-
return;
|
|
86
|
-
case 'ImageRequestPrimitive':
|
|
87
|
-
return;
|
|
88
|
-
case 'ImageSourcePrimitive':
|
|
89
|
-
imports.add('#include <react/renderer/components/image/conversions.h>');
|
|
90
|
-
return;
|
|
91
|
-
case 'DimensionPrimitive':
|
|
92
|
-
imports.add('#include <react/renderer/components/view/conversions.h>');
|
|
93
|
-
return;
|
|
94
|
-
default:
|
|
95
|
-
name;
|
|
96
|
-
throw new Error(`Invalid name, got ${name}`);
|
|
82
|
+
for (const include of getCppConversionIncludesForReservedPrimitive(name)) {
|
|
83
|
+
imports.add(include);
|
|
97
84
|
}
|
|
98
85
|
}
|
|
99
86
|
properties.forEach(prop => {
|
|
@@ -15,6 +15,9 @@ import type {
|
|
|
15
15
|
PropTypeAnnotation,
|
|
16
16
|
} from '../../CodegenSchema';
|
|
17
17
|
|
|
18
|
+
const {
|
|
19
|
+
getCppConversionIncludesForReservedPrimitive,
|
|
20
|
+
} = require('../ReservedPrimitiveTypes');
|
|
18
21
|
const {getEnumName, parseValidUnionType, toSafeCppString} = require('../Utils');
|
|
19
22
|
|
|
20
23
|
function toIntEnumValueName(propName: string, value: number): string {
|
|
@@ -134,24 +137,8 @@ function getImports(
|
|
|
134
137
|
| 'PointPrimitive'
|
|
135
138
|
| 'DimensionPrimitive',
|
|
136
139
|
) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
return;
|
|
140
|
-
case 'PointPrimitive':
|
|
141
|
-
return;
|
|
142
|
-
case 'EdgeInsetsPrimitive':
|
|
143
|
-
return;
|
|
144
|
-
case 'ImageRequestPrimitive':
|
|
145
|
-
return;
|
|
146
|
-
case 'ImageSourcePrimitive':
|
|
147
|
-
imports.add('#include <react/renderer/components/image/conversions.h>');
|
|
148
|
-
return;
|
|
149
|
-
case 'DimensionPrimitive':
|
|
150
|
-
imports.add('#include <react/renderer/components/view/conversions.h>');
|
|
151
|
-
return;
|
|
152
|
-
default:
|
|
153
|
-
(name: empty);
|
|
154
|
-
throw new Error(`Invalid name, got ${name}`);
|
|
140
|
+
for (const include of getCppConversionIncludesForReservedPrimitive(name)) {
|
|
141
|
+
imports.add(include);
|
|
155
142
|
}
|
|
156
143
|
}
|
|
157
144
|
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
3
|
+
const {
|
|
4
|
+
getJavaImportsForReservedPrimitive
|
|
5
|
+
} = require('../ReservedPrimitiveTypes');
|
|
6
|
+
const {
|
|
7
|
+
toSafeIdentifier
|
|
8
|
+
} = require('../Utils');
|
|
6
9
|
function getInterfaceJavaClassName(componentName) {
|
|
7
10
|
return `${componentName.replace(/^RCT/, '')}ManagerInterface`;
|
|
8
11
|
}
|
|
@@ -10,11 +13,7 @@ function getDelegateJavaClassName(componentName) {
|
|
|
10
13
|
return `${componentName.replace(/^RCT/, '')}ManagerDelegate`;
|
|
11
14
|
}
|
|
12
15
|
function toSafeJavaString(input, shouldUpperCaseFirst) {
|
|
13
|
-
|
|
14
|
-
if (shouldUpperCaseFirst === false) {
|
|
15
|
-
return parts.join('');
|
|
16
|
-
}
|
|
17
|
-
return parts.map(upperCaseFirst).join('');
|
|
16
|
+
return toSafeIdentifier(input, shouldUpperCaseFirst !== false);
|
|
18
17
|
}
|
|
19
18
|
function getImports(component, type) {
|
|
20
19
|
const imports = new Set();
|
|
@@ -38,31 +37,8 @@ function getImports(component, type) {
|
|
|
38
37
|
}
|
|
39
38
|
});
|
|
40
39
|
function addImportsForNativeName(name) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (type === 'delegate') {
|
|
44
|
-
imports.add('import com.facebook.react.bridge.ColorPropConverter;');
|
|
45
|
-
}
|
|
46
|
-
return;
|
|
47
|
-
case 'ImageSourcePrimitive':
|
|
48
|
-
imports.add('import com.facebook.react.bridge.ReadableMap;');
|
|
49
|
-
return;
|
|
50
|
-
case 'PointPrimitive':
|
|
51
|
-
imports.add('import com.facebook.react.bridge.ReadableMap;');
|
|
52
|
-
return;
|
|
53
|
-
case 'EdgeInsetsPrimitive':
|
|
54
|
-
imports.add('import com.facebook.react.bridge.ReadableMap;');
|
|
55
|
-
return;
|
|
56
|
-
case 'DimensionPrimitive':
|
|
57
|
-
if (type === 'delegate') {
|
|
58
|
-
imports.add('import com.facebook.react.bridge.DimensionPropConverter;');
|
|
59
|
-
} else {
|
|
60
|
-
imports.add('import com.facebook.yoga.YogaValue;');
|
|
61
|
-
}
|
|
62
|
-
return;
|
|
63
|
-
default:
|
|
64
|
-
name;
|
|
65
|
-
throw new Error(`Invalid ReservedPropTypeAnnotation name, got ${name}`);
|
|
40
|
+
for (const javaImport of getJavaImportsForReservedPrimitive(name, type)) {
|
|
41
|
+
imports.add(javaImport);
|
|
66
42
|
}
|
|
67
43
|
}
|
|
68
44
|
component.props.forEach(prop => {
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
|
|
13
13
|
import type {ComponentShape} from '../../CodegenSchema';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
15
|
+
const {
|
|
16
|
+
getJavaImportsForReservedPrimitive,
|
|
17
|
+
} = require('../ReservedPrimitiveTypes');
|
|
18
|
+
const {toSafeIdentifier} = require('../Utils');
|
|
18
19
|
|
|
19
20
|
function getInterfaceJavaClassName(componentName: string): string {
|
|
20
21
|
return `${componentName.replace(/^RCT/, '')}ManagerInterface`;
|
|
@@ -28,13 +29,7 @@ function toSafeJavaString(
|
|
|
28
29
|
input: string,
|
|
29
30
|
shouldUpperCaseFirst?: boolean,
|
|
30
31
|
): string {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (shouldUpperCaseFirst === false) {
|
|
34
|
-
return parts.join('');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return parts.map(upperCaseFirst).join('');
|
|
32
|
+
return toSafeIdentifier(input, shouldUpperCaseFirst !== false);
|
|
38
33
|
}
|
|
39
34
|
|
|
40
35
|
function getImports(
|
|
@@ -74,33 +69,8 @@ function getImports(
|
|
|
74
69
|
| 'PointPrimitive'
|
|
75
70
|
| 'DimensionPrimitive',
|
|
76
71
|
) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (type === 'delegate') {
|
|
80
|
-
imports.add('import com.facebook.react.bridge.ColorPropConverter;');
|
|
81
|
-
}
|
|
82
|
-
return;
|
|
83
|
-
case 'ImageSourcePrimitive':
|
|
84
|
-
imports.add('import com.facebook.react.bridge.ReadableMap;');
|
|
85
|
-
return;
|
|
86
|
-
case 'PointPrimitive':
|
|
87
|
-
imports.add('import com.facebook.react.bridge.ReadableMap;');
|
|
88
|
-
return;
|
|
89
|
-
case 'EdgeInsetsPrimitive':
|
|
90
|
-
imports.add('import com.facebook.react.bridge.ReadableMap;');
|
|
91
|
-
return;
|
|
92
|
-
case 'DimensionPrimitive':
|
|
93
|
-
if (type === 'delegate') {
|
|
94
|
-
imports.add(
|
|
95
|
-
'import com.facebook.react.bridge.DimensionPropConverter;',
|
|
96
|
-
);
|
|
97
|
-
} else {
|
|
98
|
-
imports.add('import com.facebook.yoga.YogaValue;');
|
|
99
|
-
}
|
|
100
|
-
return;
|
|
101
|
-
default:
|
|
102
|
-
(name: empty);
|
|
103
|
-
throw new Error(`Invalid ReservedPropTypeAnnotation name, got ${name}`);
|
|
72
|
+
for (const javaImport of getJavaImportsForReservedPrimitive(name, type)) {
|
|
73
|
+
imports.add(javaImport);
|
|
104
74
|
}
|
|
105
75
|
}
|
|
106
76
|
|
|
@@ -272,15 +272,7 @@ class FlowParser implements Parser {
|
|
|
272
272
|
return types[typeAnnotation.typeParameters.params[0].id.name];
|
|
273
273
|
}
|
|
274
274
|
|
|
275
|
-
|
|
276
|
-
* This FlowFixMe is supposed to refer to an InterfaceDeclaration or TypeAlias
|
|
277
|
-
* declaration type. Unfortunately, we don't have those types, because flow-parser
|
|
278
|
-
* generates them, and flow-parser is not type-safe. In the future, we should find
|
|
279
|
-
* a way to get these types from our flow parser library.
|
|
280
|
-
*
|
|
281
|
-
* TODO(T71778680): Flow type AST Nodes
|
|
282
|
-
*/
|
|
283
|
-
|
|
275
|
+
// TODO(T71778680): Flow type AST Nodes
|
|
284
276
|
getTypes(ast: $FlowFixMe): TypeDeclarationMap {
|
|
285
277
|
return ast.body.reduce((types, node) => {
|
|
286
278
|
if (
|
|
@@ -298,9 +298,7 @@ class TypeScriptParser implements Parser {
|
|
|
298
298
|
return types[typeAnnotation.typeParameters.params[0].typeName.name];
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
|
|
302
|
-
* TODO(T108222691): Use flow-types for @babel/parser
|
|
303
|
-
*/
|
|
301
|
+
// TODO(T108222691): Use flow-types for @babel/parser
|
|
304
302
|
getTypes(ast: $FlowFixMe): TypeDeclarationMap {
|
|
305
303
|
return ast.body.reduce((types, node) => {
|
|
306
304
|
switch (node.type) {
|