@callstack/brownfield-cli 6.1.0 → 6.1.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @callstack/brownfield-cli
|
|
2
2
|
|
|
3
|
+
## 6.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#519](https://github.com/callstack/react-native-brownfield/pull/519) [`a9726c1`](https://github.com/callstack/react-native-brownfield/commit/a9726c137c61fe2e59c039555a955632a5d86aec) Thanks [@RaphaelFakhri](https://github.com/RaphaelFakhri)! - `brownfield navigation:codegen` now generates `NSNumber` for optional `number` and `boolean` method parameters on iOS. Previously, the generated Swift delegate used `Double?` and `Bool?`, which can't be represented in an `@objc` protocol, so the iOS build failed.
|
|
8
|
+
|
|
3
9
|
## 6.1.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../../src/navigation/generators/ios.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"ios.d.ts","sourceRoot":"","sources":["../../../src/navigation/generators/ios.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAe,eAAe,EAAE,MAAM,aAAa,CAAC;AAyBhE,UAAU,sBAAsB;IAC9B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AA2CD,UAAU,uBAAuB;IAC/B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED,UAAU,qBAAsB,SAAQ,sBAAsB;CAAG;AA+CjE,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,eAAe,EAAE,EAC1B,OAAO,GAAE,uBAA4B,GACpC,MAAM,CA+BR;AAED,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,eAAe,EAAE,EAC1B,OAAO,GAAE,qBAA0B,GAClC,MAAM,CAkCR"}
|
|
@@ -12,6 +12,12 @@ const TS_TO_SWIFT_TYPE = {
|
|
|
12
12
|
void: 'Void',
|
|
13
13
|
Object: '[String: Any]',
|
|
14
14
|
};
|
|
15
|
+
/**
|
|
16
|
+
* Optional `number` and `boolean` values are boxed in `NSNumber`, both in the
|
|
17
|
+
* React Native codegen spec and because Swift `Double?` and `Bool?` can't be
|
|
18
|
+
* represented in an `@objc` protocol.
|
|
19
|
+
*/
|
|
20
|
+
const BOXED_OPTIONAL_TS_TYPES = new Set(['number', 'boolean']);
|
|
15
21
|
function mapTsTypeToObjC(tsType, nullable = false, options = {}) {
|
|
16
22
|
if (tsType.startsWith('Promise<')) {
|
|
17
23
|
return 'void';
|
|
@@ -19,6 +25,9 @@ function mapTsTypeToObjC(tsType, nullable = false, options = {}) {
|
|
|
19
25
|
if (options.modelTypeNames?.includes(tsType)) {
|
|
20
26
|
return nullable ? 'NSDictionary * _Nullable' : 'NSDictionary *';
|
|
21
27
|
}
|
|
28
|
+
if (nullable && BOXED_OPTIONAL_TS_TYPES.has(tsType)) {
|
|
29
|
+
return 'NSNumber * _Nullable';
|
|
30
|
+
}
|
|
22
31
|
const mapped = TS_TO_OBJC_TYPE[tsType];
|
|
23
32
|
if (mapped) {
|
|
24
33
|
if (nullable && mapped.includes('*')) {
|
|
@@ -41,6 +50,9 @@ function mapTsTypeToSwift(tsType, optional = false, options = {}) {
|
|
|
41
50
|
const inner = tsType.slice(8, -1);
|
|
42
51
|
return mapTsTypeToSwift(inner, optional, options);
|
|
43
52
|
}
|
|
53
|
+
if (optional && BOXED_OPTIONAL_TS_TYPES.has(tsType)) {
|
|
54
|
+
return 'NSNumber?';
|
|
55
|
+
}
|
|
44
56
|
const mapped = TS_TO_SWIFT_TYPE[tsType];
|
|
45
57
|
if (mapped) {
|
|
46
58
|
return optional ? `${mapped}?` : mapped;
|
package/package.json
CHANGED
|
@@ -16,6 +16,13 @@ const TS_TO_SWIFT_TYPE: Record<string, string> = {
|
|
|
16
16
|
Object: '[String: Any]',
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Optional `number` and `boolean` values are boxed in `NSNumber`, both in the
|
|
21
|
+
* React Native codegen spec and because Swift `Double?` and `Bool?` can't be
|
|
22
|
+
* represented in an `@objc` protocol.
|
|
23
|
+
*/
|
|
24
|
+
const BOXED_OPTIONAL_TS_TYPES = new Set(['number', 'boolean']);
|
|
25
|
+
|
|
19
26
|
interface ObjCTypeMappingOptions {
|
|
20
27
|
modelTypeNames?: string[];
|
|
21
28
|
}
|
|
@@ -33,6 +40,10 @@ function mapTsTypeToObjC(
|
|
|
33
40
|
return nullable ? 'NSDictionary * _Nullable' : 'NSDictionary *';
|
|
34
41
|
}
|
|
35
42
|
|
|
43
|
+
if (nullable && BOXED_OPTIONAL_TS_TYPES.has(tsType)) {
|
|
44
|
+
return 'NSNumber * _Nullable';
|
|
45
|
+
}
|
|
46
|
+
|
|
36
47
|
const mapped = TS_TO_OBJC_TYPE[tsType];
|
|
37
48
|
if (mapped) {
|
|
38
49
|
if (nullable && mapped.includes('*')) {
|
|
@@ -73,6 +84,10 @@ function mapTsTypeToSwift(
|
|
|
73
84
|
return mapTsTypeToSwift(inner, optional, options);
|
|
74
85
|
}
|
|
75
86
|
|
|
87
|
+
if (optional && BOXED_OPTIONAL_TS_TYPES.has(tsType)) {
|
|
88
|
+
return 'NSNumber?';
|
|
89
|
+
}
|
|
90
|
+
|
|
76
91
|
const mapped = TS_TO_SWIFT_TYPE[tsType];
|
|
77
92
|
if (mapped) {
|
|
78
93
|
return optional ? `${mapped}?` : mapped;
|