@iternio/react-native-auto-play 0.4.8 → 0.4.9

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 CHANGED
@@ -314,6 +314,32 @@ The library does **not** bundle any icon font — the consuming app must provide
314
314
 
315
315
  For cross-platform compatibility use **lowercase names with underscores only** (e.g. `material_symbols`).
316
316
 
317
+ **or**
318
+
319
+ 1. use expo-font
320
+ ```js
321
+ [
322
+ 'expo-font',
323
+ {
324
+ android: {
325
+ fonts: [
326
+ {
327
+ fontFamily: 'MaterialSymbols',
328
+ fontDefinitions: [
329
+ {
330
+ path: './assets/fonts/material_symbols.ttf',
331
+ weight: 800,
332
+ },
333
+ ],
334
+ },
335
+ ],
336
+ },
337
+ ios: ['./assets/fonts/material_symbols.ttf'],
338
+ },
339
+ ],
340
+ ```
341
+ For cross-platform compatibility use **lowercase names with underscores only** (e.g. `material_symbols`).
342
+
317
343
  2. Register the font and an optional glyph map at startup:
318
344
 
319
345
  ```ts
@@ -37,6 +37,10 @@ class HybridAutoPlay : HybridAutoPlaySpec() {
37
37
  return AndroidAutoSession.getIsConnected()
38
38
  }
39
39
 
40
+ override fun isCarServiceRunning(): Boolean {
41
+ return AndroidAutoService.instance != null
42
+ }
43
+
40
44
  override fun addListenerRenderState(
41
45
  moduleName: String, callback: (VisibilityState) -> Unit
42
46
  ): () -> Unit {
@@ -83,6 +83,10 @@ class HybridAutoPlay: HybridAutoPlaySpec {
83
83
  return SceneStore.isRootModuleConnected()
84
84
  }
85
85
 
86
+ func isCarServiceRunning() throws -> Bool {
87
+ return SceneStore.isRootModuleConnected()
88
+ }
89
+
86
90
  func addSafeAreaInsetsListener(
87
91
  moduleName: String,
88
92
  callback: @escaping (SafeAreaInsets) -> Void
@@ -9,6 +9,7 @@ export interface CarPlayDashboardButton extends BaseCarPlayDashboardButton {
9
9
  export type CarPlayDashboardEvent = EventName | VisibilityState;
10
10
  declare class Dashboard {
11
11
  private component;
12
+ private componentRegistered;
12
13
  isConnected: boolean;
13
14
  readonly id = "CarPlayDashboard";
14
15
  constructor();
@@ -9,6 +9,7 @@ const HybridCarPlayDashboard = Platform.OS === 'ios'
9
9
  : null;
10
10
  class Dashboard {
11
11
  component = null;
12
+ componentRegistered = false;
12
13
  isConnected = false;
13
14
  id = 'CarPlayDashboard';
14
15
  constructor() {
@@ -27,15 +28,20 @@ class Dashboard {
27
28
  return;
28
29
  }
29
30
  const { component, isConnected } = this;
30
- if (!isConnected || component == null) {
31
+ if (component == null) {
31
32
  return;
32
33
  }
33
- AppRegistry.registerComponent(this.id, () => (props) => React.createElement(SafeAreaInsetsProvider, {
34
- moduleName: this.id,
35
- // biome-ignore lint/correctness/noChildrenProp: there is no other way in a ts file
36
- children: React.createElement(component, props),
37
- }));
38
- HybridCarPlayDashboard.initRootView();
34
+ if (!this.componentRegistered) {
35
+ AppRegistry.registerComponent(this.id, () => (props) => React.createElement(SafeAreaInsetsProvider, {
36
+ moduleName: this.id,
37
+ // biome-ignore lint/correctness/noChildrenProp: there is no other way in a ts file
38
+ children: React.createElement(component, props),
39
+ }));
40
+ this.componentRegistered = true;
41
+ }
42
+ if (isConnected) {
43
+ HybridCarPlayDashboard.initRootView();
44
+ }
39
45
  }
40
46
  setComponent(component) {
41
47
  if (Platform.OS !== 'ios') {
@@ -69,4 +69,10 @@ export interface AutoPlay extends HybridObject<{
69
69
  * @returns true if AutoPlay is connected, false otherwise.
70
70
  */
71
71
  isConnected(): boolean;
72
+ /**
73
+ * Check if the native AutoPlay is currently running.
74
+ * Use this to distinguish a headless execution triggered by AA / CP
75
+ * from one triggered by other sources (e.g. notification updates).
76
+ */
77
+ isCarServiceRunning(): boolean;
72
78
  }
@@ -260,5 +260,10 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
260
260
  auto __result = method(_javaPart);
261
261
  return static_cast<bool>(__result);
262
262
  }
263
+ bool JHybridAutoPlaySpec::isCarServiceRunning() {
264
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean()>("isCarServiceRunning");
265
+ auto __result = method(_javaPart);
266
+ return static_cast<bool>(__result);
267
+ }
263
268
 
264
269
  } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -65,6 +65,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
65
65
  std::function<void()> addSafeAreaInsetsListener(const std::string& moduleName, const std::function<void(const SafeAreaInsets& /* insets */)>& callback) override;
66
66
  std::shared_ptr<Promise<void>> setTemplateHeaderActions(const std::string& templateId, const std::optional<std::vector<NitroAction>>& headerActions) override;
67
67
  bool isConnected() override;
68
+ bool isCarServiceRunning() override;
68
69
 
69
70
  private:
70
71
  jni::global_ref<JHybridAutoPlaySpec::JavaPart> _javaPart;
@@ -92,6 +92,10 @@ abstract class HybridAutoPlaySpec: HybridObject() {
92
92
  @DoNotStrip
93
93
  @Keep
94
94
  abstract fun isConnected(): Boolean
95
+
96
+ @DoNotStrip
97
+ @Keep
98
+ abstract fun isCarServiceRunning(): Boolean
95
99
 
96
100
  // Default implementation of `HybridObject.toString()`
97
101
  override fun toString(): String {
@@ -194,6 +194,14 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
194
194
  auto __value = std::move(__result.value());
195
195
  return __value;
196
196
  }
197
+ inline bool isCarServiceRunning() override {
198
+ auto __result = _swiftPart.isCarServiceRunning();
199
+ if (__result.hasError()) [[unlikely]] {
200
+ std::rethrow_exception(__result.error());
201
+ }
202
+ auto __value = std::move(__result.value());
203
+ return __value;
204
+ }
197
205
 
198
206
  private:
199
207
  ReactNativeAutoPlay::HybridAutoPlaySpec_cxx _swiftPart;
@@ -24,6 +24,7 @@ public protocol HybridAutoPlaySpec_protocol: HybridObject {
24
24
  func addSafeAreaInsetsListener(moduleName: String, callback: @escaping (_ insets: SafeAreaInsets) -> Void) throws -> () -> Void
25
25
  func setTemplateHeaderActions(templateId: String, headerActions: [NitroAction]?) throws -> Promise<Void>
26
26
  func isConnected() throws -> Bool
27
+ func isCarServiceRunning() throws -> Bool
27
28
  }
28
29
 
29
30
  public extension HybridAutoPlaySpec_protocol {
@@ -369,4 +369,16 @@ open class HybridAutoPlaySpec_cxx {
369
369
  return bridge.create_Result_bool_(__exceptionPtr)
370
370
  }
371
371
  }
372
+
373
+ @inline(__always)
374
+ public final func isCarServiceRunning() -> bridge.Result_bool_ {
375
+ do {
376
+ let __result = try self.__implementation.isCarServiceRunning()
377
+ let __resultCpp = __result
378
+ return bridge.create_Result_bool_(__resultCpp)
379
+ } catch (let __error) {
380
+ let __exceptionPtr = __error.toCpp()
381
+ return bridge.create_Result_bool_(__exceptionPtr)
382
+ }
383
+ }
372
384
  }
@@ -25,6 +25,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
25
25
  prototype.registerHybridMethod("addSafeAreaInsetsListener", &HybridAutoPlaySpec::addSafeAreaInsetsListener);
26
26
  prototype.registerHybridMethod("setTemplateHeaderActions", &HybridAutoPlaySpec::setTemplateHeaderActions);
27
27
  prototype.registerHybridMethod("isConnected", &HybridAutoPlaySpec::isConnected);
28
+ prototype.registerHybridMethod("isCarServiceRunning", &HybridAutoPlaySpec::isCarServiceRunning);
28
29
  });
29
30
  }
30
31
 
@@ -77,6 +77,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
77
77
  virtual std::function<void()> addSafeAreaInsetsListener(const std::string& moduleName, const std::function<void(const SafeAreaInsets& /* insets */)>& callback) = 0;
78
78
  virtual std::shared_ptr<Promise<void>> setTemplateHeaderActions(const std::string& templateId, const std::optional<std::vector<NitroAction>>& headerActions) = 0;
79
79
  virtual bool isConnected() = 0;
80
+ virtual bool isCarServiceRunning() = 0;
80
81
 
81
82
  protected:
82
83
  // Hybrid Setup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -25,6 +25,7 @@ export type CarPlayDashboardEvent = EventName | VisibilityState;
25
25
 
26
26
  class Dashboard {
27
27
  private component: React.ComponentType<RootComponentInitialProps> | null = null;
28
+ private componentRegistered = false;
28
29
  public isConnected = false;
29
30
  public readonly id = 'CarPlayDashboard';
30
31
 
@@ -47,20 +48,26 @@ class Dashboard {
47
48
  }
48
49
 
49
50
  const { component, isConnected } = this;
50
- if (!isConnected || component == null) {
51
+ if (component == null) {
51
52
  return;
52
53
  }
53
54
 
54
- AppRegistry.registerComponent(
55
- this.id,
56
- () => (props) =>
57
- React.createElement(SafeAreaInsetsProvider, {
58
- moduleName: this.id,
59
- // biome-ignore lint/correctness/noChildrenProp: there is no other way in a ts file
60
- children: React.createElement(component, props),
61
- })
62
- );
63
- HybridCarPlayDashboard.initRootView();
55
+ if (!this.componentRegistered) {
56
+ AppRegistry.registerComponent(
57
+ this.id,
58
+ () => (props) =>
59
+ React.createElement(SafeAreaInsetsProvider, {
60
+ moduleName: this.id,
61
+ // biome-ignore lint/correctness/noChildrenProp: there is no other way in a ts file
62
+ children: React.createElement(component, props),
63
+ })
64
+ );
65
+ this.componentRegistered = true;
66
+ }
67
+
68
+ if (isConnected) {
69
+ HybridCarPlayDashboard.initRootView();
70
+ }
64
71
  }
65
72
 
66
73
  public setComponent(component: React.ComponentType<RootComponentInitialProps>) {
@@ -92,4 +92,11 @@ export interface AutoPlay extends HybridObject<{ android: 'kotlin'; ios: 'swift'
92
92
  * @returns true if AutoPlay is connected, false otherwise.
93
93
  */
94
94
  isConnected(): boolean;
95
+
96
+ /**
97
+ * Check if the native AutoPlay is currently running.
98
+ * Use this to distinguish a headless execution triggered by AA / CP
99
+ * from one triggered by other sources (e.g. notification updates).
100
+ */
101
+ isCarServiceRunning(): boolean;
95
102
  }