nitrogen 0.33.1 → 0.33.3

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}()
@@ -34,7 +34,6 @@ return ${returnType.parseFromSwiftToCpp('__result', 'swift')}
34
34
  const code = `
35
35
  ${createFileMetadataString(`${swiftClassName}.swift`)}
36
36
 
37
- import Foundation
38
37
  ${imports.join('\n')}
39
38
 
40
39
  /**
@@ -58,7 +58,6 @@ public ${hasBaseClass ? 'override func' : 'func'} getCxxWrapper() -> ${name.Hybr
58
58
  const protocolCode = `
59
59
  ${createFileMetadataString(`${protocolName}.swift`)}
60
60
 
61
- import Foundation
62
61
  ${imports.join('\n')}
63
62
 
64
63
  /// See \`\`${protocolName}\`\`
@@ -43,7 +43,7 @@ public final func afterUpdate() {
43
43
  }
44
44
  `.trim(), `
45
45
  public final func maybePrepareForRecycle() {
46
- guard let recyclable = __implementation as? RecyclableView else { return }
46
+ guard let recyclable = __implementation as? any RecyclableView else { return }
47
47
  recyclable.prepareForRecycle()
48
48
  }
49
49
  `.trim());
@@ -82,7 +82,6 @@ public override func getCxxPart() -> bridge.${baseBridge.specializationName} {
82
82
  const swiftCxxWrapperCode = `
83
83
  ${createFileMetadataString(`${name.HybridTSpecCxx}.swift`)}
84
84
 
85
- import Foundation
86
85
  ${imports.join('\n')}
87
86
 
88
87
  /**
@@ -11,11 +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
- 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
- const autolinkingClassName = getAutolinkingClassName(hybridObjectName);
17
- return `${namespace}::${autolinkingClassName}::create();`;
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
- swiftRegistrationClass: `
26
- public final class ${autolinkingClassName}: AutolinkedClass {
27
- public static func create() -> ${bridge.getTypeCode('swift')} {
28
- let hybridObject = ${swiftClassName}()
29
- return ${indent(bridge.parseFromSwiftToCpp('hybridObject', 'swift'), ' ')}
30
- }
31
- public static var isRecyclableHybridView: Bool {
32
- return ${swiftClassName}.self is any RecyclableView.Type
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: [
@@ -28,7 +28,6 @@ var ${p.escapedName}: ${p.getCode('swift')} {
28
28
  const code = `
29
29
  ${createFileMetadataString(`${struct.structName}.swift`)}
30
30
 
31
- import Foundation
32
31
  ${imports.join('\n')}
33
32
 
34
33
  /**
@@ -225,7 +225,7 @@ namespace ${namespace} {
225
225
  void ${descriptorClassName}::adopt(react::ShadowNode& shadowNode) const {
226
226
  // This is called immediately after \`ShadowNode\` is created, cloned or in progress.
227
227
  // On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++.
228
- auto& concreteShadowNode = dynamic_cast<${shadowNodeClassName}&>(shadowNode);
228
+ auto& concreteShadowNode = static_cast<${shadowNodeClassName}&>(shadowNode);
229
229
  const ${propsClassName}& props = concreteShadowNode.getConcreteProps();
230
230
  ${stateClassName} state;
231
231
  state.setProps(props);
@@ -33,7 +33,7 @@ import ${javaNamespace}.*
33
33
  /**
34
34
  * Represents the React Native \`ViewManager\` for the "${spec.name}" Nitro HybridView.
35
35
  */
