nitrogen 0.33.0 → 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.
@@ -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, swiftRegistrationClass } = createSwiftHybridObjectRegistration({
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(swiftRegistrationClass);
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,10 +11,11 @@ interface Props {
11
11
  }
12
12
  interface SwiftHybridObjectRegistration {
13
13
  cppCode: string;
14
- swiftRegistrationClass: string;
14
+ swiftRegistrationMethods: string;
15
15
  requiredImports: SourceImport[];
16
16
  }
17
17
  export declare function getAutolinkingNamespace(): string;
18
18
  export declare function getHybridObjectConstructorCall(hybridObjectName: string): string;
19
+ export declare function getIsRecyclableCall(hybridObjectName: string): string;
19
20
  export declare function createSwiftHybridObjectRegistration({ hybridObjectName, swiftClassName, }: Props): SwiftHybridObjectRegistration;
20
21
  export {};
@@ -10,22 +10,25 @@ export function getAutolinkingNamespace() {
10
10
  }
11
11
  export function getHybridObjectConstructorCall(hybridObjectName) {
12
12
  const namespace = getAutolinkingNamespace();
13
- return `${namespace}::${hybridObjectName}::create();`;
13
+ return `${namespace}::create${hybridObjectName}();`;
14
+ }
15
+ export function getIsRecyclableCall(hybridObjectName) {
16
+ const namespace = getAutolinkingNamespace();
17
+ return `${namespace}::is${hybridObjectName}Recyclable();`;
14
18
  }
15
19
  export function createSwiftHybridObjectRegistration({ hybridObjectName, swiftClassName, }) {
16
20
  const { HybridTSpecSwift } = getHybridObjectName(hybridObjectName);
17
21
  const type = new HybridObjectType(hybridObjectName, 'swift', [], NitroConfig.current);
18
22
  const bridge = new SwiftCxxBridgedType(type);
19
23
  return {
20
- swiftRegistrationClass: `
21
- public final class ${hybridObjectName}: AutolinkedClass {
22
- public static func create() -> ${bridge.getTypeCode('swift')} {
23
- let hybridObject = ${swiftClassName}()
24
- return ${indent(bridge.parseFromSwiftToCpp('hybridObject', 'swift'), ' ')}
25
- }
26
- public static var isRecyclableHybridView: Bool {
27
- return ${swiftClassName}.self is any RecyclableView.Type
28
- }
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
29
32
  }
30
33
  `.trim(),
31
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 { getAutolinkingNamespace, getHybridObjectConstructorCall, } from '../../syntax/swift/SwiftHybridObjectRegistration.js';
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 ${getAutolinkingNamespace()}::${spec.name}::isRecyclableHybridView();
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.0",
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.0",
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, swiftRegistrationClass } =
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(swiftRegistrationClass)
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,7 +18,7 @@ interface Props {
18
18
 
19
19
  interface SwiftHybridObjectRegistration {
20
20
  cppCode: string
21
- swiftRegistrationClass: string
21
+ swiftRegistrationMethods: string
22
22
  requiredImports: SourceImport[]
23
23
  }
24
24
 
@@ -32,7 +32,12 @@ export function getHybridObjectConstructorCall(
32
32
  hybridObjectName: string
33
33
  ): string {
34
34
  const namespace = getAutolinkingNamespace()
35
- return `${namespace}::${hybridObjectName}::create();`
35
+ return `${namespace}::create${hybridObjectName}();`
36
+ }
37
+
38
+ export function getIsRecyclableCall(hybridObjectName: string): string {
39
+ const namespace = getAutolinkingNamespace()
40
+ return `${namespace}::is${hybridObjectName}Recyclable();`
36
41
  }
37
42
 
38
43
  export function createSwiftHybridObjectRegistration({
@@ -50,15 +55,14 @@ export function createSwiftHybridObjectRegistration({
50
55
  const bridge = new SwiftCxxBridgedType(type)
51
56
 
52
57
  return {
53
- swiftRegistrationClass: `
54
- public final class ${hybridObjectName}: AutolinkedClass {
55
- public static func create() -> ${bridge.getTypeCode('swift')} {
56
- let hybridObject = ${swiftClassName}()
57
- return ${indent(bridge.parseFromSwiftToCpp('hybridObject', 'swift'), ' ')}
58
- }
59
- public static var isRecyclableHybridView: Bool {
60
- return ${swiftClassName}.self is any RecyclableView.Type
61
- }
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
62
66
  }
63
67
  `.trim(),
64
68
  requiredImports: [
@@ -11,8 +11,8 @@ import {
11
11
  import { getUmbrellaHeaderName } from '../../autolinking/ios/createSwiftUmbrellaHeader.js'
12
12
  import { getHybridObjectName } from '../../syntax/getHybridObjectName.js'
13
13
  import {
14
- getAutolinkingNamespace,
15
14
  getHybridObjectConstructorCall,
15
+ getIsRecyclableCall,
16
16
  } from '../../syntax/swift/SwiftHybridObjectRegistration.js'
17
17
  import { indent } from '../../utils.js'
18
18
  import { SwiftCxxBridgedType } from '../../syntax/swift/SwiftCxxBridgedType.js'
@@ -142,7 +142,7 @@ using namespace ${namespace}::views;
142
142
  }
143
143
 
144
144
  + (BOOL)shouldBeRecycled {
145
- return ${getAutolinkingNamespace()}::${spec.name}::isRecyclableHybridView();
145
+ return ${getIsRecyclableCall(spec.name)}
146
146
  }
147
147
 
148
148
  - (void)prepareForRecycle {
@@ -1,10 +0,0 @@
1
- import type { Language } from '../../getPlatformSpecs.js';
2
- import type { SourceFile, SourceImport } from '../SourceFile.js';
3
- import type { Type, TypeKind } from './Type.js';
4
- export declare class Int32Type implements Type {
5
- get canBePassedByReference(): boolean;
6
- get kind(): TypeKind;
7
- getCode(language: Language): string;
8
- getExtraFiles(): SourceFile[];
9
- getRequiredImports(language: Language): SourceImport[];
10
- }
@@ -1,36 +0,0 @@
1
- export class Int32Type {
2
- get canBePassedByReference() {
3
- // It's a primitive
4
- return false;
5
- }
6
- get kind() {
7
- return 'int32';
8
- }
9
- getCode(language) {
10
- switch (language) {
11
- case 'c++':
12
- return 'int32_t';
13
- case 'swift':
14
- return 'Int32';
15
- case 'kotlin':
16
- return 'Int';
17
- default:
18
- throw new Error(`Language ${language} is not yet supported for Int32Type!`);
19
- }
20
- }
21
- getExtraFiles() {
22
- return [];
23
- }
24
- getRequiredImports(language) {
25
- if (language === 'c++') {
26
- return [
27
- {
28
- language: language,
29
- name: 'cstdint',
30
- space: 'system',
31
- },
32
- ];
33
- }
34
- return [];
35
- }
36
- }