@iternio/react-native-auto-play 0.1.9 → 0.1.11

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.
@@ -5,12 +5,14 @@ import com.margelo.nitro.core.Promise
5
5
  import com.margelo.nitro.swe.iternio.reactnativeautoplay.template.AndroidAutoTemplate
6
6
  import com.margelo.nitro.swe.iternio.reactnativeautoplay.template.MessageTemplate
7
7
  import com.margelo.nitro.swe.iternio.reactnativeautoplay.utils.ThreadUtil
8
+ import java.util.concurrent.ConcurrentHashMap
9
+ import java.util.concurrent.CopyOnWriteArrayList
8
10
 
9
11
  class HybridAutoPlay : HybridAutoPlaySpec() {
10
12
  override fun addListener(
11
13
  eventType: EventName, callback: () -> Unit
12
14
  ): () -> Unit {
13
- val callbacks = listeners.getOrPut(eventType) { mutableListOf() }
15
+ val callbacks = listeners.getOrPut(eventType) { CopyOnWriteArrayList() }
14
16
  callbacks.add(callback)
15
17
 
16
18
  if (eventType == EventName.DIDCONNECT && AndroidAutoSession.getIsConnected()) {
@@ -30,7 +32,7 @@ class HybridAutoPlay : HybridAutoPlaySpec() {
30
32
  moduleName: String, callback: (VisibilityState) -> Unit
31
33
  ): () -> Unit {
32
34
  val callbacks = renderStateListeners.getOrPut(moduleName) {
33
- mutableListOf()
35
+ CopyOnWriteArrayList()
34
36
  }
35
37
  callbacks.add(callback)
36
38
 
@@ -56,7 +58,7 @@ class HybridAutoPlay : HybridAutoPlaySpec() {
56
58
  moduleName: String, callback: (SafeAreaInsets) -> Unit
57
59
  ): () -> Unit {
58
60
  val callbacks = safeAreaInsetsListeners.getOrPut(moduleName) {
59
- mutableListOf()
61
+ CopyOnWriteArrayList()
60
62
  }
61
63
  callbacks.add(callback)
62
64
 
@@ -224,7 +226,6 @@ class HybridAutoPlay : HybridAutoPlaySpec() {
224
226
  }
225
227
 
226
228
 
227
-
228
229
  override fun addListenerVoiceInput(callback: (Location?, String?) -> Unit): () -> Unit {
229
230
  voiceInputListeners.add(callback)
230
231
 
@@ -236,15 +237,15 @@ class HybridAutoPlay : HybridAutoPlaySpec() {
236
237
  companion object {
237
238
  const val TAG = "HybridAutoPlay"
238
239
 
239
- private val listeners = mutableMapOf<EventName, MutableList<() -> Unit>>()
240
+ private val listeners = ConcurrentHashMap<EventName, CopyOnWriteArrayList<() -> Unit>>()
240
241
 
241
242
  private val renderStateListeners =
242
- mutableMapOf<String, MutableList<(VisibilityState) -> Unit>>()
243
+ ConcurrentHashMap<String, CopyOnWriteArrayList<(VisibilityState) -> Unit>>()
243
244
 
244
- private val voiceInputListeners = mutableListOf<(Location?, String?) -> Unit>()
245
+ private val voiceInputListeners = CopyOnWriteArrayList<(Location?, String?) -> Unit>()
245
246
 
246
247
  private val safeAreaInsetsListeners =
247
- mutableMapOf<String, MutableList<(SafeAreaInsets) -> Unit>>()
248
+ ConcurrentHashMap<String, CopyOnWriteArrayList<(SafeAreaInsets) -> Unit>>()
248
249
 
249
250
 
250
251
  fun removeListeners(templateId: String) {
@@ -2,12 +2,14 @@ package com.margelo.nitro.swe.iternio.reactnativeautoplay
2
2
 
3
3
  import com.margelo.nitro.core.Promise
4
4
  import com.margelo.nitro.swe.iternio.reactnativeautoplay.utils.ThreadUtil
5
+ import java.util.concurrent.ConcurrentHashMap
6
+ import java.util.concurrent.CopyOnWriteArrayList
5
7
 
6
8
  class HybridCluster : HybridClusterSpec() {
7
9
  override fun addListener(
8
10
  eventType: ClusterEventName, callback: (String) -> Unit
9
11
  ): () -> Unit {
10
- val callbacks = listeners.getOrPut(eventType) { mutableListOf() }
12
+ val callbacks = listeners.getOrPut(eventType) { CopyOnWriteArrayList() }
11
13
  callbacks.add(callback)
12
14
 
13
15
  eventQueue[eventType]?.forEach {
@@ -67,8 +69,8 @@ class HybridCluster : HybridClusterSpec() {
67
69
  const val TAG = "HybridCluster"
68
70
 
69
71
  private val listeners =
70
- mutableMapOf<ClusterEventName, MutableList<(clusterId: String) -> Unit>>()
71
- private val eventQueue = mutableMapOf<ClusterEventName, Array<String>>()
72
+ ConcurrentHashMap<ClusterEventName, CopyOnWriteArrayList<(clusterId: String) -> Unit>>()
73
+ private val eventQueue = ConcurrentHashMap<ClusterEventName, Array<String>>()
72
74
 
73
75
  private val colorSchemeListeners =
74
76
  mutableListOf<(clusterId: String, colorScheme: ColorScheme) -> Unit>()
@@ -250,7 +250,7 @@ class VirtualRenderer(
250
250
  private fun getMapTemplateConfig(): MapTemplateConfig? {
251
251
  val screenManager = AndroidAutoScreen.getScreen(moduleName)?.screenManager ?: return null
252
252
  val marker = screenManager.top.marker ?: return null
253
- return AndroidAutoTemplate.getConfig(marker) as MapTemplateConfig?
253
+ return AndroidAutoTemplate.getTypedConfig<MapTemplateConfig>(marker)
254
254
  }
255
255
 
256
256
  private fun initRenderer() {
@@ -380,7 +380,7 @@ class MapTemplate(
380
380
  AndroidAutoScreen.invalidateSurfaceScreens()
381
381
 
382
382
  UiThreadUtil.runOnUiThread {
383
- navigationManager.updateTrip(Trip.Builder().apply {
383
+ val trip = Trip.Builder().apply {
384
384
  addStep(
385
385
  currentStep, Parser.parseTravelEstimates(current.travelEstimates)
386
386
  )
@@ -390,7 +390,14 @@ class MapTemplate(
390
390
  getTripDestinations().forEach {
391
391
  addDestination(it.key, it.value)
392
392
  }
393
- }.build())
393
+ }.build()
394
+ try {
395
+ navigationManager.updateTrip(trip)
396
+ } catch(exception: IllegalStateException) {
397
+ // Sometimes we get a "java.lang.IllegalStateException: Navigation is not started" here, although the navigation
398
+ // is started already (we check for isNavigating at the top). So i guess this is a race condition, that we start navigation
399
+ // and the AA app is not ready yet. Unfortunately we can not ask the AA app for it's state, so we just catch the error.
400
+ }
394
401
  }
395
402
  }
396
403
  }
@@ -63,10 +63,13 @@ class TripPreviewTemplate(
63
63
 
64
64
  return MapWithContentTemplate.Builder().apply {
65
65
  val pane = Pane.Builder().apply {
66
- addRow(Row.Builder().apply {
67
- setTitle(Parser.parseText(selectedRoute.additionalInformationVariants))
68
- addText(Parser.parseText(selectedRoute.selectionSummaryVariants))
69
- }.build())
66
+ selectedRoute.additionalInformationVariants.firstOrNull()
67
+ ?.takeIf { it.isNotEmpty() }?.let {
68
+ addRow(Row.Builder().apply {
69
+ setTitle(Parser.parseText(selectedRoute.additionalInformationVariants))
70
+ addText(Parser.parseText(selectedRoute.selectionSummaryVariants))
71
+ }.build())
72
+ }
70
73
  addRow(Row.Builder().apply {
71
74
  setTitle(
72
75
  "${textConfig.travelEstimatesTitle} ${
@@ -37,6 +37,18 @@ class HeadUnitSceneDelegate: AutoPlayScene, CPTemplateApplicationSceneDelegate {
37
37
  HybridAutoPlay.emit(event: .didconnect)
38
38
  }
39
39
 
40
+ func templateApplicationScene(
41
+ _ templateApplicationScene: CPTemplateApplicationScene,
42
+ didConnect interfaceController: CPInterfaceController
43
+ ) {
44
+ self.interfaceController = AutoPlayInterfaceController(
45
+ interfaceController: interfaceController
46
+ )
47
+
48
+ connect(props: [:])
49
+ HybridAutoPlay.emit(event: .didconnect)
50
+ }
51
+
40
52
  func templateApplicationScene(
41
53
  _ templateApplicationScene: CPTemplateApplicationScene,
42
54
  didDisconnectInterfaceController interfaceController:
@@ -0,0 +1,8 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { CleanupCallback } from '../types/Event';
3
+ export interface VoiceInput extends HybridObject<{
4
+ android: 'kotlin';
5
+ ios: 'swift';
6
+ }> {
7
+ registerVoiceInputListener(callback: (voiceInputResult?: string, error?: string) => void): CleanupCallback;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -1,7 +0,0 @@
1
- /**
2
- * A hook to determine if the CarPlay/Android Auto screen is currently focused (visible).
3
- *
4
- * @param moduleName The name of the module to listen to.
5
- * @returns `true` if the screen is focused, `false` otherwise.
6
- */
7
- export declare function useIsAutoPlayFocused(moduleName: string): boolean;
@@ -1,20 +0,0 @@
1
- import { useEffect, useState } from 'react';
2
- import { HybridAutoPlay } from '..';
3
- /**
4
- * A hook to determine if the CarPlay/Android Auto screen is currently focused (visible).
5
- *
6
- * @param moduleName The name of the module to listen to.
7
- * @returns `true` if the screen is focused, `false` otherwise.
8
- */
9
- export function useIsAutoPlayFocused(moduleName) {
10
- const [isFocused, setIsFocused] = useState(false);
11
- useEffect(() => {
12
- const remove = HybridAutoPlay.addListenerRenderState(moduleName, (state) => {
13
- setIsFocused(state === 'didAppear');
14
- });
15
- return () => {
16
- remove();
17
- };
18
- }, [moduleName]);
19
- return isFocused;
20
- }
package/lib/hybrid.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { AutoPlay as NitroAutoPlay } from './specs/AutoPlay.nitro';
2
- export declare const HybridAutoPlay: NitroAutoPlay;
package/lib/hybrid.js DELETED
@@ -1,2 +0,0 @@
1
- import { NitroModules } from 'react-native-nitro-modules';
2
- export const HybridAutoPlay = NitroModules.createHybridObject('AutoPlay');