36
- open class ${manager}: SimpleViewManager<View>() {
36
+ public class ${manager}: SimpleViewManager<View>() {
37
37
  init {
38
38
  if (RecyclableView::class.java.isAssignableFrom(${viewImplementation}::class.java)) {
39
39
  // Enable view recycling
@@ -126,7 +126,7 @@ namespace ${cxxNamespace} {
126
126
 
127
127
  using namespace facebook;
128
128
 
129
- class J${stateUpdaterName}: public jni::JavaClass<J${stateUpdaterName}> {
129
+ class J${stateUpdaterName} final: public jni::JavaClass<J${stateUpdaterName}> {
130
130
  public:
131
131
  static constexpr auto kJavaDescriptor = "L${updaterJniDescriptor};";
132
132
 
@@ -186,7 +186,7 @@ void J${stateUpdaterName}::updateViewProps(jni::alias_ref<jni::JClass> /* class
186
186
  static_cast<react::StateWrapperImpl::javaobject>(rawStateWrapper)};
187
187
 
188
188
  std::shared_ptr<const react::State> state = stateWrapper->cthis()->getState();
189
- auto concreteState = std::dynamic_pointer_cast<const ConcreteStateData>(state);
189
+ auto concreteState = std::static_pointer_cast<const ConcreteStateData>(state);
190
190
  const ${stateClassName}& data = concreteState->getData();
191
191
  const std::optional<${propsClassName}>& maybeProps = data.getProps();
192
192
  if (!maybeProps.has_value()) {
@@ -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 { getAutolinkingClassName, 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()}::${getAutolinkingClassName(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.1",
3
+ "version": "0.33.3",
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.1",
38
+ "react-native-nitro-modules": "^0.33.3",
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}()
@@ -41,7 +41,6 @@ return ${returnType.parseFromSwiftToCpp('__result', 'swift')}
41
41
  const code = `
42
42
  ${createFileMetadataString(`${swiftClassName}.swift`)}
43
43
 
44
- import Foundation
45
44
  ${imports.join('\n')}
46
45
 
47
46
  /**
@@ -70,7 +70,6 @@ public ${hasBaseClass ? 'override func' : 'func'} getCxxWrapper() -> ${name.Hybr
70
70
  const protocolCode = `
71
71
  ${createFileMetadataString(`${protocolName}.swift`)}
72
72
 
73
- import Foundation
74
73
  ${imports.join('\n')}
75
74
 
76
75
  /// See \`\`${protocolName}\`\`
@@ -66,7 +66,7 @@ public final func afterUpdate() {
66
66
  `.trim(),
67
67
  `
68
68
  public final func maybePrepareForRecycle() {
69
- guard let recyclable = __implementation as? RecyclableView else { return }
69
+ guard let recyclable = __implementation as? any RecyclableView else { return }
70
70
  recyclable.prepareForRecycle()
71
71
  }
72
72
  `.trim()
@@ -130,7 +130,6 @@ public override func getCxxPart() -> bridge.${baseBridge.specializationName} {
130
130
  const swiftCxxWrapperCode = `
131
131
  ${createFileMetadataString(`${name.HybridTSpecCxx}.swift`)}
132
132
 
133
- import Foundation
134
133
  ${imports.join('\n')}
135
134
 
136
135
  /**
@@ -18,14 +18,10 @@ 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
 
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
- const autolinkingClassName = getAutolinkingClassName(hybridObjectName)
40
- return `${namespace}::${autolinkingClassName}::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();`
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
- swiftRegistrationClass: `
60
- public final class ${autolinkingClassName}: AutolinkedClass {
61
- public static func create() -> ${bridge.getTypeCode('swift')} {
62
- let hybridObject = ${swiftClassName}()
63
- return ${indent(bridge.parseFromSwiftToCpp('hybridObject', 'swift'), ' ')}
64
- }
65
- public static var isRecyclableHybridView: Bool {
66
- return ${swiftClassName}.self is any RecyclableView.Type
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: [
@@ -37,7 +37,6 @@ var ${p.escapedName}: ${p.getCode('swift')} {
37
37
  const code = `
38
38
  ${createFileMetadataString(`${struct.structName}.swift`)}
39
39
 
40
- import Foundation
41
40
  ${imports.join('\n')}
42
41
 
43
42
  /**
@@ -272,7 +272,7 @@ namespace ${namespace} {
272
272
  void ${descriptorClassName}::adopt(react::ShadowNode& shadowNode) const {
273
273
  // This is called immediately after \`ShadowNode\` is created, cloned or in progress.
274
274
  // On Android, we need to wrap props in our state, which gets routed through Java and later unwrapped in JNI/C++.
275
- auto& concreteShadowNode = dynamic_cast<${shadowNodeClassName}&>(shadowNode);
275
+ auto& concreteShadowNode = static_cast<${shadowNodeClassName}&>(shadowNode);
276
276
  const ${propsClassName}& props = concreteShadowNode.getConcreteProps();
277
277
  ${stateClassName} state;
278
278
  state.setProps(props);
@@ -53,7 +53,7 @@ import ${javaNamespace}.*
53
53
  /**
54
54
  * Represents the React Native \`ViewManager\` for the "${spec.name}" Nitro HybridView.
55
55
  */
56
- open class ${manager}: SimpleViewManager<View>() {
56
+ public class ${manager}: SimpleViewManager<View>() {
57
57
  init {
58
58
  if (RecyclableView::class.java.isAssignableFrom(${viewImplementation}::class.java)) {
59
59
  // Enable view recycling
@@ -152,7 +152,7 @@ namespace ${cxxNamespace} {
152
152
 
153
153
  using namespace facebook;
154
154
 
155
- class J${stateUpdaterName}: public jni::JavaClass<J${stateUpdaterName}> {
155
+ class J${stateUpdaterName} final: public jni::JavaClass<J${stateUpdaterName}> {
156
156
  public:
157
157
  static constexpr auto kJavaDescriptor = "L${updaterJniDescriptor};";
158
158
 
@@ -213,7 +213,7 @@ void J${stateUpdaterName}::updateViewProps(jni::alias_ref<jni::JClass> /* class
213
213
  static_cast<react::StateWrapperImpl::javaobject>(rawStateWrapper)};
214
214
 
215
215
  std::shared_ptr<const react::State> state = stateWrapper->cthis()->getState();
216
- auto concreteState = std::dynamic_pointer_cast<const ConcreteStateData>(state);
216
+ auto concreteState = std::static_pointer_cast<const ConcreteStateData>(state);
217
217
  const ${stateClassName}& data = concreteState->getData();
218
218
  const std::optional<${propsClassName}>& maybeProps = data.getProps();
219
219
  if (!maybeProps.has_value()) {
@@ -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 ${getAutolinkingNamespace()}::${getAutolinkingClassName(spec.name)}::isRecyclableHybridView();
145
+ return ${getIsRecyclableCall(spec.name)}
147
146
  }
148
147
 
149
148
  - (void)prepareForRecycle {