@iternio/react-native-auto-play 0.0.11 → 0.1.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 (37) hide show
  1. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/AndroidAutoSession.kt +59 -1
  2. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt +19 -0
  3. package/ios/ReactHelpers/NitroSurface.h +10 -0
  4. package/ios/ReactHelpers/NitroSurface.m +51 -0
  5. package/ios/hybrid/HybridAutoPlay.swift +7 -0
  6. package/ios/scenes/AutoPlayScene.swift +1 -20
  7. package/lib/hooks/useVoiceInput.d.ts +8 -0
  8. package/lib/hooks/useVoiceInput.js +38 -0
  9. package/lib/index.d.ts +1 -0
  10. package/lib/index.js +1 -0
  11. package/lib/specs/AutoPlay.nitro.d.ts +8 -1
  12. package/lib/types/Event.d.ts +4 -0
  13. package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +2 -0
  14. package/nitrogen/generated/android/c++/JFunc_void_std__optional_Location__std__optional_std__string_.hpp +78 -0
  15. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.cpp +20 -0
  16. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.hpp +1 -0
  17. package/nitrogen/generated/android/c++/JLocation.hpp +61 -0
  18. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_std__optional_Location__std__optional_std__string_.kt +80 -0
  19. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlaySpec.kt +9 -0
  20. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Location.kt +41 -0
  21. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.cpp +8 -0
  22. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.hpp +55 -15
  23. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Umbrella.hpp +3 -0
  24. package/nitrogen/generated/ios/c++/HybridAutoPlaySpecSwift.hpp +12 -1
  25. package/nitrogen/generated/ios/swift/Func_void_std__optional_Location__std__optional_std__string_.swift +54 -0
  26. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec.swift +1 -0
  27. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec_cxx.swift +32 -0
  28. package/nitrogen/generated/ios/swift/Location.swift +46 -0
  29. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.cpp +1 -0
  30. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.hpp +5 -1
  31. package/nitrogen/generated/shared/c++/Location.hpp +79 -0
  32. package/package.json +1 -1
  33. package/src/hooks/useVoiceInput.ts +54 -0
  34. package/src/index.ts +1 -0
  35. package/src/specs/AutoPlay.nitro.ts +17 -1
  36. package/src/types/Event.ts +4 -0
  37. package/ios/ReactHelpers/RCTRootView.h +0 -29
@@ -2,6 +2,7 @@ package com.margelo.nitro.swe.iternio.reactnativeautoplay
2
2
 
3
3
  import android.content.Intent
4
4
  import android.content.res.Configuration
5
+ import android.util.Log
5
6
  import androidx.car.app.CarContext
6
7
  import androidx.car.app.Screen
7
8
  import androidx.car.app.Session
@@ -135,6 +136,63 @@ class AndroidAutoSession(sessionInfo: SessionInfo, private val reactApplication:
135
136
  AndroidAutoScreen.invalidateScreens()
136
137
  }
137
138
 
