nitrogen 0.33.1 → 0.33.2
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/autolinking/ios/createHybridObjectInitializer.js +2 -19
- package/lib/syntax/swift/SwiftCxxBridgedType.js +1 -1
- package/lib/syntax/swift/SwiftHybridObjectRegistration.d.ts +2 -2
- package/lib/syntax/swift/SwiftHybridObjectRegistration.js +13 -15
- package/lib/views/swift/SwiftHybridViewManager.js +2 -2
- package/package.json +2 -2
- package/src/autolinking/ios/createHybridObjectInitializer.ts +2 -19
- package/src/syntax/swift/SwiftCxxBridgedType.ts +1 -1
- package/src/syntax/swift/SwiftHybridObjectRegistration.ts +15 -17
- package/src/views/swift/SwiftHybridViewManager.ts +2 -3
|
@@ -28,13 +28,13 @@ export function createHybridObjectIntializer() {
|
|
|
28
28
|
if (config?.swift != null) {
|
|
29
29
|
// Autolink a Swift HybridObject!
|
|
30
30
|
containsSwiftObjects = true;
|
|
31
|
-
const { cppCode, requiredImports,
|
|
31
|
+
const { cppCode, requiredImports, swiftRegistrationMethods } = createSwiftHybridObjectRegistration({
|
|
32
32
|
hybridObjectName: hybridObjectName,
|
|
33
33
|
swiftClassName: config.swift,
|
|
34
34
|
});
|
|
35
35
|
cppImports.push(...requiredImports);
|
|
36
36
|
cppRegistrations.push(cppCode);
|
|
37
|
-
swiftRegistrations.push(
|
|
37
|
+
swiftRegistrations.push(swiftRegistrationMethods);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
if (cppRegistrations.length === 0) {
|
|
@@ -79,23 +79,6 @@ import NitroModules
|
|
|
79
79
|
public final class ${autolinkingClassName} {
|
|
80
80
|
public typealias bridge = ${bridgeNamespace}
|
|
81
81
|
|
|
82
|
-
private protocol AutolinkedClass {
|
|
83
|
-
associatedtype T
|
|
84
|
-
/**
|
|
85
|
-
* Creates an instance of the Swift class that implements the HybridObject's spec,
|
|
86
|
-
* and wraps it in a Swift class that can directly interop with C++.
|
|
87
|
-
*
|
|
88
|
-
* This is generated by Nitrogen and will initialize the class specified
|
|
89
|
-
* in the \`"autolinking"\` property of \`nitro.json\`.
|
|
90
|
-
*/
|
|
91
|
-
static func create() -> T
|
|
92
|
-
/**
|
|
93
|
-
* Returns whether this concrete implementation is also
|
|
94
|
-
* conforming to the \`RecyclableView\` protocol, or not.
|
|
95
|
-
*/
|
|
96
|
-
static var isRecyclableHybridView: Bool { get }
|
|
97
|
-
}
|
|
98
|
-
|
|
99
82
|
${indent(swiftRegistrations.join('\n\n'), ' ')}
|
|
100
83
|
}
|
|
101
84
|
`.trim();
|
|
@@ -310,7 +310,7 @@ export class SwiftCxxBridgedType {
|
|
|
310
310
|
switch (language) {
|
|
311
311
|
case 'swift':
|
|
312
312
|
return `
|
|
313
|
-
{ () -> ${name.HybridTSpec} in
|
|
313
|
+
{ () -> any ${name.HybridTSpec} in
|
|
314
314
|
let __unsafePointer = ${getFunc}(${cppParameterName})
|
|
315
315
|
let __instance = ${name.HybridTSpecCxx}.fromUnsafe(__unsafePointer)
|
|
316
316
|
return __instance.get${name.HybridTSpec}()
|
|
@@ -11,11 +11,11 @@ interface Props {
|
|
|
11
11
|
}
|
|
12
12
|
interface SwiftHybridObjectRegistration {
|
|
13
13
|
cppCode: string;
|
|
14
|
-
|
|
14
|
+
swiftRegistrationMethods: string;
|
|
15
15
|
requiredImports: SourceImport[];
|
|
16
16
|
}
|
|
17
|
-
export declare function getAutolinkingClassName(hybridObjectName: string): string;
|
|
18
17
|
export declare function getAutolinkingNamespace(): string;
|
|
19
18
|
export declare function getHybridObjectConstructorCall(hybridObjectName: string): string;
|
|
19
|
+
export declare function getIsRecyclableCall(hybridObjectName: string): string;
|
|
20
20
|
export declare function createSwiftHybridObjectRegistration({ hybridObjectName, swiftClassName, }: Props): SwiftHybridObjectRegistration;
|
|
21
21
|
export {};
|
|
@@ -3,9 +3,6 @@ import { indent } from '../../utils.js';
|
|
|
3
3
|
import { getHybridObjectName } from '../getHybridObjectName.js';
|
|
4
4
|
import { HybridObjectType } from '../types/HybridObjectType.js';
|
|
5
5
|
import { SwiftCxxBridgedType } from './SwiftCxxBridgedType.js';
|
|
6
|
-
export function getAutolinkingClassName(hybridObjectName) {
|
|
7
|
-
return `Autolinked${hybridObjectName}`;
|
|
8
|
-
}
|
|
9
6
|
export function getAutolinkingNamespace() {
|
|
10
7
|
const swiftNamespace = NitroConfig.current.getIosModuleName();
|
|
11
8
|
const autolinkingClassName = `${swiftNamespace}Autolinking`;
|
|
@@ -13,24 +10,25 @@ export function getAutolinkingNamespace() {
|
|
|
13
10
|
}
|
|
14
11
|
export function getHybridObjectConstructorCall(hybridObjectName) {
|
|
15
12
|
const namespace = getAutolinkingNamespace();
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
return `${namespace}::create${hybridObjectName}();`;
|
|
14
|
+
}
|
|
15
|
+
export function getIsRecyclableCall(hybridObjectName) {
|
|
16
|
+
const namespace = getAutolinkingNamespace();
|
|
17
|
+
return `${namespace}::is${hybridObjectName}Recyclable();`;
|
|
18
18
|
}
|
|
19
19
|
export function createSwiftHybridObjectRegistration({ hybridObjectName, swiftClassName, }) {
|
|
20
20
|
const { HybridTSpecSwift } = getHybridObjectName(hybridObjectName);
|
|
21
21
|
const type = new HybridObjectType(hybridObjectName, 'swift', [], NitroConfig.current);
|
|
22
22
|
const bridge = new SwiftCxxBridgedType(type);
|
|
23
|
-
const autolinkingClassName = getAutolinkingClassName(hybridObjectName);
|
|
24
23
|
return {
|
|
25
|
-
|
|
26
|
-
public
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
24
|
+
swiftRegistrationMethods: `
|
|
25
|
+
public static func create${hybridObjectName}() -> ${bridge.getTypeCode('swift')} {
|
|
26
|
+
let hybridObject = ${swiftClassName}()
|
|
27
|
+
return ${indent(bridge.parseFromSwiftToCpp('hybridObject', 'swift'), ' ')}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public static func is${hybridObjectName}Recyclable() -> Bool {
|
|
31
|
+
return ${swiftClassName}.self is any RecyclableView.Type
|
|
34
32
|
}
|
|
35
33
|
`.trim(),
|
|
36
34
|
requiredImports: [
|
|
@@ -2,7 +2,7 @@ import { createViewComponentShadowNodeFiles, getViewComponentNames, } from '../C
|
|
|
2
2
|
import { createFileMetadataString, escapeCppName, } from '../../syntax/helpers.js';
|
|
3
3
|
import { getUmbrellaHeaderName } from '../../autolinking/ios/createSwiftUmbrellaHeader.js';
|
|
4
4
|
import { getHybridObjectName } from '../../syntax/getHybridObjectName.js';
|
|
5
|
-
import {
|
|
5
|
+
import { getHybridObjectConstructorCall, getIsRecyclableCall, } from '../../syntax/swift/SwiftHybridObjectRegistration.js';
|
|
6
6
|
import { indent } from '../../utils.js';
|
|
7
7
|
import { SwiftCxxBridgedType } from '../../syntax/swift/SwiftCxxBridgedType.js';
|
|
8
8
|
export function createSwiftHybridViewManager(spec) {
|
|
@@ -118,7 +118,7 @@ using namespace ${namespace}::views;
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
+ (BOOL)shouldBeRecycled {
|
|
121
|
-
return ${
|
|
121
|
+
return ${getIsRecyclableCall(spec.name)}
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
- (void)prepareForRecycle {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitrogen",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.2",
|
|
4
4
|
"description": "The code-generator for react-native-nitro-modules.",
|
|
5
5
|
"main": "lib/index",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"chalk": "^5.3.0",
|
|
38
|
-
"react-native-nitro-modules": "^0.33.
|
|
38
|
+
"react-native-nitro-modules": "^0.33.2",
|
|
39
39
|
"ts-morph": "^27.0.0",
|
|
40
40
|
"yargs": "^18.0.0",
|
|
41
41
|
"zod": "^4.0.5"
|
|
@@ -37,14 +37,14 @@ export function createHybridObjectIntializer(): [ObjcFile, SwiftFile] | [] {
|
|
|
37
37
|
if (config?.swift != null) {
|
|
38
38
|
// Autolink a Swift HybridObject!
|
|
39
39
|
containsSwiftObjects = true
|
|
40
|
-
const { cppCode, requiredImports,
|
|
40
|
+
const { cppCode, requiredImports, swiftRegistrationMethods } =
|
|
41
41
|
createSwiftHybridObjectRegistration({
|
|
42
42
|
hybridObjectName: hybridObjectName,
|
|
43
43
|
swiftClassName: config.swift,
|
|
44
44
|
})
|
|
45
45
|
cppImports.push(...requiredImports)
|
|
46
46
|
cppRegistrations.push(cppCode)
|
|
47
|
-
swiftRegistrations.push(
|
|
47
|
+
swiftRegistrations.push(swiftRegistrationMethods)
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -93,23 +93,6 @@ import NitroModules
|
|
|
93
93
|
public final class ${autolinkingClassName} {
|
|
94
94
|
public typealias bridge = ${bridgeNamespace}
|
|
95
95
|
|
|
96
|
-
private protocol AutolinkedClass {
|
|
97
|
-
associatedtype T
|
|
98
|
-
/**
|
|
99
|
-
* Creates an instance of the Swift class that implements the HybridObject's spec,
|
|
100
|
-
* and wraps it in a Swift class that can directly interop with C++.
|
|
101
|
-
*
|
|
102
|
-
* This is generated by Nitrogen and will initialize the class specified
|
|
103
|
-
* in the \`"autolinking"\` property of \`nitro.json\`.
|
|
104
|
-
*/
|
|
105
|
-
static func create() -> T
|
|
106
|
-
/**
|
|
107
|
-
* Returns whether this concrete implementation is also
|
|
108
|
-
* conforming to the \`RecyclableView\` protocol, or not.
|
|
109
|
-
*/
|
|
110
|
-
static var isRecyclableHybridView: Bool { get }
|
|
111
|
-
}
|
|
112
|
-
|
|
113
96
|
${indent(swiftRegistrations.join('\n\n'), ' ')}
|
|
114
97
|
}
|
|
115
98
|
`.trim()
|
|
@@ -353,7 +353,7 @@ export class SwiftCxxBridgedType implements BridgedType<'swift', 'c++'> {
|
|
|
353
353
|
switch (language) {
|
|
354
354
|
case 'swift':
|
|
355
355
|
return `
|
|
356
|
-
{ () -> ${name.HybridTSpec} in
|
|
356
|
+
{ () -> any ${name.HybridTSpec} in
|
|
357
357
|
let __unsafePointer = ${getFunc}(${cppParameterName})
|
|
358
358
|
let __instance = ${name.HybridTSpecCxx}.fromUnsafe(__unsafePointer)
|
|
359
359
|
return __instance.get${name.HybridTSpec}()
|
|
@@ -18,14 +18,10 @@ interface Props {
|
|
|
18
18
|
|
|
19
19
|
interface SwiftHybridObjectRegistration {
|
|
20
20
|
cppCode: string
|
|
21
|
-
|
|
21
|
+
swiftRegistrationMethods: string
|
|
22
22
|
requiredImports: SourceImport[]
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export function getAutolinkingClassName(hybridObjectName: string): string {
|
|
26
|
-
return `Autolinked${hybridObjectName}`
|
|
27
|
-
}
|
|
28
|
-
|
|
29
25
|
export function getAutolinkingNamespace() {
|
|
30
26
|
const swiftNamespace = NitroConfig.current.getIosModuleName()
|
|
31
27
|
const autolinkingClassName = `${swiftNamespace}Autolinking`
|
|
@@ -36,8 +32,12 @@ export function getHybridObjectConstructorCall(
|
|
|
36
32
|
hybridObjectName: string
|
|
37
33
|
): string {
|
|
38
34
|
const namespace = getAutolinkingNamespace()
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
return `${namespace}::create${hybridObjectName}();`
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getIsRecyclableCall(hybridObjectName: string): string {
|
|
39
|
+
const namespace = getAutolinkingNamespace()
|
|
40
|
+
return `${namespace}::is${hybridObjectName}Recyclable();`
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export function createSwiftHybridObjectRegistration({
|
|
@@ -53,18 +53,16 @@ export function createSwiftHybridObjectRegistration({
|
|
|
53
53
|
NitroConfig.current
|
|
54
54
|
)
|
|
55
55
|
const bridge = new SwiftCxxBridgedType(type)
|
|
56
|
-
const autolinkingClassName = getAutolinkingClassName(hybridObjectName)
|
|
57
56
|
|
|
58
57
|
return {
|
|
59
|
-
|
|
60
|
-
public
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
58
|
+
swiftRegistrationMethods: `
|
|
59
|
+
public static func create${hybridObjectName}() -> ${bridge.getTypeCode('swift')} {
|
|
60
|
+
let hybridObject = ${swiftClassName}()
|
|
61
|
+
return ${indent(bridge.parseFromSwiftToCpp('hybridObject', 'swift'), ' ')}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public static func is${hybridObjectName}Recyclable() -> Bool {
|
|
65
|
+
return ${swiftClassName}.self is any RecyclableView.Type
|
|
68
66
|
}
|
|
69
67
|
`.trim(),
|
|
70
68
|
requiredImports: [
|
|
@@ -11,9 +11,8 @@ import {
|
|
|
11
11
|
import { getUmbrellaHeaderName } from '../../autolinking/ios/createSwiftUmbrellaHeader.js'
|
|
12
12
|
import { getHybridObjectName } from '../../syntax/getHybridObjectName.js'
|
|
13
13
|
import {
|
|
14
|
-
getAutolinkingClassName,
|
|
15
|
-
getAutolinkingNamespace,
|
|
16
14
|
getHybridObjectConstructorCall,
|
|
15
|
+
getIsRecyclableCall,
|
|
17
16
|
} from '../../syntax/swift/SwiftHybridObjectRegistration.js'
|
|
18
17
|
import { indent } from '../../utils.js'
|
|
19
18
|
import { SwiftCxxBridgedType } from '../../syntax/swift/SwiftCxxBridgedType.js'
|
|
@@ -143,7 +142,7 @@ using namespace ${namespace}::views;
|
|
|
143
142
|
}
|
|
144
143
|
|
|
145
144
|
+ (BOOL)shouldBeRecycled {
|
|
146
|
-
return ${
|
|
145
|
+
return ${getIsRecyclableCall(spec.name)}
|
|
147
146
|
}
|
|
148
147
|
|
|
149
148
|
- (void)prepareForRecycle {
|