@iternio/react-native-auto-play 0.1.8 → 0.1.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.
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt +9 -8
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridCluster.kt +5 -3
- package/ios/templates/MapTemplate.swift +9 -9
- package/lib/hooks/useIsAutoPlayFocused.d.ts +7 -0
- package/lib/hooks/useIsAutoPlayFocused.js +20 -0
- package/lib/hybrid.d.ts +2 -0
- package/lib/hybrid.js +2 -0
- package/package.json +1 -1
- package/lib/specs/VoiceInput.nitro.d.ts +0 -8
- package/lib/specs/VoiceInput.nitro.js +0 -1
package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt
CHANGED
|
@@ -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) {
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
240
|
+
private val listeners = ConcurrentHashMap<EventName, CopyOnWriteArrayList<() -> Unit>>()
|
|
240
241
|
|
|
241
242
|
private val renderStateListeners =
|
|
242
|
-
|
|
243
|
+
ConcurrentHashMap<String, CopyOnWriteArrayList<(VisibilityState) -> Unit>>()
|
|
243
244
|
|
|
244
|
-
private val voiceInputListeners =
|
|
245
|
+
private val voiceInputListeners = CopyOnWriteArrayList<(Location?, String?) -> Unit>()
|
|
245
246
|
|
|
246
247
|
private val safeAreaInsetsListeners =
|
|
247
|
-
|
|
248
|
+
ConcurrentHashMap<String, CopyOnWriteArrayList<(SafeAreaInsets) -> Unit>>()
|
|
248
249
|
|
|
249
250
|
|
|
250
251
|
fun removeListeners(templateId: String) {
|
package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridCluster.kt
CHANGED
|
@@ -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) {
|
|
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
|
-
|
|
71
|
-
private val eventQueue =
|
|
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>()
|
|
@@ -533,15 +533,6 @@ class MapTemplate: NSObject, AutoPlayTemplate, AutoPlayHeaderProviding,
|
|
|
533
533
|
startedTrip trip: CPTrip,
|
|
534
534
|
using routeChoice: CPRouteChoice
|
|
535
535
|
) {
|
|
536
|
-
if let onTripStarted = self.onTripStarted {
|
|
537
|
-
let tripId = trip.id
|
|
538
|
-
let routeId = routeChoice.id
|
|
539
|
-
|
|
540
|
-
onTripStarted(tripId, routeId)
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
hideTripSelector()
|
|
544
|
-
|
|
545
536
|
let trip = CPTrip(
|
|
546
537
|
origin: trip.origin,
|
|
547
538
|
destination: trip.destination,
|
|
@@ -550,6 +541,15 @@ class MapTemplate: NSObject, AutoPlayTemplate, AutoPlayHeaderProviding,
|
|
|
550
541
|
)
|
|
551
542
|
|
|
552
543
|
startNavigation(trip: trip)
|
|
544
|
+
|
|
545
|
+
if let onTripStarted = self.onTripStarted {
|
|
546
|
+
let tripId = trip.id
|
|
547
|
+
let routeId = routeChoice.id
|
|
548
|
+
|
|
549
|
+
onTripStarted(tripId, routeId)
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
hideTripSelector()
|
|
553
553
|
}
|
|
554
554
|
|
|
555
555
|
func updateVisibleTravelEstimate(
|
|
@@ -0,0 +1,7 @@
|
|
|
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;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
ADDED
package/lib/hybrid.js
ADDED
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|