139
+ override fun onNewIntent(intent: Intent) {
140
+ val action = intent.action ?: return
141
+
142
+ if (action == CarContext.ACTION_NAVIGATE) {
143
+ intent.data?.schemeSpecificPart?.let { schemeSpecificPart ->
144
+ try {
145
+ // Parse the geo URI format: lat,lon?q=query&mode=x&intent=y
146
+ val queryIndex = schemeSpecificPart.indexOf("?q=")
147
+
148
+ val location = if (queryIndex > 0) {
149
+ val coordinatesPart = schemeSpecificPart.substring(0, queryIndex)
150
+ parseCoordinates(coordinatesPart)
151
+ } else {
152
+ null
153
+ }
154
+
155
+ val query = if (queryIndex >= 0) {
156
+ val queryPart = schemeSpecificPart.substring(queryIndex + 3) // Skip "?q="
157
+ val additionalParamsIndex = queryPart.indexOf('&')
158
+
159
+ if (additionalParamsIndex >= 0) {
160
+ val rawQuery = queryPart.substring(0, additionalParamsIndex)
161
+ java.net.URLDecoder.decode(rawQuery, "UTF-8")
162
+ } else {
163
+ java.net.URLDecoder.decode(queryPart, "UTF-8")
164
+ }
165
+ } else {
166
+ java.net.URLDecoder.decode(schemeSpecificPart, "UTF-8")
167
+ }
168
+
169
+ HybridAutoPlay.emitVoiceInput(location, query)
170
+ } catch (e: Exception) {
171
+ Log.e(TAG, "Failed to parse navigation intent: ${e.message}")
172
+ }
173
+ }
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Parses coordinates from a string in format "lat,lon".
179
+ * Returns null for invalid formats or 0,0 coordinates (which indicate "use geocoding").
180
+ */
181
+ private fun parseCoordinates(coordinatesPart: String): Location? {
182
+ val parts = coordinatesPart.split(",")
183
+ if (parts.size != 2) return null
184
+
185
+ val lat = parts[0].toDoubleOrNull() ?: return null
186
+ val lon = parts[1].toDoubleOrNull() ?: return null
187
+
188
+ // Treat 0,0 as "no coordinates" - it means use geocoding for the query
189
+ if (lat == 0.0 && lon == 0.0) {
190
+ return null
191
+ }
192
+
193
+ return Location(lat, lon)
194
+ }
195
+
138
196
  private val sessionLifecycleObserver = object : DefaultLifecycleObserver {
139
197
  override fun onCreate(owner: LifecycleOwner) {
140
198
  sessions[moduleName]?.state = VisibilityState.WILLAPPEAR
@@ -201,7 +259,7 @@ class AndroidAutoSession(sessionInfo: SessionInfo, private val reactApplication:
201
259
  }
202
260
 
203
261
  fun getCarContext(marker: String): CarContext? {
204
- return sessions.get(marker)?.carContext
262
+ return sessions[marker]?.carContext
205
263
  }
206
264
 
207
265
  fun getRootContext(): CarContext? {
@@ -223,6 +223,16 @@ class HybridAutoPlay : HybridAutoPlaySpec() {
223
223
  }
224
224
  }
225
225
 
226
+
227
+
228
+ override fun addListenerVoiceInput(callback: (Location?, String?) -> Unit): () -> Unit {
229
+ voiceInputListeners.add(callback)
230
+
231
+ return {
232
+ voiceInputListeners.remove(callback)
233
+ }
234
+ }
235
+
226
236
  companion object {
227
237
  const val TAG = "HybridAutoPlay"
228
238
 
@@ -230,6 +240,9 @@ class HybridAutoPlay : HybridAutoPlaySpec() {
230
240
 
231
241
  private val renderStateListeners =
232
242
  mutableMapOf<String, MutableList<(VisibilityState) -> Unit>>()
243
+
244
+ private val voiceInputListeners = mutableListOf<(Location?, String?) -> Unit>()
245
+
233
246
  private val safeAreaInsetsListeners =
234
247
  mutableMapOf<String, MutableList<(SafeAreaInsets) -> Unit>>()
235
248
 
@@ -249,6 +262,12 @@ class HybridAutoPlay : HybridAutoPlaySpec() {
249
262
  }
250
263
  }
251
264
 
265
+ fun emitVoiceInput(location: Location?, query: String?) {
266
+ voiceInputListeners.forEach {
267
+ it(location, query)
268
+ }
269
+ }
270
+
252
271
  fun emitSafeAreaInsets(
253
272
  moduleName: String,
254
273
  top: Double,
@@ -0,0 +1,10 @@
1
+ //
2
+ // NitroSurface.h
3
+ // Pods
4
+ //
5
+ // Created by Manuel Auer on 28.11.25.
6
+ //
7
+
8
+ @interface NitroSurface : NSObject
9
+ + (void)stop:(nullable UIView *)view;
10
+ @end
@@ -0,0 +1,51 @@
1
+ //
2
+ // NitroSurface.m
3
+ // Pods
4
+ //
5
+ // Created by Manuel Auer on 28.11.25.
6
+ //
7
+
8
+ #import "NitroSurface.h"
9
+ #import <React/RCTInvalidating.h>
10
+ #import <React/RCTRootView.h>
11
+ #import <React/RCTSurface.h>
12
+ #import <React/RCTSurfaceHostingProxyRootView.h>
13
+
14
+ @implementation NitroSurface
15
+
16
+ + (void)stop:(nullable UIView *)view {
17
+ if (view == nil) {
18
+ NSLog(@"[AutoPlay] View is nil, ignoring");
19
+ return;
20
+ }
21
+
22
+ if ([view isKindOfClass:[RCTSurfaceHostingProxyRootView class]]) {
23
+ RCTSurfaceHostingProxyRootView *rootView =
24
+ (RCTSurfaceHostingProxyRootView *)view;
25
+ RCTSurface *surface = rootView.surface;
26
+
27
+ if (surface == nil) {
28
+ NSLog(@"[AutoPlay] surface == nil, cannot stop");
29
+ return;
30
+ }
31
+
32
+ [surface stop];
33
+ return;
34
+ }
35
+
36
+ if ([view isKindOfClass:[RCTRootView class]]) {
37
+ RCTRootView *rootView = (RCTRootView *)view;
38
+ UIView<RCTInvalidating> *contentView = (UIView<RCTInvalidating> *)rootView.contentView;
39
+
40
+ if ([contentView conformsToProtocol:@protocol(RCTInvalidating)]) {
41
+ [contentView invalidate];
42
+ } else {
43
+ NSLog(@"[AutoPlay] contentView does not conform to RCTInvalidating");
44
+ }
45
+ return;
46
+ }
47
+
48
+ NSLog(@"[AutoPlay] View is not recognized type, ignoring");
49
+ }
50
+
51
+ @end
@@ -107,6 +107,13 @@ class HybridAutoPlay: HybridAutoPlaySpec {
107
107
  }
108
108
  }
109
109
 
110
+ func addListenerVoiceInput(
111
+ callback: @escaping (Location?, String?) -> Void
112
+ ) throws -> () -> Void {
113
+ // TODO: Inplement voice input
114
+ return {}
115
+ }
116
+
110
117
  // MARK: set/push/pop templates
111
118
  func setRootTemplate(templateId: String) throws -> Promise<Void> {
112
119
  return Promise.async {
@@ -7,10 +7,6 @@
7
7
 
8
8
  import CarPlay
9
9
 
10
- #if RCT_NEW_ARCH_ENABLED
11
- import React
12
- #endif
13
-
14
10
  class AutoPlayScene: UIResponder {
15
11
  var initialProperties: [String: Any] = [:]
16
12
  var moduleName: String?
@@ -46,22 +42,7 @@ class AutoPlayScene: UIResponder {
46
42
  }
47
43
 
48
44
  func disconnect() {
49
- #if RCT_NEW_ARCH_ENABLED
50
- if let rootView = self.window?.rootViewController?.view
51
- as? RCTSurfaceHostingProxyRootView
52
- {
53
- rootView.surface.stop()
54
- }
55
- #else
56
- if let rootView = self.window?.rootViewController?.view
57
- as? RCTRootView
58
- {
59
- if let contentView = rootView.contentView as? RCTInvalidating {
60
- contentView.invalidate()
61
- }
62
- }
63
- #endif
64
-
45
+ NitroSurface.stop(self.window?.rootViewController?.view)
65
46
  self.window = nil
66
47
  isConnected = false
67
48
 
@@ -0,0 +1,8 @@
1
+ import { type Location } from '..';
2
+ export declare const useVoiceInput: () => {
3
+ voiceInputResult: {
4
+ coordinates: Location | undefined;
5
+ query: string | undefined;
6
+ } | undefined;
7
+ resetVoiceInputResult: () => void;
8
+ };
@@ -0,0 +1,38 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { HybridAutoPlay } from '..';
3
+ export const useVoiceInput = () => {
4
+ const [isConnected, setIsConnected] = useState(false);
5
+ const [voiceInputResult, setVoiceInputResult] = useState();
6
+ /**
7
+ * Resets the voice input result to undefined. This is useful when you want to clear the voice input result after processing it.
8
+ */
9
+ const resetVoiceInputResult = useCallback(() => {
10
+ setVoiceInputResult(undefined);
11
+ }, []);
12
+ useEffect(() => {
13
+ const removeDidConnect = HybridAutoPlay.addListener('didConnect', () => setIsConnected(true));
14
+ const removeDidDisconnect = HybridAutoPlay.addListener('didDisconnect', () => setIsConnected(false));
15
+ setIsConnected(HybridAutoPlay.isConnected());
16
+ return () => {
17
+ removeDidConnect();
18
+ removeDidDisconnect();
19
+ };
20
+ }, []);
21
+ useEffect(() => {
22
+ if (!isConnected) {
23
+ return;
24
+ }
25
+ const remove = HybridAutoPlay.addListenerVoiceInput((coordinates, query) => {
26
+ if (coordinates || query) {
27
+ setVoiceInputResult({ coordinates, query });
28
+ }
29
+ else {
30
+ setVoiceInputResult(undefined);
31
+ }
32
+ });
33
+ return () => {
34
+ remove();
35
+ };
36
+ }, [isConnected]);
37
+ return { voiceInputResult, resetVoiceInputResult };
38
+ };
package/lib/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from './components/SafeAreaView';
15
15
  export * from './hooks/useAndroidAutoTelemetry';
16
16
  export * from './hooks/useMapTemplate';
17
17
  export * from './hooks/useSafeAreaInsets';
18
+ export * from './hooks/useVoiceInput';
18
19
  export * from './scenes/AutoPlayCluster';
19
20
  export * from './scenes/CarPlayDashboardScene';
20
21
  export * from './templates/GridTemplate';
package/lib/index.js CHANGED
@@ -20,6 +20,7 @@ export * from './components/SafeAreaView';
20
20
  export * from './hooks/useAndroidAutoTelemetry';
21
21
  export * from './hooks/useMapTemplate';
22
22
  export * from './hooks/useSafeAreaInsets';
23
+ export * from './hooks/useVoiceInput';
23
24
  export * from './scenes/AutoPlayCluster';
24
25
  export * from './scenes/CarPlayDashboardScene';
25
26
  export * from './templates/GridTemplate';
@@ -1,6 +1,6 @@
1
1
  import type { HybridObject } from 'react-native-nitro-modules';
2
2
  import type { TemplateConfig } from '../templates/Template';
3
- import type { CleanupCallback, EventName, SafeAreaInsets, VisibilityState } from '../types/Event';
3
+ import type { CleanupCallback, EventName, Location, SafeAreaInsets, VisibilityState } from '../types/Event';
4
4
  import type { NitroAction } from '../utils/NitroAction';
5
5
  export interface NitroTemplateConfig extends TemplateConfig {
6
6
  id: string;
@@ -23,6 +23,13 @@ export interface AutoPlay extends HybridObject<{
23
23
  * @param moduleName on of @AutoPlayModules, a cluster scene uuid or your main for the WindowApplicationSceneDelegate
24
24
  */
25
25
  addListenerRenderState(moduleName: string, callback: (payload: VisibilityState) => void): CleanupCallback;
26
+ /**
27
+ * Adds a listener for voice input events. Not implemented on iOS.
28
+ * @param callback the callback to receive the voice input
29
+ * @returns callback to remove the listener
30
+ * @namespace Android
31
+ */
32
+ addListenerVoiceInput(callback: (coordinates: Location | undefined, query: string | undefined) => void): CleanupCallback;
26
33
  /**
27
34
  * sets the specified template as root template, initializes a new stack
28
35
  * Promise might contain an error message in case setting root template failed
@@ -12,3 +12,7 @@ export type SafeAreaInsets = {
12
12
  */
13
13
  isLegacyLayout?: boolean;
14
14
  };
15
+ export interface Location {
16
+ lat: number;
17
+ lon: number;
18
+ }
@@ -20,6 +20,7 @@
20
20
  #include "JFunc_void_std__optional_Telemetry__std__optional_std__string_.hpp"
21
21
  #include "JHybridAutoPlaySpec.hpp"
22
22
  #include "JFunc_void_VisibilityState.hpp"
23
+ #include "JFunc_void_std__optional_Location__std__optional_std__string_.hpp"
23
24
  #include "JFunc_void_SafeAreaInsets.hpp"
24
25
  #include "JHybridClusterSpec.hpp"
25
26
  #include "JFunc_void_std__string.hpp"
@@ -56,6 +57,7 @@ int initialize(JavaVM* vm) {
56
57
  margelo::nitro::swe::iternio::reactnativeautoplay::JFunc_void_std__optional_Telemetry__std__optional_std__string__cxx::registerNatives();
57
58
  margelo::nitro::swe::iternio::reactnativeautoplay::JHybridAutoPlaySpec::registerNatives();
58
59
  margelo::nitro::swe::iternio::reactnativeautoplay::JFunc_void_VisibilityState_cxx::registerNatives();
60
+ margelo::nitro::swe::iternio::reactnativeautoplay::JFunc_void_std__optional_Location__std__optional_std__string__cxx::registerNatives();
59
61
  margelo::nitro::swe::iternio::reactnativeautoplay::JFunc_void_SafeAreaInsets_cxx::registerNatives();
60
62
  margelo::nitro::swe::iternio::reactnativeautoplay::JHybridClusterSpec::registerNatives();
61
63
  margelo::nitro::swe::iternio::reactnativeautoplay::JFunc_void_std__string_cxx::registerNatives();
@@ -0,0 +1,78 @@
1
+ ///
2
+ /// JFunc_void_std__optional_Location__std__optional_std__string_.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include "Location.hpp"
14
+ #include <optional>
15
+ #include <string>
16
+ #include <functional>
17
+ #include "JLocation.hpp"
18
+
19
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
20
+
21
+ using namespace facebook;
22
+
23
+ /**
24
+ * Represents the Java/Kotlin callback `(coordinates: Location?, query: String?) -> Unit`.
25
+ * This can be passed around between C++ and Java/Kotlin.
26
+ */
27
+ struct JFunc_void_std__optional_Location__std__optional_std__string_: public jni::JavaClass<JFunc_void_std__optional_Location__std__optional_std__string_> {
28
+ public:
29
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_std__optional_Location__std__optional_std__string_;";
30
+
31
+ public:
32
+ /**
33
+ * Invokes the function this `JFunc_void_std__optional_Location__std__optional_std__string_` instance holds through JNI.
34
+ */
35
+ void invoke(const std::optional<Location>& coordinates, const std::optional<std::string>& query) const {
36
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JLocation> /* coordinates */, jni::alias_ref<jni::JString> /* query */)>("invoke");
37
+ method(self(), coordinates.has_value() ? JLocation::fromCpp(coordinates.value()) : nullptr, query.has_value() ? jni::make_jstring(query.value()) : nullptr);
38
+ }
39
+ };
40
+
41
+ /**
42
+ * An implementation of Func_void_std__optional_Location__std__optional_std__string_ that is backed by a C++ implementation (using `std::function<...>`)
43
+ */
44
+ struct JFunc_void_std__optional_Location__std__optional_std__string__cxx final: public jni::HybridClass<JFunc_void_std__optional_Location__std__optional_std__string__cxx, JFunc_void_std__optional_Location__std__optional_std__string_> {
45
+ public:
46
+ static jni::local_ref<JFunc_void_std__optional_Location__std__optional_std__string_::javaobject> fromCpp(const std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>& func) {
47
+ return JFunc_void_std__optional_Location__std__optional_std__string__cxx::newObjectCxxArgs(func);
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Invokes the C++ `std::function<...>` this `JFunc_void_std__optional_Location__std__optional_std__string__cxx` instance holds.
53
+ */
54
+ void invoke_cxx(jni::alias_ref<JLocation> coordinates, jni::alias_ref<jni::JString> query) {
55
+ _func(coordinates != nullptr ? std::make_optional(coordinates->toCpp()) : std::nullopt, query != nullptr ? std::make_optional(query->toStdString()) : std::nullopt);
56
+ }
57
+
58
+ public:
59
+ [[nodiscard]]
60
+ inline const std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>& getFunction() const {
61
+ return _func;
62
+ }
63
+
64
+ public:
65
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_std__optional_Location__std__optional_std__string__cxx;";
66
+ static void registerNatives() {
67
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__optional_Location__std__optional_std__string__cxx::invoke_cxx)});
68
+ }
69
+
70
+ private:
71
+ explicit JFunc_void_std__optional_Location__std__optional_std__string__cxx(const std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>& func): _func(func) { }
72
+
73
+ private:
74
+ friend HybridBase;
75
+ std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)> _func;
76
+ };
77
+
78
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -11,6 +11,8 @@
11
11
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class EventName; }
12
12
  // Forward declaration of `VisibilityState` to properly resolve imports.
13
13
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class VisibilityState; }
14
+ // Forward declaration of `Location` to properly resolve imports.
15
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct Location; }
14
16
  // Forward declaration of `SafeAreaInsets` to properly resolve imports.
15
17
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct SafeAreaInsets; }
16
18
  // Forward declaration of `NitroAction` to properly resolve imports.
@@ -38,7 +40,10 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class NitroBu
38
40
  #include "VisibilityState.hpp"
39
41
  #include "JFunc_void_VisibilityState.hpp"
40
42
  #include "JVisibilityState.hpp"
43
+ #include "Location.hpp"
41
44
  #include <optional>
45
+ #include "JFunc_void_std__optional_Location__std__optional_std__string_.hpp"
46
+ #include "JLocation.hpp"
42
47
  #include "SafeAreaInsets.hpp"
43
48
  #include "JFunc_void_SafeAreaInsets.hpp"
44
49
  #include "JSafeAreaInsets.hpp"
@@ -122,6 +127,21 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
122
127
  }
123
128
  }();
124
129
  }
