react-native-nitro-modules 0.9.2 → 0.10.0
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/README.md +3 -3
- package/cpp/core/BoxedHybridObject.cpp +29 -0
- package/cpp/core/BoxedHybridObject.hpp +36 -0
- package/cpp/templates/FutureType.hpp +1 -1
- package/cpp/templates/TypeIndex.hpp +29 -0
- package/cpp/turbomodule/NativeNitroModules.cpp +31 -16
- package/cpp/turbomodule/NativeNitroModules.hpp +2 -3
- package/cpp/utils/NitroDefines.hpp +5 -0
- package/ios/core/AnyMapHolder.hpp +8 -0
- package/ios/core/AnyMapHolder.swift +65 -39
- package/lib/NativeNitroModules.d.ts +0 -1
- package/lib/NitroModules.d.ts +35 -0
- package/lib/NitroModules.js +27 -0
- package/lib/NitroModulesTurboModule.d.ts +2 -1
- package/lib/commonjs/NitroModules.js +31 -3
- package/lib/commonjs/NitroModules.js.map +1 -1
- package/lib/commonjs/NitroModulesTurboModule.js.map +1 -1
- package/lib/module/NitroModules.js +31 -3
- package/lib/module/NitroModules.js.map +1 -1
- package/lib/module/NitroModulesTurboModule.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/HybridObject.d.ts +99 -0
- package/lib/typescript/NitroModules.d.ts +84 -0
- package/lib/typescript/NitroModules.d.ts.map +1 -1
- package/lib/typescript/NitroModulesTurboModule.d.ts +2 -1
- package/lib/typescript/NitroModulesTurboModule.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NitroModules.ts +37 -5
- package/src/NitroModulesTurboModule.ts +2 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { HybridObject } from './HybridObject';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a boxed {@linkcode HybridObject} that can later be unboxed again.
|
|
4
|
+
* This is implemented as a `jsi::HostObject`.
|
|
5
|
+
*/
|
|
6
|
+
export interface BoxedHybridObject<T extends HybridObject> {
|
|
7
|
+
/**
|
|
8
|
+
* Unboxes the {@linkcode HybridObject}.
|
|
9
|
+
* This can be called from a different Runtime than the one it was boxed in.
|
|
10
|
+
*/
|
|
11
|
+
unbox(): T;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A lazy proxy for initializing Nitro Modules HybridObjects.
|
|
15
|
+
*/
|
|
16
|
+
export declare const NitroModules: {
|
|
17
|
+
/**
|
|
18
|
+
* Create a new instance of the `HybridObject` {@linkcode T}.
|
|
19
|
+
*
|
|
20
|
+
* {@linkcode T} has to be registered beforehand under the name {@linkcode name}
|
|
21
|
+
* in the native Nitro Modules `HybridObjectRegistry`.
|
|
22
|
+
*
|
|
23
|
+
* @param name The name of the `HybridObject` under which it was registered at.
|
|
24
|
+
* @returns An instance of {@linkcode T}
|
|
25
|
+
* @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.
|
|
26
|
+
*/
|
|
27
|
+
createHybridObject<T extends HybridObject<any>>(name: string): T;
|
|
28
|
+
/**
|
|
29
|
+
* Get a list of all registered Hybrid Objects.
|
|
30
|
+
*/
|
|
31
|
+
getAllHybridObjectNames(): string[];
|
|
32
|
+
/**
|
|
33
|
+
* Returns whether a HybridObject under the given {@linkcode name} is registered, or not.
|
|
34
|
+
*/
|
|
35
|
+
hasHybridObject(name: string): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Returns whether the given {@linkcode object} has a `NativeState` or not.
|
|
38
|
+
*
|
|
39
|
+
* This can be a quick way to check if an object is a valid {@linkcode HybridObject},
|
|
40
|
+
* and has not yet been disposed.
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const someObject = NitroModules.createHybridObject<Some>('Some')
|
|
44
|
+
* console.log(NitroModules.hasNativeState(someObject)) // -> true
|
|
45
|
+
* someObject.dispose()
|
|
46
|
+
* console.log(NitroModules.hasNativeState(someObject)) // -> false
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
hasNativeState(object: object): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Forcefully removes the `NativeState` of the given {@linkcode object}.
|
|
52
|
+
*/
|
|
53
|
+
removeNativeState(object: object): void;
|
|
54
|
+
/**
|
|
55
|
+
* Gets the current build type configuration as defined in the `NITRO_DEBUG`
|
|
56
|
+
* preprocessor flag.
|
|
57
|
+
*/
|
|
58
|
+
readonly buildType: "debug" | "release";
|
|
59
|
+
/**
|
|
60
|
+
* Boxes the given {@linkcode hybridObject} into a {@linkcode BoxedHybridObject<T>}, which can
|
|
61
|
+
* later be unboxed in a separate Runtime.
|
|
62
|
+
*
|
|
63
|
+
* While Nitro is runtime-agnostic and all `HybridObject`s can be used from a any Runtime,
|
|
64
|
+
* some threading/worklet libraries (like [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core))
|
|
65
|
+
* do not yet support copying over `HybridObject`s as they use newer JSI APIs like `jsi::NativeState`.
|
|
66
|
+
*
|
|
67
|
+
* While those APIs are not yet available, you can still use every Nitro Hybrid Object in a separate
|
|
68
|
+
* Runtime/Worklet context by just boxing it yourself:
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const something = NitroModules.createHybridObject<Something>('Something')
|
|
73
|
+
* const boxed = NitroModules.box(something)
|
|
74
|
+
* const context = Worklets.createContext('DummyContext')
|
|
75
|
+
* context.runAsync(() => {
|
|
76
|
+
* 'worklet'
|
|
77
|
+
* const unboxed = boxed.unbox()
|
|
78
|
+
* console.log(unboxed.name) // --> "Something"
|
|
79
|
+
* })
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
box<T extends HybridObject>(hybridObject: T): BoxedHybridObject<T>;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=NitroModules.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NitroModules.d.ts","sourceRoot":"","sources":["../../src/NitroModules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"NitroModules.d.ts","sourceRoot":"","sources":["../../src/NitroModules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAElD;;;GAGG;AACH,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,YAAY;IACvD;;;OAGG;IACH,KAAK,IAAI,CAAC,CAAA;CACX;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;IACvB;;;;;;;;;OASG;uBACgB,CAAC,SAAS,YAAY,CAAC,GAAG,CAAC,QAAQ,MAAM,GAAG,CAAC;IAKhE;;OAEG;+BACwB,MAAM,EAAE;IAInC;;OAEG;0BACmB,MAAM,GAAG,OAAO;IAItC;;;;;;;;;;;;OAYG;2BACoB,MAAM,GAAG,OAAO;IAIvC;;OAEG;8BACuB,MAAM,GAAG,IAAI;IAIvC;;;OAGG;;IAKH;;;;;;;;;;;;;;;;;;;;;;OAsBG;QACC,CAAC,SAAS,YAAY,gBAAgB,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC;CAInE,CAAA"}
|
|
@@ -2,12 +2,13 @@ import type { TurboModule } from 'react-native';
|
|
|
2
2
|
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
3
|
export interface NativeNitroSpec extends TurboModule {
|
|
4
4
|
install(): void;
|
|
5
|
-
createHybridObject(name: string
|
|
5
|
+
createHybridObject(name: string): UnsafeObject;
|
|
6
6
|
hasHybridObject(name: string): boolean;
|
|
7
7
|
getAllHybridObjectNames(): string[];
|
|
8
8
|
hasNativeState(obj: UnsafeObject): boolean;
|
|
9
9
|
removeNativeState(obj: UnsafeObject): void;
|
|
10
10
|
buildType: 'debug' | 'release';
|
|
11
|
+
box(obj: UnsafeObject): UnsafeObject;
|
|
11
12
|
}
|
|
12
13
|
export declare function getNativeNitroModules(): NativeNitroSpec;
|
|
13
14
|
declare global {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NitroModulesTurboModule.d.ts","sourceRoot":"","sources":["../../src/NitroModulesTurboModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAA;AAM7E,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAElD,OAAO,IAAI,IAAI,CAAA;IAEf,kBAAkB,CAAC,IAAI,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"NitroModulesTurboModule.d.ts","sourceRoot":"","sources":["../../src/NitroModulesTurboModule.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAA;AAM7E,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAElD,OAAO,IAAI,IAAI,CAAA;IAEf,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;IAC9C,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IACtC,uBAAuB,IAAI,MAAM,EAAE,CAAA;IAEnC,cAAc,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAA;IAC1C,iBAAiB,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI,CAAA;IAC1C,SAAS,EAAE,OAAO,GAAG,SAAS,CAAA;IAC9B,GAAG,CAAC,GAAG,EAAE,YAAY,GAAG,YAAY,CAAA;CACrC;AAGD,wBAAgB,qBAAqB,IAAI,eAAe,CAevD;AAED,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,sBAAsB,EAAE,EAAE,CAAA;IAC9B,IAAI,iBAAiB,EAAE,EAAE,CAAA;CAC1B;AAED,wBAAgB,cAAc,YAI7B"}
|
package/package.json
CHANGED
package/src/NitroModules.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { getNativeNitroModules } from './NitroModulesTurboModule'
|
|
2
2
|
import type { HybridObject } from './HybridObject'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Represents a boxed {@linkcode HybridObject} that can later be unboxed again.
|
|
6
|
+
* This is implemented as a `jsi::HostObject`.
|
|
7
|
+
*/
|
|
8
|
+
export interface BoxedHybridObject<T extends HybridObject> {
|
|
9
|
+
/**
|
|
10
|
+
* Unboxes the {@linkcode HybridObject}.
|
|
11
|
+
* This can be called from a different Runtime than the one it was boxed in.
|
|
12
|
+
*/
|
|
13
|
+
unbox(): T
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
/**
|
|
@@ -73,4 +78,31 @@ export const NitroModules = {
|
|
|
73
78
|
const nitro = getNativeNitroModules()
|
|
74
79
|
return nitro.buildType
|
|
75
80
|
},
|
|
81
|
+
/**
|
|
82
|
+
* Boxes the given {@linkcode hybridObject} into a {@linkcode BoxedHybridObject<T>}, which can
|
|
83
|
+
* later be unboxed in a separate Runtime.
|
|
84
|
+
*
|
|
85
|
+
* While Nitro is runtime-agnostic and all `HybridObject`s can be used from a any Runtime,
|
|
86
|
+
* some threading/worklet libraries (like [react-native-worklets-core](https://github.com/margelo/react-native-worklets-core))
|
|
87
|
+
* do not yet support copying over `HybridObject`s as they use newer JSI APIs like `jsi::NativeState`.
|
|
88
|
+
*
|
|
89
|
+
* While those APIs are not yet available, you can still use every Nitro Hybrid Object in a separate
|
|
90
|
+
* Runtime/Worklet context by just boxing it yourself:
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* const something = NitroModules.createHybridObject<Something>('Something')
|
|
95
|
+
* const boxed = NitroModules.box(something)
|
|
96
|
+
* const context = Worklets.createContext('DummyContext')
|
|
97
|
+
* context.runAsync(() => {
|
|
98
|
+
* 'worklet'
|
|
99
|
+
* const unboxed = boxed.unbox()
|
|
100
|
+
* console.log(unboxed.name) // --> "Something"
|
|
101
|
+
* })
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
box<T extends HybridObject>(hybridObject: T): BoxedHybridObject<T> {
|
|
105
|
+
const nitro = getNativeNitroModules()
|
|
106
|
+
return nitro.box(hybridObject) as BoxedHybridObject<T>
|
|
107
|
+
},
|
|
76
108
|
}
|
|
@@ -10,13 +10,14 @@ export interface NativeNitroSpec extends TurboModule {
|
|
|
10
10
|
// Set up
|
|
11
11
|
install(): void
|
|
12
12
|
// Hybrid Objects stuff
|
|
13
|
-
createHybridObject(name: string
|
|
13
|
+
createHybridObject(name: string): UnsafeObject
|
|
14
14
|
hasHybridObject(name: string): boolean
|
|
15
15
|
getAllHybridObjectNames(): string[]
|
|
16
16
|
// JSI Helpers
|
|
17
17
|
hasNativeState(obj: UnsafeObject): boolean
|
|
18
18
|
removeNativeState(obj: UnsafeObject): void
|
|
19
19
|
buildType: 'debug' | 'release'
|
|
20
|
+
box(obj: UnsafeObject): UnsafeObject
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
let turboModule: NativeNitroSpec | undefined
|