react-native-nitro-modules 0.31.2 → 0.31.4

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 (50) hide show
  1. package/android/src/main/cpp/core/JAnyMap.hpp +30 -3
  2. package/android/src/main/cpp/core/JAnyValue.hpp +2 -2
  3. package/android/src/main/java/com/margelo/nitro/NitroModulesPackage.kt +2 -3
  4. package/android/src/main/java/com/margelo/nitro/core/AnyMap.kt +48 -0
  5. package/android/src/main/java/com/margelo/nitro/core/AnyValue.kt +58 -0
  6. package/android/src/main/java/com/margelo/nitro/core/HybridObject.kt +10 -0
  7. package/cpp/core/AnyMap.cpp +13 -0
  8. package/cpp/core/AnyMap.hpp +16 -10
  9. package/cpp/prototype/HybridObjectPrototype.cpp +9 -1
  10. package/cpp/utils/NitroDefines.hpp +1 -1
  11. package/ios/core/AnyMap.swift +126 -9
  12. package/ios/core/HybridObject.swift +9 -0
  13. package/lib/commonjs/AnyHybridObject.js +6 -0
  14. package/lib/commonjs/AnyHybridObject.js.map +1 -0
  15. package/lib/commonjs/index.js +11 -0
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/views/getHostComponent.js.map +1 -1
  18. package/lib/module/AnyHybridObject.js +4 -0
  19. package/lib/module/AnyHybridObject.js.map +1 -0
  20. package/lib/module/index.js +1 -0
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/views/getHostComponent.js.map +1 -1
  23. package/lib/tsconfig.build.tsbuildinfo +1 -1
  24. package/lib/typescript/AnyHybridObject.d.ts +10 -0
  25. package/lib/typescript/AnyHybridObject.d.ts.map +1 -0
  26. package/lib/typescript/BoxedHybridObject.d.ts +1 -1
  27. package/lib/typescript/BoxedHybridObject.d.ts.map +1 -1
  28. package/lib/typescript/CustomType.d.ts +1 -1
  29. package/lib/typescript/HybridObject.d.ts +6 -9
  30. package/lib/typescript/HybridObject.d.ts.map +1 -1
  31. package/lib/typescript/NitroModulesProxy.d.ts +8 -5
  32. package/lib/typescript/NitroModulesProxy.d.ts.map +1 -1
  33. package/lib/typescript/getHybridObjectConstructor.d.ts +1 -1
  34. package/lib/typescript/getHybridObjectConstructor.d.ts.map +1 -1
  35. package/lib/typescript/index.d.ts +1 -0
  36. package/lib/typescript/index.d.ts.map +1 -1
  37. package/lib/typescript/views/HybridView.d.ts +6 -3
  38. package/lib/typescript/views/HybridView.d.ts.map +1 -1
  39. package/lib/typescript/views/getHostComponent.d.ts +4 -2
  40. package/lib/typescript/views/getHostComponent.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/src/AnyHybridObject.ts +10 -0
  43. package/src/BoxedHybridObject.ts +1 -1
  44. package/src/CustomType.ts +1 -1
  45. package/src/HybridObject.ts +6 -9
  46. package/src/NitroModulesProxy.ts +6 -5
  47. package/src/getHybridObjectConstructor.ts +1 -1
  48. package/src/index.ts +1 -0
  49. package/src/views/HybridView.ts +5 -3
  50. package/src/views/getHostComponent.ts +4 -2
@@ -5,8 +5,8 @@
5
5
  * to platform-specific languages like Swift or Kotlin
6
6
  */
7
7
  export interface PlatformSpec {
8
- ios?: 'swift' | 'c++'
9
- android?: 'kotlin' | 'c++'
8
+ ios?: 'c++' | 'swift'
9
+ android?: 'c++' | 'kotlin'
10
10
  }
11
11
 
12
12
  /**
@@ -19,9 +19,7 @@ export interface PlatformSpec {
19
19
  * All `HybridObject`s are implemented using `NativeState`, and inherit their properties
20
20
  * and methods from their prototype, so the actual JS object is empty.
21
21
  *
22
- * @type Platforms: The type of platforms this HybridObject will be implemented in. By default, it is
23
- * a C++ `HybridObject`.
24
- * @default { ios: 'c++', android: 'c++' }
22
+ * @type Platforms: The type of platforms this HybridObject will be implemented in.
25
23
  * @example
26
24
  * ```ts
27
25
  * interface Photo extends HybridObject<{ ios: 'swift', android: 'kotlin' }> {
@@ -32,7 +30,7 @@ export interface PlatformSpec {
32
30
  * }
33
31
  * ```
34
32
  */