130
+ std::function<void()> JHybridAutoPlaySpec::addListenerVoiceInput(const std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>& callback) {
131
+ static const auto method = javaClassStatic()->getMethod<jni::local_ref<JFunc_void::javaobject>(jni::alias_ref<JFunc_void_std__optional_Location__std__optional_std__string_::javaobject> /* callback */)>("addListenerVoiceInput_cxx");
132
+ auto __result = method(_javaPart, JFunc_void_std__optional_Location__std__optional_std__string__cxx::fromCpp(callback));
133
+ return [&]() -> std::function<void()> {
134
+ if (__result->isInstanceOf(JFunc_void_cxx::javaClassStatic())) [[likely]] {
135
+ auto downcast = jni::static_ref_cast<JFunc_void_cxx::javaobject>(__result);
136
+ return downcast->cthis()->getFunction();
137
+ } else {
138
+ auto __resultRef = jni::make_global(__result);
139
+ return [__resultRef]() -> void {
140
+ return __resultRef->invoke();
141
+ };
142
+ }
143
+ }();
144
+ }
125
145
  std::shared_ptr<Promise<void>> JHybridAutoPlaySpec::setRootTemplate(const std::string& templateId) {
126
146
  static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* templateId */)>("setRootTemplate");
127
147
  auto __result = method(_javaPart, jni::make_jstring(templateId));
