@os1-platform/dispatch-mobile 2.1.30 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +4 -91
  2. package/android/.gradle/7.5/checksums/checksums.lock +0 -0
  3. package/android/.gradle/7.5/checksums/sha1-checksums.bin +0 -0
  4. package/android/.gradle/7.5/fileHashes/fileHashes.lock +0 -0
  5. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  6. package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
  7. package/android/.idea/{other.xml → caches/deviceStreaming.xml} +98 -21
  8. package/android/build.gradle +1 -0
  9. package/android/src/main/AndroidManifest.xml +1 -0
  10. package/android/src/main/java/com/dispatchsdk/DispatchSdkPackage.kt +5 -1
  11. package/android/src/main/java/com/dispatchsdk/location/LocationModule.kt +79 -0
  12. package/android/src/main/java/com/dispatchsdk/permissions/PermissionModule.kt +90 -0
  13. package/ios/EventEmitter.swift +13 -1
  14. package/ios/LocationManager.swift +143 -0
  15. package/ios/LocationModule.m +19 -0
  16. package/ios/LocationModule.swift +32 -0
  17. package/ios/PermissionsModule.m +21 -0
  18. package/ios/PermissionsModule.swift +24 -0
  19. package/ios/RNEventEmitter.m +2 -8
  20. package/ios/RNEventEmitter.swift +13 -19
  21. package/lib/commonjs/components/executiontasks/doodle/SignatureET.js +5 -3
  22. package/lib/commonjs/components/executiontasks/doodle/SignatureET.js.map +1 -1
  23. package/lib/commonjs/components/executiontasks/imageCapture/ImageCapture.js +5 -3
  24. package/lib/commonjs/components/executiontasks/imageCapture/ImageCapture.js.map +1 -1
  25. package/lib/commonjs/index.js +0 -3
  26. package/lib/commonjs/index.js.map +1 -1
  27. package/lib/commonjs/manager/location/LocationManager.js +91 -46
  28. package/lib/commonjs/manager/location/LocationManager.js.map +1 -1
  29. package/lib/commonjs/native/LocationModule.js +47 -0
  30. package/lib/commonjs/native/LocationModule.js.map +1 -0
  31. package/lib/commonjs/native/PermissionModule.js +21 -0
  32. package/lib/commonjs/native/PermissionModule.js.map +1 -0
  33. package/lib/commonjs/utils/ExecTaskUtils.js +3 -3
  34. package/lib/commonjs/utils/ExecTaskUtils.js.map +1 -1
  35. package/lib/commonjs/utils/SdkUtils.js +12 -4
  36. package/lib/commonjs/utils/SdkUtils.js.map +1 -1
  37. package/lib/module/components/executiontasks/doodle/SignatureET.js +5 -3
  38. package/lib/module/components/executiontasks/doodle/SignatureET.js.map +1 -1
  39. package/lib/module/components/executiontasks/imageCapture/ImageCapture.js +5 -3
  40. package/lib/module/components/executiontasks/imageCapture/ImageCapture.js.map +1 -1
  41. package/lib/module/index.js +0 -3
  42. package/lib/module/index.js.map +1 -1
  43. package/lib/module/manager/location/LocationManager.js +90 -44
  44. package/lib/module/manager/location/LocationManager.js.map +1 -1
  45. package/lib/module/native/LocationModule.js +41 -0
  46. package/lib/module/native/LocationModule.js.map +1 -0
  47. package/lib/module/native/PermissionModule.js +15 -0
  48. package/lib/module/native/PermissionModule.js.map +1 -0
  49. package/lib/module/utils/ExecTaskUtils.js +3 -3
  50. package/lib/module/utils/ExecTaskUtils.js.map +1 -1
  51. package/lib/module/utils/SdkUtils.js +12 -4
  52. package/lib/module/utils/SdkUtils.js.map +1 -1
  53. package/lib/typescript/index.d.ts +0 -4
  54. package/lib/typescript/manager/location/LocationManager.d.ts +4 -2
  55. package/lib/typescript/native/LocationModule.d.ts +14 -0
  56. package/lib/typescript/native/PermissionModule.d.ts +6 -0
  57. package/package.json +3 -5
  58. package/src/components/executiontasks/doodle/SignatureET.tsx +6 -4
  59. package/src/components/executiontasks/imageCapture/ImageCapture.tsx +6 -3
  60. package/src/index.tsx +0 -7
  61. package/src/manager/location/LocationManager.ts +93 -41
  62. package/src/native/LocationModule.ts +52 -0
  63. package/src/native/PermissionModule.ts +21 -0
  64. package/src/utils/ExecTaskUtils.ts +3 -3
  65. package/src/utils/SdkUtils.ts +15 -5
  66. package/android/.gradle/6.8/fileChanges/last-build.bin +0 -0
  67. package/android/.gradle/6.8/fileHashes/fileHashes.lock +0 -0
  68. package/android/.gradle/6.8/gc.properties +0 -0
