@iternio/react-native-auto-play 0.0.11 → 0.0.12

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 (56) 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/hybrid/HybridAutoPlay.swift +7 -0
  4. package/lib/hooks/useVoiceInput.d.ts +8 -0
  5. package/lib/hooks/useVoiceInput.js +38 -0
  6. package/lib/index.d.ts +1 -0
  7. package/lib/index.js +1 -0
  8. package/lib/specs/AutoPlay.nitro.d.ts +8 -1
  9. package/lib/specs/VoiceInput.nitro.d.ts +8 -0
  10. package/lib/types/Event.d.ts +4 -0
  11. package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +2 -0
  12. package/nitrogen/generated/android/c++/JFunc_void_std__optional_Location__std__optional_std__string_.hpp +78 -0
  13. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.cpp +20 -0
  14. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.hpp +1 -0
  15. package/nitrogen/generated/android/c++/JLocation.hpp +61 -0
  16. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_std__optional_Location__std__optional_std__string_.kt +80 -0
  17. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlaySpec.kt +9 -0
  18. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Location.kt +41 -0
  19. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.cpp +8 -0
  20. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.hpp +55 -15
  21. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Umbrella.hpp +3 -0
  22. package/nitrogen/generated/ios/c++/HybridAutoPlaySpecSwift.hpp +12 -1
  23. package/nitrogen/generated/ios/swift/Func_void_std__optional_Location__std__optional_std__string_.swift +54 -0
  24. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec.swift +1 -0
  25. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec_cxx.swift +32 -0
  26. package/nitrogen/generated/ios/swift/Location.swift +46 -0
  27. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.cpp +1 -0
  28. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.hpp +5 -1
  29. package/nitrogen/generated/shared/c++/Location.hpp +79 -0
  30. package/package.json +1 -1
  31. package/src/hooks/useVoiceInput.ts +54 -0
  32. package/src/index.ts +1 -0
  33. package/src/specs/AutoPlay.nitro.ts +17 -1
  34. package/src/types/Event.ts +4 -0
  35. package/lib/specs/HybridAndroidAutoTelemetry.nitro.d.ts +0 -15
  36. package/lib/specs/HybridAutoPlay.nitro.d.ts +0 -64
  37. package/lib/specs/HybridAutoPlay.nitro.js +0 -1
  38. package/lib/specs/HybridCarPlayDashboard.nitro.d.ts +0 -22
  39. package/lib/specs/HybridCarPlayDashboard.nitro.js +0 -1
  40. package/lib/specs/HybridCluster.nitro.d.ts +0 -19
  41. package/lib/specs/HybridCluster.nitro.js +0 -1
  42. package/lib/specs/HybridGridTemplate.nitro.d.ts +0 -14
  43. package/lib/specs/HybridGridTemplate.nitro.js +0 -1
  44. package/lib/specs/HybridInformationTemplate.nitro.d.ts +0 -13
  45. package/lib/specs/HybridInformationTemplate.nitro.js +0 -1
  46. package/lib/specs/HybridListTemplate.nitro.d.ts +0 -13
  47. package/lib/specs/HybridListTemplate.nitro.js +0 -1
  48. package/lib/specs/HybridMapTemplate.nitro.d.ts +0 -25
  49. package/lib/specs/HybridMapTemplate.nitro.js +0 -1
  50. package/lib/specs/HybridMessageTemplate.nitro.d.ts +0 -12
  51. package/lib/specs/HybridMessageTemplate.nitro.js +0 -1
  52. package/lib/specs/HybridSearchTemplate.nitro.d.ts +0 -13
  53. package/lib/specs/HybridSearchTemplate.nitro.js +0 -1
  54. package/lib/types/GestureEvents.d.ts +0 -37
  55. package/lib/types/GestureEvents.js +0 -1
  56. /package/lib/specs/{HybridAndroidAutoTelemetry.nitro.js → VoiceInput.nitro.js} +0 -0
