react-native-geo-activity-kit 1.2.1 → 1.2.4
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 +1 -2
- package/android/src/main/java/com/rngeoactivitykit/SensorModule.kt +46 -12
- package/lib/module/index.js +5 -5
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +9 -3
package/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
package com.rngeoactivitykit
|
|
2
2
|
|
|
3
|
+
import android.content.BroadcastReceiver
|
|
4
|
+
import android.content.Context
|
|
3
5
|
import android.content.Intent
|
|
6
|
+
import android.content.IntentFilter
|
|
7
|
+
import android.location.LocationManager
|
|
4
8
|
import android.os.Build
|
|
5
9
|
import com.facebook.react.bridge.*
|
|
10
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
6
11
|
import com.google.android.gms.location.Priority
|
|
7
12
|
|
|
8
13
|
class SensorModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
@@ -10,29 +15,60 @@ class SensorModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
10
15
|
private val notificationHelper = NotificationHelper(reactContext)
|
|
11
16
|
private val locationHelper = LocationHelper(reactContext)
|
|
12
17
|
|
|
13
|
-
// Connect Motion Logic to Location Logic
|
|
14
18
|
private val motionDetector = MotionDetector(reactContext) { newState ->
|
|
15
19
|
onMotionStateChanged(newState)
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
private var locationInterval: Long = 30000
|
|
22
|
+
private var locationInterval: Long = 30000
|
|
23
|
+
|
|
24
|
+
// --- NEW: Hardware GPS Toggle Receiver ---
|
|
25
|
+
private val gpsStatusReceiver = object : BroadcastReceiver() {
|
|
26
|
+
override fun onReceive(context: Context?, intent: Intent?) {
|
|
27
|
+
if (intent?.action == LocationManager.PROVIDERS_CHANGED_ACTION) {
|
|
28
|
+
val locationManager = context?.getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
|
29
|
+
val isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
|
|
30
|
+
|
|
31
|
+
val params = Arguments.createMap()
|
|
32
|
+
params.putBoolean("enabled", isGpsEnabled)
|
|
33
|
+
|
|
34
|
+
// Emit event to React Native
|
|
35
|
+
sendEvent("onGpsStatusChanged", params)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
19
39
|
|
|
20
40
|
override fun getName(): String = "RNSensorModule"
|
|
21
41
|
|
|
22
|
-
|
|
42
|
+
private fun sendEvent(eventName: String, params: WritableMap) {
|
|
43
|
+
if (reactApplicationContext.hasActiveCatalystInstance()) {
|
|
44
|
+
reactApplicationContext
|
|
45
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
46
|
+
.emit(eventName, params)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
23
50
|
private fun onMotionStateChanged(state: String) {
|
|
24
51
|
if (state == "MOVING") {
|
|
25
|
-
// High Power
|
|
26
52
|
locationHelper.updateLocationRequest(Priority.PRIORITY_HIGH_ACCURACY, locationInterval)
|
|
27
53
|
locationHelper.startLocationUpdates()
|
|
28
54
|
} else {
|
|
29
|
-
// Low Power (Cell/Wifi) & Slow Updates
|
|
30
55
|
locationHelper.updateLocationRequest(Priority.PRIORITY_BALANCED_POWER_ACCURACY, 180000)
|
|
31
56
|
locationHelper.startLocationUpdates()
|
|
32
57
|
}
|
|
33
58
|
}
|
|
34
59
|
|
|
35
|
-
// ---
|
|
60
|
+
// --- NEW: Native Method to Start GPS Listener ---
|
|
61
|
+
@ReactMethod
|
|
62
|
+
fun registerGpsListener(promise: Promise) {
|
|
63
|
+
try {
|
|
64
|
+
val filter = IntentFilter(LocationManager.PROVIDERS_CHANGED_ACTION)
|
|
65
|
+
reactApplicationContext.registerReceiver(gpsStatusReceiver, filter)
|
|
66
|
+
promise.resolve(true)
|
|
67
|
+
} catch (e: Exception) {
|
|
68
|
+
promise.reject("REGISTER_FAILED", e.message)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
36
72
|
@ReactMethod
|
|
37
73
|
fun startForegroundService(title: String, body: String, promise: Promise) {
|
|
38
74
|
try {
|
|
@@ -82,7 +118,6 @@ class SensorModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
82
118
|
}
|
|
83
119
|
}
|
|
84
120
|
|
|
85
|
-
// --- Sensor Methods ---
|
|
86
121
|
@ReactMethod
|
|
87
122
|
fun startMotionDetector(threshold: Double, promise: Promise) {
|
|
88
123
|
val success = motionDetector.start(threshold)
|
|
@@ -90,11 +125,8 @@ class SensorModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
90
125
|
promise.reject("NO_SENSOR", "Accelerometer not available")
|
|
91
126
|
return
|
|
92
127
|
}
|
|
93
|
-
|
|
94
|
-
// Start Location immediately (Balanced Mode)
|
|
95
128
|
locationHelper.updateLocationRequest(Priority.PRIORITY_BALANCED_POWER_ACCURACY, 180000)
|
|
96
129
|
locationHelper.startLocationUpdates()
|
|
97
|
-
|
|
98
130
|
promise.resolve(true)
|
|
99
131
|
}
|
|
100
132
|
|
|
@@ -159,13 +191,15 @@ class SensorModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
|
|
|
159
191
|
@ReactMethod fun addListener(eventName: String) {}
|
|
160
192
|
@ReactMethod fun removeListeners(count: Int) {}
|
|
161
193
|
|
|
162
|
-
// Cleanup
|
|
163
194
|
override fun onCatalystInstanceDestroy() {
|
|
195
|
+
try {
|
|
196
|
+
reactApplicationContext.unregisterReceiver(gpsStatusReceiver)
|
|
197
|
+
} catch (e: Exception) {}
|
|
198
|
+
|
|
164
199
|
super.onCatalystInstanceDestroy()
|
|
165
200
|
motionDetector.stop()
|
|
166
201
|
locationHelper.stopLocationUpdates()
|
|
167
202
|
|
|
168
|
-
// Optional: Stop service if you want app death to kill service
|
|
169
203
|
val intent = Intent(reactApplicationContext, TrackingService::class.java)
|
|
170
204
|
intent.action = TrackingService.ACTION_STOP
|
|
171
205
|
reactApplicationContext.startService(intent)
|
package/lib/module/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { NativeModules, NativeEventEmitter
|
|
4
|
-
const LINKING_ERROR = `The package 'react-native-geo-activity-kit' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
-
ios: "- You have run 'pod install'\n",
|
|
6
|
-
default: ''
|
|
7
|
-
}) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
3
|
+
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
4
|
+
const LINKING_ERROR = `The package 'react-native-geo-activity-kit' doesn't seem to be linked. Make sure: \n\n` + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
|
|
8
5
|
const RNSensorModule = NativeModules.RNSensorModule ? NativeModules.RNSensorModule : new Proxy({}, {
|
|
9
6
|
get() {
|
|
10
7
|
throw new Error(LINKING_ERROR);
|
|
@@ -27,6 +24,9 @@ export default {
|
|
|
27
24
|
fireGenericAlert: (title, body, id) => RNSensorModule.fireGenericAlert(title, body, id),
|
|
28
25
|
cancelGenericAlert: id => RNSensorModule.cancelGenericAlert(id),
|
|
29
26
|
isAvailable: () => RNSensorModule.isAvailable(),
|
|
27
|
+
// --- NEW GPS HARDWARE METHODS ---
|
|
28
|
+
registerGpsListener: () => RNSensorModule.registerGpsListener(),
|
|
29
|
+
addGpsStatusListener: cb => emitter.addListener('onGpsStatusChanged', event => cb(event)),
|
|
30
30
|
// Listeners
|
|
31
31
|
addMotionListener: cb => emitter.addListener('onMotionStateChanged', cb),
|
|
32
32
|
addLocationLogListener: cb => emitter.addListener('onLocationLog', cb),
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeModules","NativeEventEmitter","
|
|
1
|
+
{"version":3,"names":["NativeModules","NativeEventEmitter","LINKING_ERROR","RNSensorModule","Proxy","get","Error","emitter","startForegroundService","title","body","stopForegroundService","updateServiceNotification","startMotionDetector","threshold","stopMotionDetector","setUpdateInterval","ms","setLocationUpdateInterval","setStabilityThresholds","start","stop","fireGeofenceAlert","type","userName","fireGenericAlert","id","cancelGenericAlert","isAvailable","registerGpsListener","addGpsStatusListener","cb","addListener","event","addMotionListener","addLocationLogListener","addLocationErrorListener"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,kBAAkB,QAAQ,cAAc;AAEhE,MAAMC,aAAa,GACjB,wFAAwF,GACxF,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,cAAc,GAAGH,aAAa,CAACG,cAAc,GAC/CH,aAAa,CAACG,cAAc,GAC5B,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACJ,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEL,MAAMK,OAAO,GAAG,IAAIN,kBAAkB,CAACE,cAAc,CAAC;AAEtD,eAAe;EACb;EACAK,sBAAsB,EAAEA,CAACC,KAAa,EAAEC,IAAY,KAClDP,cAAc,CAACK,sBAAsB,CAACC,KAAK,EAAEC,IAAI,CAAC;EAEpDC,qBAAqB,EAAEA,CAAA,KACrBR,cAAc,CAACQ,qBAAqB,CAAC,CAAC;EAExCC,yBAAyB,EAAEA,CAACH,KAAa,EAAEC,IAAY,KACrDP,cAAc,CAACS,yBAAyB,CAACH,KAAK,EAAEC,IAAI,CAAC;EAEvD;EACAG,mBAAmB,EAAEA,CAACC,SAAiB,GAAG,GAAG,KAC3CX,cAAc,CAACU,mBAAmB,CAACC,SAAS,CAAC;EAE/CC,kBAAkB,EAAEA,CAAA,KAAMZ,cAAc,CAACY,kBAAkB,CAAC,CAAC;EAE7DC,iBAA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 +11,10 @@ declare const _default: {
|
|
|
11
11
|
fireGenericAlert: (title: string, body: string, id: number) => any;
|
|
12
12
|
cancelGenericAlert: (id: number) => any;
|
|
13
13
|
isAvailable: () => any;
|
|
14
|
+
registerGpsListener: () => Promise<boolean>;
|
|
15
|
+
addGpsStatusListener: (cb: (event: {
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
}) => void) => import("react-native").EventSubscription;
|
|
14
18
|
addMotionListener: (cb: (event: any) => void) => import("react-native").EventSubscription;
|
|
15
19
|
addLocationLogListener: (cb: (event: any) => void) => import("react-native").EventSubscription;
|
|
16
20
|
addLocationErrorListener: (cb: (event: any) => void) => import("react-native").EventSubscription;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":";oCAsBkC,MAAM,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;iCAG5C,OAAO,CAAC,OAAO,CAAC;uCAGR,MAAM,QAAQ,MAAM,KAAG,OAAO,CAAC,OAAO,CAAC;sCAIzC,MAAM;;6BAKf,MAAM;qCAEE,MAAM;qCAGN,MAAM,SAAa,MAAM;8BAI/B,MAAM,YAAY,MAAM;8BAGxB,MAAM,QAAQ,MAAM,MAAM,MAAM;6BAGjC,MAAM;;+BAKN,OAAO,CAAC,OAAO,CAAC;+BAGd,CAAC,KAAK,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI;4BAIxC,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI;iCAGf,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI;mCAGlB,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI;;AAlDrD,wBAoDE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-geo-activity-kit",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Battery-efficient location tracking with motion detection and native notifications.",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -170,4 +170,4 @@
|
|
|
170
170
|
],
|
|
171
171
|
"version": "0.55.1"
|
|
172
172
|
}
|
|
173
|
-
}
|
|
173
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { NativeModules, NativeEventEmitter
|
|
1
|
+
import { NativeModules, NativeEventEmitter } from 'react-native';
|
|
2
2
|
|
|
3
3
|
const LINKING_ERROR =
|
|
4
4
|
`The package 'react-native-geo-activity-kit' doesn't seem to be linked. Make sure: \n\n` +
|
|
5
|
-
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
6
5
|
'- You rebuilt the app after installing the package\n' +
|
|
7
6
|
'- You are not using Expo Go\n';
|
|
8
7
|
|
|
@@ -55,6 +54,13 @@ export default {
|
|
|
55
54
|
|
|
56
55
|
isAvailable: () => RNSensorModule.isAvailable(),
|
|
57
56
|
|
|
57
|
+
// --- NEW GPS HARDWARE METHODS ---
|
|
58
|
+
registerGpsListener: (): Promise<boolean> =>
|
|
59
|
+
RNSensorModule.registerGpsListener(),
|
|
60
|
+
|
|
61
|
+
addGpsStatusListener: (cb: (event: { enabled: boolean }) => void) =>
|
|
62
|
+
emitter.addListener('onGpsStatusChanged', (event: any) => cb(event)),
|
|
63
|
+
|
|
58
64
|
// Listeners
|
|
59
65
|
addMotionListener: (cb: (event: any) => void) =>
|
|
60
66
|
emitter.addListener('onMotionStateChanged', cb),
|
|
@@ -64,4 +70,4 @@ export default {
|
|
|
64
70
|
|
|
65
71
|
addLocationErrorListener: (cb: (event: any) => void) =>
|
|
66
72
|
emitter.addListener('onLocationError', cb),
|
|
67
|
-
};
|
|
73
|
+
};
|