@iternio/react-native-auto-play 0.5.8 → 0.5.10

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 (44) hide show
  1. package/README.md +8 -0
  2. package/android/build.gradle +14 -2
  3. package/android/gradle.properties +2 -0
  4. package/android/src/automotive/AndroidManifest-nonnav.xml +78 -0
  5. package/android/src/main/AndroidManifest-nonnav.xml +35 -0
  6. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/AndroidAutoService.kt +6 -1
  7. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAndroidWindowInformation.kt +49 -0
  8. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt +1 -0
  9. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/VirtualRenderer.kt +116 -29
  10. package/lib/components/WindowInformationWrapper.d.ts +15 -0
  11. package/lib/components/WindowInformationWrapper.js +17 -0
  12. package/lib/hybrid/HybridAndroidWindowInformation.android.d.ts +2 -0
  13. package/lib/hybrid/HybridAndroidWindowInformation.android.js +2 -0
  14. package/lib/hybrid/HybridAndroidWindowInformation.d.ts +2 -0
  15. package/lib/hybrid/HybridAndroidWindowInformation.js +1 -0
  16. package/lib/index.d.ts +2 -1
  17. package/lib/index.js +2 -1
  18. package/lib/scenes/AutoPlayCluster.js +6 -1
  19. package/lib/specs/AndroidWindowInformation.nitro.d.ts +22 -0
  20. package/lib/specs/AndroidWindowInformation.nitro.js +1 -0
  21. package/lib/templates/MapTemplate.js +6 -1
  22. package/lib/types/RootComponent.d.ts +4 -0
  23. package/nitro.json +6 -0
  24. package/nitrogen/generated/android/ReactNativeAutoPlay+autolinking.cmake +2 -0
  25. package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +18 -0
  26. package/nitrogen/generated/android/c++/JFunc_void_WindowInformation.hpp +77 -0
  27. package/nitrogen/generated/android/c++/JHybridAndroidWindowInformationSpec.cpp +68 -0
  28. package/nitrogen/generated/android/c++/JHybridAndroidWindowInformationSpec.hpp +63 -0
  29. package/nitrogen/generated/android/c++/JWindowInformation.hpp +65 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_WindowInformation.kt +80 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAndroidWindowInformationSpec.kt +59 -0
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/WindowInformation.kt +61 -0
  33. package/nitrogen/generated/shared/c++/HybridAndroidWindowInformationSpec.cpp +21 -0
  34. package/nitrogen/generated/shared/c++/HybridAndroidWindowInformationSpec.hpp +65 -0
  35. package/nitrogen/generated/shared/c++/WindowInformation.hpp +91 -0
  36. package/package.json +1 -1
  37. package/src/components/WindowInformationWrapper.tsx +30 -0
  38. package/src/hybrid/HybridAndroidWindowInformation.android.ts +5 -0
  39. package/src/hybrid/HybridAndroidWindowInformation.ts +3 -0
  40. package/src/index.ts +2 -1
  41. package/src/scenes/AutoPlayCluster.ts +6 -1
  42. package/src/specs/AndroidWindowInformation.nitro.ts +24 -0
  43. package/src/templates/MapTemplate.ts +6 -1
  44. package/src/types/RootComponent.ts +4 -0