@@ -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.0.12",
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,15 +0,0 @@
1
- import type { HybridObject } from 'react-native-nitro-modules';
2
- import type { CleanupCallback } from '../types/Event';
3
- import type { Telemetry } from '../types/Telemetry';
4
- export interface HybridAndroidAutoTelemetry extends HybridObject<{
5
- android: 'kotlin';
6
- }> {
7
- /**
8
- * Register a listener for Android Auto telemetry data. Should be registered only after the telemetry permissions are granted otherwise no data will be received.
9
- * @param callback the callback to receive the telemetry data
10
- * @param error the error message if the telemetry listener failed to start
11
- * @returns callback to remove the listener
12
- * @namespace Android
13
- */
14
- registerTelemetryListener(callback: (tlm?: Telemetry, error?: string) => void): CleanupCallback;
15
- }
@@ -1,64 +0,0 @@
1
- import type { HybridObject } from 'react-native-nitro-modules';
2
- import type { TemplateConfig } from '../templates/Template';
3
- import type { CleanupCallback, EventName, SafeAreaInsets, VisibilityState } from '../types/Event';
4
- import type { NitroAction } from '../utils/NitroAction';
5
- export interface NitroTemplateConfig extends TemplateConfig {
6
- id: string;
7
- }
8
- export interface HybridAutoPlay extends HybridObject<{
9
- android: 'kotlin';
10
- ios: 'swift';
11
- }> {
12
- /**
13
- * attach a listener for didConnect and didDisconnect
14
- * @namespace all
15
- * @param eventType generic events
16
- * @returns callback to remove the listener
17
- */
18
- addListener(eventType: EventName, callback: () => void): CleanupCallback;
19
- /**
20
- * adds a listener for the session/scene state
21
- * fires willAppear & didAppear when the scene/session is visible
22
- * fires willDisappear & didDisappear when the scene/session is not visible
23
- * @param moduleName on of @AutoPlayModules, a cluster scene uuid or your main for the WindowApplicationSceneDelegate
24
- */
25
- addListenerRenderState(moduleName: string, callback: (payload: VisibilityState) => void): CleanupCallback;
26
- /**
27
- * sets the specified template as root template, initializes a new stack
28
- * Promise might contain an error message in case setting root template failed
29
- * can be used on any Android screen/iOS scene
30
- */
31
- setRootTemplate(templateId: string): Promise<void>;
32
- /**
33
- * push a template to the AutoPlayRoot Android screen/iOS scene
34
- */
35
- pushTemplate(templateId: string): Promise<void>;
36
- /**
37
- * remove the top template from the stack
38
- * @param animate - defaults to true
39
- */
40
- popTemplate(animate?: boolean): Promise<void>;
41
- /**
42
- * remove all templates from the stack except the root template
43
- * @param animate - defaults to true
44
- */
45
- popToRootTemplate(animate?: boolean): Promise<void>;
46
- /**
47
- * removes all templates until the specified one is the top template
48
- */
49
- popToTemplate(templateId: string, animate?: boolean): Promise<void>;
50
- /**
51
- * callback for safe area insets changes
52
- * @param insets the insets that you use to determine the safe area for this view.
53
- */
54
- addSafeAreaInsetsListener(moduleName: string, callback: (insets: SafeAreaInsets) => void): CleanupCallback;
55
- /**
56
- * update a templates headerActions
57
- */
58
- setTemplateHeaderActions(templateId: string, headerActions?: Array<NitroAction>): void;
59
- /**
60
- * Check if AutoPlay is connected.
61
- * @returns true if AutoPlay is connected, false otherwise.
62
- */
63
- isConnected(): boolean;
64
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
1
- import type { HybridObject } from 'react-native-nitro-modules';
2
- import type { CleanupCallback, EventName } from '../types/Event';
3
- import type { ColorScheme } from '../types/RootComponent';
4
- import type { NitroImage } from '../utils/NitroImage';
5
- export interface BaseCarPlayDashboardButton {
6
- titleVariants: Array<string>;
7
- subtitleVariants: Array<string>;
8
- onPress: () => void;
9
- launchHeadUnitScene?: boolean;
10
- }
11
- interface NitroCarPlayDashboardButton extends BaseCarPlayDashboardButton {
12
- image: NitroImage;
13
- }
14
- export interface HybridCarPlayDashboard extends HybridObject<{
15
- ios: 'swift';
16
- }> {
17
- addListener(eventType: EventName, callback: () => void): CleanupCallback;
18
- setButtons(buttons: Array<NitroCarPlayDashboardButton>): Promise<void>;
19
- initRootView(): void;
20
- addListenerColorScheme(callback: (payload: ColorScheme) => void): CleanupCallback;
21
- }
22
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,19 +0,0 @@
1
- import type { HybridObject } from 'react-native-nitro-modules';
2
- import type { CleanupCallback } from '../types/Event';
3
- import type { ColorScheme } from '../types/RootComponent';
4
- import type { NitroAttributedString } from '../utils/NitroAttributedString';
5
- type ClusterEventName = 'didConnect' | 'didConnectWithWindow' | 'didDisconnect' | 'didDisconnectFromWindow';
6
- export type ZoomEvent = 'in' | 'out';
7
- export interface HybridCluster extends HybridObject<{
8
- android: 'kotlin';
9
- ios: 'swift';
10
- }> {
11
- addListener(eventType: ClusterEventName, callback: (clusterId: string) => void): CleanupCallback;
12
- initRootView(clusterId: string): Promise<void>;
13
- setAttributedInactiveDescriptionVariants(clusterId: string, attributedInactiveDescriptionVariants: Array<NitroAttributedString>): void;
14
- addListenerColorScheme(callback: (clusterId: string, payload: ColorScheme) => void): CleanupCallback;
15
- addListenerZoom(callback: (clusterId: string, payload: ZoomEvent) => void): CleanupCallback;
16
- addListenerCompass(callback: (clusterId: string, payload: boolean) => void): CleanupCallback;
17
- addListenerSpeedLimit(callback: (clusterId: string, payload: boolean) => void): CleanupCallback;
18
- }
19
- export {};