react-native-nitro-modules 0.9.1 → 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/registry/HybridObjectRegistry.cpp +12 -7
- 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 +28 -1
- package/lib/{typescript/NativeNitroModules.d.ts → NitroModulesTurboModule.d.ts} +4 -4
- package/lib/NitroModulesTurboModule.js +23 -0
- package/lib/NitroModulesTurboModule.web.d.ts +1 -0
- package/lib/NitroModulesTurboModule.web.js +4 -0
- package/lib/commonjs/NitroModules.js +38 -10
- package/lib/commonjs/NitroModules.js.map +1 -1
- package/lib/commonjs/{NativeNitroModules.js → NitroModulesTurboModule.js} +5 -1
- package/lib/commonjs/NitroModulesTurboModule.js.map +1 -0
- package/lib/commonjs/NitroModulesTurboModule.web.js +11 -0
- package/lib/commonjs/NitroModulesTurboModule.web.js.map +1 -0
- package/lib/module/NitroModules.js +32 -4
- package/lib/module/NitroModules.js.map +1 -1
- package/lib/module/{NativeNitroModules.js → NitroModulesTurboModule.js} +6 -1
- package/lib/module/NitroModulesTurboModule.js.map +1 -0
- package/lib/module/NitroModulesTurboModule.web.js +7 -0
- package/lib/module/NitroModulesTurboModule.web.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/HybridObject.d.ts +99 -0
- package/lib/typescript/NitroModules.d.ts +35 -0
- package/lib/typescript/NitroModules.d.ts.map +1 -1
- package/lib/typescript/NitroModulesTurboModule.d.ts +19 -0
- package/lib/typescript/NitroModulesTurboModule.d.ts.map +1 -0
- package/lib/typescript/NitroModulesTurboModule.web.d.ts +2 -0
- package/lib/typescript/NitroModulesTurboModule.web.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/NitroModules.ts +38 -6
- package/src/{NativeNitroModules.ts → NitroModulesTurboModule.ts} +10 -5
- package/src/NitroModulesTurboModule.web.ts +7 -0
- package/lib/commonjs/NativeNitroModules.js.map +0 -1
- package/lib/commonjs/NativeNitroModules.web.js +0 -10
- package/lib/commonjs/NativeNitroModules.web.js.map +0 -1
- package/lib/module/NativeNitroModules.js.map +0 -1
- package/lib/module/NativeNitroModules.web.js +0 -6
- package/lib/module/NativeNitroModules.web.js.map +0 -1
- package/lib/typescript/NativeNitroModules.d.ts.map +0 -1
- package/lib/typescript/NativeNitroModules.web.d.ts.map +0 -1
- package/src/NativeNitroModules.web.ts +0 -9
package/src/NitroModules.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { getNativeNitroModules } from './
|
|
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
|
}
|
|
@@ -3,25 +3,30 @@ import { TurboModuleRegistry } from 'react-native'
|
|
|
3
3
|
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes'
|
|
4
4
|
import { ModuleNotFoundError } from './ModuleNotFoundError'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// This TurboModule is *not* codegen'd.
|
|
7
|
+
// It's handwritten, because otherwise the app's CMakeLists wants to build it.
|
|
8
|
+
// Instead, we want to build it ourselves and have full control over the CMakeLists.
|
|
9
|
+
export interface NativeNitroSpec extends TurboModule {
|
|
7
10
|
// Set up
|
|
8
11
|
install(): void
|
|
9
12
|
// Hybrid Objects stuff
|
|
10
|
-
createHybridObject(name: string
|
|
13
|
+
createHybridObject(name: string): UnsafeObject
|
|
11
14
|
hasHybridObject(name: string): boolean
|
|
12
15
|
getAllHybridObjectNames(): string[]
|
|
13
16
|
// JSI Helpers
|
|
14
17
|
hasNativeState(obj: UnsafeObject): boolean
|
|
15
18
|
removeNativeState(obj: UnsafeObject): void
|
|
16
19
|
buildType: 'debug' | 'release'
|
|
20
|
+
box(obj: UnsafeObject): UnsafeObject
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
let turboModule:
|
|
20
|
-
export function getNativeNitroModules():
|
|
23
|
+
let turboModule: NativeNitroSpec | undefined
|
|
24
|
+
export function getNativeNitroModules(): NativeNitroSpec {
|
|
21
25
|
if (turboModule == null) {
|
|
22
26
|
try {
|
|
23
27
|
// 1. Get (and initialize) the C++ TurboModule
|
|
24
|
-
turboModule =
|
|
28
|
+
turboModule =
|
|
29
|
+
TurboModuleRegistry.getEnforcing<NativeNitroSpec>('NitroModulesCxx')
|
|
25
30
|
|
|
26
31
|
// 2. Install Dispatcher and required bindings into the Runtime
|
|
27
32
|
turboModule.install()
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Platform } from 'react-native'
|
|
2
|
+
|
|
3
|
+
export function getNativeNitroModules(): never {
|
|
4
|
+
throw new Error(
|
|
5
|
+
`Native NitroModules are not available on ${Platform.OS}! Make sure you're not calling getNativeNitroModules() in a ${Platform.OS} (.${Platform.OS}.ts) environment.`
|
|
6
|
+
)
|
|
7
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_reactNative","require","_ModuleNotFoundError","turboModule","getNativeNitroModules","TurboModuleRegistry","getEnforcing","install","e","ModuleNotFoundError","isRuntimeAlive","cache","global","__nitroModulesJSICache","dispatcher","__nitroDispatcher"],"sourceRoot":"../../src","sources":["NativeNitroModules.ts"],"mappings":";;;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA,IAAAC,oBAAA,GAAAD,OAAA;AAeA,IAAIE,WAA6B;AAC1B,SAASC,qBAAqBA,CAAA,EAAS;EAC5C,IAAID,WAAW,IAAI,IAAI,EAAE;IACvB,IAAI;MACF;MACAA,WAAW,GAAGE,gCAAmB,CAACC,YAAY,CAAO,iBAAiB,CAAC;;MAEvE;MACAH,WAAW,CAACI,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC,OAAOC,CAAC,EAAE;MACV,MAAM,IAAIC,wCAAmB,CAACD,CAAC,CAAC;IAClC;EACF;EAEA,OAAOL,WAAW;AACpB;AAOO,SAASO,cAAcA,CAAA,EAAG;EAC/B,MAAMC,KAAK,GAAGC,MAAM,CAACC,sBAAsB;EAC3C,MAAMC,UAAU,GAAGF,MAAM,CAACG,iBAAiB;EAC3C,OAAOJ,KAAK,IAAI,IAAI,IAAIG,UAAU,IAAI,IAAI;AAC5C","ignoreList":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getNativeNitroModules = getNativeNitroModules;
|
|
7
|
-
function getNativeNitroModules() {
|
|
8
|
-
throw new Error(`Native NitroModules are not available on web! Make sure you're not calling getNativeNitroModules() in a web (.web.ts) environment.`);
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=NativeNitroModules.web.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["getNativeNitroModules","Error"],"sourceRoot":"../../src","sources":["NativeNitroModules.web.ts"],"mappings":";;;;;;AAIO,SAASA,qBAAqBA,CAAA,EAAS;EAC5C,MAAM,IAAIC,KAAK,CACb,oIACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","ModuleNotFoundError","turboModule","getNativeNitroModules","getEnforcing","install","e","isRuntimeAlive","cache","global","__nitroModulesJSICache","dispatcher","__nitroDispatcher"],"sourceRoot":"../../src","sources":["NativeNitroModules.ts"],"mappings":";;AACA,SAASA,mBAAmB,QAAQ,cAAc;AAElD,SAASC,mBAAmB,QAAQ,uBAAuB;AAe3D,IAAIC,WAA6B;AACjC,OAAO,SAASC,qBAAqBA,CAAA,EAAS;EAC5C,IAAID,WAAW,IAAI,IAAI,EAAE;IACvB,IAAI;MACF;MACAA,WAAW,GAAGF,mBAAmB,CAACI,YAAY,CAAO,iBAAiB,CAAC;;MAEvE;MACAF,WAAW,CAACG,OAAO,CAAC,CAAC;IACvB,CAAC,CAAC,OAAOC,CAAC,EAAE;MACV,MAAM,IAAIL,mBAAmB,CAACK,CAAC,CAAC;IAClC;EACF;EAEA,OAAOJ,WAAW;AACpB;AAOA,OAAO,SAASK,cAAcA,CAAA,EAAG;EAC/B,MAAMC,KAAK,GAAGC,MAAM,CAACC,sBAAsB;EAC3C,MAAMC,UAAU,GAAGF,MAAM,CAACG,iBAAiB;EAC3C,OAAOJ,KAAK,IAAI,IAAI,IAAIG,UAAU,IAAI,IAAI;AAC5C","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["getNativeNitroModules","Error"],"sourceRoot":"../../src","sources":["NativeNitroModules.web.ts"],"mappings":";;AAIA,OAAO,SAASA,qBAAqBA,CAAA,EAAS;EAC5C,MAAM,IAAIC,KAAK,CACb,oIACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NativeNitroModules.d.ts","sourceRoot":"","sources":["../../src/NativeNitroModules.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAA;AAG7E,MAAM,WAAW,IAAK,SAAQ,WAAW;IAEvC,OAAO,IAAI,IAAI,CAAA;IAEf,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY,GAAG,YAAY,CAAA;IACnE,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;CAC/B;AAGD,wBAAgB,qBAAqB,IAAI,IAAI,CAc5C;AAED,OAAO,CAAC,MAAM,CAAC;IACb,IAAI,sBAAsB,EAAE,EAAE,CAAA;IAC9B,IAAI,iBAAiB,EAAE,EAAE,CAAA;CAC1B;AAED,wBAAgB,cAAc,YAI7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NativeNitroModules.web.d.ts","sourceRoot":"","sources":["../../src/NativeNitroModules.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAE/C,MAAM,WAAW,IAAK,SAAQ,WAAW;CAAG;AAE5C,wBAAgB,qBAAqB,IAAI,IAAI,CAI5C"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { TurboModule } from 'react-native'
|
|
2
|
-
|
|
3
|
-
export interface Spec extends TurboModule {}
|
|
4
|
-
|
|
5
|
-
export function getNativeNitroModules(): Spec {
|
|
6
|
-
throw new Error(
|
|
7
|
-
`Native NitroModules are not available on web! Make sure you're not calling getNativeNitroModules() in a web (.web.ts) environment.`
|
|
8
|
-
)
|
|
9
|
-
}
|