35
- export interface HybridObject<Platforms extends PlatformSpec = {}> {
33
+ export interface HybridObject<Platforms extends PlatformSpec> {
36
34
  /**
37
35
  * Holds a type-name describing the native `HybridObject` instance.
38
36
  *
@@ -41,7 +39,7 @@ export interface HybridObject<Platforms extends PlatformSpec = {}> {
41
39
  *
42
40
  * Nitro prototypes also have a `__type`.
43
41
  *
44
- * - For actual HybridObject instances, this is `NativeState<...>`
42
+ * - For actual HybridObject instances, this is `HybridObject<...>`
45
43
  * - For prototypes this is `Prototype<...>`.
46
44
  *
47
45
  * @internal
@@ -76,14 +74,13 @@ export interface HybridObject<Platforms extends PlatformSpec = {}> {
76
74
  * ```ts
77
75
  * const hybridA = SomeModule.getExistingHybridInstance()
78
76
  * const hybridB = SomeModule.getExistingHybridInstance()
79
- * console.log(hybridA === hybridB) // false
80
77
  * console.log(hybridA.equals(hybridB)) // true
81
78
  * ```
82
79
  */
83
80
  equals(other: HybridObject<Platforms>): boolean
84
81
  /**
85
82
  * Disposes any resources this {@linkcode HybridObject} might hold natively,
86
- * and finally releases this {@linkcode HybridObject}'s `NativeState`.
83
+ * and releases this {@linkcode HybridObject}'s `NativeState`.
87
84
  *
88
85
  * After calling {@linkcode dispose()}, this object can no longer be used.
89
86
  *
@@ -7,7 +7,8 @@ import type { BoxedHybridObject } from './BoxedHybridObject'
7
7
  * This is a `HybridObject` on the native side as well, and is expected to be
8
8
  * installed into the runtime's `global` via the NativeModule/TurboModule's `install()` function.
9
9
  */
10
- export interface NitroModulesProxy extends HybridObject {
10
+ export interface NitroModulesProxy
11
+ extends HybridObject<{ ios: 'c++'; android: 'c++' }> {
11
12
  /**
12
13
  * Create a new instance of the `HybridObject` {@linkcode T}.
13
14
  *
@@ -18,7 +19,7 @@ export interface NitroModulesProxy extends HybridObject {
18
19
  * @returns An instance of {@linkcode T}
19
20
  * @throws an Error if {@linkcode T} has not been registered under the name {@linkcode name}.
20
21
  */
21
- createHybridObject<T extends HybridObject>(name: string): T
22
+ createHybridObject<T extends HybridObject<{}>>(name: string): T
22
23
  /**
23
24
  * Returns whether a HybridObject under the given {@linkcode name} is registered, or not.
24
25
  */
@@ -26,7 +27,7 @@ export interface NitroModulesProxy extends HybridObject {
26
27
  /**
27
28
  * Returns whether the given {@linkcode object} is a {@linkcode HybridObject}, or not.
28
29
  */
29
- isHybridObject(object: object): object is HybridObject
30
+ isHybridObject(object: object): object is HybridObject<{}>
30
31
  /**
31
32
  * Get a list of all registered Hybrid Objects.
32
33
  */
@@ -67,7 +68,7 @@ export interface NitroModulesProxy extends HybridObject {
67
68
  * })
68
69
  * ```
69
70
  */
70
- box<T extends HybridObject>(obj: T): BoxedHybridObject<T>
71
+ box<T extends HybridObject<{}>>(obj: T): BoxedHybridObject<T>
71
72
 
72
73
  /**
73
74
  * Returns whether the given {@linkcode object} has NativeState or not.
@@ -80,5 +81,5 @@ export interface NitroModulesProxy extends HybridObject {
80
81
  *
81
82
  * This is achieved by just doing a round-trip from JS -> native -> JS.
82
83
  */
83
- updateMemorySize(obj: HybridObject): HybridObject
84
+ updateMemorySize<T extends HybridObject<{}>>(obj: T): T
84
85
  }
@@ -16,7 +16,7 @@ const cache = new Map<string, Function>()
16
16
  * image1 instanceof HybridImage // --> true
17
17
  * ```
18
18
  */
19
- export function getHybridObjectConstructor<T extends HybridObject>(
19
+ export function getHybridObjectConstructor<T extends HybridObject<{}>>(
20
20
  name: string
21
21
  ): { new (): T } {
22
22
  // Cache functions for performance.
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './HybridObject'
2
2
  export * from './NitroModules'
3
3
  export * from './AnyMap'
4
+ export * from './AnyHybridObject'
4
5
  export * from './CustomType'
5
6
  export * from './getHybridObjectConstructor'
6
7
  export * from './Sync'
@@ -81,12 +81,14 @@ export interface HybridViewMethods {}
81
81
  export type HybridRef<
82
82
  Props extends HybridViewProps,
83
83
  Methods extends HybridViewMethods = {},
84
- > = HybridObject & Props & Methods
84
+ Platforms extends ViewPlatformSpec = { ios: 'swift'; android: 'kotlin' },
85
+ > = HybridObject<Platforms> & Props & Methods
85
86
 
86
87
  /**
87
88
  * This interface acts as a tag for Hybrid Views so nitrogen detects them.
88
89
  */
89
- interface HybridViewTag extends HybridObject {}
90
+ interface HybridViewTag<Platforms extends ViewPlatformSpec>
91
+ extends HybridObject<Platforms> {}
90
92
 
91
93
  /**
92
94
  * Represents a Nitro Hybrid View.
@@ -112,4 +114,4 @@ export type HybridView<
112
114
  Props extends HybridViewProps,
113
115
  Methods extends HybridViewMethods = {},
114
116
  Platforms extends ViewPlatformSpec = { ios: 'swift'; android: 'kotlin' },
115
- > = HybridViewTag & HybridObject<Platforms> & Props & Methods
117
+ > = HybridViewTag<Platforms> & HybridObject<Platforms> & Props & Methods
@@ -38,13 +38,15 @@ interface DefaultHybridViewProps<RefType> {
38
38
  * function App() {
39
39
  * return (
40
40
  * <HybridScrollView
41
- * hybridRef={{ f: (ref) => {
41
+ * hybridRef={callback((ref) => {
42
42
  * ref.current.scrollTo(400)
43
- * }
43
+ * })}
44
44
  * />
45
45
  * )
46
46
  * }
47
47
  * ```
48
+ * @note If you're wondering about the `callback(...)` syntax, see
49
+ * ["Callbacks have to be wrapped"](https://nitro.margelo.com/docs/view-components#callbacks-have-to-be-wrapped).
48
50
  */
49
51
  hybridRef?: (ref: RefType) => void
50
52
  }