react-native-nitro-modules 0.2.0 → 0.4.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 +8 -2
- package/android/CMakeLists.txt +4 -4
- package/android/src/main/cpp/JNIOnLoad.cpp +7 -6
- package/android/src/main/java/com/margelo/nitro/HybridObject.kt +0 -11
- package/android/src/main/java/com/margelo/nitro/HybridObjectRegistry.java +2 -13
- package/android/src/main/java/com/margelo/nitro/NitroModulesPackage.java +12 -0
- package/cpp/core/AnyMap.hpp +12 -0
- package/cpp/core/HybridObject.cpp +0 -1
- package/cpp/jsi/JSICache.cpp +1 -3
- package/cpp/jsi/JSIConverter+Promise.hpp +2 -2
- package/cpp/jsi/{Promise.cpp → JSPromise.cpp} +6 -6
- package/cpp/jsi/{Promise.hpp → JSPromise.hpp} +10 -10
- package/cpp/registry/HybridObjectRegistry.cpp +22 -2
- package/cpp/registry/HybridObjectRegistry.hpp +6 -4
- package/cpp/turbomodule/NativeNitroModules.cpp +38 -2
- package/cpp/turbomodule/NativeNitroModules.hpp +2 -0
- package/cpp/utils/NitroDefines.hpp +6 -0
- package/ios/core/Promise.cpp +10 -0
- package/ios/core/Promise.hpp +43 -0
- package/ios/platform/ThreadUtils.cpp +1 -0
- package/lib/HybridObject.d.ts +13 -7
- package/lib/NativeNitroModules.d.ts +2 -0
- package/lib/NitroModules.d.ts +9 -1
- package/lib/NitroModules.js +15 -1
- package/lib/commonjs/NativeNitroModules.js.map +1 -1
- package/lib/commonjs/NitroModules.js +15 -1
- package/lib/commonjs/NitroModules.js.map +1 -1
- package/lib/module/NativeNitroModules.js.map +1 -1
- package/lib/module/NitroModules.js +15 -1
- package/lib/module/NitroModules.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/typescript/AnyMap.d.ts +17 -0
- package/lib/typescript/AnyMap.d.ts.map +1 -0
- package/lib/typescript/HybridObject.d.ts +13 -7
- package/lib/typescript/HybridObject.d.ts.map +1 -1
- package/lib/typescript/ModuleNotFoundError.d.ts +7 -0
- package/lib/typescript/ModuleNotFoundError.d.ts.map +1 -0
- package/lib/typescript/NativeNitroModules.d.ts +15 -0
- package/lib/typescript/NativeNitroModules.d.ts.map +1 -0
- package/lib/typescript/NativeNitroModules.web.d.ts +5 -0
- package/lib/typescript/NativeNitroModules.web.d.ts.map +1 -0
- package/lib/typescript/NitroModules.d.ts +26 -0
- package/lib/typescript/NitroModules.d.ts.map +1 -1
- package/lib/typescript/__tests__/index.test.d.ts +1 -0
- package/lib/typescript/__tests__/index.test.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/HybridObject.ts +13 -7
- package/src/NativeNitroModules.ts +2 -0
- package/src/NitroModules.ts +15 -1
- package/lib/NativeNitro.d.ts +0 -8
- package/lib/NativeNitro.js +0 -3
- package/lib/createTestObject.d.ts +0 -22
- package/lib/createTestObject.js +0 -7
package/src/HybridObject.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Describes the languages this component will be implemented in.
|
|
3
|
+
*
|
|
4
|
+
* By default, everything has a C++ base, and can optionally be bridged down
|
|
5
|
+
* to platform-specific languages like Swift or Kotlin
|
|
3
6
|
*/
|
|
4
7
|
export interface PlatformSpec {
|
|
5
8
|
ios?: 'swift' | 'c++'
|
|
@@ -7,14 +10,17 @@ export interface PlatformSpec {
|
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
|
-
* Represents a Nitro `HybridObject` which is implemented
|
|
11
|
-
* or
|
|
13
|
+
* Represents a Nitro `HybridObject` which is implemented in a native language like
|
|
14
|
+
* C++, Swift or Kotlin.
|
|
15
|
+
* Every Nitro `HybridObject` has a C++ base, and can optionally be bridged down to Swift or Kotlin.
|
|
12
16
|
*
|
|
13
17
|
* `HybridObject`s use the Nitro Tunnel for efficient, low-overhead JS <-> Native communication.
|
|
14
18
|
*
|
|
15
19
|
* All `HybridObject`s are implemented using `NativeState`, and inherit their properties
|
|
16
20
|
* and methods from their prototype, so the actual JS object is empty.
|
|
17
21
|
*
|
|
22
|
+
* @type Platforms: The type of platforms this HybridObject will be implemented in. By default, it is
|
|
23
|
+
* a C++ `HybridObject`.
|
|
18
24
|
* @example
|
|
19
25
|
* ```ts
|
|
20
26
|
* interface Photo extends HybridObject<{ ios: 'swift', android: 'kotlin' }> {
|
|
@@ -25,7 +31,7 @@ export interface PlatformSpec {
|
|
|
25
31
|
* }
|
|
26
32
|
* ```
|
|
27
33
|
*/
|
|
28
|
-
export interface HybridObject<
|
|
34
|
+
export interface HybridObject<Platforms extends PlatformSpec = {}> {
|
|
29
35
|
/**
|
|
30
36
|
* Holds a type-name describing the native `HybridObject` instance.
|
|
31
37
|
*
|
|
@@ -34,8 +40,8 @@ export interface HybridObject<Spec extends PlatformSpec> {
|
|
|
34
40
|
*
|
|
35
41
|
* Nitro prototypes also have a `__type`.
|
|
36
42
|
*
|
|
37
|
-
* For actual HybridObject instances, this is `NativeState
|
|
38
|
-
* prototypes this is `Prototype<...>`.
|
|
43
|
+
* - For actual HybridObject instances, this is `NativeState<...>`
|
|
44
|
+
* - For prototypes this is `Prototype<...>`.
|
|
39
45
|
*
|
|
40
46
|
* @internal
|
|
41
47
|
* @private
|
|
@@ -49,7 +55,7 @@ export interface HybridObject<Spec extends PlatformSpec> {
|
|
|
49
55
|
/**
|
|
50
56
|
* Returns a string representation of the given `HybridObject`.
|
|
51
57
|
*
|
|
52
|
-
* Unless overridden by the `HybridObject`, this will return
|
|
58
|
+
* Unless overridden by the `HybridObject`, this will return the name of the object.
|
|
53
59
|
*
|
|
54
60
|
* @example
|
|
55
61
|
* ```ts
|
|
@@ -73,5 +79,5 @@ export interface HybridObject<Spec extends PlatformSpec> {
|
|
|
73
79
|
* console.log(hybridA.equals(hybridB)) // true
|
|
74
80
|
* ```
|
|
75
81
|
*/
|
|
76
|
-
equals(other: HybridObject<
|
|
82
|
+
equals(other: HybridObject<Platforms>): boolean
|
|
77
83
|
}
|
|
@@ -6,6 +6,8 @@ import { ModuleNotFoundError } from './ModuleNotFoundError'
|
|
|
6
6
|
export interface Spec extends TurboModule {
|
|
7
7
|
install(): void
|
|
8
8
|
createHybridObject(name: string, args?: UnsafeObject): UnsafeObject
|
|
9
|
+
hasHybridObject(name: string): boolean
|
|
10
|
+
getAllHybridObjectNames(): string[]
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
let turboModule: Spec | undefined
|
package/src/NitroModules.ts
CHANGED
|
@@ -22,9 +22,23 @@ export const NitroModules = {
|
|
|
22
22
|
* @returns An instance of {@linkcode T}
|
|
23
23
|
* @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
createHybridObject<T extends HybridObject<any>>(name: string): T {
|
|
26
26
|
const nitro = getNativeNitroModules()
|
|
27
27
|
const instance = nitro.createHybridObject(name)
|
|
28
28
|
return instance as T
|
|
29
29
|
},
|
|
30
|
+
/**
|
|
31
|
+
* Get a list of all registered Hybrid Objects.
|
|
32
|
+
*/
|
|
33
|
+
getAllHybridObjectNames(): string[] {
|
|
34
|
+
const nitro = getNativeNitroModules()
|
|
35
|
+
return nitro.getAllHybridObjectNames()
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* Returns whether a HybridObject under the given {@linkcode name} is registered, or not.
|
|
39
|
+
*/
|
|
40
|
+
hasHybridObject(name: string): boolean {
|
|
41
|
+
const nitro = getNativeNitroModules()
|
|
42
|
+
return nitro.hasHybridObject(name)
|
|
43
|
+
},
|
|
30
44
|
}
|
package/lib/NativeNitro.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { TurboModule } from 'react-native';
|
|
2
|
-
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';
|
|
3
|
-
export interface Spec extends TurboModule {
|
|
4
|
-
install(): void;
|
|
5
|
-
createTestHybridObject(): UnsafeObject;
|
|
6
|
-
createSwiftTestHybridObject(): UnsafeObject;
|
|
7
|
-
}
|
|
8
|
-
export declare const NitroModules: Spec;
|
package/lib/NativeNitro.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { type HybridObject } from '.';
|
|
2
|
-
export interface TestHybridObject extends HybridObject<{}> {
|
|
3
|
-
int: number;
|
|
4
|
-
string: string;
|
|
5
|
-
nullableString: string | undefined;
|
|
6
|
-
multipleArguments(first: number, second: boolean, third: string): Record<string, number>;
|
|
7
|
-
getIntGetter(): () => number;
|
|
8
|
-
sayHelloCallback(callback: (name: string) => void): void;
|
|
9
|
-
createNewHybridObject(): TestHybridObject;
|
|
10
|
-
calculateFibonacci(count: number): bigint;
|
|
11
|
-
calculateFibonacciAsync(count: number): Promise<bigint>;
|
|
12
|
-
asyncVoidFunc(): Promise<void>;
|
|
13
|
-
syncVoidFunc(): void;
|
|
14
|
-
throwError(): void;
|
|
15
|
-
}
|
|
16
|
-
export declare function createCppTestHybridObject(): TestHybridObject;
|
|
17
|
-
export interface SwiftTestHybridObject extends HybridObject<{}> {
|
|
18
|
-
int: number;
|
|
19
|
-
throwError(): number;
|
|
20
|
-
asyncMethod(): Promise<number>;
|
|
21
|
-
}
|
|
22
|
-
export declare function createSwiftTestHybridObject(): SwiftTestHybridObject;
|
package/lib/createTestObject.js
DELETED