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.
Files changed (53) hide show
  1. package/README.md +8 -2
  2. package/android/CMakeLists.txt +4 -4
  3. package/android/src/main/cpp/JNIOnLoad.cpp +7 -6
  4. package/android/src/main/java/com/margelo/nitro/HybridObject.kt +0 -11
  5. package/android/src/main/java/com/margelo/nitro/HybridObjectRegistry.java +2 -13
  6. package/android/src/main/java/com/margelo/nitro/NitroModulesPackage.java +12 -0
  7. package/cpp/core/AnyMap.hpp +12 -0
  8. package/cpp/core/HybridObject.cpp +0 -1
  9. package/cpp/jsi/JSICache.cpp +1 -3
  10. package/cpp/jsi/JSIConverter+Promise.hpp +2 -2
  11. package/cpp/jsi/{Promise.cpp → JSPromise.cpp} +6 -6
  12. package/cpp/jsi/{Promise.hpp → JSPromise.hpp} +10 -10
  13. package/cpp/registry/HybridObjectRegistry.cpp +22 -2
  14. package/cpp/registry/HybridObjectRegistry.hpp +6 -4
  15. package/cpp/turbomodule/NativeNitroModules.cpp +38 -2
  16. package/cpp/turbomodule/NativeNitroModules.hpp +2 -0
  17. package/cpp/utils/NitroDefines.hpp +6 -0
  18. package/ios/core/Promise.cpp +10 -0
  19. package/ios/core/Promise.hpp +43 -0
  20. package/ios/platform/ThreadUtils.cpp +1 -0
  21. package/lib/HybridObject.d.ts +13 -7
  22. package/lib/NativeNitroModules.d.ts +2 -0
  23. package/lib/NitroModules.d.ts +9 -1
  24. package/lib/NitroModules.js +15 -1
  25. package/lib/commonjs/NativeNitroModules.js.map +1 -1
  26. package/lib/commonjs/NitroModules.js +15 -1
  27. package/lib/commonjs/NitroModules.js.map +1 -1
  28. package/lib/module/NativeNitroModules.js.map +1 -1
  29. package/lib/module/NitroModules.js +15 -1
  30. package/lib/module/NitroModules.js.map +1 -1
  31. package/lib/tsconfig.tsbuildinfo +1 -1
  32. package/lib/typescript/AnyMap.d.ts +17 -0
  33. package/lib/typescript/AnyMap.d.ts.map +1 -0
  34. package/lib/typescript/HybridObject.d.ts +13 -7
  35. package/lib/typescript/HybridObject.d.ts.map +1 -1
  36. package/lib/typescript/ModuleNotFoundError.d.ts +7 -0
  37. package/lib/typescript/ModuleNotFoundError.d.ts.map +1 -0
  38. package/lib/typescript/NativeNitroModules.d.ts +15 -0
  39. package/lib/typescript/NativeNitroModules.d.ts.map +1 -0
  40. package/lib/typescript/NativeNitroModules.web.d.ts +5 -0
  41. package/lib/typescript/NativeNitroModules.web.d.ts.map +1 -0
  42. package/lib/typescript/NitroModules.d.ts +26 -0
  43. package/lib/typescript/NitroModules.d.ts.map +1 -1
  44. package/lib/typescript/__tests__/index.test.d.ts +1 -0
  45. package/lib/typescript/__tests__/index.test.d.ts.map +1 -0
  46. package/package.json +2 -2
  47. package/src/HybridObject.ts +13 -7
  48. package/src/NativeNitroModules.ts +2 -0
  49. package/src/NitroModules.ts +15 -1
  50. package/lib/NativeNitro.d.ts +0 -8
  51. package/lib/NativeNitro.js +0 -3
  52. package/lib/createTestObject.d.ts +0 -22
  53. package/lib/createTestObject.js +0 -7
@@ -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 natively in either C++,
11
- * or Swift/Kotlin.
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<Spec extends PlatformSpec> {
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<...>`, for
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 a list of all properties.
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<Spec>): boolean
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
@@ -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
- get<T extends HybridObject<any>>(name: string): T {
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
  }
@@ -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;
@@ -1,3 +0,0 @@
1
- import { TurboModuleRegistry } from 'react-native';
2
- export const NitroModules = TurboModuleRegistry.getEnforcing('NitroModulesCxx');
3
- NitroModules.install();
@@ -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;
@@ -1,7 +0,0 @@
1
- import { NitroModules } from '.';
2
- export function createCppTestHybridObject() {
3
- return NitroModules.get('TestHybridObject');
4
- }
5
- export function createSwiftTestHybridObject() {
6
- return NitroModules.get('SwiftTestObject');
7
- }