@@ -56,6 +56,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
56
56
  // Methods
57
57
  std::function<void()> addListener(EventName eventType, const std::function<void()>& callback) override;
58
58
  std::function<void()> addListenerRenderState(const std::string& moduleName, const std::function<void(VisibilityState /* payload */)>& callback) override;
59
+ std::function<void()> addListenerVoiceInput(const std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>& callback) override;
59
60
  std::shared_ptr<Promise<void>> setRootTemplate(const std::string& templateId) override;
60
61
  std::shared_ptr<Promise<void>> pushTemplate(const std::string& templateId) override;
61
62
  std::shared_ptr<Promise<void>> popTemplate(std::optional<bool> animate) override;
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// JLocation.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "Location.hpp"
12
+
13
+
14
+
15
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "Location" and the the Kotlin data class "Location".
21
+ */
22
+ struct JLocation final: public jni::JavaClass<JLocation> {
23
+ public:
24
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/swe/iternio/reactnativeautoplay/Location;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct Location by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ Location toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldLat = clazz->getField<double>("lat");
35
+ double lat = this->getFieldValue(fieldLat);
36
+ static const auto fieldLon = clazz->getField<double>("lon");
37
+ double lon = this->getFieldValue(fieldLon);
38
+ return Location(
39
+ lat,
40
+ lon
41
+ );
42
+ }
43
+
44
+ public:
45
+ /**
46
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
47
+ */
48
+ [[maybe_unused]]
49
+ static jni::local_ref<JLocation::javaobject> fromCpp(const Location& value) {
50
+ using JSignature = JLocation(double, double);
51
+ static const auto clazz = javaClassStatic();
52
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
53
+ return create(
54
+ clazz,
55
+ value.lat,
56
+ value.lon
57
+ );
58
+ }
59
+ };
60
+
61
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// Func_void_std__optional_Location__std__optional_std__string_.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.swe.iternio.reactnativeautoplay
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.jni.HybridData
12
+ import com.facebook.proguard.annotations.DoNotStrip
13
+ import dalvik.annotation.optimization.FastNative
14
+
15
+
16
+ /**
17
+ * Represents the JavaScript callback `(coordinates: optional, query: optional) => void`.
18
+ * This can be either implemented in C++ (in which case it might be a callback coming from JS),
19
+ * or in Kotlin/Java (in which case it is a native callback).
20
+ */
21
+ @DoNotStrip
22
+ @Keep
23
+ @Suppress("ClassName", "RedundantUnitReturnType")
24
+ fun interface Func_void_std__optional_Location__std__optional_std__string_: (Location?, String?) -> Unit {
25
+ /**
26
+ * Call the given JS callback.
27
+ * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
28
+ */
29
+ @DoNotStrip
30
+ @Keep
31
+ override fun invoke(coordinates: Location?, query: String?): Unit
32
+ }
33
+
34
+ /**
35
+ * Represents the JavaScript callback `(coordinates: optional, query: optional) => void`.
36
+ * This is implemented in C++, via a `std::function<...>`.
37
+ * The callback might be coming from JS.
38
+ */
39
+ @DoNotStrip
40
+ @Keep
41
+ @Suppress(
42
+ "KotlinJniMissingFunction", "unused",
43
+ "RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
44
+ "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
45
+ )
46
+ class Func_void_std__optional_Location__std__optional_std__string__cxx: Func_void_std__optional_Location__std__optional_std__string_ {
47
+ @DoNotStrip
48
+ @Keep
49
+ private val mHybridData: HybridData
50
+
51
+ @DoNotStrip
52
+ @Keep
53
+ private constructor(hybridData: HybridData) {
54
+ mHybridData = hybridData
55
+ }
56
+
57
+ @DoNotStrip
58
+ @Keep
59
+ override fun invoke(coordinates: Location?, query: String?): Unit
60
+ = invoke_cxx(coordinates,query)
61
+
62
+ @FastNative
63
+ private external fun invoke_cxx(coordinates: Location?, query: String?): Unit
64
+ }
65
+
66
+ /**
67
+ * Represents the JavaScript callback `(coordinates: optional, query: optional) => void`.
68
+ * This is implemented in Java/Kotlin, via a `(Location?, String?) -> Unit`.
69
+ * The callback is always coming from native.
70
+ */
71
+ @DoNotStrip
72
+ @Keep
73
+ @Suppress("ClassName", "RedundantUnitReturnType", "unused")
74
+ class Func_void_std__optional_Location__std__optional_std__string__java(private val function: (Location?, String?) -> Unit): Func_void_std__optional_Location__std__optional_std__string_ {
75
+ @DoNotStrip
76
+ @Keep
77
+ override fun invoke(coordinates: Location?, query: String?): Unit {
78
+ return this.function(coordinates, query)
79
+ }
80
+ }
@@ -64,6 +64,15 @@ abstract class HybridAutoPlaySpec: HybridObject() {
64
64
  return Func_void_java(__result)
65
65
  }