@@ -0,0 +1,91 @@
1
+ ///
2
+ /// WindowInformation.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+
34
+
35
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (WindowInformation).
39
+ */
40
+ struct WindowInformation final {
41
+ public:
42
+ double width SWIFT_PRIVATE;
43
+ double height SWIFT_PRIVATE;
44
+ double scale SWIFT_PRIVATE;
45
+
46
+ public:
47
+ WindowInformation() = default;
48
+ explicit WindowInformation(double width, double height, double scale): width(width), height(height), scale(scale) {}
49
+
50
+ public:
51
+ friend bool operator==(const WindowInformation& lhs, const WindowInformation& rhs) = default;
52
+ };
53
+
54
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
55
+
56
+ namespace margelo::nitro {
57
+
58
+ // C++ WindowInformation <> JS WindowInformation (object)
59
+ template <>
60
+ struct JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::WindowInformation> final {
61
+ static inline margelo::nitro::swe::iternio::reactnativeautoplay::WindowInformation fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
62
+ jsi::Object obj = arg.asObject(runtime);
63
+ return margelo::nitro::swe::iternio::reactnativeautoplay::WindowInformation(
64
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
65
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height"))),
66
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "scale")))
67
+ );
68
+ }
69
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::swe::iternio::reactnativeautoplay::WindowInformation& arg) {
70
+ jsi::Object obj(runtime);
71
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "width"), JSIConverter<double>::toJSI(runtime, arg.width));
72
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "height"), JSIConverter<double>::toJSI(runtime, arg.height));
73
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "scale"), JSIConverter<double>::toJSI(runtime, arg.scale));
74
+ return obj;
75
+ }
76
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
77
+ if (!value.isObject()) {
78
+ return false;
79
+ }
80
+ jsi::Object obj = value.getObject(runtime);
81
+ if (!nitro::isPlainObject(runtime, obj)) {
82
+ return false;
83
+ }
84
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width")))) return false;
85
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))) return false;
86
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "scale")))) return false;
87
+ return true;
88
+ }
89
+ };
90
+
91
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.5.8",
3
+ "version": "0.5.10",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -0,0 +1,30 @@
1
+ import type React from 'react';
2
+ import { createElement, useEffect, useState } from 'react';
3
+ import { HybridAndroidWindowInformation } from '../hybrid/HybridAndroidWindowInformation';
4
+ import type { RootComponentInitialProps } from '../types/RootComponent';
5
+
6
+ /**
7
+ * Renders a user-provided root component and keeps its `window` prop up to date when the host
8
+ * recreates the render surface with new dimensions (some head units run Android Auto windowed
9
+ * and resize it at runtime), so consumers can simply read `props.window` without registering a
10
+ * listener themselves.
11
+ * On iOS this only passes the initial props through — CarPlay windows keep their size for the
12
+ * lifetime of a scene, so there is nothing to subscribe to.
13
+ */
14
+ export function WindowInformationWrapper({
15
+ moduleName,
16
+ component,
17
+ componentProps,
18
+ }: {
19
+ moduleName: string;
20
+ component: React.ComponentType<RootComponentInitialProps>;
21
+ componentProps: RootComponentInitialProps;
22
+ }) {
23
+ const [window, setWindow] = useState(componentProps.window);
24
+
25
+ useEffect(() => {
26
+ return HybridAndroidWindowInformation?.addWindowInformationListener(moduleName, setWindow);
27
+ }, [moduleName]);
28
+
29
+ return createElement(component, { ...componentProps, window });
30
+ }
@@ -0,0 +1,5 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import type { AndroidWindowInformation } from '../specs/AndroidWindowInformation.nitro';
3
+
4
+ export const HybridAndroidWindowInformation: AndroidWindowInformation | null =
5
+ NitroModules.createHybridObject<AndroidWindowInformation>('AndroidWindowInformation');
@@ -0,0 +1,3 @@
1
+ import type { AndroidWindowInformation } from '../specs/AndroidWindowInformation.nitro';
2
+
3
+ export const HybridAndroidWindowInformation: AndroidWindowInformation | null = null;
package/src/index.ts CHANGED
@@ -2,13 +2,14 @@ import { Platform } from 'react-native';
2
2
  import { NitroModules } from 'react-native-nitro-modules';
3
3
  import AutoPlayHeadlessJsTask from './AutoPlayHeadlessJsTask';
4
4
  import { HybridAndroidAutoTelemetry } from './hybrid/HybridAndroidAutoTelemetry';
5
+ import { HybridAndroidWindowInformation } from './hybrid/HybridAndroidWindowInformation';
5
6
  import { HybridAutoPlay } from './hybrid/HybridAutoPlay';
6
7
  import { HybridVoice } from './hybrid/HybridVoice';
7
8
  import type { AndroidAutomotive } from './specs/AndroidAutomotive.nitro';
8
9
 
9
10
  AutoPlayHeadlessJsTask.registerHeadlessTask(HybridAutoPlay);
10
11
 
11
- export { HybridAndroidAutoTelemetry, HybridAutoPlay, HybridVoice };
12
+ export { HybridAndroidAutoTelemetry, HybridAndroidWindowInformation, HybridAutoPlay, HybridVoice };
12
13
 
