@iternio/react-native-auto-play 0.0.10 → 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 (79) 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/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/MapTemplate.kt +10 -6
  4. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/Parser.kt +3 -0
  5. package/ios/hybrid/HybridAutoPlay.swift +7 -0
  6. package/ios/hybrid/HybridMapTemplate.swift +8 -1
  7. package/ios/templates/MapTemplate.swift +8 -7
  8. package/lib/hooks/useVoiceInput.d.ts +8 -0
  9. package/lib/hooks/useVoiceInput.js +38 -0
  10. package/lib/index.d.ts +1 -0
  11. package/lib/index.js +1 -0
  12. package/lib/specs/AutoPlay.nitro.d.ts +8 -1
  13. package/lib/specs/VoiceInput.nitro.d.ts +8 -0
  14. package/lib/templates/MapTemplate.js +4 -0
  15. package/lib/types/Event.d.ts +4 -0
  16. package/lib/types/Maneuver.d.ts +5 -2
  17. package/lib/utils/NitroManeuver.d.ts +4 -1
  18. package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +2 -0
  19. package/nitrogen/generated/android/c++/JFunc_void_std__optional_Location__std__optional_std__string_.hpp +78 -0
  20. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.cpp +20 -0
  21. package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.hpp +1 -0
  22. package/nitrogen/generated/android/c++/JHybridMapTemplateSpec.cpp +5 -1
  23. package/nitrogen/generated/android/c++/JHybridMapTemplateSpec.hpp +1 -1
  24. package/nitrogen/generated/android/c++/JLocation.hpp +61 -0
  25. package/nitrogen/generated/android/c++/JNitroLoadingManeuver.hpp +57 -0
  26. package/nitrogen/generated/android/c++/JNitroManeuver.cpp +6 -2
  27. package/nitrogen/generated/android/c++/JNitroManeuver.hpp +19 -2
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_std__optional_Location__std__optional_std__string_.kt +80 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlaySpec.kt +9 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Location.kt +41 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/NitroLoadingManeuver.kt +38 -0
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/NitroManeuver.kt +15 -2
  33. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.cpp +8 -0
  34. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.hpp +74 -25
  35. package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Umbrella.hpp +6 -0
  36. package/nitrogen/generated/ios/c++/HybridAutoPlaySpecSwift.hpp +12 -1
  37. package/nitrogen/generated/ios/c++/HybridMapTemplateSpecSwift.hpp +4 -1
  38. package/nitrogen/generated/ios/swift/Func_void_std__optional_Location__std__optional_std__string_.swift +54 -0
  39. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec.swift +1 -0
  40. package/nitrogen/generated/ios/swift/HybridAutoPlaySpec_cxx.swift +32 -0
  41. package/nitrogen/generated/ios/swift/HybridMapTemplateSpec_cxx.swift +4 -1
  42. package/nitrogen/generated/ios/swift/Location.swift +46 -0
  43. package/nitrogen/generated/ios/swift/NitroLoadingManeuver.swift +35 -0
  44. package/nitrogen/generated/ios/swift/NitroManeuver.swift +2 -1
  45. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.cpp +1 -0
  46. package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.hpp +5 -1
  47. package/nitrogen/generated/shared/c++/HybridMapTemplateSpec.hpp +4 -1
  48. package/nitrogen/generated/shared/c++/Location.hpp +79 -0
  49. package/nitrogen/generated/shared/c++/NitroLoadingManeuver.hpp +75 -0
  50. package/package.json +1 -1
  51. package/src/hooks/useVoiceInput.ts +54 -0
  52. package/src/index.ts +1 -0
  53. package/src/specs/AutoPlay.nitro.ts +17 -1
  54. package/src/templates/MapTemplate.ts +5 -0
  55. package/src/types/Event.ts +4 -0
  56. package/src/types/Maneuver.ts +8 -1
  57. package/src/utils/NitroManeuver.ts +8 -1
  58. package/lib/specs/HybridAndroidAutoTelemetry.nitro.d.ts +0 -15
  59. package/lib/specs/HybridAutoPlay.nitro.d.ts +0 -64
  60. package/lib/specs/HybridAutoPlay.nitro.js +0 -1
  61. package/lib/specs/HybridCarPlayDashboard.nitro.d.ts +0 -22
  62. package/lib/specs/HybridCarPlayDashboard.nitro.js +0 -1
  63. package/lib/specs/HybridCluster.nitro.d.ts +0 -19
  64. package/lib/specs/HybridCluster.nitro.js +0 -1
  65. package/lib/specs/HybridGridTemplate.nitro.d.ts +0 -14
  66. package/lib/specs/HybridGridTemplate.nitro.js +0 -1
  67. package/lib/specs/HybridInformationTemplate.nitro.d.ts +0 -13
  68. package/lib/specs/HybridInformationTemplate.nitro.js +0 -1
  69. package/lib/specs/HybridListTemplate.nitro.d.ts +0 -13
  70. package/lib/specs/HybridListTemplate.nitro.js +0 -1
  71. package/lib/specs/HybridMapTemplate.nitro.d.ts +0 -25
  72. package/lib/specs/HybridMapTemplate.nitro.js +0 -1
  73. package/lib/specs/HybridMessageTemplate.nitro.d.ts +0 -12
  74. package/lib/specs/HybridMessageTemplate.nitro.js +0 -1
  75. package/lib/specs/HybridSearchTemplate.nitro.d.ts +0 -13
  76. package/lib/specs/HybridSearchTemplate.nitro.js +0 -1
  77. package/lib/types/GestureEvents.d.ts +0 -37
  78. package/lib/types/GestureEvents.js +0 -1
  79. /package/lib/specs/{HybridAndroidAutoTelemetry.nitro.js → VoiceInput.nitro.js} +0 -0
