react-native-nitro-modules 0.21.0 → 0.22.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 (65) hide show
  1. package/NitroModules.podspec +4 -1
  2. package/README.md +1 -1
  3. package/android/CMakeLists.txt +1 -0
  4. package/android/build.gradle +4 -2
  5. package/android/gradle.properties +2 -2
  6. package/android/src/main/cpp/platform/ThreadUtils.cpp +4 -4
  7. package/android/src/main/cpp/registry/JHybridObjectRegistry.hpp +2 -0
  8. package/android/src/main/java/com/margelo/nitro/core/HybridObject.kt +10 -9
  9. package/android/src/main/java/com/margelo/nitro/core/HybridObjectInitializer.java +4 -0
  10. package/android/src/main/java/com/margelo/nitro/core/HybridObjectRegistry.java +2 -0
  11. package/android/src/main/java/com/margelo/nitro/views/HybridView.kt +23 -0
  12. package/cpp/core/HybridFunction.hpp +1 -1
  13. package/cpp/core/HybridObject.cpp +7 -6
  14. package/cpp/core/HybridObject.hpp +2 -2
  15. package/cpp/core/Promise.hpp +1 -1
  16. package/cpp/entrypoint/HybridNitroModulesProxy.cpp +8 -0
  17. package/cpp/entrypoint/HybridNitroModulesProxy.hpp +1 -0
  18. package/cpp/jsi/JSICache.cpp +1 -0
  19. package/cpp/jsi/JSICache.hpp +6 -0
  20. package/cpp/jsi/JSIConverter+Exception.hpp +1 -1
  21. package/cpp/jsi/JSIConverter+HostObject.hpp +1 -1
  22. package/cpp/jsi/JSIConverter+HybridObject.hpp +1 -1
  23. package/cpp/jsi/JSIConverter+Tuple.hpp +1 -1
  24. package/cpp/jsi/JSIConverter+Variant.hpp +1 -1
  25. package/cpp/jsi/JSIHelpers.hpp +1 -1
  26. package/cpp/prototype/HybridObjectPrototype.cpp +1 -1
  27. package/cpp/registry/HybridObjectRegistry.cpp +25 -12
  28. package/cpp/registry/HybridObjectRegistry.hpp +1 -0
  29. package/cpp/utils/AssertPromiseState.hpp +1 -1
  30. package/cpp/utils/BorrowingReference.hpp +4 -2
  31. package/cpp/utils/NitroDefines.hpp +13 -1
  32. package/cpp/utils/NitroHash.hpp +17 -0
  33. package/cpp/utils/{TypeInfo.hpp → NitroTypeInfo.hpp} +1 -1
  34. package/cpp/utils/OwningReference.hpp +15 -2
  35. package/cpp/views/CachedProp.hpp +43 -0
  36. package/ios/core/HybridContext.hpp +1 -1
  37. package/ios/core/{HybridObjectSpec.swift → HybridObject.swift} +10 -2
  38. package/ios/utils/RuntimeError.hpp +1 -1
  39. package/ios/views/HybridView.swift +41 -0
  40. package/lib/commonjs/index.js +11 -0
  41. package/lib/commonjs/index.js.map +1 -1
  42. package/lib/commonjs/views/HybridView.js +17 -0
  43. package/lib/commonjs/views/HybridView.js.map +1 -0
  44. package/lib/commonjs/views/getHostComponent.js +22 -0
  45. package/lib/commonjs/views/getHostComponent.js.map +1 -0
  46. package/lib/module/index.js +1 -0
  47. package/lib/module/index.js.map +1 -1
  48. package/lib/module/views/HybridView.js +30 -0
  49. package/lib/module/views/HybridView.js.map +1 -0
  50. package/lib/module/views/getHostComponent.js +15 -0
  51. package/lib/module/views/getHostComponent.js.map +1 -0
  52. package/lib/tsconfig.build.tsbuildinfo +1 -1
  53. package/lib/typescript/NitroModulesProxy.d.ts +7 -0
  54. package/lib/typescript/NitroModulesProxy.d.ts.map +1 -1
  55. package/lib/typescript/index.d.ts +1 -0
  56. package/lib/typescript/index.d.ts.map +1 -1
  57. package/lib/typescript/views/HybridView.d.ts +35 -0
  58. package/lib/typescript/views/HybridView.d.ts.map +1 -0
  59. package/lib/typescript/views/getHostComponent.d.ts +13 -0
  60. package/lib/typescript/views/getHostComponent.d.ts.map +1 -0
  61. package/package.json +3 -2
  62. package/src/NitroModulesProxy.ts +8 -0
  63. package/src/index.ts +1 -0
  64. package/src/views/HybridView.ts +37 -0
  65. package/src/views/getHostComponent.ts +26 -0
@@ -0,0 +1,37 @@
1
+ import type { HybridObject } from '../HybridObject'
2
+
3
+ /**
4
+ * Describes the languages this view will be implemented in.
5
+ */
6
+ export interface ViewPlatformSpec {
7
+ ios?: 'swift'
8
+ android?: 'kotlin'
9
+ }
10
+
11
+ /**
12
+ * Represents a Nitro `HybridView` which is implemented in a native language
13
+ * like Swift or Kotlin.
14
+ *
15
+ * `HybridViews`s use the Nitro Tunnel for efficient, low-overhead JS <-> Native communication.
16
+ *
17
+ * All `HybridViews`s have a C++ Fabric View base with a backing Shadow Node.
18
+ *
19
+ * - TypeScript Properties (`name: Type`) will be React Props
20
+ * - TypeScript Methods (`name(): Type`) will be Ref Methods
21
+ *
22
+ * @example
23
+ * ```tsx
24
+ * export interface Camera extends HybridView {
25
+ * zoom: number
26
+ * flash: boolean
27
+ * takePhoto(): Image
28
+ * }
29
+ * ```
30
+ */
31
+ export interface HybridView<
32
+ Platforms extends ViewPlatformSpec = { ios: 'swift'; android: 'kotlin' },
33
+ > extends HybridObject<Platforms> {
34
+ /* empty interface for now */
35
+ }
36
+
37
+ export * from './getHostComponent'
@@ -0,0 +1,26 @@
1
+ import { Platform, type HostComponent } from 'react-native'
2
+ // @ts-expect-error this unfortunately isn't typed or default-exported.
3
+ import * as NativeComponentRegistry from 'react-native/Libraries/NativeComponent/NativeComponentRegistry'
4
+
5
+ export interface ViewConfig<Props> {
6
+ uiViewClassName: string
7
+ supportsRawText?: boolean
8
+ bubblingEventTypes: Record<string, unknown>
9
+ directEventTypes: Record<string, unknown>
10
+ validAttributes: Record<keyof Props, boolean>
11
+ }
12
+
13
+ /**
14
+ * Finds and returns a native view (aka {@linkcode HostComponent}) via the given {@linkcode name}.
15
+ */
16
+ export function getHostComponent<Props>(
17
+ name: string,
18
+ getViewConfig: () => ViewConfig<Props>
19
+ ): HostComponent<Props> {
20
+ if (NativeComponentRegistry == null) {
21
+ throw new Error(
22
+ `NativeComponentRegistry is not available on ${Platform.OS}!`
23
+ )
24
+ }
25
+ return NativeComponentRegistry.get<Props>(name, getViewConfig)
26
+ }