react-native-nitro-location-tracking 0.1.9 → 0.1.11
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/README.md +37 -0
- package/android/build.gradle +1 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/NitroLocationTracking.kt +10 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/PermissionStatusMonitor.kt +92 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/ProviderStatusMonitor.kt +87 -23
- package/ios/LocationEngine.swift +59 -3
- package/ios/NitroLocationTracking.swift +6 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NitroLocationTracking.nitro.d.ts +2 -0
- package/lib/typescript/src/NitroLocationTracking.nitro.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_PermissionStatus.hpp +77 -0
- package/nitrogen/generated/android/c++/JHybridNitroLocationTrackingSpec.cpp +5 -0
- package/nitrogen/generated/android/c++/JHybridNitroLocationTrackingSpec.hpp +1 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/Func_void_PermissionStatus.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/HybridNitroLocationTrackingSpec.kt +9 -0
- package/nitrogen/generated/android/nitrolocationtrackingOnLoad.cpp +2 -0
- package/nitrogen/generated/ios/c++/HybridNitroLocationTrackingSpecSwift.hpp +6 -0
- package/nitrogen/generated/ios/swift/HybridNitroLocationTrackingSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridNitroLocationTrackingSpec_cxx.swift +16 -0
- package/nitrogen/generated/shared/c++/HybridNitroLocationTrackingSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridNitroLocationTrackingSpec.hpp +1 -0
- package/package.json +1 -1
- package/src/NitroLocationTracking.nitro.ts +3 -0
- package/src/index.tsx +1 -0
package/README.md
CHANGED
|
@@ -531,6 +531,42 @@ async function setup() {
|
|
|
531
531
|
| iOS | Calls `requestAlwaysAuthorization()`. If permission is already determined, resolves immediately with current status. If `start()` was called before permission was granted, tracking auto-starts once the user allows. |
|
|
532
532
|
| Android | Uses React Native's `PermissionAwareActivity` to show the system permission dialog for `ACCESS_FINE_LOCATION` + `ACCESS_COARSE_LOCATION`. Resolves with the resulting status after the user responds. |
|
|
533
533
|
|
|
534
|
+
### Permission Change Listener
|
|
535
|
+
|
|
536
|
+
Listen for permission changes in real time. The callback fires whenever the user changes the location permission (via the system dialog, the Settings app, or MDM policy changes):
|
|
537
|
+
|
|
538
|
+
```tsx
|
|
539
|
+
import NitroLocationModule from 'react-native-nitro-location-tracking';
|
|
540
|
+
|
|
541
|
+
// Register a listener — fires whenever the permission status changes
|
|
542
|
+
NitroLocationModule.onPermissionStatusChange((status) => {
|
|
543
|
+
console.log('Permission changed to:', status);
|
|
544
|
+
// status: 'notDetermined' | 'denied' | 'restricted' | 'whenInUse' | 'always'
|
|
545
|
+
|
|
546
|
+
switch (status) {
|
|
547
|
+
case 'always':
|
|
548
|
+
console.log('Background location granted — full tracking available');
|
|
549
|
+
break;
|
|
550
|
+
case 'whenInUse':
|
|
551
|
+
console.log('Foreground only — background tracking may not work');
|
|
552
|
+
break;
|
|
553
|
+
case 'denied':
|
|
554
|
+
Alert.alert('Location Required', 'Please re-enable location in Settings');
|
|
555
|
+
break;
|
|
556
|
+
case 'restricted':
|
|
557
|
+
console.warn('Location restricted by parental controls or MDM');
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
**Platform behavior:**
|
|
564
|
+
|
|
565
|
+
| Platform | Mechanism | When the callback fires |
|
|
566
|
+
| -------- | --------- | ----------------------- |
|
|
567
|
+
| iOS | `locationManagerDidChangeAuthorization` delegate | Immediately when the user changes permission (system dialog, Settings, MDM) |
|
|
568
|
+
| Android | `ProcessLifecycleOwner` lifecycle observer | When the app returns to foreground after the user changes permission in Settings |
|
|
569
|
+
|
|
534
570
|
## API Reference
|
|
535
571
|
|
|
536
572
|
### Types
|
|
@@ -671,6 +707,7 @@ type PermissionStatus =
|
|
|
671
707
|
| `onProviderStatusChange(callback)` | `void` | Register GPS/network provider status callback |
|
|
672
708
|
| `getLocationPermissionStatus()` | `PermissionStatus` | Check current location permission without prompting |
|
|
673
709
|
| `requestLocationPermission()` | `Promise<PermissionStatus>` | Request location permission and return the resulting status |
|
|
710
|
+
| `onPermissionStatusChange(callback)` | `void` | Register a callback that fires when location permission status changes |
|
|
674
711
|
| `showLocalNotification(title, body)` | `void` | Show a local notification |
|
|
675
712
|
| `updateForegroundNotification(title, body)` | `void` | Update the foreground service notification |
|
|
676
713
|
| `destroy()` | `void` | Stop tracking and disconnect |
|
package/android/build.gradle
CHANGED
|
@@ -119,4 +119,5 @@ dependencies {
|
|
|
119
119
|
implementation "com.squareup.okhttp3:okhttp:4.12.0"
|
|
120
120
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0"
|
|
121
121
|
implementation "androidx.core:core-ktx:1.15.0"
|
|
122
|
+
implementation "androidx.lifecycle:lifecycle-process:2.8.7"
|
|
122
123
|
}
|
package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/NitroLocationTracking.kt
CHANGED
|
@@ -26,6 +26,7 @@ class NitroLocationTracking : HybridNitroLocationTrackingSpec() {
|
|
|
26
26
|
private var notificationService: NotificationService? = null
|
|
27
27
|
private var geofenceManager: GeofenceManager? = null
|
|
28
28
|
private var providerStatusMonitor: ProviderStatusMonitor? = null
|
|
29
|
+
private var permissionStatusMonitor: PermissionStatusMonitor? = null
|
|
29
30
|
|
|
30
31
|
private var locationCallback: ((LocationData) -> Unit)? = null
|
|
31
32
|
private var motionCallback: ((Boolean) -> Unit)? = null
|
|
@@ -34,6 +35,7 @@ class NitroLocationTracking : HybridNitroLocationTrackingSpec() {
|
|
|
34
35
|
private var geofenceCallback: ((GeofenceEvent, String) -> Unit)? = null
|
|
35
36
|
private var speedAlertCallback: ((SpeedAlertType, Double) -> Unit)? = null
|
|
36
37
|
private var providerStatusCallback: ((LocationProviderStatus, LocationProviderStatus) -> Unit)? = null
|
|
38
|
+
private var permissionStatusCallback: ((PermissionStatus) -> Unit)? = null
|
|
37
39
|
|
|
38
40
|
private var locationConfig: LocationConfig? = null
|
|
39
41
|
|
|
@@ -50,6 +52,7 @@ class NitroLocationTracking : HybridNitroLocationTrackingSpec() {
|
|
|
50
52
|
notificationService = NotificationService(context)
|
|
51
53
|
geofenceManager = GeofenceManager(context)
|
|
52
54
|
providerStatusMonitor = ProviderStatusMonitor(context)
|
|
55
|
+
permissionStatusMonitor = PermissionStatusMonitor(context)
|
|
53
56
|
locationEngine?.dbWriter = dbWriter
|
|
54
57
|
connectionManager.dbWriter = dbWriter
|
|
55
58
|
Log.d(TAG, "Components initialized successfully")
|
|
@@ -286,6 +289,12 @@ class NitroLocationTracking : HybridNitroLocationTrackingSpec() {
|
|
|
286
289
|
return PermissionStatus.ALWAYS
|
|
287
290
|
}
|
|
288
291
|
|
|
292
|
+
override fun onPermissionStatusChange(callback: (status: PermissionStatus) -> Unit) {
|
|
293
|
+
permissionStatusCallback = callback
|
|
294
|
+
ensureInitialized()
|
|
295
|
+
permissionStatusMonitor?.setCallback(callback)
|
|
296
|
+
}
|
|
297
|
+
|
|
289
298
|
override fun requestLocationPermission(): Promise<PermissionStatus> {
|
|
290
299
|
return Promise.async {
|
|
291
300
|
suspendCoroutine { cont ->
|
|
@@ -379,5 +388,6 @@ class NitroLocationTracking : HybridNitroLocationTrackingSpec() {
|
|
|
379
388
|
notificationService?.stopForegroundService()
|
|
380
389
|
geofenceManager?.destroy()
|
|
381
390
|
providerStatusMonitor?.destroy()
|
|
391
|
+
permissionStatusMonitor?.destroy()
|
|
382
392
|
}
|
|
383
393
|
}
|
package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/PermissionStatusMonitor.kt
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
package com.margelo.nitro.nitrolocationtracking
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.pm.PackageManager
|
|
5
|
+
import android.os.Build
|
|
6
|
+
import android.os.Handler
|
|
7
|
+
import android.os.Looper
|
|
8
|
+
import android.util.Log
|
|
9
|
+
import androidx.core.content.ContextCompat
|
|
10
|
+
import androidx.lifecycle.DefaultLifecycleObserver
|
|
11
|
+
import androidx.lifecycle.LifecycleOwner
|
|
12
|
+
import androidx.lifecycle.ProcessLifecycleOwner
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Monitors location‐permission changes by comparing the permission status
|
|
16
|
+
* every time the app comes to the foreground (`ON_START`).
|
|
17
|
+
*
|
|
18
|
+
* Android has no broadcast for permission changes, so consuming the
|
|
19
|
+
* lifecycle is the standard approach (same as react-native-permissions).
|
|
20
|
+
*/
|
|
21
|
+
class PermissionStatusMonitor(private val context: Context) {
|
|
22
|
+
|
|
23
|
+
companion object {
|
|
24
|
+
private const val TAG = "PermissionStatusMonitor"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private var callback: ((PermissionStatus) -> Unit)? = null
|
|
28
|
+
private var lastStatus: PermissionStatus? = null
|
|
29
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
30
|
+
|
|
31
|
+
private val lifecycleObserver = object : DefaultLifecycleObserver {
|
|
32
|
+
override fun onStart(owner: LifecycleOwner) {
|
|
33
|
+
checkAndNotify()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fun setCallback(callback: (PermissionStatus) -> Unit) {
|
|
38
|
+
this.callback = callback
|
|
39
|
+
// Capture the current status so we only fire on actual changes
|
|
40
|
+
lastStatus = getCurrentPermissionStatus()
|
|
41
|
+
|
|
42
|
+
// addObserver MUST be called on the main thread
|
|
43
|
+
mainHandler.post {
|
|
44
|
+
try {
|
|
45
|
+
ProcessLifecycleOwner.get().lifecycle.addObserver(lifecycleObserver)
|
|
46
|
+
Log.d(TAG, "Registered lifecycle observer for permission changes")
|
|
47
|
+
} catch (e: Exception) {
|
|
48
|
+
Log.e(TAG, "Failed to register lifecycle observer: ${e.message}")
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private fun checkAndNotify() {
|
|
54
|
+
val current = getCurrentPermissionStatus()
|
|
55
|
+
if (current != lastStatus) {
|
|
56
|
+
Log.d(TAG, "Permission status changed: $lastStatus -> $current")
|
|
57
|
+
lastStatus = current
|
|
58
|
+
callback?.invoke(current)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private fun getCurrentPermissionStatus(): PermissionStatus {
|
|
63
|
+
val fineGranted = ContextCompat.checkSelfPermission(
|
|
64
|
+
context, android.Manifest.permission.ACCESS_FINE_LOCATION
|
|
65
|
+
) == PackageManager.PERMISSION_GRANTED
|
|
66
|
+
|
|
67
|
+
if (!fineGranted) {
|
|
68
|
+
return PermissionStatus.DENIED
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Fine location granted — check background
|
|
72
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
73
|
+
val bgGranted = ContextCompat.checkSelfPermission(
|
|
74
|
+
context, android.Manifest.permission.ACCESS_BACKGROUND_LOCATION
|
|
75
|
+
) == PackageManager.PERMISSION_GRANTED
|
|
76
|
+
return if (bgGranted) PermissionStatus.ALWAYS else PermissionStatus.WHENINUSE
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Pre-Android 10: fine location = always
|
|
80
|
+
return PermissionStatus.ALWAYS
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
fun destroy() {
|
|
84
|
+
mainHandler.post {
|
|
85
|
+
try {
|
|
86
|
+
ProcessLifecycleOwner.get().lifecycle.removeObserver(lifecycleObserver)
|
|
87
|
+
} catch (_: Exception) {}
|
|
88
|
+
}
|
|
89
|
+
callback = null
|
|
90
|
+
lastStatus = null
|
|
91
|
+
}
|
|
92
|
+
}
|
package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/ProviderStatusMonitor.kt
CHANGED
|
@@ -1,27 +1,54 @@
|
|
|
1
1
|
package com.margelo.nitro.nitrolocationtracking
|
|
2
2
|
|
|
3
|
-
import android.content.BroadcastReceiver
|
|
4
3
|
import android.content.Context
|
|
5
|
-
import android.
|
|
6
|
-
import android.content.IntentFilter
|
|
4
|
+
import android.database.ContentObserver
|
|
7
5
|
import android.location.LocationManager
|
|
8
6
|
import android.os.Build
|
|
7
|
+
import android.os.Handler
|
|
8
|
+
import android.os.Looper
|
|
9
|
+
import android.provider.Settings
|
|
9
10
|
import android.util.Log
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Monitors GPS / network location provider status changes using a ContentObserver
|
|
14
|
+
* on Settings.Secure.LOCATION_MODE.
|
|
15
|
+
*
|
|
16
|
+
* Why ContentObserver instead of BroadcastReceiver?
|
|
17
|
+
* Several OEMs (notably Samsung) suppress PROVIDERS_CHANGED_ACTION broadcasts,
|
|
18
|
+
* making BroadcastReceiver unreliable. ContentObserver watches the Settings DB
|
|
19
|
+
* directly and fires on all devices.
|
|
20
|
+
*
|
|
21
|
+
* Implementation notes:
|
|
22
|
+
* - ContentObserver.onChange fires BEFORE the LocationManager reflects the new
|
|
23
|
+
* state, so we post a short delayed read (150 ms) to get the correct values.
|
|
24
|
+
* - onChange can fire multiple times per toggle; we debounce with a pending
|
|
25
|
+
* Runnable and deduplicate by comparing with lastGps / lastNetwork.
|
|
26
|
+
*/
|
|
11
27
|
class ProviderStatusMonitor(private val context: Context) {
|
|
12
28
|
|
|
13
29
|
companion object {
|
|
14
30
|
private const val TAG = "ProviderStatusMonitor"
|
|
31
|
+
/** Delay (ms) to let the system apply the setting before we read it. */
|
|
32
|
+
private const val READ_DELAY_MS = 150L
|
|
15
33
|
}
|
|
16
34
|
|
|
17
35
|
private val locationManager =
|
|
18
36
|
context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
|
37
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
38
|
+
|
|
19
39
|
private var callback: ((LocationProviderStatus, LocationProviderStatus) -> Unit)? = null
|
|
20
|
-
private var
|
|
40
|
+
private var contentObserver: ContentObserver? = null
|
|
41
|
+
private var pendingNotify: Runnable? = null
|
|
42
|
+
|
|
43
|
+
// Track last-notified values to avoid duplicate callbacks
|
|
44
|
+
private var lastGps: LocationProviderStatus? = null
|
|
45
|
+
private var lastNetwork: LocationProviderStatus? = null
|
|
21
46
|
|
|
22
47
|
fun setCallback(callback: (LocationProviderStatus, LocationProviderStatus) -> Unit) {
|
|
23
48
|
this.callback = callback
|
|
24
|
-
|
|
49
|
+
registerObserver()
|
|
50
|
+
// Emit current status immediately (no delay needed — values are already settled)
|
|
51
|
+
emitCurrentStatus()
|
|
25
52
|
}
|
|
26
53
|
|
|
27
54
|
fun isLocationServicesEnabled(): Boolean {
|
|
@@ -33,41 +60,78 @@ class ProviderStatusMonitor(private val context: Context) {
|
|
|
33
60
|
}
|
|
34
61
|
}
|
|
35
62
|
|
|
36
|
-
|
|
37
|
-
if (receiver != null) return
|
|
63
|
+
// ── Observer registration ────────────────────────────────────────────
|
|
38
64
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
65
|
+
private fun registerObserver() {
|
|
66
|
+
if (contentObserver != null) return
|
|
67
|
+
|
|
68
|
+
contentObserver = object : ContentObserver(mainHandler) {
|
|
69
|
+
override fun onChange(selfChange: Boolean) {
|
|
70
|
+
super.onChange(selfChange)
|
|
71
|
+
scheduleNotify()
|
|
44
72
|
}
|
|
45
73
|
}
|
|
46
74
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
75
|
+
// LOCATION_MODE is the single authoritative setting for the global
|
|
76
|
+
// location toggle (GPS + Network). Watching only this avoids the
|
|
77
|
+
// double-fire that occurs when observing LOCATION_PROVIDERS_ALLOWED too.
|
|
78
|
+
context.contentResolver.registerContentObserver(
|
|
79
|
+
Settings.Secure.getUriFor(Settings.Secure.LOCATION_MODE),
|
|
80
|
+
false,
|
|
81
|
+
contentObserver!!
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
Log.d(TAG, "ContentObserver registered")
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ── Debounced + delayed notification ─────────────────────────────────
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Schedule a delayed read of the provider status.
|
|
91
|
+
* If onChange fires multiple times in quick succession, the previous
|
|
92
|
+
* pending Runnable is cancelled so we only read once after things settle.
|
|
93
|
+
*/
|
|
94
|
+
private fun scheduleNotify() {
|
|
95
|
+
pendingNotify?.let { mainHandler.removeCallbacks(it) }
|
|
96
|
+
|
|
97
|
+
val runnable = Runnable { emitCurrentStatus() }
|
|
98
|
+
pendingNotify = runnable
|
|
99
|
+
mainHandler.postDelayed(runnable, READ_DELAY_MS)
|
|
54
100
|
}
|
|
55
101
|
|
|
56
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Read the current GPS + Network provider state and invoke the callback
|
|
104
|
+
* only if the values actually changed since the last notification.
|
|
105
|
+
*/
|
|
106
|
+
private fun emitCurrentStatus() {
|
|
57
107
|
val gps = if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
|
|
58
108
|
LocationProviderStatus.ENABLED else LocationProviderStatus.DISABLED
|
|
59
109
|
val network = if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
|
|
60
110
|
LocationProviderStatus.ENABLED else LocationProviderStatus.DISABLED
|
|
111
|
+
|
|
112
|
+
// Deduplicate — only fire if something actually changed
|
|
113
|
+
if (gps == lastGps && network == lastNetwork) return
|
|
114
|
+
|
|
115
|
+
lastGps = gps
|
|
116
|
+
lastNetwork = network
|
|
117
|
+
Log.d(TAG, "Provider status changed: GPS=$gps, Network=$network")
|
|
61
118
|
callback?.invoke(gps, network)
|
|
62
119
|
}
|
|
63
120
|
|
|
121
|
+
// ── Cleanup ──────────────────────────────────────────────────────────
|
|
122
|
+
|
|
64
123
|
fun destroy() {
|
|
65
|
-
|
|
124
|
+
pendingNotify?.let { mainHandler.removeCallbacks(it) }
|
|
125
|
+
pendingNotify = null
|
|
126
|
+
|
|
127
|
+
contentObserver?.let {
|
|
66
128
|
try {
|
|
67
|
-
context.
|
|
129
|
+
context.contentResolver.unregisterContentObserver(it)
|
|
68
130
|
} catch (_: Exception) {}
|
|
69
131
|
}
|
|
70
|
-
|
|
132
|
+
contentObserver = null
|
|
71
133
|
callback = null
|
|
134
|
+
lastGps = null
|
|
135
|
+
lastNetwork = null
|
|
72
136
|
}
|
|
73
137
|
}
|
package/ios/LocationEngine.swift
CHANGED
|
@@ -21,7 +21,31 @@ class LocationEngine: NSObject, CLLocationManagerDelegate {
|
|
|
21
21
|
var rejectMockLocations: Bool = false
|
|
22
22
|
let speedMonitor = SpeedMonitor()
|
|
23
23
|
let tripCalculator = TripCalculator()
|
|
24
|
-
var providerStatusCallback: ((LocationProviderStatus, LocationProviderStatus) -> Void)?
|
|
24
|
+
var providerStatusCallback: ((LocationProviderStatus, LocationProviderStatus) -> Void)? {
|
|
25
|
+
didSet {
|
|
26
|
+
// Emit current status immediately when the callback is first set
|
|
27
|
+
if providerStatusCallback != nil {
|
|
28
|
+
let enabled = CLLocationManager.locationServicesEnabled()
|
|
29
|
+
let status: LocationProviderStatus = enabled ? .enabled : .disabled
|
|
30
|
+
lastProviderEnabled = enabled
|
|
31
|
+
providerStatusCallback?(status, status)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
var permissionStatusCallback: ((PermissionStatus) -> Void)? {
|
|
36
|
+
didSet {
|
|
37
|
+
// Emit current status immediately when the callback is first set
|
|
38
|
+
if permissionStatusCallback != nil {
|
|
39
|
+
let current = Self.mapAuthStatus(CLLocationManager.authorizationStatus())
|
|
40
|
+
lastPermissionStatus = current
|
|
41
|
+
permissionStatusCallback?(current)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Deduplication: track last-notified values
|
|
47
|
+
private var lastPermissionStatus: PermissionStatus?
|
|
48
|
+
private var lastProviderEnabled: Bool?
|
|
25
49
|
|
|
26
50
|
/// The most recently received location from Core Location (for distance calculations)
|
|
27
51
|
var lastCLLocation: CLLocation? {
|
|
@@ -192,6 +216,8 @@ class LocationEngine: NSObject, CLLocationManagerDelegate {
|
|
|
192
216
|
return CLLocationManager.locationServicesEnabled()
|
|
193
217
|
}
|
|
194
218
|
|
|
219
|
+
// MARK: - Authorization / Provider change delegate
|
|
220
|
+
|
|
195
221
|
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
|
|
196
222
|
guard manager === locationManager else { return }
|
|
197
223
|
|
|
@@ -212,9 +238,39 @@ class LocationEngine: NSObject, CLLocationManagerDelegate {
|
|
|
212
238
|
}
|
|
213
239
|
}
|
|
214
240
|
|
|
241
|
+
// Notify JS about permission status change (deduplicated)
|
|
242
|
+
let permStatus = Self.mapAuthStatus(authStatus)
|
|
243
|
+
if permStatus != lastPermissionStatus {
|
|
244
|
+
lastPermissionStatus = permStatus
|
|
245
|
+
permissionStatusCallback?(permStatus)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// Notify JS about provider status change (deduplicated)
|
|
215
249
|
let enabled = CLLocationManager.locationServicesEnabled()
|
|
216
|
-
|
|
217
|
-
|
|
250
|
+
if enabled != lastProviderEnabled {
|
|
251
|
+
lastProviderEnabled = enabled
|
|
252
|
+
let status: LocationProviderStatus = enabled ? .enabled : .disabled
|
|
253
|
+
providerStatusCallback?(status, status)
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// MARK: - Helpers
|
|
258
|
+
|
|
259
|
+
private static func mapAuthStatus(_ status: CLAuthorizationStatus) -> PermissionStatus {
|
|
260
|
+
switch status {
|
|
261
|
+
case .notDetermined:
|
|
262
|
+
return .notdetermined
|
|
263
|
+
case .restricted:
|
|
264
|
+
return .restricted
|
|
265
|
+
case .denied:
|
|
266
|
+
return .denied
|
|
267
|
+
case .authorizedWhenInUse:
|
|
268
|
+
return .wheninuse
|
|
269
|
+
case .authorizedAlways:
|
|
270
|
+
return .always
|
|
271
|
+
@unknown default:
|
|
272
|
+
return .notdetermined
|
|
273
|
+
}
|
|
218
274
|
}
|
|
219
275
|
}
|
|
220
276
|
|
|
@@ -16,6 +16,7 @@ class NitroLocationTracking: HybridNitroLocationTrackingSpec {
|
|
|
16
16
|
private var geofenceCallback: ((GeofenceEvent, String) -> Void)?
|
|
17
17
|
private var speedAlertCallback: ((SpeedAlertType, Double) -> Void)?
|
|
18
18
|
private var providerStatusCallback: ((LocationProviderStatus, LocationProviderStatus) -> Void)?
|
|
19
|
+
private var permissionStatusCallback: ((PermissionStatus) -> Void)?
|
|
19
20
|
private var permissionPromise: Promise<PermissionStatus>?
|
|
20
21
|
|
|
21
22
|
override init() {
|
|
@@ -236,6 +237,11 @@ class NitroLocationTracking: HybridNitroLocationTrackingSpec {
|
|
|
236
237
|
return promise
|
|
237
238
|
}
|
|
238
239
|
|
|
240
|
+
func onPermissionStatusChange(callback: @escaping (PermissionStatus) -> Void) throws {
|
|
241
|
+
permissionStatusCallback = callback
|
|
242
|
+
locationEngine.permissionStatusCallback = callback
|
|
243
|
+
}
|
|
244
|
+
|
|
239
245
|
// MARK: - Distance Utilities
|
|
240
246
|
|
|
241
247
|
func getDistanceBetween(lat1: Double, lon1: Double, lat2: Double, lon2: Double) throws -> Double {
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useState","useEffect","useCallback","useRef","NitroModules","NitroLocationModule","createHybridObject","requestLocationPermission","LocationSmoother","shortestRotation","calculateBearing","useDriverLocation","config","location","setLocation","isMoving","setIsMoving","isTracking","setIsTracking","configJson","JSON","stringify","trackingRef","parsed","parse","configure","onLocation","onMotionChange","current","stopTracking","startTracking","useRideConnection","connectionState","setConnectionState","lastMessage","setLastMessage","configureConnection","onConnectionStateChange","onMessage","disconnectWebSocket","connect","connectWebSocket","disconnect","send","m","sendMessage"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,WAAW,EAAEC,MAAM,QAAQ,OAAO;AAChE,SAASC,YAAY,QAAQ,4BAA4B;AAQzD,MAAMC,mBAAmB,GACvBD,YAAY,CAACE,kBAAkB,CAC7B,uBACF,CAAC;AAEH,eAAeD,mBAAmB;AAClC,SAASE,yBAAyB,QAAQ,wBAAqB;AAC/D,SAASC,gBAAgB,QAAQ,uBAAoB;AACrD,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,cAAW;AAC9D;;
|
|
1
|
+
{"version":3,"names":["useState","useEffect","useCallback","useRef","NitroModules","NitroLocationModule","createHybridObject","requestLocationPermission","LocationSmoother","shortestRotation","calculateBearing","useDriverLocation","config","location","setLocation","isMoving","setIsMoving","isTracking","setIsTracking","configJson","JSON","stringify","trackingRef","parsed","parse","configure","onLocation","onMotionChange","current","stopTracking","startTracking","useRideConnection","connectionState","setConnectionState","lastMessage","setLastMessage","configureConnection","onConnectionStateChange","onMessage","disconnectWebSocket","connect","connectWebSocket","disconnect","send","m","sendMessage"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,WAAW,EAAEC,MAAM,QAAQ,OAAO;AAChE,SAASC,YAAY,QAAQ,4BAA4B;AAQzD,MAAMC,mBAAmB,GACvBD,YAAY,CAACE,kBAAkB,CAC7B,uBACF,CAAC;AAEH,eAAeD,mBAAmB;AAClC,SAASE,yBAAyB,QAAQ,wBAAqB;AAC/D,SAASC,gBAAgB,QAAQ,uBAAoB;AACrD,SAASC,gBAAgB,EAAEC,gBAAgB,QAAQ,cAAW;AAC9D;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AAC,EAAE,EAAE;EACP,CAAC;AACH;AAEA,OAAO,SAASa,iBAAiBA,CAACnB,MAAwB,EAAE;EAC1D,MAAM,CAACoB,eAAe,EAAEC,kBAAkB,CAAC,GAAGjC,QAAQ,CAEpD,cAAc,CAAC;EACjB,MAAM,CAACkC,WAAW,EAAEC,cAAc,CAAC,GAAGnC,QAAQ,CAAgB,IAAI,CAAC;EAEnEC,SAAS,CAAC,MAAM;IACdI,mBAAmB,CAAC+B,mBAAmB,CAACxB,MAAM,CAAC;IAC/CP,mBAAmB,CAACgC,uBAAuB,CAACJ,kBAAkB,CAAC;IAC/D5B,mBAAmB,CAACiC,SAAS,CAACH,cAAc,CAAC;IAC7C,OAAO,MAAM;MACX9B,mBAAmB,CAACkC,mBAAmB,CAAC,CAAC;IAC3C,CAAC;EACH,CAAC,EAAE,CAAC3B,MAAM,CAAC,CAAC;EAEZ,OAAO;IACLoB,eAAe;IACfE,WAAW;IACXM,OAAO,EAAEtC,WAAW,CAAC,MAAMG,mBAAmB,CAACoC,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC;IACtEC,UAAU,EAAExC,WAAW,CACrB,MAAMG,mBAAmB,CAACkC,mBAAmB,CAAC,CAAC,EAC/C,EACF,CAAC;IACDI,IAAI,EAAEzC,WAAW,CAAE0C,CAAS,IAAKvC,mBAAmB,CAACwC,WAAW,CAACD,CAAC,CAAC,EAAE,EAAE;EACzE,CAAC;AACH","ignoreList":[]}
|
|
@@ -61,6 +61,7 @@ export interface TripStats {
|
|
|
61
61
|
export type LocationProviderStatus = 'enabled' | 'disabled';
|
|
62
62
|
export type ProviderStatusCallback = (gps: LocationProviderStatus, network: LocationProviderStatus) => void;
|
|
63
63
|
export type PermissionStatus = 'notDetermined' | 'denied' | 'restricted' | 'whenInUse' | 'always';
|
|
64
|
+
export type PermissionStatusCallback = (status: PermissionStatus) => void;
|
|
64
65
|
export interface NitroLocationTracking extends HybridObject<{
|
|
65
66
|
ios: 'swift';
|
|
66
67
|
android: 'kotlin';
|
|
@@ -97,6 +98,7 @@ export interface NitroLocationTracking extends HybridObject<{
|
|
|
97
98
|
onProviderStatusChange(callback: ProviderStatusCallback): void;
|
|
98
99
|
getLocationPermissionStatus(): PermissionStatus;
|
|
99
100
|
requestLocationPermission(): Promise<PermissionStatus>;
|
|
101
|
+
onPermissionStatusChange(callback: PermissionStatusCallback): void;
|
|
100
102
|
getDistanceBetween(lat1: number, lon1: number, lat2: number, lon2: number): number;
|
|
101
103
|
getDistanceToGeofence(regionId: string): number;
|
|
102
104
|
showLocalNotification(title: string, body: string): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NitroLocationTracking.nitro.d.ts","sourceRoot":"","sources":["../../../src/NitroLocationTracking.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAI/D,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,GAAG,KAAK,CAAC;AACxD,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,cAAc,GAAG,cAAc,CAAC;AAI5E,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,aAAa,CAAC;IAC/B,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE,OAAO,CAAC;IACrB,2BAA2B,EAAE,MAAM,CAAC;IACp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
@@ -4,7 +4,7 @@ export default NitroLocationModule;
|
|
|
4
4
|
export { requestLocationPermission } from './requestPermission';
|
|
5
5
|
export { LocationSmoother } from './LocationSmoother';
|
|
6
6
|
export { shortestRotation, calculateBearing } from './bearing';
|
|
7
|
-
export type { NitroLocationTracking, LocationData, LocationConfig, ConnectionConfig, GeofenceRegion, GeofenceEvent, GeofenceCallback, SpeedConfig, SpeedAlertType, SpeedAlertCallback, TripStats, LocationProviderStatus, ProviderStatusCallback, PermissionStatus, } from './NitroLocationTracking.nitro';
|
|
7
|
+
export type { NitroLocationTracking, LocationData, LocationConfig, ConnectionConfig, GeofenceRegion, GeofenceEvent, GeofenceCallback, SpeedConfig, SpeedAlertType, SpeedAlertCallback, TripStats, LocationProviderStatus, ProviderStatusCallback, PermissionStatus, PermissionStatusCallback, } from './NitroLocationTracking.nitro';
|
|
8
8
|
export declare function useDriverLocation(config: LocationConfig): {
|
|
9
9
|
location: LocationData | null;
|
|
10
10
|
isMoving: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACd,gBAAgB,EACjB,MAAM,+BAA+B,CAAC;AAEvC,QAAA,MAAM,mBAAmB,uBAGtB,CAAC;AAEJ,eAAe,mBAAmB,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE/D,YAAY,EACV,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACd,gBAAgB,EACjB,MAAM,+BAA+B,CAAC;AAEvC,QAAA,MAAM,mBAAmB,uBAGtB,CAAC;AAEJ,eAAe,mBAAmB,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE/D,YAAY,EACV,qBAAqB,EACrB,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,SAAS,EACT,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EAChB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AAEvC,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc;;;;;;EAuCvD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,gBAAgB;;;;;cAuBhC,MAAM;EAE/B"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JFunc_void_PermissionStatus.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include <functional>
|
|
12
|
+
|
|
13
|
+
#include "PermissionStatus.hpp"
|
|
14
|
+
#include <functional>
|
|
15
|
+
#include <NitroModules/JNICallable.hpp>
|
|
16
|
+
#include "JPermissionStatus.hpp"
|
|
17
|
+
|
|
18
|
+
namespace margelo::nitro::nitrolocationtracking {
|
|
19
|
+
|
|
20
|
+
using namespace facebook;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Represents the Java/Kotlin callback `(status: PermissionStatus) -> Unit`.
|
|
24
|
+
* This can be passed around between C++ and Java/Kotlin.
|
|
25
|
+
*/
|
|
26
|
+
struct JFunc_void_PermissionStatus: public jni::JavaClass<JFunc_void_PermissionStatus> {
|
|
27
|
+
public:
|
|
28
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrolocationtracking/Func_void_PermissionStatus;";
|
|
29
|
+
|
|
30
|
+
public:
|
|
31
|
+
/**
|
|
32
|
+
* Invokes the function this `JFunc_void_PermissionStatus` instance holds through JNI.
|
|
33
|
+
*/
|
|
34
|
+
void invoke(PermissionStatus status) const {
|
|
35
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JPermissionStatus> /* status */)>("invoke");
|
|
36
|
+
method(self(), JPermissionStatus::fromCpp(status));
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* An implementation of Func_void_PermissionStatus that is backed by a C++ implementation (using `std::function<...>`)
|
|
42
|
+
*/
|
|
43
|
+
class JFunc_void_PermissionStatus_cxx final: public jni::HybridClass<JFunc_void_PermissionStatus_cxx, JFunc_void_PermissionStatus> {
|
|
44
|
+
public:
|
|
45
|
+
static jni::local_ref<JFunc_void_PermissionStatus::javaobject> fromCpp(const std::function<void(PermissionStatus /* status */)>& func) {
|
|
46
|
+
return JFunc_void_PermissionStatus_cxx::newObjectCxxArgs(func);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public:
|
|
50
|
+
/**
|
|
51
|
+
* Invokes the C++ `std::function<...>` this `JFunc_void_PermissionStatus_cxx` instance holds.
|
|
52
|
+
*/
|
|
53
|
+
void invoke_cxx(jni::alias_ref<JPermissionStatus> status) {
|
|
54
|
+
_func(status->toCpp());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
[[nodiscard]]
|
|
59
|
+
inline const std::function<void(PermissionStatus /* status */)>& getFunction() const {
|
|
60
|
+
return _func;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public:
|
|
64
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrolocationtracking/Func_void_PermissionStatus_cxx;";
|
|
65
|
+
static void registerNatives() {
|
|
66
|
+
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_PermissionStatus_cxx::invoke_cxx)});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private:
|
|
70
|
+
explicit JFunc_void_PermissionStatus_cxx(const std::function<void(PermissionStatus /* status */)>& func): _func(func) { }
|
|
71
|
+
|
|
72
|
+
private:
|
|
73
|
+
friend HybridBase;
|
|
74
|
+
std::function<void(PermissionStatus /* status */)> _func;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
} // namespace margelo::nitro::nitrolocationtracking
|
|
@@ -69,6 +69,7 @@ namespace margelo::nitro::nitrolocationtracking { enum class LocationProviderSta
|
|
|
69
69
|
#include "LocationProviderStatus.hpp"
|
|
70
70
|
#include "JFunc_void_LocationProviderStatus_LocationProviderStatus.hpp"
|
|
71
71
|
#include "JLocationProviderStatus.hpp"
|
|
72
|
+
#include "JFunc_void_PermissionStatus.hpp"
|
|
72
73
|
|
|
73
74
|
namespace margelo::nitro::nitrolocationtracking {
|
|
74
75
|
|
|
@@ -281,6 +282,10 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
281
282
|
return __promise;
|
|
282
283
|
}();
|
|
283
284
|
}
|
|
285
|
+
void JHybridNitroLocationTrackingSpec::onPermissionStatusChange(const std::function<void(PermissionStatus /* status */)>& callback) {
|
|
286
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_PermissionStatus::javaobject> /* callback */)>("onPermissionStatusChange_cxx");
|
|
287
|
+
method(_javaPart, JFunc_void_PermissionStatus_cxx::fromCpp(callback));
|
|
288
|
+
}
|
|
284
289
|
double JHybridNitroLocationTrackingSpec::getDistanceBetween(double lat1, double lon1, double lat2, double lon2) {
|
|
285
290
|
static const auto method = javaClassStatic()->getMethod<double(double /* lat1 */, double /* lon1 */, double /* lat2 */, double /* lon2 */)>("getDistanceBetween");
|
|
286
291
|
auto __result = method(_javaPart, lat1, lon1, lat2, lon2);
|
|
@@ -87,6 +87,7 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
87
87
|
void onProviderStatusChange(const std::function<void(LocationProviderStatus /* gps */, LocationProviderStatus /* network */)>& callback) override;
|
|
88
88
|
PermissionStatus getLocationPermissionStatus() override;
|
|
89
89
|
std::shared_ptr<Promise<PermissionStatus>> requestLocationPermission() override;
|
|
90
|
+
void onPermissionStatusChange(const std::function<void(PermissionStatus /* status */)>& callback) override;
|
|
90
91
|
double getDistanceBetween(double lat1, double lon1, double lat2, double lon2) override;
|
|
91
92
|
double getDistanceToGeofence(const std::string& regionId) override;
|
|
92
93
|
void showLocalNotification(const std::string& title, const std::string& body) override;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_PermissionStatus.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.nitrolocationtracking
|
|
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 `(status: enum) => 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_PermissionStatus: (PermissionStatus) -> 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(status: PermissionStatus): Unit
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents the JavaScript callback `(status: enum) => 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_PermissionStatus_cxx: Func_void_PermissionStatus {
|
|
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(status: PermissionStatus): Unit
|
|
60
|
+
= invoke_cxx(status)
|
|
61
|
+
|
|
62
|
+
@FastNative
|
|
63
|
+
private external fun invoke_cxx(status: PermissionStatus): Unit
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Represents the JavaScript callback `(status: enum) => void`.
|
|
68
|
+
* This is implemented in Java/Kotlin, via a `(PermissionStatus) -> Unit`.
|
|
69
|
+
* The callback is always coming from native.
|
|
70
|
+
*/
|
|
71
|
+
@DoNotStrip
|
|
72
|
+
@Keep
|
|
73
|
+
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
74
|
+
class Func_void_PermissionStatus_java(private val function: (PermissionStatus) -> Unit): Func_void_PermissionStatus {
|
|
75
|
+
@DoNotStrip
|
|
76
|
+
@Keep
|
|
77
|
+
override fun invoke(status: PermissionStatus): Unit {
|
|
78
|
+
return this.function(status)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -209,6 +209,15 @@ abstract class HybridNitroLocationTrackingSpec: HybridObject() {
|
|
|
209
209
|
@Keep
|
|
210
210
|
abstract fun requestLocationPermission(): Promise<PermissionStatus>
|
|
211
211
|
|
|
212
|
+
abstract fun onPermissionStatusChange(callback: (status: PermissionStatus) -> Unit): Unit
|
|
213
|
+
|
|
214
|
+
@DoNotStrip
|
|
215
|
+
@Keep
|
|
216
|
+
private fun onPermissionStatusChange_cxx(callback: Func_void_PermissionStatus): Unit {
|
|
217
|
+
val __result = onPermissionStatusChange(callback)
|
|
218
|
+
return __result
|
|
219
|
+
}
|
|
220
|
+
|
|
212
221
|
@DoNotStrip
|
|
213
222
|
@Keep
|
|
214
223
|
abstract fun getDistanceBetween(lat1: Double, lon1: Double, lat2: Double, lon2: Double): Double
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
#include "JFunc_void_GeofenceEvent_std__string.hpp"
|
|
24
24
|
#include "JFunc_void_SpeedAlertType_double.hpp"
|
|
25
25
|
#include "JFunc_void_LocationProviderStatus_LocationProviderStatus.hpp"
|
|
26
|
+
#include "JFunc_void_PermissionStatus.hpp"
|
|
26
27
|
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
27
28
|
|
|
28
29
|
namespace margelo::nitro::nitrolocationtracking {
|
|
@@ -42,6 +43,7 @@ int initialize(JavaVM* vm) {
|
|
|
42
43
|
margelo::nitro::nitrolocationtracking::JFunc_void_GeofenceEvent_std__string_cxx::registerNatives();
|
|
43
44
|
margelo::nitro::nitrolocationtracking::JFunc_void_SpeedAlertType_double_cxx::registerNatives();
|
|
44
45
|
margelo::nitro::nitrolocationtracking::JFunc_void_LocationProviderStatus_LocationProviderStatus_cxx::registerNatives();
|
|
46
|
+
margelo::nitro::nitrolocationtracking::JFunc_void_PermissionStatus_cxx::registerNatives();
|
|
45
47
|
|
|
46
48
|
// Register Nitro Hybrid Objects
|
|
47
49
|
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
@@ -318,6 +318,12 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
318
318
|
auto __value = std::move(__result.value());
|
|
319
319
|
return __value;
|
|
320
320
|
}
|
|
321
|
+
inline void onPermissionStatusChange(const std::function<void(PermissionStatus /* status */)>& callback) override {
|
|
322
|
+
auto __result = _swiftPart.onPermissionStatusChange(callback);
|
|
323
|
+
if (__result.hasError()) [[unlikely]] {
|
|
324
|
+
std::rethrow_exception(__result.error());
|
|
325
|
+
}
|
|
326
|
+
}
|
|
321
327
|
inline double getDistanceBetween(double lat1, double lon1, double lat2, double lon2) override {
|
|
322
328
|
auto __result = _swiftPart.getDistanceBetween(std::forward<decltype(lat1)>(lat1), std::forward<decltype(lon1)>(lon1), std::forward<decltype(lat2)>(lat2), std::forward<decltype(lon2)>(lon2));
|
|
323
329
|
if (__result.hasError()) [[unlikely]] {
|
|
@@ -45,6 +45,7 @@ public protocol HybridNitroLocationTrackingSpec_protocol: HybridObject {
|
|
|
45
45
|
func onProviderStatusChange(callback: @escaping (_ gps: LocationProviderStatus, _ network: LocationProviderStatus) -> Void) throws -> Void
|
|
46
46
|
func getLocationPermissionStatus() throws -> PermissionStatus
|
|
47
47
|
func requestLocationPermission() throws -> Promise<PermissionStatus>
|
|
48
|
+
func onPermissionStatusChange(callback: @escaping (_ status: PermissionStatus) -> Void) throws -> Void
|
|
48
49
|
func getDistanceBetween(lat1: Double, lon1: Double, lat2: Double, lon2: Double) throws -> Double
|
|
49
50
|
func getDistanceToGeofence(regionId: String) throws -> Double
|
|
50
51
|
func showLocalNotification(title: String, body: String) throws -> Void
|
|
@@ -543,6 +543,22 @@ open class HybridNitroLocationTrackingSpec_cxx {
|
|
|
543
543
|
}
|
|
544
544
|
}
|
|
545
545
|
|
|
546
|
+
@inline(__always)
|
|
547
|
+
public final func onPermissionStatusChange(callback: bridge.Func_void_PermissionStatus) -> bridge.Result_void_ {
|
|
548
|
+
do {
|
|
549
|
+
try self.__implementation.onPermissionStatusChange(callback: { () -> (PermissionStatus) -> Void in
|
|
550
|
+
let __wrappedFunction = bridge.wrap_Func_void_PermissionStatus(callback)
|
|
551
|
+
return { (__status: PermissionStatus) -> Void in
|
|
552
|
+
__wrappedFunction.call(__status.rawValue)
|
|
553
|
+
}
|
|
554
|
+
}())
|
|
555
|
+
return bridge.create_Result_void_()
|
|
556
|
+
} catch (let __error) {
|
|
557
|
+
let __exceptionPtr = __error.toCpp()
|
|
558
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
|
|
546
562
|
@inline(__always)
|
|
547
563
|
public final func getDistanceBetween(lat1: Double, lon1: Double, lat2: Double, lon2: Double) -> bridge.Result_double_ {
|
|
548
564
|
do {
|
|
@@ -46,6 +46,7 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
46
46
|
prototype.registerHybridMethod("onProviderStatusChange", &HybridNitroLocationTrackingSpec::onProviderStatusChange);
|
|
47
47
|
prototype.registerHybridMethod("getLocationPermissionStatus", &HybridNitroLocationTrackingSpec::getLocationPermissionStatus);
|
|
48
48
|
prototype.registerHybridMethod("requestLocationPermission", &HybridNitroLocationTrackingSpec::requestLocationPermission);
|
|
49
|
+
prototype.registerHybridMethod("onPermissionStatusChange", &HybridNitroLocationTrackingSpec::onPermissionStatusChange);
|
|
49
50
|
prototype.registerHybridMethod("getDistanceBetween", &HybridNitroLocationTrackingSpec::getDistanceBetween);
|
|
50
51
|
prototype.registerHybridMethod("getDistanceToGeofence", &HybridNitroLocationTrackingSpec::getDistanceToGeofence);
|
|
51
52
|
prototype.registerHybridMethod("showLocalNotification", &HybridNitroLocationTrackingSpec::showLocalNotification);
|
|
@@ -114,6 +114,7 @@ namespace margelo::nitro::nitrolocationtracking {
|
|
|
114
114
|
virtual void onProviderStatusChange(const std::function<void(LocationProviderStatus /* gps */, LocationProviderStatus /* network */)>& callback) = 0;
|
|
115
115
|
virtual PermissionStatus getLocationPermissionStatus() = 0;
|
|
116
116
|
virtual std::shared_ptr<Promise<PermissionStatus>> requestLocationPermission() = 0;
|
|
117
|
+
virtual void onPermissionStatusChange(const std::function<void(PermissionStatus /* status */)>& callback) = 0;
|
|
117
118
|
virtual double getDistanceBetween(double lat1, double lon1, double lat2, double lon2) = 0;
|
|
118
119
|
virtual double getDistanceToGeofence(const std::string& regionId) = 0;
|
|
119
120
|
virtual void showLocalNotification(const std::string& title, const std::string& body) = 0;
|
package/package.json
CHANGED
|
@@ -89,6 +89,8 @@ export type PermissionStatus =
|
|
|
89
89
|
| 'whenInUse'
|
|
90
90
|
| 'always';
|
|
91
91
|
|
|
92
|
+
export type PermissionStatusCallback = (status: PermissionStatus) => void;
|
|
93
|
+
|
|
92
94
|
// ─── Hybrid Object ──────────────────────────────────
|
|
93
95
|
|
|
94
96
|
export interface NitroLocationTracking
|
|
@@ -144,6 +146,7 @@ export interface NitroLocationTracking
|
|
|
144
146
|
// === Permission Status ===
|
|
145
147
|
getLocationPermissionStatus(): PermissionStatus;
|
|
146
148
|
requestLocationPermission(): Promise<PermissionStatus>;
|
|
149
|
+
onPermissionStatusChange(callback: PermissionStatusCallback): void;
|
|
147
150
|
|
|
148
151
|
// === Distance Utilities ===
|
|
149
152
|
getDistanceBetween(
|