@mapzone/nav-speed-alert 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,135 @@
1
+ package expo.modules.navspeedalert
2
+
3
+ import android.graphics.Bitmap
4
+ import android.util.Base64
5
+ import com.vietmap.alert_view_sdk.AlertViewManager
6
+ import com.vietmap.alert_view_sdk.VoiceAlertType
7
+ import com.vietmap.alert_view_sdk.VoiceCallback
8
+ import expo.modules.kotlin.modules.Module
9
+ import expo.modules.kotlin.modules.ModuleDefinition
10
+
11
+ /**
12
+ * Expo Module wrapping the native `AlertViewManager`. Function order mirrors
13
+ * the native class and the Swift module so the three can be diffed side by side.
14
+ *
15
+ * `onSigns` / `onResult` / `onReroute` are always wired. `onRestriction` and
16
+ * `onVoice` are wired only while JS has a listener, preserving native
17
+ * semantics: restriction bitmaps are only rendered when a callback exists, and
18
+ * the built-in voice player stays active until a voice callback is set.
19
+ */
20
+ class NavSpeedAlertModule : Module() {
21
+ private val mgr = AlertViewManager()
22
+
23
+ override fun definition() = ModuleDefinition {
24
+ Name("NavSpeedAlert")
25
+
26
+ Events("onSigns", "onRestriction", "onVoice", "onResult", "onReroute")
27
+
28
+ Class(AlertSignRef::class) {
29
+ Function("toBase64") { ref: AlertSignRef -> ref.toPngBase64() }
30
+ }
31
+
32
+ OnCreate {
33
+ mgr.setBitmapCallback { cur, status, next, nextDist, cam, camDist, toll, tollDist, _ ->
34
+ sendEvent(
35
+ "onSigns",
36
+ mapOf(
37
+ "current" to wrap(cur),
38
+ "speedStatus" to status,
39
+ "next" to wrap(next),
40
+ "nextDistMeters" to nextDist,
41
+ "camera" to wrap(cam),
42
+ "cameraDistMeters" to camDist,
43
+ "toll" to wrap(toll),
44
+ "tollDistMeters" to tollDist,
45
+ ),
46
+ )
47
+ }
48
+ mgr.setResultCallback { ok, code, msg ->
49
+ sendEvent("onResult", mapOf("success" to ok, "errorCode" to code, "errorMessage" to msg))
50
+ }
51
+ mgr.setRerouteCallback { lat, lng ->
52
+ sendEvent("onReroute", mapOf("lat" to lat, "lng" to lng))
53
+ }
54
+ }
55
+
56
+ OnStartObserving("onRestriction") {
57
+ mgr.setRestrictionCallback { stop, stopD, closed, closedD, vehicle, vehicleD, bua, buaD, inBua, turn, turnD ->
58
+ sendEvent(
59
+ "onRestriction",
60
+ mapOf(
61
+ "stop" to wrap(stop),
62
+ "stopDistMeters" to stopD,
63
+ "closed" to wrap(closed),
64
+ "closedDistMeters" to closedD,
65
+ "vehicle" to wrap(vehicle),
66
+ "vehicleDistMeters" to vehicleD,
67
+ "bua" to wrap(bua),
68
+ "buaDistMeters" to buaD,
69
+ "inBua" to inBua,
70
+ "turn" to wrap(turn),
71
+ "turnDistMeters" to turnD,
72
+ ),
73
+ )
74
+ }
75
+ }
76
+ OnStopObserving("onRestriction") { mgr.setRestrictionCallback(null) }
77
+
78
+ OnStartObserving("onVoice") {
79
+ // Explicit object, not a lambda: a SAM lambda would bind the 1-arg
80
+ // overload and lose trigger/priority.
81
+ mgr.setVoiceCallback(
82
+ object : VoiceCallback {
83
+ override fun onVoice(wavBytes: ByteArray) = onVoice(wavBytes, 0, 0)
84
+
85
+ override fun onVoice(wavBytes: ByteArray, trigger: Int, priority: Int) {
86
+ sendEvent(
87
+ "onVoice",
88
+ mapOf(
89
+ "wavBase64" to Base64.encodeToString(wavBytes, Base64.NO_WRAP),
90
+ "trigger" to trigger,
91
+ "priority" to priority,
92
+ ),
93
+ )
94
+ }
95
+ },
96
+ )
97
+ }
98
+ OnStopObserving("onVoice") { mgr.setVoiceCallback(null) }
99
+
100
+ Function("configure") { o: ConfigureRecord ->
101
+ mgr.configure(
102
+ o.baseUrl, o.apiKeyId, o.apiKey, o.vehicleId,
103
+ o.vehicleType, o.seats, o.weights, o.maxSnapMeters,
104
+ )
105
+ }
106
+ Function("setSegmentUrl") { url: String -> mgr.setSegmentUrl(url) }
107
+ Function("setExtraHeaders") { headers: Map<String, String> -> mgr.setExtraHeaders(headers) }
108
+ Function("setExtraBodyFields") { fields: Map<String, String> -> mgr.setExtraBodyFields(fields) }
109
+ Function("start") { polyline: String -> mgr.start(polyline) }
110
+ Function("onLocation") { lat: Double, lng: Double, bearing: Double, speedKmh: Double, accuracy: Double, fixTimeMillis: Long ->
111
+ mgr.onLocation(lat, lng, bearing, speedKmh, accuracy, fixTimeMillis)
112
+ }
113
+ Function("reset") { mgr.reset() }
114
+ Function("setMutedAlertTypes") { codes: List<Int> ->
115
+ mgr.setMutedAlertTypes(VoiceAlertType.values().filter { it.triggerValue in codes }.toSet())
116
+ }
117
+ // Async: these wait for the engine queue (a segment fetch can be in flight)
118
+ // and must not stall the JS thread.
119
+ AsyncFunction("canExportLogs") { mgr.canExportLogs() }
120
+ AsyncFunction("exportLogs") { path: String -> mgr.exportLogs(path) }
121
+
122
+ OnDestroy {
123
+ // Callbacks are process-wide in the native bridge; drop them so a torn-down
124
+ // module (JS reload) neither keeps the built-in player muted nor receives ticks.
125
+ mgr.setBitmapCallback(null)
126
+ mgr.setRestrictionCallback(null)
127
+ mgr.setVoiceCallback(null)
128
+ mgr.setResultCallback(null)
129
+ mgr.setRerouteCallback(null)
130
+ mgr.reset()
131
+ }
132
+ }
133
+
134
+ private fun wrap(bitmap: Bitmap?): AlertSignRef? = bitmap?.let { AlertSignRef(it, runtime) }
135
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "platforms": ["android", "apple"],
3
+ "apple": {
4
+ "modules": ["NavSpeedAlertModule"]
5
+ },
6
+ "android": {
7
+ "modules": ["expo.modules.navspeedalert.NavSpeedAlertModule"]
8
+ }
9
+ }
@@ -0,0 +1,20 @@
1
+ import ExpoModulesCore
2
+ import UIKit
3
+
4
+ /// Hands a sign UIImage to JS without copying pixels. `nativeRefType = "image"`
5
+ /// is what lets `expo-image` accept the ref directly as `source`.
6
+ ///
7
+ /// Releasing only drops this reference; expo-image may still be drawing the
8
+ /// image, and ARC reclaims it once nobody holds it.
9
+ final class AlertSignRef: SharedRef<UIImage> {
10
+ override var nativeRefType: String { "image" }
11
+
12
+ static func wrap(_ image: UIImage?) -> AlertSignRef? {
13
+ image.map { AlertSignRef($0) }
14
+ }
15
+
16
+ /// PNG bytes as base64 for hosts that do not use `expo-image`.
17
+ func toPngBase64() -> String {
18
+ ref.pngData()?.base64EncodedString() ?? ""
19
+ }
20
+ }
@@ -0,0 +1,13 @@
1
+ import ExpoModulesCore
2
+
3
+ /// Mirrors `ConfigureOptions` in `src/NavSpeedAlert.types.ts`.
4
+ struct ConfigureRecord: Record {
5
+ @Field(.required) var baseUrl: String = ""
6
+ @Field(.required) var apiKeyId: String = ""
7
+ @Field(.required) var apiKey: String = ""
8
+ @Field(.required) var vehicleId: String = ""
9
+ @Field(.required) var vehicleType: Int = 0
10
+ @Field(.required) var seats: Int = 0
11
+ @Field(.required) var weights: Double = 0
12
+ @Field(.required) var maxSnapMeters: Double = 0
13
+ }
@@ -0,0 +1,71 @@
1
+ import ExpoModulesCore
2
+ import UIKit
3
+
4
+ // Event payloads are `Record`s, not `[String: Any?]`: a dictionary erases the
5
+ // value type to `Optional<Any>`, which Expo's JS converter cannot map (it logs
6
+ // `unknownToJavaScriptValue: unsupported native type 'Optional<Any>'` and
7
+ // sends `undefined`). A `@Field` typed `AlertSignRef?` goes through the
8
+ // SharedObject path and reaches JS as the registered class instance.
9
+
10
+ /// Mirrors `SignsEvent` in `src/NavSpeedAlert.types.ts`.
11
+ struct SignsPayload: Record {
12
+ @Field var current: AlertSignRef?
13
+ @Field var speedStatus: Int = 0
14
+ @Field var next: AlertSignRef?
15
+ @Field var nextDistMeters: Int = 0
16
+ @Field var camera: AlertSignRef?
17
+ @Field var cameraDistMeters: Int = 0
18
+ @Field var toll: AlertSignRef?
19
+ @Field var tollDistMeters: Int = 0
20
+
21
+ init() {}
22
+
23
+ init(
24
+ current: UIImage?, speedStatus: Int, next: UIImage?, nextDistMeters: Int,
25
+ camera: UIImage?, cameraDistMeters: Int, toll: UIImage?, tollDistMeters: Int
26
+ ) {
27
+ self.current = AlertSignRef.wrap(current)
28
+ self.speedStatus = speedStatus
29
+ self.next = AlertSignRef.wrap(next)
30
+ self.nextDistMeters = nextDistMeters
31
+ self.camera = AlertSignRef.wrap(camera)
32
+ self.cameraDistMeters = cameraDistMeters
33
+ self.toll = AlertSignRef.wrap(toll)
34
+ self.tollDistMeters = tollDistMeters
35
+ }
36
+ }
37
+
38
+ /// Mirrors `RestrictionEvent` in `src/NavSpeedAlert.types.ts`.
39
+ struct RestrictionPayload: Record {
40
+ @Field var stop: AlertSignRef?
41
+ @Field var stopDistMeters: Int = 0
42
+ @Field var closed: AlertSignRef?
43
+ @Field var closedDistMeters: Int = 0
44
+ @Field var vehicle: AlertSignRef?
45
+ @Field var vehicleDistMeters: Int = 0
46
+ @Field var bua: AlertSignRef?
47
+ @Field var buaDistMeters: Int = 0
48
+ @Field var inBua: Bool = false
49
+ @Field var turn: AlertSignRef?
50
+ @Field var turnDistMeters: Int = 0
51
+
52
+ init() {}
53
+
54
+ init(
55
+ stop: UIImage?, stopDistMeters: Int, closed: UIImage?, closedDistMeters: Int,
56
+ vehicle: UIImage?, vehicleDistMeters: Int, bua: UIImage?, buaDistMeters: Int,
57
+ inBua: Bool, turn: UIImage?, turnDistMeters: Int
58
+ ) {
59
+ self.stop = AlertSignRef.wrap(stop)
60
+ self.stopDistMeters = stopDistMeters
61
+ self.closed = AlertSignRef.wrap(closed)
62
+ self.closedDistMeters = closedDistMeters
63
+ self.vehicle = AlertSignRef.wrap(vehicle)
64
+ self.vehicleDistMeters = vehicleDistMeters
65
+ self.bua = AlertSignRef.wrap(bua)
66
+ self.buaDistMeters = buaDistMeters
67
+ self.inBua = inBua
68
+ self.turn = AlertSignRef.wrap(turn)
69
+ self.turnDistMeters = turnDistMeters
70
+ }
71
+ }
@@ -0,0 +1,28 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'NavSpeedAlert'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.description = package['description']
10
+ s.license = package['license']
11
+ s.author = package['author']
12
+ s.homepage = package['homepage']
13
+ s.platforms = { :ios => '16.4' }
14
+ s.swift_version = '5.9'
15
+ s.source = { git: package['repository']['url'], tag: "ios-#{s.version}" }
16
+ s.static_framework = true
17
+
18
+ s.dependency 'ExpoModulesCore'
19
+ # Pinned to the native SDK release this wrapper was verified against.
20
+ s.dependency 'MapZoneAlertView', '= 1.0.1'
21
+
22
+ # Swift/Objective-C compatibility
23
+ s.pod_target_xcconfig = {
24
+ 'DEFINES_MODULE' => 'YES',
25
+ }
26
+
27
+ s.source_files = "**/*.{h,m,mm,swift,hpp,cpp}"
28
+ end
@@ -0,0 +1,105 @@
1
+ import AlertViewSDK
2
+ import ExpoModulesCore
3
+ import UIKit
4
+
5
+ /// Expo Module wrapping the native `AlertViewManager`. Function order mirrors
6
+ /// the native class and the Kotlin module so the three can be diffed side by side.
7
+ ///
8
+ /// `onSigns` / `onResult` / `onReroute` are always wired. `onRestriction` and
9
+ /// `onVoice` are wired only while JS has a listener, preserving native
10
+ /// semantics: restriction images are only rendered when a callback exists, and
11
+ /// the built-in voice player stays active until a voice callback is set.
12
+ ///
13
+ /// Events go through `emit(event:payload:)` (JSI), not `sendEvent`: the latter
14
+ /// still uses the legacy bridge emitter on iOS, which serializes the body and
15
+ /// drops `SharedObject` values such as `AlertSignRef`. The two sign events use
16
+ /// `Record` payloads for the same reason (see `EventPayloads.swift`); the
17
+ /// primitive-only events (`onResult`, `onReroute`, `onVoice`) keep dictionaries.
18
+ public class NavSpeedAlertModule: Module {
19
+ private let mgr = AlertViewManager()
20
+
21
+ public func definition() -> ModuleDefinition {
22
+ Name("NavSpeedAlert")
23
+
24
+ Events("onSigns", "onRestriction", "onVoice", "onResult", "onReroute")
25
+
26
+ Class(AlertSignRef.self) {
27
+ Function("toBase64") { (ref: AlertSignRef) in ref.toPngBase64() }
28
+ }
29
+
30
+ OnCreate {
31
+ mgr.setBitmapCallback { [weak self] cur, status, next, nextDist, cam, camDist, toll, tollDist in
32
+ let payload = SignsPayload(
33
+ current: cur, speedStatus: status, next: next, nextDistMeters: nextDist,
34
+ camera: cam, cameraDistMeters: camDist, toll: toll, tollDistMeters: tollDist
35
+ )
36
+ self?.emit(event: "onSigns", payload: payload)
37
+ }
38
+ mgr.setResultCallback { [weak self] ok, code, msg in
39
+ let payload: [String: Any?] = ["success": ok, "errorCode": code, "errorMessage": msg]
40
+ self?.emit(event: "onResult", payload: payload)
41
+ }
42
+ mgr.setRerouteCallback { [weak self] lat, lng in
43
+ let payload: [String: Any?] = ["lat": lat, "lng": lng]
44
+ self?.emit(event: "onReroute", payload: payload)
45
+ }
46
+ }
47
+
48
+ OnStartObserving("onRestriction") {
49
+ mgr.setRestrictionCallback { [weak self] stop, stopD, closed, closedD, vehicle, vehicleD, bua, buaD, inBua, turn, turnD in
50
+ let payload = RestrictionPayload(
51
+ stop: stop, stopDistMeters: stopD, closed: closed, closedDistMeters: closedD,
52
+ vehicle: vehicle, vehicleDistMeters: vehicleD, bua: bua, buaDistMeters: buaD,
53
+ inBua: inBua, turn: turn, turnDistMeters: turnD
54
+ )
55
+ self?.emit(event: "onRestriction", payload: payload)
56
+ }
57
+ }
58
+ OnStopObserving("onRestriction") { mgr.setRestrictionCallback(nil) }
59
+
60
+ OnStartObserving("onVoice") {
61
+ mgr.setVoiceCallback { [weak self] wav, trigger, priority in
62
+ let payload: [String: Any?] = [
63
+ "wavBase64": wav.base64EncodedString(),
64
+ "trigger": trigger,
65
+ "priority": priority,
66
+ ]
67
+ self?.emit(event: "onVoice", payload: payload)
68
+ }
69
+ }
70
+ OnStopObserving("onVoice") { mgr.setVoiceCallback(nil) }
71
+
72
+ Function("configure") { (o: ConfigureRecord) in
73
+ mgr.configure(
74
+ baseUrl: o.baseUrl, apiKeyId: o.apiKeyId, apiKey: o.apiKey, vehicleId: o.vehicleId,
75
+ vehicleType: o.vehicleType, seats: o.seats, weights: o.weights, maxSnapMeters: o.maxSnapMeters
76
+ )
77
+ }
78
+ Function("setSegmentUrl") { (url: String) in mgr.setSegmentUrl(url) }
79
+ Function("setExtraHeaders") { (headers: [String: String]) -> String? in mgr.setExtraHeaders(headers) }
80
+ Function("setExtraBodyFields") { (fields: [String: String]) -> String? in mgr.setExtraBodyFields(fields) }
81
+ Function("start") { (polyline: String) in mgr.start(polyline) }
82
+ Function("onLocation") { (lat: Double, lng: Double, bearing: Double, speedKmh: Double, accuracy: Double, fixTimeMillis: Int64) in
83
+ mgr.onLocation(lat: lat, lng: lng, bearing: bearing, speedKmh: speedKmh, accuracy: accuracy, fixTimeMillis: fixTimeMillis)
84
+ }
85
+ Function("reset") { mgr.reset() }
86
+ Function("setMutedAlertTypes") { (codes: [Int]) in
87
+ mgr.setMutedAlertTypes(Set(codes.compactMap(VoiceAlertType.init(rawValue:))))
88
+ }
89
+ // Async: these wait for the engine queue (a segment fetch can be in flight)
90
+ // and must not stall the JS thread.
91
+ AsyncFunction("canExportLogs") { () -> Bool in mgr.canExportLogs() }
92
+ AsyncFunction("exportLogs") { (path: String) -> Int in mgr.exportLogs(toFile: path) }
93
+
94
+ OnDestroy {
95
+ // Drop every callback so a torn-down module (JS reload) neither keeps the
96
+ // built-in player muted nor receives ticks.
97
+ mgr.setBitmapCallback(nil)
98
+ mgr.setRestrictionCallback(nil)
99
+ mgr.setVoiceCallback(nil)
100
+ mgr.setResultCallback(nil)
101
+ mgr.setRerouteCallback(nil)
102
+ mgr.reset()
103
+ }
104
+ }
105
+ }
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@mapzone/nav-speed-alert",
3
+ "version": "1.0.0",
4
+ "description": "Warning for speed, camera, toll and restriction violations on a route in React Native navigation apps.",
5
+ "main": "build/index.js",
6
+ "types": "build/index.d.ts",
7
+ "files": [
8
+ "build",
9
+ "src",
10
+ "android",
11
+ "ios",
12
+ "expo-module.config.json",
13
+ "README.md",
14
+ "CHANGELOG.md",
15
+ "LICENSE",
16
+ "!android/build",
17
+ "!ios/build",
18
+ "!**/.*"
19
+ ],
20
+ "scripts": {
21
+ "build": "node internal/module_scripts/build.js",
22
+ "clean": "node internal/module_scripts/clean.js",
23
+ "lint": "eslint src/",
24
+ "test": "node internal/module_scripts/test.js",
25
+ "prepare": "node internal/module_scripts/prepare.js",
26
+ "prepack": "node internal/module_scripts/prepare.js",
27
+ "open:ios": "node internal/module_scripts/open-ios.js",
28
+ "open:android": "node internal/module_scripts/open-android.js"
29
+ },
30
+ "keywords": [
31
+ "react-native",
32
+ "expo",
33
+ "expo-module",
34
+ "mapzone",
35
+ "vietmap",
36
+ "speed-alert",
37
+ "navigation",
38
+ "speed-camera"
39
+ ],
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/mapzone-global/mapzone-nav-speed-alert-react-native"
43
+ },
44
+ "bugs": {
45
+ "url": "https://github.com/mapzone-global/mapzone-nav-speed-alert-react-native/issues"
46
+ },
47
+ "author": "Map Zone <toannn@vietmap.vn>",
48
+ "license": "MIT",
49
+ "homepage": "https://github.com/mapzone-global/mapzone-nav-speed-alert-react-native#readme",
50
+ "publishConfig": {
51
+ "access": "public"
52
+ },
53
+ "engines": {
54
+ "node": ">=20.19.4"
55
+ },
56
+ "devDependencies": {
57
+ "@babel/core": "^7.26.0",
58
+ "@types/jest": "^29.2.1",
59
+ "@types/react": "~19.2.0",
60
+ "babel-preset-expo": "~57.0.12",
61
+ "eslint": "~9.39.4",
62
+ "eslint-config-universe": "^15.0.3",
63
+ "expo": "~57.0.23",
64
+ "expo-image": "~57.0.5",
65
+ "expo-modules-core": "~57.0.18",
66
+ "jest": "^29.7.0",
67
+ "jest-expo": "~57.0.5",
68
+ "prettier": "^3.0.0",
69
+ "react": "19.2.3",
70
+ "react-native": "0.86.3",
71
+ "typescript": "^5.9.2"
72
+ },
73
+ "jest": {
74
+ "preset": "jest-expo",
75
+ "roots": [
76
+ "<rootDir>/src"
77
+ ]
78
+ },
79
+ "peerDependencies": {
80
+ "expo": ">=57",
81
+ "expo-image": ">=3",
82
+ "react": "*",
83
+ "react-native": ">=0.86"
84
+ }
85
+ }
@@ -0,0 +1,132 @@
1
+ import type { SharedRef } from 'expo-modules-core';
2
+
3
+ /**
4
+ * Credentials and vehicle profile for the native engine. All fields are
5
+ * required; call `configure()` once before `start()`. The application id
6
+ * (bundle id) is resolved natively.
7
+ */
8
+ export type ConfigureOptions = {
9
+ baseUrl: string;
10
+ apiKeyId: string;
11
+ apiKey: string;
12
+ vehicleId: string;
13
+ /** Vehicle class 1..9 as defined by the alert service. */
14
+ vehicleType: number;
15
+ seats: number;
16
+ weights: number;
17
+ /** Maximum distance (m) a GPS fix may be from the route and still snap to it. */
18
+ maxSnapMeters: number;
19
+ };
20
+
21
+ /** One GPS sample forwarded to the engine. */
22
+ export type LocationFix = {
23
+ lat: number;
24
+ lng: number;
25
+ /** Heading in degrees, 0 = north. */
26
+ bearing: number;
27
+ speedKmh: number;
28
+ /** Horizontal accuracy in metres. */
29
+ accuracy: number;
30
+ /** Fix timestamp, epoch milliseconds. */
31
+ fixTimeMillis: number;
32
+ };
33
+
34
+ /**
35
+ * Voice alert categories that can be muted. Values MUST match
36
+ * `VoiceAlertType.java` / `VoiceAlertType.swift` in the native SDK.
37
+ */
38
+ export enum VoiceAlertType {
39
+ SPEED_CAMERA = 3,
40
+ TOLL = 4,
41
+ TRAFFIC_ENFORCEMENT_CAMERA = 6,
42
+ RED_LIGHT_CAMERA = 7,
43
+ AI_CAMERA = 8,
44
+ NO_LEFT_TURN = 9,
45
+ NO_RIGHT_TURN = 10,
46
+ NO_UTURN = 11,
47
+ NO_OVERTAKING = 12,
48
+ NO_OVERTAKING_END = 13,
49
+ NO_PARKING = 14,
50
+ NO_STRAIGHT = 15,
51
+ BUILDUP_AREA_START = 16,
52
+ BUILDUP_AREA_END = 17,
53
+ REST_STATION = 18,
54
+ NO_STOPPING = 19,
55
+ ROAD_CLOSED = 20,
56
+ VEHICLE_RESTRICTED = 21,
57
+ }
58
+
59
+ /** 0 = within limit, 1 = within 5 km/h of the limit, 2 = over the limit. */
60
+ export type SpeedStatus = 0 | 1 | 2;
61
+
62
+ /**
63
+ * Native reference to a rendered sign image (Bitmap on Android, UIImage on
64
+ * iOS). Pass it straight to `expo-image` as `source`. Call `release()` when
65
+ * the tick it belongs to is no longer displayed.
66
+ */
67
+ export declare class AlertSignRef extends SharedRef<'image'> {
68
+ /** PNG-encoded bytes as base64 for hosts that do not use `expo-image`. */
69
+ toBase64(): string;
70
+ }
71
+
72
+ /** Emitted on every GPS tick after `start()`; a `null` slot means nothing to show. */
73
+ export type SignsEvent = {
74
+ current: AlertSignRef | null;
75
+ speedStatus: SpeedStatus;
76
+ next: AlertSignRef | null;
77
+ nextDistMeters: number;
78
+ camera: AlertSignRef | null;
79
+ cameraDistMeters: number;
80
+ toll: AlertSignRef | null;
81
+ tollDistMeters: number;
82
+ };
83
+
84
+ /**
85
+ * Emitted on every GPS tick while at least one `onRestriction` listener is
86
+ * registered. `*DistMeters === 0` means "currently on it".
87
+ */
88
+ export type RestrictionEvent = {
89
+ stop: AlertSignRef | null;
90
+ stopDistMeters: number;
91
+ closed: AlertSignRef | null;
92
+ closedDistMeters: number;
93
+ vehicle: AlertSignRef | null;
94
+ vehicleDistMeters: number;
95
+ bua: AlertSignRef | null;
96
+ buaDistMeters: number;
97
+ inBua: boolean;
98
+ turn: AlertSignRef | null;
99
+ turnDistMeters: number;
100
+ };
101
+
102
+ /**
103
+ * Emitted instead of playing through the built-in player while at least one
104
+ * `onVoice` listener is registered. `wavBase64` is PCM16 mono 22050 Hz.
105
+ */
106
+ export type VoiceEvent = {
107
+ wavBase64: string;
108
+ trigger: number;
109
+ /** 0 = current (lowest), 1 = normal, 2 = speeding. */
110
+ priority: number;
111
+ };
112
+
113
+ /** Result of fetching one route segment. `errorCode === 0` on success. */
114
+ export type ResultEvent = {
115
+ success: boolean;
116
+ errorCode: number;
117
+ errorMessage: string;
118
+ };
119
+
120
+ /** The vehicle left the route; host should request a new route from this point. */
121
+ export type RerouteEvent = {
122
+ lat: number;
123
+ lng: number;
124
+ };
125
+
126
+ export type NavSpeedAlertEvents = {
127
+ onSigns: (event: SignsEvent) => void;
128
+ onRestriction: (event: RestrictionEvent) => void;
129
+ onVoice: (event: VoiceEvent) => void;
130
+ onResult: (event: ResultEvent) => void;
131
+ onReroute: (event: RerouteEvent) => void;
132
+ };
@@ -0,0 +1,26 @@
1
+ import { NativeModule, requireNativeModule } from 'expo';
2
+
3
+ import type { ConfigureOptions, NavSpeedAlertEvents } from './NavSpeedAlert.types';
4
+
5
+ /** Raw native surface. Method order mirrors `AlertViewManager` in the native SDK. */
6
+ declare class NavSpeedAlertNativeModule extends NativeModule<NavSpeedAlertEvents> {
7
+ configure(options: ConfigureOptions): void;
8
+ setSegmentUrl(url: string): void;
9
+ setExtraHeaders(headers: Record<string, string>): string | null;
10
+ setExtraBodyFields(fields: Record<string, string>): string | null;
11
+ start(routePolyline: string): void;
12
+ onLocation(
13
+ lat: number,
14
+ lng: number,
15
+ bearing: number,
16
+ speedKmh: number,
17
+ accuracy: number,
18
+ fixTimeMillis: number
19
+ ): void;
20
+ reset(): void;
21
+ setMutedAlertTypes(codes: number[]): void;
22
+ canExportLogs(): Promise<boolean>;
23
+ exportLogs(path: string): Promise<number>;
24
+ }
25
+
26
+ export default requireNativeModule<NavSpeedAlertNativeModule>('NavSpeedAlert');