66
66
 
67
+ abstract fun addListenerVoiceInput(callback: (coordinates: Location?, query: String?) -> Unit): () -> Unit
68
+
69
+ @DoNotStrip
70
+ @Keep
71
+ private fun addListenerVoiceInput_cxx(callback: Func_void_std__optional_Location__std__optional_std__string_): Func_void {
72
+ val __result = addListenerVoiceInput(callback)
73
+ return Func_void_java(__result)
74
+ }
75
+
67
76
  @DoNotStrip
68
77
  @Keep
69
78
  abstract fun setRootTemplate(templateId: String): Promise<Unit>
@@ -0,0 +1,41 @@
1
+ ///
2
+ /// Location.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.swe.iternio.reactnativeautoplay
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+
14
+ /**
15
+ * Represents the JavaScript object/struct "Location".
16
+ */
17
+ @DoNotStrip
18
+ @Keep
19
+ data class Location(
20
+ @DoNotStrip
21
+ @Keep
22
+ val lat: Double,
23
+ @DoNotStrip
24
+ @Keep
25
+ val lon: Double
26
+ ) {
27
+ /* primary constructor */
28
+
29
+ private companion object {
30
+ /**
31
+ * Constructor called from C++
32
+ */
33
+ @DoNotStrip
34
+ @Keep
35
+ @Suppress("unused")
36
+ @JvmStatic
37
+ private fun fromCpp(lat: Double, lon: Double): Location {
38
+ return Location(lat, lon)
39
+ }
40
+ }
41
+ }
@@ -37,6 +37,14 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay::bridge::swift {
37
37
  };
38
38
  }
39
39
 
40
+ // pragma MARK: std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>
41
+ Func_void_std__optional_Location__std__optional_std__string_ create_Func_void_std__optional_Location__std__optional_std__string_(void* NON_NULL swiftClosureWrapper) noexcept {
42
+ auto swiftClosure = ReactNativeAutoPlay::Func_void_std__optional_Location__std__optional_std__string_::fromUnsafe(swiftClosureWrapper);
43
+ return [swiftClosure = std::move(swiftClosure)](const std::optional<Location>& coordinates, const std::optional<std::string>& query) mutable -> void {
44
+ swiftClosure.call(coordinates, query);
45
+ };
46
+ }
47
+
40
48
  // pragma MARK: std::function<void(const std::exception_ptr& /* error */)>
41
49
  Func_void_std__exception_ptr create_Func_void_std__exception_ptr(void* NON_NULL swiftClosureWrapper) noexcept {
42
50
  auto swiftClosure = ReactNativeAutoPlay::Func_void_std__exception_ptr::fromUnsafe(swiftClosureWrapper);
@@ -52,6 +52,8 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct ImageLane;
52
52
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class KeepType; }
53
53
  // Forward declaration of `LaneGuidance` to properly resolve imports.
54
54
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct LaneGuidance; }
55
+ // Forward declaration of `Location` to properly resolve imports.
56
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct Location; }
55
57
  // Forward declaration of `ManeuverType` to properly resolve imports.
56
58
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class ManeuverType; }
57
59
  // Forward declaration of `NavigationAlertAction` to properly resolve imports.
@@ -166,6 +168,7 @@ namespace ReactNativeAutoPlay { class HybridSearchTemplateSpec_cxx; }
166
168
  #include "ImageLane.hpp"
167
169
  #include "KeepType.hpp"
168
170
  #include "LaneGuidance.hpp"
171
+ #include "Location.hpp"
169
172
  #include "ManeuverType.hpp"
170
173
  #include "NavigationAlertAction.hpp"
171
174
  #include "NitroAction.hpp"
@@ -262,6 +265,58 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay::bridge::swift {
262
265
  return Func_void_VisibilityState_Wrapper(std::move(value));
263
266
  }
264
267
 
268
+ // pragma MARK: std::optional<Location>
269
+ /**
270
+ * Specialized version of `std::optional<Location>`.
271
+ */
272
+ using std__optional_Location_ = std::optional<Location>;
273
+ inline std::optional<Location> create_std__optional_Location_(const Location& value) noexcept {
274
+ return std::optional<Location>(value);
275
+ }
276
+ inline bool has_value_std__optional_Location_(const std::optional<Location>& optional) noexcept {
277
+ return optional.has_value();
278
+ }
279
+ inline Location get_std__optional_Location_(const std::optional<Location>& optional) noexcept {
280
+ return *optional;
281
+ }
282
+
283
+ // pragma MARK: std::optional<std::string>
284
+ /**
285
+ * Specialized version of `std::optional<std::string>`.
286
+ */
287
+ using std__optional_std__string_ = std::optional<std::string>;
288
+ inline std::optional<std::string> create_std__optional_std__string_(const std::string& value) noexcept {
289
+ return std::optional<std::string>(value);
290
+ }
291
+ inline bool has_value_std__optional_std__string_(const std::optional<std::string>& optional) noexcept {
292
+ return optional.has_value();
293
+ }
294
+ inline std::string get_std__optional_std__string_(const std::optional<std::string>& optional) noexcept {
295
+ return *optional;
296
+ }
297
+
298
+ // pragma MARK: std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>
299
+ /**
300
+ * Specialized version of `std::function<void(const std::optional<Location>&, const std::optional<std::string>&)>`.
301
+ */
302
+ using Func_void_std__optional_Location__std__optional_std__string_ = std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>;
303
+ /**
304
+ * Wrapper class for a `std::function<void(const std::optional<Location>& / * coordinates * /, const std::optional<std::string>& / * query * /)>`, this can be used from Swift.
305
+ */
306
+ class Func_void_std__optional_Location__std__optional_std__string__Wrapper final {
307
+ public:
308
+ explicit Func_void_std__optional_Location__std__optional_std__string__Wrapper(std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>&& func): _function(std::make_unique<std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>>(std::move(func))) {}
309
+ inline void call(std::optional<Location> coordinates, std::optional<std::string> query) const noexcept {
310
+ _function->operator()(coordinates, query);
311
+ }
312
+ private:
313
+ std::unique_ptr<std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>> _function;
314
+ } SWIFT_NONCOPYABLE;
315
+ Func_void_std__optional_Location__std__optional_std__string_ create_Func_void_std__optional_Location__std__optional_std__string_(void* NON_NULL swiftClosureWrapper) noexcept;
316
+ inline Func_void_std__optional_Location__std__optional_std__string__Wrapper wrap_Func_void_std__optional_Location__std__optional_std__string_(Func_void_std__optional_Location__std__optional_std__string_ value) noexcept {
317
+ return Func_void_std__optional_Location__std__optional_std__string__Wrapper(std::move(value));
318
+ }
319
+
265
320
  // pragma MARK: std::shared_ptr<Promise<void>>
