nitrogen 0.32.0 → 0.32.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/syntax/helpers.js +1 -2
- package/lib/syntax/kotlin/FbjniHybridObject.js +8 -0
- package/lib/syntax/swift/SwiftHybridObjectBridge.js +14 -0
- package/lib/syntax/types/Int32Type.d.ts +10 -0
- package/lib/syntax/types/Int32Type.js +36 -0
- package/lib/views/kotlin/KotlinHybridViewManager.js +6 -0
- package/lib/views/swift/SwiftHybridViewManager.js +6 -0
- package/package.json +2 -2
- package/src/syntax/helpers.ts +1 -2
- package/src/syntax/kotlin/FbjniHybridObject.ts +8 -0
- package/src/syntax/swift/SwiftHybridObjectBridge.ts +14 -0
- package/src/views/kotlin/KotlinHybridViewManager.ts +6 -0
- package/src/views/swift/SwiftHybridViewManager.ts +6 -0
package/lib/syntax/helpers.js
CHANGED
|
@@ -3,13 +3,12 @@ import { getTypeAs } from './types/getTypeAs.js';
|
|
|
3
3
|
import { OptionalType } from './types/OptionalType.js';
|
|
4
4
|
import { ArrayType } from './types/ArrayType.js';
|
|
5
5
|
export function createFileMetadataString(filename, comment = '///') {
|
|
6
|
-
const now = new Date();
|
|
7
6
|
return `
|
|
8
7
|
${comment}
|
|
9
8
|
${comment} ${filename}
|
|
10
9
|
${comment} This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
11
10
|
${comment} https://github.com/mrousavy/nitro
|
|
12
|
-
${comment} Copyright ©
|
|
11
|
+
${comment} Copyright © Marc Rousavy @ Margelo
|
|
13
12
|
${comment}
|
|
14
13
|
`.trim();
|
|
15
14
|
}
|
|
@@ -93,6 +93,7 @@ ${spaces} public virtual ${name.HybridTSpec} {
|
|
|
93
93
|
|
|
94
94
|
public:
|
|
95
95
|
size_t getExternalMemorySize() noexcept override;
|
|
96
|
+
bool equals(const std::shared_ptr<HybridObject>& other) override;
|
|
96
97
|
void dispose() noexcept override;
|
|
97
98
|
std::string toString() override;
|
|
98
99
|
|
|
@@ -172,6 +173,13 @@ namespace ${cxxNamespace} {
|
|
|
172
173
|
return method(_javaPart);
|
|
173
174
|
}
|
|
174
175
|
|
|
176
|
+
bool ${name.JHybridTSpec}::equals(const std::shared_ptr<HybridObject>& other) {
|
|
177
|
+
if (auto otherCast = std::dynamic_pointer_cast<${name.JHybridTSpec}>(other)) {
|
|
178
|
+
return _javaPart == otherCast->_javaPart;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
|
|
175
183
|
void ${name.JHybridTSpec}::dispose() noexcept {
|
|
176
184
|
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
177
185
|
method(_javaPart);
|
|
@@ -168,6 +168,14 @@ ${hasBase ? `open class ${name.HybridTSpecCxx} : ${baseClasses.join(', ')}` : `o
|
|
|
168
168
|
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Compares this object with the given [other] object for reference equality.
|
|
173
|
+
*/
|
|
174
|
+
@inline(__always)
|
|
175
|
+
public func equals(other: ${name.HybridTSpecCxx}) -> Bool {
|
|
176
|
+
return self.__implementation === other.__implementation
|
|
177
|
+
}
|
|
178
|
+
|
|
171
179
|
/**
|
|
172
180
|
* Call dispose() on the Swift class.
|
|
173
181
|
* This _may_ be called manually from JS.
|
|
@@ -335,6 +343,12 @@ namespace ${cxxNamespace} {
|
|
|
335
343
|
inline size_t getExternalMemorySize() noexcept override {
|
|
336
344
|
return _swiftPart.getMemorySize();
|
|
337
345
|
}
|
|
346
|
+
bool equals(const std::shared_ptr<HybridObject>& other) override {
|
|
347
|
+
if (auto otherCast = std::dynamic_pointer_cast<${name.HybridTSpecSwift}>(other)) {
|
|
348
|
+
return _swiftPart.equals(otherCast->_swiftPart);
|
|
349
|
+
}
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
338
352
|
void dispose() noexcept override {
|
|
339
353
|
_swiftPart.dispose();
|
|
340
354
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
}
|
|
@@ -61,6 +61,12 @@ open class ${manager}: SimpleViewManager<View>() {
|
|
|
61
61
|
// 2. Continue in base View props
|
|
62
62
|
return super.updateState(view, props, stateWrapper)
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
protected override fun setupViewRecycling() {
|
|
66
|
+
// TODO: Recycling should be controllable by the user. WIP, but disabled for now.
|
|
67
|
+
// By not calling \`super.setupViewRecycling()\`, we effectively
|
|
68
|
+
// disable view recycling for now.
|
|
69
|
+
}
|
|
64
70
|
}
|
|
65
71
|
`.trim();
|
|
66
72
|
const updaterKotlinCode = `
|
|
@@ -52,6 +52,7 @@ using namespace ${namespace}::views;
|
|
|
52
52
|
* Represents the React Native View holder for the Nitro "${spec.name}" HybridView.
|
|
53
53
|
*/
|
|
54
54
|
@interface ${component}: RCTViewComponentView
|
|
55
|
+
+ (BOOL)shouldBeRecycled;
|
|
55
56
|
@end
|
|
56
57
|
|
|
57
58
|
@implementation ${component} {
|
|
@@ -67,6 +68,11 @@ using namespace ${namespace}::views;
|
|
|
67
68
|
return react::concreteComponentDescriptorProvider<${descriptorClassName}>();
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
+ (BOOL)shouldBeRecycled {
|
|
72
|
+
// TODO: Recycling should be controllable by the user. WIP, but disabled for now.
|
|
73
|
+
return NO;
|
|
74
|
+
}
|
|
75
|
+
|
|
70
76
|
- (instancetype) init {
|
|
71
77
|
if (self = [super init]) {
|
|
72
78
|
std::shared_ptr<${HybridTSpec}> hybridView = ${getHybridObjectConstructorCall(spec.name)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nitrogen",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.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.32.
|
|
38
|
+
"react-native-nitro-modules": "^0.32.2",
|
|
39
39
|
"ts-morph": "^27.0.0",
|
|
40
40
|
"yargs": "^18.0.0",
|
|
41
41
|
"zod": "^4.0.5"
|
package/src/syntax/helpers.ts
CHANGED
|
@@ -11,13 +11,12 @@ export function createFileMetadataString(
|
|
|
11
11
|
filename: string,
|
|
12
12
|
comment: Comment = '///'
|
|
13
13
|
): string {
|
|
14
|
-
const now = new Date()
|
|
15
14
|
return `
|
|
16
15
|
${comment}
|
|
17
16
|
${comment} ${filename}
|
|
18
17
|
${comment} This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
19
18
|
${comment} https://github.com/mrousavy/nitro
|
|
20
|
-
${comment} Copyright ©
|
|
19
|
+
${comment} Copyright © Marc Rousavy @ Margelo
|
|
21
20
|
${comment}
|
|
22
21
|
`.trim()
|
|
23
22
|
}
|
|
@@ -112,6 +112,7 @@ ${spaces} public virtual ${name.HybridTSpec} {
|
|
|
112
112
|
|
|
113
113
|
public:
|
|
114
114
|
size_t getExternalMemorySize() noexcept override;
|
|
115
|
+
bool equals(const std::shared_ptr<HybridObject>& other) override;
|
|
115
116
|
void dispose() noexcept override;
|
|
116
117
|
std::string toString() override;
|
|
117
118
|
|
|
@@ -194,6 +195,13 @@ namespace ${cxxNamespace} {
|
|
|
194
195
|
return method(_javaPart);
|
|
195
196
|
}
|
|
196
197
|
|
|
198
|
+
bool ${name.JHybridTSpec}::equals(const std::shared_ptr<HybridObject>& other) {
|
|
199
|
+
if (auto otherCast = std::dynamic_pointer_cast<${name.JHybridTSpec}>(other)) {
|
|
200
|
+
return _javaPart == otherCast->_javaPart;
|
|
201
|
+
}
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
|
|
197
205
|
void ${name.JHybridTSpec}::dispose() noexcept {
|
|
198
206
|
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
199
207
|
method(_javaPart);
|
|
@@ -215,6 +215,14 @@ ${hasBase ? `open class ${name.HybridTSpecCxx} : ${baseClasses.join(', ')}` : `o
|
|
|
215
215
|
return MemoryHelper.getSizeOf(self.__implementation) + self.__implementation.memorySize
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
/**
|
|
219
|
+
* Compares this object with the given [other] object for reference equality.
|
|
220
|
+
*/
|
|
221
|
+
@inline(__always)
|
|
222
|
+
public func equals(other: ${name.HybridTSpecCxx}) -> Bool {
|
|
223
|
+
return self.__implementation === other.__implementation
|
|
224
|
+
}
|
|
225
|
+
|
|
218
226
|
/**
|
|
219
227
|
* Call dispose() on the Swift class.
|
|
220
228
|
* This _may_ be called manually from JS.
|
|
@@ -399,6 +407,12 @@ namespace ${cxxNamespace} {
|
|
|
399
407
|
inline size_t getExternalMemorySize() noexcept override {
|
|
400
408
|
return _swiftPart.getMemorySize();
|
|
401
409
|
}
|
|
410
|
+
bool equals(const std::shared_ptr<HybridObject>& other) override {
|
|
411
|
+
if (auto otherCast = std::dynamic_pointer_cast<${name.HybridTSpecSwift}>(other)) {
|
|
412
|
+
return _swiftPart.equals(otherCast->_swiftPart);
|
|
413
|
+
}
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
402
416
|
void dispose() noexcept override {
|
|
403
417
|
_swiftPart.dispose();
|
|
404
418
|
}
|
|
@@ -81,6 +81,12 @@ open class ${manager}: SimpleViewManager<View>() {
|
|
|
81
81
|
// 2. Continue in base View props
|
|
82
82
|
return super.updateState(view, props, stateWrapper)
|
|
83
83
|
}
|
|
84
|
+
|
|
85
|
+
protected override fun setupViewRecycling() {
|
|
86
|
+
// TODO: Recycling should be controllable by the user. WIP, but disabled for now.
|
|
87
|
+
// By not calling \`super.setupViewRecycling()\`, we effectively
|
|
88
|
+
// disable view recycling for now.
|
|
89
|
+
}
|
|
84
90
|
}
|
|
85
91
|
`.trim()
|
|
86
92
|
|
|
@@ -73,6 +73,7 @@ using namespace ${namespace}::views;
|
|
|
73
73
|
* Represents the React Native View holder for the Nitro "${spec.name}" HybridView.
|
|
74
74
|
*/
|
|
75
75
|
@interface ${component}: RCTViewComponentView
|
|
76
|
+
+ (BOOL)shouldBeRecycled;
|
|
76
77
|
@end
|
|
77
78
|
|
|
78
79
|
@implementation ${component} {
|
|
@@ -88,6 +89,11 @@ using namespace ${namespace}::views;
|
|
|
88
89
|
return react::concreteComponentDescriptorProvider<${descriptorClassName}>();
|
|
89
90
|
}
|
|
90
91
|
|
|
92
|
+
+ (BOOL)shouldBeRecycled {
|
|
93
|
+
// TODO: Recycling should be controllable by the user. WIP, but disabled for now.
|
|
94
|
+
return NO;
|
|
95
|
+
}
|
|
96
|
+
|
|
91
97
|
- (instancetype) init {
|
|
92
98
|
if (self = [super init]) {
|
|
93
99
|
std::shared_ptr<${HybridTSpec}> hybridView = ${getHybridObjectConstructorCall(spec.name)}
|