@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.
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/AndroidAutoSession.kt +59 -1
- package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt +19 -0
- package/ios/hybrid/HybridAutoPlay.swift +7 -0
- package/lib/hooks/useVoiceInput.d.ts +8 -0
- package/lib/hooks/useVoiceInput.js +38 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/specs/AutoPlay.nitro.d.ts +8 -1
- package/lib/specs/VoiceInput.nitro.d.ts +8 -0
- package/lib/types/Event.d.ts +4 -0
- package/nitrogen/generated/android/ReactNativeAutoPlayOnLoad.cpp +2 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__optional_Location__std__optional_std__string_.hpp +78 -0
- package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.cpp +20 -0
- package/nitrogen/generated/android/c++/JHybridAutoPlaySpec.hpp +1 -0
- package/nitrogen/generated/android/c++/JLocation.hpp +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Func_void_std__optional_Location__std__optional_std__string_.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlaySpec.kt +9 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/Location.kt +41 -0
- package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Bridge.hpp +55 -15
- package/nitrogen/generated/ios/ReactNativeAutoPlay-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridAutoPlaySpecSwift.hpp +12 -1
- package/nitrogen/generated/ios/swift/Func_void_std__optional_Location__std__optional_std__string_.swift +54 -0
- package/nitrogen/generated/ios/swift/HybridAutoPlaySpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridAutoPlaySpec_cxx.swift +32 -0
- package/nitrogen/generated/ios/swift/Location.swift +46 -0
- package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridAutoPlaySpec.hpp +5 -1
- package/nitrogen/generated/shared/c++/Location.hpp +79 -0
- package/package.json +1 -1
- package/src/hooks/useVoiceInput.ts +54 -0
- package/src/index.ts +1 -0
- package/src/specs/AutoPlay.nitro.ts +17 -1
- package/src/types/Event.ts +4 -0
- package/lib/specs/HybridAndroidAutoTelemetry.nitro.d.ts +0 -15
- package/lib/specs/HybridAutoPlay.nitro.d.ts +0 -64
- package/lib/specs/HybridAutoPlay.nitro.js +0 -1
- package/lib/specs/HybridCarPlayDashboard.nitro.d.ts +0 -22
- package/lib/specs/HybridCarPlayDashboard.nitro.js +0 -1
- package/lib/specs/HybridCluster.nitro.d.ts +0 -19
- package/lib/specs/HybridCluster.nitro.js +0 -1
- package/lib/specs/HybridGridTemplate.nitro.d.ts +0 -14
- package/lib/specs/HybridGridTemplate.nitro.js +0 -1
- package/lib/specs/HybridInformationTemplate.nitro.d.ts +0 -13
- package/lib/specs/HybridInformationTemplate.nitro.js +0 -1
- package/lib/specs/HybridListTemplate.nitro.d.ts +0 -13
- package/lib/specs/HybridListTemplate.nitro.js +0 -1
- package/lib/specs/HybridMapTemplate.nitro.d.ts +0 -25
- package/lib/specs/HybridMapTemplate.nitro.js +0 -1
- package/lib/specs/HybridMessageTemplate.nitro.d.ts +0 -12
- package/lib/specs/HybridMessageTemplate.nitro.js +0 -1
- package/lib/specs/HybridSearchTemplate.nitro.d.ts +0 -13
- package/lib/specs/HybridSearchTemplate.nitro.js +0 -1
- package/lib/types/GestureEvents.d.ts +0 -37
- package/lib/types/GestureEvents.js +0 -1
- /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
|
|
262
|
+
return sessions[marker]?.carContext
|
|
205
263
|
}
|
|
206
264
|
|
|
207
265
|
fun getRootContext(): CarContext? {
|
package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/HybridAutoPlay.kt
CHANGED
|
@@ -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,
|
|
@@ -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 {
|
|
@@ -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
|
+
}
|
package/lib/types/Event.d.ts
CHANGED
|
@@ -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);
|