266
321
  /**
267
322
  * Specialized version of `std::shared_ptr<Promise<void>>`.
@@ -333,21 +388,6 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay::bridge::swift {
333
388
  return Func_void_SafeAreaInsets_Wrapper(std::move(value));
334
389
  }
335
390
 
336
- // pragma MARK: std::optional<std::string>
337
- /**
338
- * Specialized version of `std::optional<std::string>`.
339
- */
340
- using std__optional_std__string_ = std::optional<std::string>;
341
- inline std::optional<std::string> create_std__optional_std__string_(const std::string& value) noexcept {
342
- return std::optional<std::string>(value);
343
- }
344
- inline bool has_value_std__optional_std__string_(const std::optional<std::string>& optional) noexcept {
345
- return optional.has_value();
346
- }
347
- inline std::string get_std__optional_std__string_(const std::optional<std::string>& optional) noexcept {
348
- return *optional;
349
- }
350
-
351
391
  // pragma MARK: std::optional<double>
352
392
  /**
353
393
  * Specialized version of `std::optional<double>`.
@@ -62,6 +62,8 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class KeepTyp
62
62
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct LaneGuidance; }
63
63
  // Forward declaration of `ListTemplateConfig` to properly resolve imports.
64
64
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct ListTemplateConfig; }
65
+ // Forward declaration of `Location` to properly resolve imports.
66
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct Location; }
65
67
  // Forward declaration of `ManeuverType` to properly resolve imports.
66
68
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class ManeuverType; }
67
69
  // Forward declaration of `MapTemplateConfig` to properly resolve imports.
@@ -173,6 +175,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class ZoomEve
173
175
  #include "KeepType.hpp"
174
176
  #include "LaneGuidance.hpp"
175
177
  #include "ListTemplateConfig.hpp"
178
+ #include "Location.hpp"
176
179
  #include "ManeuverType.hpp"
177
180
  #include "MapTemplateConfig.hpp"
178
181
  #include "MessageTemplateConfig.hpp"
@@ -16,6 +16,8 @@ namespace ReactNativeAutoPlay { class HybridAutoPlaySpec_cxx; }
16
16
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class EventName; }
17
17
  // Forward declaration of `VisibilityState` to properly resolve imports.
18
18
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class VisibilityState; }
19
+ // Forward declaration of `Location` to properly resolve imports.
20
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct Location; }
19
21
  // Forward declaration of `SafeAreaInsets` to properly resolve imports.
20
22
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct SafeAreaInsets; }
21
23
  // Forward declaration of `NitroAction` to properly resolve imports.
@@ -37,8 +39,9 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class NitroBu
37
39
  #include "EventName.hpp"
38
40
  #include <string>
39
41
  #include "VisibilityState.hpp"
40
- #include <NitroModules/Promise.hpp>
42
+ #include "Location.hpp"
41
43
  #include <optional>
44
+ #include <NitroModules/Promise.hpp>
42
45
  #include "SafeAreaInsets.hpp"
43
46
  #include "NitroAction.hpp"
44
47
  #include <vector>
@@ -110,6 +113,14 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
110
113
  auto __value = std::move(__result.value());
111
114
  return __value;
112
115
  }
116
+ inline std::function<void()> addListenerVoiceInput(const std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>& callback) override {
117
+ auto __result = _swiftPart.addListenerVoiceInput(callback);
118
+ if (__result.hasError()) [[unlikely]] {
119
+ std::rethrow_exception(__result.error());
120
+ }
121
+ auto __value = std::move(__result.value());
122
+ return __value;
123
+ }
113
124
  inline std::shared_ptr<Promise<void>> setRootTemplate(const std::string& templateId) override {
114
125
  auto __result = _swiftPart.setRootTemplate(templateId);
115
126
  if (__result.hasError()) [[unlikely]] {
@@ -0,0 +1,54 @@
1
+ ///
2
+ /// Func_void_std__optional_Location__std__optional_std__string_.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+
11
+ /**
12
+ * Wraps a Swift `(_ coordinates: Location?, _ query: String?) -> Void` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_void_std__optional_Location__std__optional_std__string_ {
16
+ public typealias bridge = margelo.nitro.swe.iternio.reactnativeautoplay.bridge.swift
17
+
18
+ private let closure: (_ coordinates: Location?, _ query: String?) -> Void
19
+
20
+ public init(_ closure: @escaping (_ coordinates: Location?, _ query: String?) -> Void) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(coordinates: bridge.std__optional_Location_, query: bridge.std__optional_std__string_) -> Void {
26
+ self.closure(coordinates.value, { () -> String? in
27
+ if bridge.has_value_std__optional_std__string_(query) {
28
+ let __unwrapped = bridge.get_std__optional_std__string_(query)
29
+ return String(__unwrapped)
30
+ } else {
31
+ return nil
32
+ }
33
+ }())
34
+ }
35
+
36
+ /**
37
+ * Casts this instance to a retained unsafe raw pointer.
38
+ * This acquires one additional strong reference on the object!
39
+ */
40
+ @inline(__always)
41
+ public func toUnsafe() -> UnsafeMutableRawPointer {
42
+ return Unmanaged.passRetained(self).toOpaque()
43
+ }
44
+
45
+ /**
46
+ * Casts an unsafe pointer to a `Func_void_std__optional_Location__std__optional_std__string_`.
47
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__optional_Location__std__optional_std__string_>`.
48
+ * This removes one strong reference from the object!
49
+ */
50
+ @inline(__always)
51
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__optional_Location__std__optional_std__string_ {
52
+ return Unmanaged<Func_void_std__optional_Location__std__optional_std__string_>.fromOpaque(pointer).takeRetainedValue()
53
+ }
54
+ }
@@ -17,6 +17,7 @@ public protocol HybridAutoPlaySpec_protocol: HybridObject {
17
17
  // Methods
18
18
  func addListener(eventType: EventName, callback: @escaping () -> Void) throws -> () -> Void
19
19
  func addListenerRenderState(moduleName: String, callback: @escaping (_ payload: VisibilityState) -> Void) throws -> () -> Void
20
+ func addListenerVoiceInput(callback: @escaping (_ coordinates: Location?, _ query: String?) -> Void) throws -> () -> Void
20
21
  func setRootTemplate(templateId: String) throws -> Promise<Void>
21
22
  func pushTemplate(templateId: String) throws -> Promise<Void>
22
23
  func popTemplate(animate: Bool?) throws -> Promise<Void>
@@ -158,6 +158,38 @@ open class HybridAutoPlaySpec_cxx {
158
158
  }
159
159
  }