@@ -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,
@@ -86,10 +86,6 @@ class MapTemplate(
86
86
  if (isNavigating) {
87
87
  navigationInfo?.let {
88
88
  setNavigationInfo(it)
89
- } ?: run {
90
- setNavigationInfo(RoutingInfo.Builder().apply {
91
- setLoading(true)
92
- }.build())
93
89
  }
94
90
  }
95
91
  config.onDidChangePanningInterface?.let {
@@ -309,13 +305,19 @@ class MapTemplate(
309
305
 
310
306
  val routingInfo = maneuvers.asFirstOrNull()
311
307
  val messageInfo = maneuvers.asSecondOrNull()
308
+ val loadingInfo = maneuvers.asThirdOrNull()
312
309
 
313
- if (routingInfo.isNullOrEmpty() && messageInfo == null) {
310
+ if (routingInfo.isNullOrEmpty() && messageInfo == null && loadingInfo == null) {
314
311
  navigationInfo = null
315
312
  AndroidAutoScreen.invalidateSurfaceScreens()
316
313
  return
317
314
  }
318
315
 
316
+ if (loadingInfo != null) {
317
+ navigationInfo = RoutingInfo.Builder().setLoading(true).build()
318
+ return
319
+ }
320
+
319
321
  if (messageInfo != null) {
320
322
  val backgroundColor =
321
323
  if (context.isDarkMode) messageInfo.cardBackgroundColor.darkColor else messageInfo.cardBackgroundColor.lightColor
@@ -359,7 +361,9 @@ class MapTemplate(
359
361
 
360
362
  val notificationText = currentStep.cue?.toString()
361
363
 
362
- val notificationTitle = "${currentDistance.displayDistance.toInt()} ${Parser.parseDistanceUnit(currentDistance.displayUnit)}"
364
+ val notificationTitle = "${currentDistance.displayDistance.toInt()} ${
365
+ Parser.parseDistanceUnit(currentDistance.displayUnit)
366
+ }"
363
367
 
364
368
  it.notify(
365
369
  notificationTitle, notificationText, notificationIcon
@@ -670,6 +670,9 @@ object Parser {
670
670
  setManeuver(parseManeuver(context, nitroManeuver))
671
671
  nitroManeuver.linkedLaneGuidance?.let { laneGuidance ->
672
672
  val lanes = laneGuidance.lanes.mapNotNull { it.asFirstOrNull() }
673
+ if (lanes.isEmpty()) {
674
+ return@let
675
+ }
673
676
  lanes.forEach { lane ->
674
677
  addLane(Lane.Builder().apply {
675
678
  addDirection(
@@ -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 {
@@ -29,7 +29,7 @@ class HybridMapTemplate: HybridMapTemplateSpec {
29
29
  "\(templateId) is not a MapTemplate"
30
30
  )
31
31
  }
32
-
32
+
33
33
  await MainActor.run {
34
34
  template.config.mapButtons = buttons
35
35
  template.invalidate()
@@ -141,6 +141,13 @@ class HybridMapTemplate: HybridMapTemplateSpec {
141
141
  {
142
142
  template.updateManeuvers(messageManeuver: messageManeuver)
143
143
  }()
144
+ case .third(let loadingManeuver):
145
+ {
146
+ template.navigationSession?.pauseTrip(
147
+ for: .loading,
148
+ description: nil
149
+ )
150
+ }()
144
151
  }
145
152
 
146
153
  }
@@ -182,9 +182,7 @@ class MapTemplate: NSObject, AutoPlayTemplate, AutoPlayHeaderProviding,
182
182
 
183
183
  template.tripEstimateStyle = isDark ? .dark : .light
184
184
 
185
- DispatchQueue.main.async {
186
- self.invalidate()
187
- }
185
+ invalidate()
188
186
  }
189
187
 
190
188
  // MARK: gestures
@@ -502,9 +500,7 @@ class MapTemplate: NSObject, AutoPlayTemplate, AutoPlayHeaderProviding,
502
500
  onTripSelected = nil
503
501
  onTripStarted = nil
504
502
 
505
- DispatchQueue.main.async {
506
- self.invalidate()
507
- }
503
+ invalidate()
508
504
  }
509
505
 
510
506
  func mapTemplate(
@@ -616,11 +612,16 @@ class MapTemplate: NSObject, AutoPlayTemplate, AutoPlayHeaderProviding,
616
612
  func updateManeuvers(maneuvers: [NitroRoutingManeuver]) {
617
613
  guard let navigationSession = navigationSession else { return }
618
614
 
615
+ if maneuvers.isEmpty {
616
+ navigationSession.upcomingManeuvers = []
617
+ return
618
+ }
619
+
619
620
  if #unavailable(iOS 15.4),
620
621
  let color = maneuvers.first?.cardBackgroundColor
621
622
  {
622
623
  // before iOS 15.4 the color had to be set on the template
623
- // later on the maneuer which Parser.parseManeuver does
624
+ // later on the maneuver which Parser.parseManeuver does
624
625
  template.guidanceBackgroundColor = Parser.parseColor(color: color)
625
626
  }
626
627
 
@@ -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
@@ -0,0 +1,8 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+ import type { CleanupCallback } from '../types/Event';
3
+ export interface VoiceInput extends HybridObject<{
4
+ android: 'kotlin';
5
+ ios: 'swift';
6
+ }> {
7
+ registerVoiceInputListener(callback: (voiceInputResult?: string, error?: string) => void): CleanupCallback;
8
+ }
@@ -105,6 +105,10 @@ export class MapTemplate extends Template {
105
105
  HybridMapTemplate.updateManeuvers(this.id, nitroManeuvers);
106
106
  return;
107
107
  }
108
+ if (maneuvers.type === 'loading') {
109
+ HybridMapTemplate.updateManeuvers(this.id, { isLoading: true });
110
+ return;
111
+ }
108
112
  const messageManeuver = NitroManeuverUtil.convert(maneuvers);
109
113
  HybridMapTemplate.updateManeuvers(this.id, messageManeuver);
110
114
  }
@@ -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
+ }
@@ -196,7 +196,10 @@ export type MessageManeuver = {
196
196
  cardBackgroundColor: ThemedColor | string;
197
197
  type: 'message';
198
198
  };
199
+ export type LoadingManeuver = {
200
+ type: 'loading';
201
+ };
199
202
  export type AutoManeuver = (Array<RoutingManeuver> & {
200
- length: 1 | 2;
201
- }) | MessageManeuver;
203
+ length: 0 | 1 | 2;
204
+ }) | MessageManeuver | LoadingManeuver;
202
205
  export {};
@@ -33,7 +33,10 @@ export interface NitroMessageManeuver {
33
33
  image?: NitroImage;
34
34
  cardBackgroundColor: NitroColor;
35
35
  }
36
- export type NitroManeuver = Array<NitroRoutingManeuver> | NitroMessageManeuver;
36
+ interface NitroLoadingManeuver {
37
+ isLoading: true;
38
+ }
39
+ export type NitroManeuver = Array<NitroRoutingManeuver> | NitroMessageManeuver | NitroLoadingManeuver;
37
40
  declare function convert(autoManeuver: MessageManeuver): NitroMessageManeuver;
38
41
  declare function convert(autoManeuver: RoutingManeuver): NitroRoutingManeuver;
39
42
  export declare const NitroManeuverUtil: {
@@ -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;
@@ -65,6 +65,8 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct TripPreview
65
65
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct NitroRoutingManeuver; }
66
66
  // Forward declaration of `NitroMessageManeuver` to properly resolve imports.
67
67
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct NitroMessageManeuver; }
68
+ // Forward declaration of `NitroLoadingManeuver` to properly resolve imports.
69
+ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct NitroLoadingManeuver; }
68
70
  // Forward declaration of `NitroAttributedString` to properly resolve imports.
69
71
  namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct NitroAttributedString; }
70
72
  // Forward declaration of `NitroAttributedStringImage` to properly resolve imports.
@@ -167,6 +169,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct TripConfig;
167
169
  #include "JFunc_void_std__string_std__string.hpp"
168
170
  #include "NitroRoutingManeuver.hpp"
169
171
  #include "NitroMessageManeuver.hpp"
172
+ #include "NitroLoadingManeuver.hpp"
170
173
  #include "JNitroManeuver.hpp"
171
174
  #include "JNitroRoutingManeuver.hpp"
172
175
  #include "NitroAttributedString.hpp"
@@ -195,6 +198,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay { struct TripConfig;
195
198
  #include "ManeuverType.hpp"
196
199
  #include "JManeuverType.hpp"
197
200
  #include "JNitroMessageManeuver.hpp"
201
+ #include "JNitroLoadingManeuver.hpp"
198
202
  #include "TripConfig.hpp"
199
203
  #include "JTripConfig.hpp"
200
204
 
@@ -314,7 +318,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
314
318
  return __array;
315
319
  }());
316
320
  }
317
- void JHybridMapTemplateSpec::updateManeuvers(const std::string& templateId, const std::variant<std::vector<NitroRoutingManeuver>, NitroMessageManeuver>& maneuvers) {
321
+ void JHybridMapTemplateSpec::updateManeuvers(const std::string& templateId, const std::variant<std::vector<NitroRoutingManeuver>, NitroMessageManeuver, NitroLoadingManeuver>& maneuvers) {
318
322
  static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JString> /* templateId */, jni::alias_ref<JNitroManeuver> /* maneuvers */)>("updateManeuvers");
319
323
  method(_javaPart, jni::make_jstring(templateId), JNitroManeuver::fromCpp(maneuvers));
320
324
  }
@@ -63,7 +63,7 @@ namespace margelo::nitro::swe::iternio::reactnativeautoplay {
63
63
  std::shared_ptr<Promise<void>> setTemplateMapButtons(const std::string& templateId, const std::optional<std::vector<NitroMapButton>>& buttons) override;
64
64
  void updateVisibleTravelEstimate(const std::string& templateId, VisibleTravelEstimate visibleTravelEstimate) override;
65
65
  void updateTravelEstimates(const std::string& templateId, const std::vector<TripPoint>& steps) override;
66
- void updateManeuvers(const std::string& templateId, const std::variant<std::vector<NitroRoutingManeuver>, NitroMessageManeuver>& maneuvers) override;
66
+ void updateManeuvers(const std::string& templateId, const std::variant<std::vector<NitroRoutingManeuver>, NitroMessageManeuver, NitroLoadingManeuver>& maneuvers) override;
67
67
  void startNavigation(const std::string& templateId, const TripConfig& trip) override;
68
68
  void stopNavigation(const std::string& templateId) override;
69
69
 
@@ -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