13
14
  export const HybridAndroidAutomotive =
14
15
  Platform.OS === 'android'
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { AppRegistry, Platform } from 'react-native';
3
3
  import { NitroModules } from 'react-native-nitro-modules';
4
4
  import { SafeAreaInsetsProvider } from '../components/SafeAreaInsetsContext';
5
+ import { WindowInformationWrapper } from '../components/WindowInformationWrapper';
5
6
  import type { Cluster as NitroCluster, ZoomEvent } from '../specs/Cluster.nitro';
6
7
  import type { ColorScheme, RootComponentInitialProps } from '../types/RootComponent';
7
8
  import type { AutoAttributedString } from '../utils/NitroAttributedString';
@@ -62,7 +63,11 @@ class Cluster {
62
63
  React.createElement(SafeAreaInsetsProvider, {
63
64
  moduleName: clusterId,
64
65
  // biome-ignore lint/correctness/noChildrenProp: there is no other way in a ts file
65
- children: React.createElement(component, props),
66
+ children: React.createElement(WindowInformationWrapper, {
67
+ moduleName: clusterId,
68
+ component,
69
+ componentProps: props,
70
+ }),
66
71
  })
67
72
  );
68
73
 
@@ -0,0 +1,24 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { CleanupCallback } from '../types/Event';
3
+ import type { WindowInformation } from '../types/RootComponent';
4
+
5
+ /**
6
+ * Android-only access to render-surface window dimensions. On iOS this module does not exist —
7
+ * use the platform-split `HybridAndroidWindowInformation` wrapper which resolves to `null` there.
8
+ */
9
+ export interface AndroidWindowInformation extends HybridObject<{ android: 'kotlin' }> {
10
+ /**
11
+ * callback for window dimension changes, fired when the host recreates the render surface
12
+ * with a different size (some head units run Android Auto windowed and resize it at runtime).
13
+ * Root components rendered via a template's `component` prop do NOT need this — their
14
+ * `window` prop is kept up to date automatically. Use this listener only for
15
+ * size-dependent logic living outside a root component.
16
+ * Fires with the last known window information immediately if the surface is already initialized.
17
+ * @param moduleName one of @AutoPlayModules or a cluster scene uuid
18
+ * @namespace Android
19
+ */
20
+ addWindowInformationListener(
21
+ moduleName: string,
22
+ callback: (window: WindowInformation) => void
23
+ ): CleanupCallback;
24
+ }
@@ -4,6 +4,7 @@ import { NitroModules } from 'react-native-nitro-modules';
4
4
  import type { AutoText } from '..';
5
5
  import { MapTemplateProvider } from '../components/MapTemplateContext';
6
6
  import { SafeAreaInsetsProvider } from '../components/SafeAreaInsetsContext';
7
+ import { WindowInformationWrapper } from '../components/WindowInformationWrapper';
7
8
  import { HybridAutoPlay } from '../hybrid/HybridAutoPlay';
8
9
  import type { MapTemplate as NitroMapTemplate } from '../specs/MapTemplate.nitro';
9
10
  import type { ActionButtonAndroid, MapButton, MapPanButton } from '../types/Button';
@@ -196,7 +197,11 @@ export class MapTemplate extends Template<MapTemplateConfig, MapTemplateConfig['
196
197
  children: React.createElement(SafeAreaInsetsProvider, {
197
198
  moduleName: this.id,
198
199
  // biome-ignore lint/correctness/noChildrenProp: there is no other way in a ts file
199
- children: React.createElement(component, props),
200
+ children: React.createElement(WindowInformationWrapper, {
201
+ moduleName: this.id,
202
+ component,
203
+ componentProps: props,
204
+ }),
200
205
  }),
201
206
  })
202
207
  );
@@ -21,6 +21,10 @@ export type RootComponentInitialProps = {
21
21
  * this is the initial color scheme, add onAppearanceDidChange on MapTemplate to get updates
22
22
  */
23
23
  colorScheme: ColorScheme;
24
+ /**
25
+ * the dimensions of the render surface, kept up to date when the host resizes the surface
26
+ * (e.g. head units running Android Auto windowed)
27
+ */
24
28
  window: WindowInformation;
25
29
  };
26
30