160
160
 
161
+ @inline(__always)
162
+ public final func addListenerVoiceInput(callback: bridge.Func_void_std__optional_Location__std__optional_std__string_) -> bridge.Result_std__function_void____ {
163
+ do {
164
+ let __result = try self.__implementation.addListenerVoiceInput(callback: { () -> (Location?, String?) -> Void in
165
+ let __wrappedFunction = bridge.wrap_Func_void_std__optional_Location__std__optional_std__string_(callback)
166
+ return { (__coordinates: Location?, __query: String?) -> Void in
167
+ __wrappedFunction.call({ () -> bridge.std__optional_Location_ in
168
+ if let __unwrappedValue = __coordinates {
169
+ return bridge.create_std__optional_Location_(__unwrappedValue)
170
+ } else {
171
+ return .init()
172
+ }
173
+ }(), { () -> bridge.std__optional_std__string_ in
174
+ if let __unwrappedValue = __query {
175
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
176
+ } else {
177
+ return .init()
178
+ }
179
+ }())
180
+ }
181
+ }())
182
+ let __resultCpp = { () -> bridge.Func_void in
183
+ let __closureWrapper = Func_void(__result)
184
+ return bridge.create_Func_void(__closureWrapper.toUnsafe())
185
+ }()
186
+ return bridge.create_Result_std__function_void____(__resultCpp)
187
+ } catch (let __error) {
188
+ let __exceptionPtr = __error.toCpp()
189
+ return bridge.create_Result_std__function_void____(__exceptionPtr)
190
+ }
191
+ }
192
+
161
193
  @inline(__always)
162
194
  public final func setRootTemplate(templateId: std.string) -> bridge.Result_std__shared_ptr_Promise_void___ {
163
195
  do {
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Location.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `Location`, backed by a C++ struct.
12
+ */
13
+ public typealias Location = margelo.nitro.swe.iternio.reactnativeautoplay.Location
14
+
15
+ public extension Location {
16
+ private typealias bridge = margelo.nitro.swe.iternio.reactnativeautoplay.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `Location`.
20
+ */
21
+ init(lat: Double, lon: Double) {
22
+ self.init(lat, lon)
23
+ }
24
+
25
+ var lat: Double {
26
+ @inline(__always)
27
+ get {
28
+ return self.__lat
29
+ }
30
+ @inline(__always)
31
+ set {
32
+ self.__lat = newValue
33
+ }
34
+ }
35
+
36
+ var lon: Double {
37
+ @inline(__always)
38
+ get {
39
+ return self.__lon
40
+ }
41
+ @inline(__always)
42
+ set {
43
+ self.__lon = newValue
44
+ }
45
+ }
46
+ }
@@ -16,6 +16,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
16
16
  registerHybrids(this, [](Prototype& prototype) {
17
17
  prototype.registerHybridMethod("addListener", &HybridAutoPlaySpec::addListener);
18
18
  prototype.registerHybridMethod("addListenerRenderState", &HybridAutoPlaySpec::addListenerRenderState);
19
+ prototype.registerHybridMethod("addListenerVoiceInput", &HybridAutoPlaySpec::addListenerVoiceInput);
19
20
  prototype.registerHybridMethod("setRootTemplate", &HybridAutoPlaySpec::setRootTemplate);
20
21
  prototype.registerHybridMethod("pushTemplate", &HybridAutoPlaySpec::pushTemplate);
21
22
  prototype.registerHybridMethod("popTemplate", &HybridAutoPlaySpec::popTemplate);
@@ -17,6 +17,8 @@
17
17
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class EventName; }
18
18
  // Forward declaration of `VisibilityState` to properly resolve imports.
19
19
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { enum class VisibilityState; }
20
+ // Forward declaration of `Location` to properly resolve imports.
21
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct Location; }
20
22
  // Forward declaration of `SafeAreaInsets` to properly resolve imports.
21
23
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct SafeAreaInsets; }
22
24
  // Forward declaration of `NitroAction` to properly resolve imports.
@@ -26,8 +28,9 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct NitroAction
26
28
  #include "EventName.hpp"
27
29
  #include <string>
28
30
  #include "VisibilityState.hpp"
29
- #include <NitroModules/Promise.hpp>
31
+ #include "Location.hpp"
30
32
  #include <optional>
33
+ #include <NitroModules/Promise.hpp>
31
34
  #include "SafeAreaInsets.hpp"
32
35
  #include "NitroAction.hpp"
33
36
  #include <vector>
@@ -65,6 +68,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
65
68
  // Methods
66
69
  virtual std::function<void()> addListener(EventName eventType, const std::function<void()>& callback) = 0;
67
70
  virtual std::function<void()> addListenerRenderState(const std::string& moduleName, const std::function<void(VisibilityState /* payload */)>& callback) = 0;
71
+ virtual std::function<void()> addListenerVoiceInput(const std::function<void(const std::optional<Location>& /* coordinates */, const std::optional<std::string>& /* query */)>& callback) = 0;
68
72
  virtual std::shared_ptr<Promise<void>> setRootTemplate(const std::string& templateId) = 0;
69
73
  virtual std::shared_ptr<Promise<void>> pushTemplate(const std::string& templateId) = 0;
70
74
  virtual std::shared_ptr<Promise<void>> popTemplate(std::optional<bool> animate) = 0;
@@ -0,0 +1,79 @@
1
+ ///
2
+ /// Location.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 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
+
26
+
27
+
28
+
29
+
30
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
31
+
32
+ /**
33
+ * A struct which can be represented as a JavaScript object (Location).
34
+ */
35
+ struct Location {
36
+ public:
37
+ double lat SWIFT_PRIVATE;
38
+ double lon SWIFT_PRIVATE;
39
+
40
+ public:
41
+ Location() = default;
42
+ explicit Location(double lat, double lon): lat(lat), lon(lon) {}
43
+ };
44
+
45
+ } // namespace margelo::nitro::swe::iternio::reactnativeautoplay
46
+
47
+ namespace margelo::nitro {
48
+
49
+ // C++ Location <> JS Location (object)
50
+ template <>
51
+ struct JSIConverter<margelo::nitro::swe::iternio::reactnativeautoplay::Location> final {
52
+ static inline margelo::nitro::swe::iternio::reactnativeautoplay::Location fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
53
+ jsi::Object obj = arg.asObject(runtime);
54
+ return margelo::nitro::swe::iternio::reactnativeautoplay::Location(
55
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "lat")),
56
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "lon"))
57
+ );
58
+ }
59
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::swe::iternio::reactnativeautoplay::Location& arg) {
60
+ jsi::Object obj(runtime);
61
+ obj.setProperty(runtime, "lat", JSIConverter<double>::toJSI(runtime, arg.lat));
62
+ obj.setProperty(runtime, "lon", JSIConverter<double>::toJSI(runtime, arg.lon));
63
+ return obj;
64
+ }
65
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
66
+ if (!value.isObject()) {
67
+ return false;
68
+ }
69
+ jsi::Object obj = value.getObject(runtime);
70
+ if (!nitro::isPlainObject(runtime, obj)) {
71
+ return false;
72
+ }
73
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "lat"))) return false;
74
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "lon"))) return false;
75
+ return true;
76
+ }
77
+ };
78
+
79
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iternio/react-native-auto-play",
3
- "version": "0.0.11",
3
+ "version": "0.1.0",
4
4
  "description": "Android Auto and Apple CarPlay for react-native",