package/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  ## Introduction
4
4
 
5
- Dispatch SDK is an expo based SDK that is written in Typescript and some Modules in Java/Kotlin.
6
- This sdk can be used to render execution task screens on ui, maintain their states, manage mts.
5
+ Dispatch SDK is an expo based SDK that is written in Typescript and some Modules are in Java/Kotlin.
6
+ This SDK can be used to render execution task screens on UI and maintain their states.
7
7
 
8
8
  `Currently supports SDK>=21 (Android)`
9
9
 
@@ -168,7 +168,8 @@ npm install @os1-platform/dispatch-mobile
168
168
  "dependencies": {
169
169
  "@apollo/client": "^3.5.6",
170
170
  "@expo-google-fonts/ibm-plex-sans": "*",
171
- "@delhivery/platform-coreos-mts-sdk": "^2.0.3",
171
+ //MTS SDK has been removed as a dependency now
172
+ //"@delhivery/platform-coreos-mts-sdk": "^2.0.3",
172
173
  "@react-native-async-storage/async-storage": "^1.15.5",
173
174
  "@react-native-community/datetimepicker": "^3.5.2",
174
175
  "@react-native-community/netinfo": "^6.0.2",
@@ -674,98 +675,10 @@ class ClassComponent extends FCM {
674
675
  }
675
676
  ```
676
677
 
677
- ## MTS
678
-
679
- ### MTS Default Config
680
-
681
- ```ts
682
- export class MTSDefaults {
683
- locationFrequency: number = 10000; // in milli seconds (no. of seconds after which location updates will happen)
684
- distanceAccuracyLimit: number = 250; // in metres
685
- speedLimit: number = 28; // in m/s
686
- mode: MTSMode = MTSMode.HYBRID;
687
- environment: MTSEnv = MTSEnv.DEV;
688
- batchSize: number = 25;
689
- isMqttCleanSession: boolean = true;
690
- mqttKeepAliveInterval: number = 15 * 60; //in seconds
691
- maxLocationAge: number = 15000; // in milliseconds
692
- maxTraceSession: number = 24 * 3600 * 100; //in milliseconds
693
- isOdometerEnabled: boolean = true;
694
- retriesBeforeFallback: number = 1;
695
- httpFailureLimit: number = 5;
696
- dataSendDelay: number = 30000; // in milli seconds
697
- alarmTime: number = 60000; // in milli seconds
698
- missingSeqCheckDuration: number = 5 * 60 * 1000; // in milli seconds
699
- odometerPushFrequency: number = 5 * 60 * 1000; // in milli seconds
700
- qosLevel: number = 1; // values can be 0 ,1
701
- }
702
- ```
703
-
704
- ### Check For Mandatory MTS Permissions
705
-
706
- ```ts
707
- let granted = await MtsLib.requestPermissionsForMTS();
708
- // if granted = true : all permissions granted
709
- // granted = false : one or more permissions denied
710
- ```
711
-
712
- ### Init MTS
713
-
714
- ```ts
715
- import type { MTSInitRequest } from '@delhivery/platform-coreos-mts-sdk';
716
-
717
- let mtsDefaults = new MtsLib.MTSDefaults();
718
- mtsDefaults.speedLimit = 5000;
719
- mtsDefaults.locationFrequency = 10000;
720
- mtsDefaults.environment = MtsLib.MTSEnv.PRE_PROD;
721
- mtsDefaults.isOdometerEnabled = false;
722
-
723
- //Change MTS default values as per your use case
724
-
725
- // ...Use this for Initiating MTS
726
- let mtsInitReq: MTSInitRequest = {
727
- appName: 'app_name',
728
- appVersion: '1',
729
- mtsDeviceID: 'deviceId', // use FCM ID here
730
- configData: mtsDefaults,
731
- baseURL: 'https://delhivery.aws.preprod.fxtrt.io/app/dispatch/v1/api/mts/',
732
- accessToken: 'token',
733
- tenantID: tenantId,
734
- };
735
- await MtsLib.initMTS(mtsInitReq);
736
- //See Error Codes for Possible error types
737
- ```
738
-
739
- ### Start MTS
740
-
741
- ```ts
742
- let startReq: MTSStartRequest = {
743
- accessToken: 'token', // update access token
744
- resetSequence: false,
745
- dispatchID: '12345', // pass dispatch ID here
746
- expiryTime: Date.now() + 24 * 2600 * 1000, // expiry time after which MTS will stop automatically
747
- };
748
- await MtsLib.startMTS(startReq);
749
- ```
750
-
751
- ### Publish Event
752
-
753
- ```ts
754
- await MtsLib.publishEvent('TESTEVENT', { battery: 56, network: 100 });
755
- ```
756
-
757
- ### Stop MTS
758
-
759
- ```ts
760
- // To stop mts
761
- await MtsLib.stopMTS();
762
- ```
763
-
764
678
  ### Error Codes
765
679
 
766
680
  ```ts
767
681
  PERMISSIONS_ERROR[2500] = 'Mandatory Android Permissions not provided';
768
- MTS_INIT_ERROR[2501] = 'MTS INIT Not called! MTS Device ID is Empty';
769
682
  PARAM_MISSING[2502] = 'Mandatory Paramater is missing in request';
770
683
  ```
771
684
 
@@ -1,6 +1,6 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
2
  <project version="4">
3
- <component name="direct_access_persist.xml">
3
+ <component name="DeviceStreaming">
4
4
  <option name="deviceSelectionList">
5
5
  <list>
6
6
  <PersistentDeviceSelectionData>
@@ -14,6 +14,17 @@
14
14
  <option name="screenX" value="720" />
15
15
  <option name="screenY" value="1280" />
16
16
  </PersistentDeviceSelectionData>
17
+ <PersistentDeviceSelectionData>
18
+ <option name="api" value="34" />
19
+ <option name="brand" value="OPPO" />
20
+ <option name="codename" value="OP573DL1" />
21
+ <option name="id" value="OP573DL1" />
22
+ <option name="manufacturer" value="OPPO" />
23
+ <option name="name" value="CPH2557" />
24
+ <option name="screenDensity" value="480" />
25
+ <option name="screenX" value="1080" />
26
+ <option name="screenY" value="2400" />
27
+ </PersistentDeviceSelectionData>
17
28
  <PersistentDeviceSelectionData>
18
29
  <option name="api" value="28" />
19
30
  <option name="brand" value="DOCOMO" />
@@ -25,6 +36,17 @@
25
36
  <option name="screenX" value="1080" />
26
37
  <option name="screenY" value="2160" />
27
38
  </PersistentDeviceSelectionData>
39
+ <PersistentDeviceSelectionData>
40
+ <option name="api" value="34" />
41
+ <option name="brand" value="Lenovo" />
42
+ <option name="codename" value="TB370FU" />
43
+ <option name="id" value="TB370FU" />
44
+ <option name="manufacturer" value="Lenovo" />
45
+ <option name="name" value="Tab P12" />
46
+ <option name="screenDensity" value="340" />
47
+ <option name="screenX" value="1840" />
48
+ <option name="screenY" value="2944" />
49
+ </PersistentDeviceSelectionData>
28
50
  <PersistentDeviceSelectionData>
29
51
  <option name="api" value="31" />
30
52
  <option name="brand" value="samsung" />
@@ -69,6 +91,28 @@
69
91
  <option name="screenX" value="1080" />
70
92
  <option name="screenY" value="2400" />
71
93
  </PersistentDeviceSelectionData>
94
+ <PersistentDeviceSelectionData>
95
+ <option name="api" value="34" />
96
+ <option name="brand" value="google" />
97
+ <option name="codename" value="caiman" />
98
+ <option name="id" value="caiman" />
99
+ <option name="manufacturer" value="Google" />
100
+ <option name="name" value="Pixel 9 Pro" />
101
+ <option name="screenDensity" value="360" />
102
+ <option name="screenX" value="960" />
103
+ <option name="screenY" value="2142" />
104
+ </PersistentDeviceSelectionData>
105
+ <PersistentDeviceSelectionData>
106
+ <option name="api" value="34" />
107
+ <option name="brand" value="google" />
108
+ <option name="codename" value="comet" />
109
+ <option name="id" value="comet" />
110
+ <option name="manufacturer" value="Google" />
111
+ <option name="name" value="Pixel 9 Pro Fold" />
112
+ <option name="screenDensity" value="390" />
113
+ <option name="screenX" value="2076" />
114
+ <option name="screenY" value="2152" />
115
+ </PersistentDeviceSelectionData>
72
116
  <PersistentDeviceSelectionData>
73
117
  <option name="api" value="29" />
74
118
  <option name="brand" value="samsung" />
@@ -91,6 +135,17 @@
91
135
  <option name="screenX" value="1440" />
92
136
  <option name="screenY" value="3088" />
93
137
  </PersistentDeviceSelectionData>
138
+ <PersistentDeviceSelectionData>
139
+ <option name="api" value="34" />
140
+ <option name="brand" value="samsung" />
141
+ <option name="codename" value="e1q" />
142
+ <option name="id" value="e1q" />
143
+ <option name="manufacturer" value="Samsung" />
144
+ <option name="name" value="Galaxy S24" />
145
+ <option name="screenDensity" value="480" />
146
+ <option name="screenX" value="1080" />
147
+ <option name="screenY" value="2340" />
148
+ </PersistentDeviceSelectionData>
94
149
  <PersistentDeviceSelectionData>
95
150
  <option name="api" value="33" />
96
151
  <option name="brand" value="google" />
@@ -102,6 +157,17 @@
102
157
  <option name="screenX" value="2208" />
103
158
  <option name="screenY" value="1840" />
104
159
  </PersistentDeviceSelectionData>
160
+ <PersistentDeviceSelectionData>
161
+ <option name="api" value="34" />
162
+ <option name="brand" value="google" />
163
+ <option name="codename" value="felix" />
164
+ <option name="id" value="felix" />
165
+ <option name="manufacturer" value="Google" />
166
+ <option name="name" value="Pixel Fold" />
167
+ <option name="screenDensity" value="420" />
168
+ <option name="screenX" value="2208" />
169
+ <option name="screenY" value="1840" />
170
+ </PersistentDeviceSelectionData>
105
171
  <PersistentDeviceSelectionData>
106
172
  <option name="api" value="33" />
107
173
  <option name="brand" value="google" />
@@ -146,6 +212,17 @@
146
212
  <option name="screenX" value="720" />
147
213
  <option name="screenY" value="1600" />
148
214
  </PersistentDeviceSelectionData>
215
+ <PersistentDeviceSelectionData>
216
+ <option name="api" value="34" />
217
+ <option name="brand" value="google" />
218
+ <option name="codename" value="komodo" />
219
+ <option name="id" value="komodo" />
220
+ <option name="manufacturer" value="Google" />
221
+ <option name="name" value="Pixel 9 Pro XL" />
222
+ <option name="screenDensity" value="360" />
223
+ <option name="screenX" value="1008" />
224
+ <option name="screenY" value="2244" />
225
+ </PersistentDeviceSelectionData>
149
226
  <PersistentDeviceSelectionData>
150
227
  <option name="api" value="33" />
151
228
  <option name="brand" value="google" />
@@ -179,17 +256,6 @@
179
256
  <option name="screenX" value="1080" />
180
257
  <option name="screenY" value="2400" />
181
258
  </PersistentDeviceSelectionData>
182
- <PersistentDeviceSelectionData>
183
- <option name="api" value="31" />
184
- <option name="brand" value="samsung" />
185
- <option name="codename" value="q2q" />
186
- <option name="id" value="q2q" />
187
- <option name="manufacturer" value="Samsung" />
188
- <option name="name" value="Galaxy Z Fold3" />
189
- <option name="screenDensity" value="420" />
190
- <option name="screenX" value="1768" />
191
- <option name="screenY" value="2208" />
192
- </PersistentDeviceSelectionData>
193
259
  <PersistentDeviceSelectionData>
194
260
  <option name="api" value="34" />
195
261
  <option name="brand" value="samsung" />
@@ -201,6 +267,17 @@
201
267
  <option name="screenX" value="1812" />
202
268
  <option name="screenY" value="2176" />
203
269
  </PersistentDeviceSelectionData>
270
+ <PersistentDeviceSelectionData>
271
+ <option name="api" value="34" />
272
+ <option name="brand" value="samsung" />
273
+ <option name="codename" value="q6q" />
274
+ <option name="id" value="q6q" />
275
+ <option name="manufacturer" value="Samsung" />
276
+ <option name="name" value="Galaxy Z Fold6" />
277
+ <option name="screenDensity" value="420" />
278
+ <option name="screenX" value="1856" />
279
+ <option name="screenY" value="2160" />
280
+ </PersistentDeviceSelectionData>
204
281
  <PersistentDeviceSelectionData>
205
282
  <option name="api" value="30" />
206
283
  <option name="brand" value="google" />
@@ -247,15 +324,15 @@
247
324
  <option name="screenY" value="2560" />
248
325
  </PersistentDeviceSelectionData>
249
326
  <PersistentDeviceSelectionData>
250
- <option name="api" value="29" />
251
- <option name="brand" value="samsung" />
252
- <option name="codename" value="x1q" />
253
- <option name="id" value="x1q" />
254
- <option name="manufacturer" value="Samsung" />
255
- <option name="name" value="Galaxy S20" />
256
- <option name="screenDensity" value="480" />
257
- <option name="screenX" value="1440" />
258
- <option name="screenY" value="3200" />
327
+ <option name="api" value="34" />
328
+ <option name="brand" value="google" />
329
+ <option name="codename" value="tokay" />
330
+ <option name="id" value="tokay" />
331
+ <option name="manufacturer" value="Google" />
332
+ <option name="name" value="Pixel 9" />
333
+ <option name="screenDensity" value="420" />
334
+ <option name="screenX" value="1080" />
335
+ <option name="screenY" value="2424" />
259
336
  </PersistentDeviceSelectionData>
260
337
  </list>
261
338
  </option>
@@ -127,4 +127,5 @@ dependencies {
127
127
  api 'com.facebook.react:react-native:+'
128
128
  implementation 'com.google.android.material:material:1.4.0'
129
129
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
130
+ implementation 'com.google.android.gms:play-services-location:20.0.0'
130
131
  }
@@ -1,6 +1,7 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
2
  package="com.dispatchsdk">
3
3
 
4
+ <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
4
5
  <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
5
6
  <uses-permission android:name="android.permission.WAKE_LOCK" />
6
7
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
@@ -1,9 +1,11 @@
1
1
  package com.dispatchsdk
2
2
 
3
+ import com.dispatchsdk.location.LocationModule
3
4
  import com.dispatchsdk.sharedPref.SharedPreferenceModule
4
5
  import com.dispatchsdk.signaturePad.RSSignatureCaptureViewManager
5
6
  import com.dispatchsdk.sync.SyncModule
6
7
  import com.dispatchsdk.utils.DispatchSdkUtils
8
+ import com.dispatchsdk.permissions.PermissionsModule
7
9
  import com.facebook.react.ReactPackage
8
10
  import com.facebook.react.bridge.NativeModule
9
11
  import com.facebook.react.bridge.ReactApplicationContext
@@ -15,7 +17,9 @@ class DispatchSdkPackage : ReactPackage {
15
17
  return listOf(
16
18
  SyncModule(reactContext),
17
19
  DispatchSdkUtils(reactContext),
18
- SharedPreferenceModule(reactContext)
20
+ SharedPreferenceModule(reactContext),
21
+ PermissionsModule(reactContext),
22
+ LocationModule(reactContext)
19
23
  )
20
24
  }
21
25
 
@@ -0,0 +1,79 @@
1
+ package com.dispatchsdk.location
2
+
3
+ import android.Manifest
4
+ import android.content.pm.PackageManager
5
+ import android.location.Location
6
+ import android.os.Looper
7
+ import androidx.core.app.ActivityCompat
8
+ import com.facebook.react.bridge.*
9
+ import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
10
+ import com.google.android.gms.location.*
11
+
12
+ class LocationModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
13
+ private val fusedLocationClient: FusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(reactContext)
14
+ private var locationCallback: LocationCallback? = null
15
+ private var lastLocation: Location? = null
16
+
17
+ override fun getName(): String {
18
+ return "LocationModule"
19
+ }
20
+
21
+ @ReactMethod
22
+ fun startLocationUpdates(promise: Promise) {
23
+ val activity = currentActivity
24
+ if (activity == null) {
25
+ promise.reject("Activity doesn't exist")
26
+ return
27
+ }
28
+
29
+ if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
30
+ ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
31
+ promise.reject("Permissions not granted")
32
+ return
33
+ }
34
+
35
+ val locationRequest = LocationRequest.create().apply {
36
+ interval = 10000 // 10 seconds
37
+ fastestInterval = 10000 // 10 seconds
38
+ priority = LocationRequest.PRIORITY_HIGH_ACCURACY
39
+ smallestDisplacement = 10f // 10 meters
40
+ }
41
+
42
+ locationCallback = object : LocationCallback() {
43
+ override fun onLocationResult(locationResult: LocationResult) {
44
+ locationResult.lastLocation?.let { location ->
45
+ lastLocation = location
46
+ // Send location update to JavaScript
47
+ val params = Arguments.createMap()
48
+ params.putDouble("latitude", location.latitude)
49
+ params.putDouble("longitude", location.longitude)
50
+ params.putDouble("accuracy", location.accuracy.toDouble())
51
+ sendEvent("locationUpdated", params)
52
+ }
53
+ }
54
+ }
55
+
56
+ try {
57
+ fusedLocationClient.requestLocationUpdates(locationRequest, locationCallback!!, Looper.getMainLooper())
58
+ promise.resolve("Location updates started")
59
+ } catch (e: Exception) {
60
+ promise.reject("Error starting location updates", e)
61
+ }
62
+ }
63
+
64
+ @ReactMethod
65
+ fun stopLocationUpdates(promise: Promise) {
66
+ locationCallback?.let {
67
+ fusedLocationClient.removeLocationUpdates(it)
68
+ promise.resolve("Location updates stopped")
69
+ } ?: run {
70
+ promise.reject("Location updates not started")
71
+ }
72
+ }
73
+
74
+ private fun sendEvent(eventName: String, params: WritableMap) {
75
+ reactApplicationContext
76
+ .getJSModule(RCTDeviceEventEmitter::class.java)
77
+ .emit(eventName, params)
78
+ }
79
+ }
@@ -0,0 +1,90 @@
1
+ package com.dispatchsdk.permissions
2
+
3
+ import android.Manifest
4
+ import android.app.Activity
5
+ import android.content.pm.PackageManager
6
+ import android.os.Build
7
+ import androidx.activity.ComponentActivity
8
+ import androidx.activity.result.contract.ActivityResultContracts
9
+ import androidx.annotation.RequiresApi
10
+ import androidx.core.content.ContextCompat
11
+ import com.facebook.react.bridge.*
12
+
13
+ class PermissionsModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
14
+ companion object {
15
+ private const val REQUEST_CODE_FOREGROUND = 1
16
+ private const val REQUEST_CODE_BACKGROUND = 2
17
+ }
18
+
19
+ private var foregroundPromise: Promise? = null
20
+ private var backgroundPromise: Promise? = null
21
+
22
+ override fun getName(): String {
23
+ return "PermissionsModule"
24
+ }
25
+
26
+ private val requestForegroundPermissionLauncher = (reactContext.currentActivity as? ComponentActivity)?.registerForActivityResult(
27
+ ActivityResultContracts.RequestPermission()
28
+ ) { isGranted: Boolean ->
29
+ foregroundPromise?.let {
30
+ if (isGranted) {
31
+ it.resolve(true)
32
+ } else {
33
+ it.reject("Permission denied")
34
+ }
35
+ foregroundPromise = null
36
+ }
37
+ }
38
+
39
+ private val requestBackgroundPermissionLauncher =
40
+ (reactContext.currentActivity as? ComponentActivity)?.registerForActivityResult(
41
+ ActivityResultContracts.RequestPermission()
42
+ ) { isGranted: Boolean ->
43
+ backgroundPromise?.let {
44
+ if (isGranted) {
45
+ it.resolve(true)
46
+ } else {
47
+ it.reject("Permission denied")
48
+ }
49
+ backgroundPromise = null
50
+ }
51
+ }
52
+
53
+ @ReactMethod
54
+ fun requestForegroundPermissions(promise: Promise) {
55
+ val activity = currentActivity
56
+ if (activity == null) {
57
+ promise.reject("Activity doesn't exist")
58
+ return
59
+ }
60
+
61
+ if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
62
+ promise.resolve(true)
63
+ } else {
64
+ foregroundPromise = promise
65
+ requestForegroundPermissionLauncher?.launch(Manifest.permission.ACCESS_FINE_LOCATION)
66
+ }
67
+ }
68
+
69
+ @ReactMethod
70
+ fun requestBackgroundPermissions(promise: Promise) {
71
+ val activity = currentActivity
72
+ if (activity == null) {
73
+ promise.reject("Activity doesn't exist")
74
+ return
75
+ }
76
+
77
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
78
+ // For devices running Android versions below Q, background location permission is not needed.
79
+ promise.resolve(true)
80
+ return
81
+ }
82
+
83
+ if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_BACKGROUND_LOCATION) == PackageManager.PERMISSION_GRANTED) {
84
+ promise.resolve(true)
85
+ } else {
86
+ backgroundPromise = promise
87
+ requestBackgroundPermissionLauncher?.launch(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
88
+ }
89
+ }
90
+ }
@@ -9,13 +9,25 @@
9
9
  import UIKit
10
10
 
11
11
  class EventEmitter{
12
+
12
13
  public static var sharedInstance = EventEmitter()
14
+
13
15
  private static var eventEmitter: RNEventEmitter!
16
+
14
17
  private init() {}
18
+
15
19
  func registerEventEmitter(eventEmitter: RNEventEmitter) {
16
20
  EventEmitter.eventEmitter = eventEmitter
17
21
  }
18
- func dispatch(name: String, body: [String:Any]?) {
22
+
23
+ func dispatch(name: String, body: Any?) {
19
24
  EventEmitter.eventEmitter.sendEvent(withName: name, body: body)
20
25
  }
26
+
27
+ /// All Events which must be support by React Native.
28
+ lazy var allEvents: [String] = {
29
+ var allEventNames: [String] = ["locationUpdated"]
30
+ return allEventNames
31
+ }()
32
+
21
33
  }