5
5
  "main": "lib/index",
6
6
  "module": "lib/index",
@@ -0,0 +1,54 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { HybridAutoPlay, type Location } from '..';
3
+
4
+ export const useVoiceInput = () => {
5
+ const [isConnected, setIsConnected] = useState(false);
6
+ const [voiceInputResult, setVoiceInputResult] = useState<
7
+ | {
8
+ coordinates: Location | undefined;
9
+ query: string | undefined;
10
+ }
11
+ | undefined
12
+ >();
13
+
14
+ /**
15
+ * Resets the voice input result to undefined. This is useful when you want to clear the voice input result after processing it.
16
+ */
17
+ const resetVoiceInputResult = useCallback(() => {
18
+ setVoiceInputResult(undefined);
19
+ }, []);
20
+
21
+ useEffect(() => {
22
+ const removeDidConnect = HybridAutoPlay.addListener('didConnect', () => setIsConnected(true));
23
+ const removeDidDisconnect = HybridAutoPlay.addListener('didDisconnect', () =>
24
+ setIsConnected(false)
25
+ );
26
+
27
+ setIsConnected(HybridAutoPlay.isConnected());
28
+
29
+ return () => {
30
+ removeDidConnect();
31
+ removeDidDisconnect();
32
+ };
33
+ }, []);
34
+
35
+ useEffect(() => {
36
+ if (!isConnected) {
37
+ return;
38
+ }
39
+
40
+ const remove = HybridAutoPlay.addListenerVoiceInput((coordinates, query) => {
41
+ if (coordinates || query) {
42
+ setVoiceInputResult({ coordinates, query });
43
+ } else {
44
+ setVoiceInputResult(undefined);
45
+ }
46
+ });
47
+
48
+ return () => {
49
+ remove();
50
+ };
51
+ }, [isConnected]);
52
+
53
+ return { voiceInputResult, resetVoiceInputResult };
54
+ };
package/src/index.ts CHANGED
@@ -27,6 +27,7 @@ export * from './components/SafeAreaView';
27
27
  export * from './hooks/useAndroidAutoTelemetry';
28
28
  export * from './hooks/useMapTemplate';
29
29
  export * from './hooks/useSafeAreaInsets';
30
+ export * from './hooks/useVoiceInput';
30
31
  export * from './scenes/AutoPlayCluster';
31
32
  export * from './scenes/CarPlayDashboardScene';
32
33
  export * from './templates/GridTemplate';
@@ -1,6 +1,12 @@
1
1
  import type { HybridObject } from 'react-native-nitro-modules';
2
2
  import type { TemplateConfig } from '../templates/Template';
3
- import type { CleanupCallback, EventName, SafeAreaInsets, VisibilityState } from '../types/Event';
3
+ import type {
4
+ CleanupCallback,
5
+ EventName,
6
+ Location,
7
+ SafeAreaInsets,
8
+ VisibilityState,
9
+ } from '../types/Event';
4
10
  import type { NitroAction } from '../utils/NitroAction';
5
11
 
6
12
  export interface NitroTemplateConfig extends TemplateConfig {
@@ -27,6 +33,16 @@ export interface AutoPlay extends HybridObject<{ android: 'kotlin'; ios: 'swift'
27
33
  callback: (payload: VisibilityState) => void
28
34
  ): CleanupCallback;
29
35
 
36
+ /**
37
+ * Adds a listener for voice input events. Not implemented on iOS.
38
+ * @param callback the callback to receive the voice input
39
+ * @returns callback to remove the listener
40
+ * @namespace Android
41
+ */
42
+ addListenerVoiceInput(
43
+ callback: (coordinates: Location | undefined, query: string | undefined) => void
44
+ ): CleanupCallback;
45
+
30
46
  /**
31
47
  * sets the specified template as root template, initializes a new stack
32
48
  * Promise might contain an error message in case setting root template failed
@@ -12,3 +12,7 @@ export type SafeAreaInsets = {
12
12
  */
13
13
  isLegacyLayout?: boolean;
14
14
  };
15
+ export interface Location {
16
+ lat: number;
17
+ lon: number;
18
+ }
@@ -1,29 +0,0 @@
1
- //
2
- // RootView.h
3
- // Pods
4
- //
5
- // Created by Manuel Auer on 07.11.25.
6
- //
7
-
8
- // this is required for old architecture support since the React pod can not be imported
9
-
10
- #ifdef RCT_NEW_ARCH_ENABLED
11
-
12
- #else
13
-
14
- #import <Foundation/Foundation.h>
15
-
16
- @protocol RCTInvalidating <NSObject>
17
-
18
- - (void)invalidate;
19
-
20
- @end
21
-
22
- @interface RCTRootView : UIView
23
- /**
24
- * The React-managed contents view of the root view.
25
- */
26
- @property(nonatomic, strong, readonly) UIView *contentView;
27
- @end
28
-
29
- #endif