hypertrack-sdk-react-native 10.0.3-psl19.1 → 11.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/CONTRIBUTING.md +1 -1
  3. package/README.md +2 -2
  4. package/android/build.gradle +5 -1
  5. package/android/gradle.properties +1 -1
  6. package/android/src/main/java/com/reactnativehypertracksdk/HyperTrackReactNativePlugin.kt +80 -115
  7. package/android/src/main/java/com/reactnativehypertracksdk/ReactNativeSerialization.kt +23 -3
  8. package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackSdkWrapper.kt +87 -220
  9. package/android/src/main/java/com/reactnativehypertracksdk/common/SdkMethod.kt +11 -9
  10. package/android/src/main/java/com/reactnativehypertracksdk/common/Serialization.kt +216 -132
  11. package/android/src/main/java/com/reactnativehypertracksdk/common/{Result.kt → WrapperResult.kt} +9 -7
  12. package/hypertrack-sdk-react-native.podspec +1 -1
  13. package/ios/HyperTrackReactNativePlugin.m +13 -11
  14. package/ios/HyperTrackReactNativePlugin.swift +141 -114
  15. package/ios/common/DictionaryDecoder.swift +5 -5
  16. package/ios/common/HyperTrackSDKWrapper.swift +44 -80
  17. package/ios/common/SDKMethod.swift +13 -12
  18. package/ios/common/Serialization.swift +190 -245
  19. package/lib/commonjs/HyperTrack/HyperTrack.js +224 -124
  20. package/lib/commonjs/HyperTrack/HyperTrack.js.map +1 -1
  21. package/lib/commonjs/HyperTrack/data_types/HyperTrackError.js +13 -17
  22. package/lib/commonjs/HyperTrack/data_types/HyperTrackError.js.map +1 -1
  23. package/lib/commonjs/HyperTrack/data_types/internal/HyperTrackErrorInternal.js.map +1 -1
  24. package/lib/commonjs/HyperTrack/data_types/internal/Metadata.js +2 -0
  25. package/lib/commonjs/HyperTrack/data_types/internal/Metadata.js.map +1 -0
  26. package/lib/commonjs/HyperTrack/data_types/internal/Name.js +2 -0
  27. package/lib/commonjs/HyperTrack/data_types/internal/Name.js.map +1 -0
  28. package/lib/commonjs/index.js +0 -7
  29. package/lib/commonjs/index.js.map +1 -1
  30. package/lib/module/HyperTrack/HyperTrack.js +224 -124
  31. package/lib/module/HyperTrack/HyperTrack.js.map +1 -1
  32. package/lib/module/HyperTrack/data_types/HyperTrackError.js +13 -17
  33. package/lib/module/HyperTrack/data_types/HyperTrackError.js.map +1 -1
  34. package/lib/module/HyperTrack/data_types/internal/HyperTrackErrorInternal.js.map +1 -1
  35. package/lib/module/HyperTrack/data_types/internal/Metadata.js +2 -0
  36. package/lib/module/HyperTrack/data_types/internal/Metadata.js.map +1 -0
  37. package/lib/module/HyperTrack/data_types/internal/Name.js +2 -0
  38. package/lib/module/HyperTrack/data_types/internal/Name.js.map +1 -0
  39. package/lib/module/index.js +0 -1
  40. package/lib/module/index.js.map +1 -1
  41. package/lib/typescript/HyperTrack/HyperTrack.d.ts +106 -54
  42. package/lib/typescript/HyperTrack/data_types/HyperTrackError.d.ts +59 -17
  43. package/lib/typescript/HyperTrack/data_types/internal/HyperTrackErrorInternal.d.ts +1 -1
  44. package/lib/typescript/HyperTrack/data_types/internal/Metadata.d.ts +4 -0
  45. package/lib/typescript/HyperTrack/data_types/internal/Name.d.ts +7 -0
  46. package/lib/typescript/index.d.ts +0 -1
  47. package/package.json +1 -1
  48. package/src/HyperTrack/HyperTrack.ts +281 -161
  49. package/src/HyperTrack/data_types/HyperTrackError.ts +73 -18
  50. package/src/HyperTrack/data_types/internal/HyperTrackErrorInternal.ts +3 -3
  51. package/src/HyperTrack/data_types/internal/Metadata.ts +4 -0
  52. package/src/HyperTrack/data_types/internal/Name.ts +7 -0
  53. package/src/index.tsx +0 -1
  54. package/android/src/main/java/com/reactnativehypertracksdk/common/HyperTrackError.kt +0 -28
  55. package/android/src/main/java/com/reactnativehypertracksdk/common/LocationError.kt +0 -9
  56. package/android/src/main/java/com/reactnativehypertracksdk/common/SdkInitParams.kt +0 -44
  57. package/ios/common/HyperTrackError.swift +0 -20
  58. package/ios/common/SDKInitParams.swift +0 -13
  59. package/lib/commonjs/HyperTrack/data_types/SdkInitParams.js +0 -2
  60. package/lib/commonjs/HyperTrack/data_types/SdkInitParams.js.map +0 -1
  61. package/lib/commonjs/HyperTrack/data_types/internal/DeviceName.js +0 -2
  62. package/lib/commonjs/HyperTrack/data_types/internal/DeviceName.js.map +0 -1
  63. package/lib/module/HyperTrack/data_types/SdkInitParams.js +0 -2
  64. package/lib/module/HyperTrack/data_types/SdkInitParams.js.map +0 -1
  65. package/lib/module/HyperTrack/data_types/internal/DeviceName.js +0 -2
  66. package/lib/module/HyperTrack/data_types/internal/DeviceName.js.map +0 -1
  67. package/lib/typescript/HyperTrack/data_types/SdkInitParams.d.ts +0 -25
  68. package/lib/typescript/HyperTrack/data_types/internal/DeviceName.d.ts +0 -4
  69. package/src/HyperTrack/data_types/SdkInitParams.ts +0 -28
  70. package/src/HyperTrack/data_types/internal/DeviceName.ts +0 -4
package/CHANGELOG.md CHANGED
@@ -3,6 +3,54 @@
3
3
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
4
4
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5
5
 
6
+ ## [11.0.0] - 2023-09-08
7
+
8
+ ### Added
9
+
10
+ - `locate()` to ask for one-time user location
11
+ - `subscribeToLocation()` to subscribe to user location updates
12
+ - `getErrors()`
13
+ - `getName()`
14
+ - `getMetadata()`
15
+ - HyperTrackError types:
16
+ - `noExemptionFromBackgroundStartRestrictions`
17
+ - `permissionsNotificationsDenied`
18
+
19
+ ### Changed
20
+
21
+ - Updated HyperTrack Android SDK to 7.0.1
22
+ - Add Android SDK plugins (`location-services-google-19-0-1` and `push-service-firebase`)
23
+ - Updated HyperTrack iOS SDK to 5.0.1
24
+ - The whole HyperTrack API is now static
25
+ - Changed the way to provide publishableKey (you need to add `HyperTrackPublishableKey` `meta-data` item to your `AndroidManifest.xml`)
26
+ - Renamed HyperTrackError types:
27
+ - `gpsSignalLost` to `locationSignalLost`
28
+ - `locationPermissionsDenied` to `permissionsLocationDenied`
29
+ - `locationPermissionsInsufficientForBackground` to `permissionsLocationInsufficientForBackground`
30
+ - `locationPermissionsNotDetermined` to `permissionsLocationNotDetermined`
31
+ - `locationPermissionsProvisional` to `locationPermissionsProvisional`
32
+ - `locationPermissionsReducedAccuracy` to `permissionsLocationReducedAccuracy`
33
+ - `locationPermissionsRestricted` to `permissionsLocationRestricted`
34
+ - Renamed `isAvailable()` to `getIsAvailable()`
35
+ - Renamed `isTracking()` to `getIsTracking()`
36
+ - Renamed `setAvailability()` to `setIsAvailable(boolean)`
37
+ - Changed `startTracking()` and `stopTracking()` to `setIsTracking(boolean)`
38
+ - Renamed `subscribeToTracking()` to `subscribeToIsTracking()`
39
+ - Renamed `subscribeToAvailability()` to `subscribeToIsAvailable()`
40
+
41
+ ### Removed
42
+
43
+ - `initialize()` method (the API is now static)
44
+ - `SdkInitParams` (the config now should be done with the `AndroidManifest` metadata and `Info.plist`)
45
+ - Motion Activity permissions are not required for tracking anymore
46
+ - HyperTrackError types:
47
+ - `motionActivityPermissionsDenied`
48
+ - `motionActivityServicesDisabled`
49
+ - `motionActivityServicesUnavailable`
50
+ - `motionActivityPermissionsRestricted`
51
+ - `networkConnectionUnavailable`
52
+ - `sync()` method
53
+
6
54
  ## [10.0.3] - 2023-08-04
7
55
 
8
56
  ### Fixed
package/CONTRIBUTING.md CHANGED
@@ -11,7 +11,7 @@
11
11
  - HyperTrackSdk_HyperTrackSDKVersion
12
12
  - ios
13
13
  - [hypertrack-sdk-react-native.podspec](hypertrack-sdk-react-native.podspec)
14
- - s.dependency 'HyperTrack/Objective-C', '**version**'
14
+ - s.dependency 'HyperTrack', '**version**'
15
15
 
16
16
  2. Increment wrapper version
17
17
 
package/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  ![GitHub](https://img.shields.io/github/license/hypertrack/sdk-react-native.svg)
4
4
  ![npm](https://img.shields.io/npm/v/hypertrack-sdk-react-native.svg)
5
- ![iOS SDK](https://img.shields.io/badge/iOS%20SDK-4.16.1-brightgreen.svg)
6
- ![Android SDK](https://img.shields.io/badge/Android%20SDK-6.4.2-brightgreen.svg)
5
+ ![iOS SDK](https://img.shields.io/badge/iOS%20SDK-5.0.1-brightgreen.svg)
6
+ ![Android SDK](https://img.shields.io/badge/Android%20SDK-7.0.1-brightgreen.svg)
7
7
 
8
8
  [HyperTrack](https://www.hypertrack.com) lets you add live location tracking to your mobile app. Live location is made available along with ongoing activity, tracking controls and tracking outage with reasons.
9
9
 
@@ -144,8 +144,12 @@ def hyperTrackSdk_version = getExtOrDefault('HyperTrackSDKVersion')
144
144
  dependencies {
145
145
  //noinspection GradleDynamicVersion
146
146
  implementation "com.facebook.react:react-native:+"
147
+
147
148
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
148
- implementation "com.hypertrack:hypertrack:$hyperTrackSdk_version"
149
+
150
+ implementation "com.hypertrack:sdk-android:$hyperTrackSdk_version"
151
+ implementation "com.hypertrack:location-services-google-19-0-1:$hyperTrackSdk_version"
152
+ implementation "com.hypertrack:push-service-firebase:$hyperTrackSdk_version"
149
153
  }
150
154
 
151
155
  if (isNewArchitectureEnabled()) {
@@ -2,5 +2,5 @@ HyperTrackSdk_kotlinVersion=1.6.21
2
2
  HyperTrackSdk_minSdkVersion=23
3
3
  HyperTrackSdk_targetSdkVersion=30
4
4
  HyperTrackSdk_compileSdkVersion=31
5
- HyperTrackSdk_HyperTrackSDKVersion=6.4.2-psl19.1
5
+ HyperTrackSdk_HyperTrackSDKVersion=7.0.1
6
6
  android.useAndroidX=true
@@ -4,120 +4,67 @@ import com.facebook.react.bridge.*
4
4
  import com.facebook.react.module.annotations.ReactModule
5
5
  import com.facebook.react.modules.core.DeviceEventManagerModule
6
6
  import com.hypertrack.sdk.*
7
- import com.hypertrack.sdk.AvailabilityStateObserver.OnAvailabilityStateChangeListener
8
- import com.hypertrack.sdk.TrackingStateObserver.OnTrackingStateChangeListener
7
+ import com.hypertrack.sdk.android.HyperTrack
9
8
  import com.reactnativehypertracksdk.common.*
9
+ import com.reactnativehypertracksdk.common.Serialization.serializeErrors
10
10
  import com.reactnativehypertracksdk.common.Serialization.serializeIsAvailable
11
11
  import com.reactnativehypertracksdk.common.Serialization.serializeIsTracking
12
+ import com.reactnativehypertracksdk.common.Serialization.serializeLocateResult
13
+ import com.reactnativehypertracksdk.common.Serialization.serializeLocation
14
+ import com.reactnativehypertracksdk.common.Serialization.serializeLocationResult
12
15
 
13
- @Suppress("ComplexRedundantLet")
14
16
  @ReactModule(name = HyperTrackReactNativePlugin.NAME)
15
17
  class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
16
18
  ReactContextBaseJavaModule(reactContext) {
17
19
 
18
- var trackingStateListener: OnTrackingStateChangeListener? = null
19
- var availabilityListener: OnAvailabilityStateChangeListener? = null
20
+ private var locateSubscription: HyperTrack.Cancellable? = null
20
21
 
21
22
  override fun getName(): String {
22
23
  return NAME
23
24
  }
24
25
 
26
+ /**
27
+ * ReactNative built-in methods
28
+ */
29
+
25
30
  @ReactMethod
26
- fun addListener(type: String?) {
27
- when (type) {
28
- EVENT_TRACKING -> {
29
- HyperTrackSdkWrapper.isTracking().let {
30
- when (it) {
31
- is Success -> {
32
- emitIsTracking(it.success)
33
- }
34
- is Failure -> {
35
- throw Exception("isTracking failed: ${it.failure}", it.failure)
36
- }
37
- }
38
- }
31
+ fun addListener(eventName: String?) {
32
+ // called when RN app subscribes to an event
33
+ when (eventName) {
34
+ EVENT_ERRORS -> {
35
+ emitEvent(EVENT_ERRORS, serializeErrors(HyperTrack.errors).toWriteableArray())
39
36
  }
40
- EVENT_AVAILABILITY -> {
41
- HyperTrackSdkWrapper.isAvailable().let {
42
- when (it) {
43
- is Success -> {
44
- emitIsAvailable(it.success)
45
- }
46
- is Failure -> {
47
- throw Exception("isAvailable failed: ${it.failure}", it.failure)
48
- }
49
- }
50
- }
37
+ EVENT_IS_AVAILABLE -> {
38
+ emitEvent(EVENT_IS_AVAILABLE, serializeIsAvailable(HyperTrack.isAvailable).toWritableMap())
51
39
  }
52
- EVENT_ERRORS -> {
53
- HyperTrackSdkWrapper.getInitialErrors().let {
54
- emitErrors(it)
55
- }
40
+ EVENT_IS_TRACKING -> {
41
+ emitEvent(EVENT_IS_TRACKING, serializeIsTracking(HyperTrack.isTracking).toWritableMap())
42
+ }
43
+ EVENT_LOCATION -> {
44
+ emitEvent(EVENT_LOCATION, serializeLocationResult(HyperTrack.location).toWritableMap())
56
45
  }
57
46
  else -> Unit
58
47
  }
59
48
  // Keep: Required for RN built in Event Emitter Calls.
60
49
  }
61
50
 
62
- @ReactMethod
63
- fun removeListeners(type: Int?) {
64
- // Keep: Required for RN built in Event Emitter Calls.
51
+ override fun initialize() {
52
+ super.initialize()
53
+ initListeners()
65
54
  }
66
55
 
67
56
  @ReactMethod
68
- fun initializeSdk(
69
- initParams: ReadableMap,
70
- promise: Promise
71
- ) {
72
- HyperTrackSdkWrapper
73
- .initializeSdk(initParams.toHashMap())
74
- .mapSuccess { sdk ->
75
- initListeners(sdk)
76
- }
77
- .toPromise(promise)
57
+ fun removeListeners(type: Int?) {
58
+ // Keep: Required for RN built in Event Emitter Calls.
78
59
  }
79
60
 
80
- private fun initListeners(sdkInstance: HyperTrack) {
81
- if (trackingStateListener != null) {
82
- sdkInstance.removeTrackingListener(trackingStateListener)
83
- trackingStateListener = null
84
- }
85
- trackingStateListener = object : OnTrackingStateChangeListener {
86
- override fun onError(trackingError: TrackingError) {
87
- emitErrors(HyperTrackSdkWrapper.getErrors(trackingError))
88
- }
89
-
90
- override fun onTrackingStart() {
91
- emitIsTracking(serializeIsTracking(true))
92
- }
93
-
94
- override fun onTrackingStop() {
95
- emitIsTracking(serializeIsTracking(false))
96
- }
97
- }.also {
98
- sdkInstance.addTrackingListener(it)
99
- }
61
+ /**
62
+ * SDK methods
63
+ */
100
64
 
101
- if (availabilityListener != null) {
102
- sdkInstance.removeAvailabilityListener(availabilityListener)
103
- availabilityListener = null
104
- }
105
- availabilityListener =
106
- object : AvailabilityStateObserver.OnAvailabilityStateChangeListener {
107
- override fun onError(p0: AvailabilityError) {
108
- // ignored, errors are handled by trackingStateListener
109
- }
110
-
111
- override fun onAvailable() {
112
- emitIsAvailable(serializeIsAvailable(true))
113
- }
114
-
115
- override fun onUnavailable() {
116
- emitIsAvailable(serializeIsAvailable(false))
117
- }
118
- }.also {
119
- sdkInstance.addAvailabilityListener(it)
120
- }
65
+ @ReactMethod
66
+ fun addGeotag(args: ReadableMap, promise: Promise) {
67
+ HyperTrackSdkWrapper.addGeotag(args.toHashMap()).toPromise(promise)
121
68
  }
122
69
 
123
70
  @ReactMethod
@@ -126,43 +73,52 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
126
73
  }
127
74
 
128
75
  @ReactMethod
129
- fun isTracking(promise: Promise) {
130
- HyperTrackSdkWrapper.isTracking().toPromise(promise)
76
+ fun getErrors(promise: Promise) {
77
+ HyperTrackSdkWrapper.getErrors().toPromise(promise)
131
78
  }
132
79
 
133
80
  @ReactMethod
134
- fun startTracking() {
135
- HyperTrackSdkWrapper.startTracking()
81
+ fun getIsAvailable(promise: Promise) {
82
+ HyperTrackSdkWrapper.getIsAvailable().toPromise(promise)
136
83
  }
137
84
 
138
85
  @ReactMethod
139
- fun stopTracking() {
140
- HyperTrackSdkWrapper.stopTracking()
86
+ fun getIsTracking(promise: Promise) {
87
+ HyperTrackSdkWrapper.getIsTracking().toPromise(promise)
141
88
  }
142
89
 
143
90
  @ReactMethod
144
- fun sync() {
145
- HyperTrackSdkWrapper.sync()
91
+ fun getLocation(promise: Promise) {
92
+ HyperTrackSdkWrapper.getLocation().toPromise(promise)
146
93
  }
147
94
 
148
95
  @ReactMethod
149
- fun addGeotag(args: ReadableMap, promise: Promise) {
150
- HyperTrackSdkWrapper.addGeotag(args.toHashMap()).toPromise(promise)
96
+ fun getMetadata(promise: Promise) {
97
+ HyperTrackSdkWrapper.getMetadata().toPromise(promise)
151
98
  }
152
99
 
153
100
  @ReactMethod
154
- fun isAvailable(promise: Promise) {
155
- HyperTrackSdkWrapper.isAvailable().toPromise(promise)
101
+ fun getName(promise: Promise) {
102
+ HyperTrackSdkWrapper.getName().toPromise(promise)
156
103
  }
157
104
 
158
105
  @ReactMethod
159
- fun setAvailability(args: ReadableMap) {
160
- HyperTrackSdkWrapper.setAvailability(args.toHashMap())
106
+ fun locate(promise: Promise) {
107
+ locateSubscription?.cancel()
108
+ locateSubscription = HyperTrack.locate {
109
+ emitEvent(EVENT_LOCATE, serializeLocateResult(it).toWritableMap())
110
+ }
111
+ Success(Unit).toPromise(promise)
161
112
  }
162
113
 
163
114
  @ReactMethod
164
- fun setName(args: ReadableMap) {
165
- HyperTrackSdkWrapper.setName(args.toHashMap())
115
+ fun setIsAvailable(args: ReadableMap) {
116
+ HyperTrackSdkWrapper.setIsAvailable(args.toHashMap())
117
+ }
118
+
119
+ @ReactMethod
120
+ fun setIsTracking(args: ReadableMap) {
121
+ HyperTrackSdkWrapper.setIsTracking(args.toHashMap())
166
122
  }
167
123
 
168
124
  @ReactMethod
@@ -171,20 +127,26 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
171
127
  }
172
128
 
173
129
  @ReactMethod
174
- fun getLocation(promise: Promise) {
175
- HyperTrackSdkWrapper.getLocation().toPromise(promise)
130
+ fun setName(args: ReadableMap) {
131
+ HyperTrackSdkWrapper.setName(args.toHashMap())
176
132
  }
177
133
 
178
- private fun emitIsTracking(isTracking: Map<String, Any?>) {
179
- emitEvent(EVENT_TRACKING, isTracking.toWritableMap())
180
- }
134
+ private fun initListeners() {
135
+ HyperTrack.subscribeToErrors {
136
+ emitEvent(EVENT_ERRORS, serializeErrors(it).toWriteableArray())
137
+ }
181
138
 
182
- private fun emitIsAvailable(isAvailable: Map<String, Any?>) {
183
- emitEvent(EVENT_AVAILABILITY, isAvailable.toWritableMap())
184
- }
139
+ HyperTrack.subscribeToIsAvailable {
140
+ emitEvent(EVENT_IS_AVAILABLE, serializeIsAvailable(it).toWritableMap())
141
+ }
185
142
 
186
- private fun emitErrors(errors: List<Map<String, Any?>>) {
187
- emitEvent(EVENT_ERRORS, errors.toWriteableArray())
143
+ HyperTrack.subscribeToIsTracking {
144
+ emitEvent(EVENT_IS_TRACKING, serializeIsTracking(it).toWritableMap())
145
+ }
146
+
147
+ HyperTrack.subscribeToLocation {
148
+ emitEvent(EVENT_LOCATION, serializeLocationResult(it).toWritableMap())
149
+ }
188
150
  }
189
151
 
190
152
  private fun emitEvent(event: String, data: WritableMap) {
@@ -193,6 +155,7 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
193
155
  .emit(event, data)
194
156
  }
195
157
 
158
+ @Suppress("SameParameterValue")
196
159
  private fun emitEvent(event: String, data: WritableArray) {
197
160
  reactApplicationContext
198
161
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
@@ -200,9 +163,11 @@ class HyperTrackReactNativePlugin(reactContext: ReactApplicationContext?) :
200
163
  }
201
164
 
202
165
  companion object {
203
- private const val EVENT_TRACKING = "onTrackingChanged"
204
- private const val EVENT_AVAILABILITY = "onAvailabilityChanged"
205
- private const val EVENT_ERRORS = "onError"
166
+ private const val EVENT_ERRORS = "errors"
167
+ private const val EVENT_IS_AVAILABLE = "isAvailable"
168
+ private const val EVENT_IS_TRACKING = "isTracking"
169
+ private const val EVENT_LOCATE = "locate"
170
+ private const val EVENT_LOCATION = "location"
206
171
 
207
172
  const val NAME = "HyperTrackReactNativePlugin"
208
173
  }
@@ -5,26 +5,33 @@ import com.facebook.react.bridge.Promise
5
5
  import com.facebook.react.bridge.WritableArray
6
6
  import com.facebook.react.bridge.WritableMap
7
7
  import com.reactnativehypertracksdk.common.Failure
8
- import com.reactnativehypertracksdk.common.Result
8
+ import com.reactnativehypertracksdk.common.WrapperResult
9
9
  import com.reactnativehypertracksdk.common.Success
10
10
 
11
11
  @Suppress("UNCHECKED_CAST")
12
- internal fun <T> Result<T>.toPromise(promise: Promise) {
12
+ internal fun <T> WrapperResult<T>.toPromise(promise: Promise) {
13
13
  when (this) {
14
14
  is Success -> {
15
15
  when (this.success) {
16
16
  is Map<*, *> -> {
17
17
  promise.resolve((this.success as Map<String, Any>).toWritableMap())
18
18
  }
19
+
20
+ is List<*> -> {
21
+ promise.resolve((this.success as List<Any>).toWriteableArray())
22
+ }
23
+
19
24
  is Unit -> {
20
25
  promise.resolve(null)
21
26
  }
27
+
22
28
  else -> {
23
29
  // using nested exception to correctly display error in RN logs
24
30
  promise.reject(Exception(IllegalArgumentException(this.success.toString())))
25
31
  }
26
32
  }
27
33
  }
34
+
28
35
  is Failure -> {
29
36
  /**
30
37
  * ReactNative NativeBridge converts the Exception to JS Error
@@ -42,7 +49,7 @@ internal fun <T> Result<T>.toPromise(promise: Promise) {
42
49
  *
43
50
  * Default ReactNative logger skips the Exception class name in logs, so we build a
44
51
  * custom Exception to include the class name in the message.
45
- *
52
+ *
46
53
  * Default Exception.toString() will print both the class name and the message
47
54
  */
48
55
  val exception = Exception(this.failure.toString())
@@ -60,9 +67,11 @@ internal fun List<Any>.toWriteableArray(): WritableArray {
60
67
  is String -> {
61
68
  writableArray.pushString(it)
62
69
  }
70
+
63
71
  is Map<*, *> -> {
64
72
  writableArray.pushMap((it as Map<String, Any>).toWritableMap())
65
73
  }
74
+
66
75
  else -> {
67
76
  throw Exception(IllegalArgumentException(it.javaClass.toString()))
68
77
  }
@@ -81,24 +90,35 @@ internal fun Map<String, Any?>.toWritableMap(): WritableMap {
81
90
  is String -> {
82
91
  putString(key, value)
83
92
  }
93
+
84
94
  is Int -> {
85
95
  putInt(key, value)
86
96
  }
97
+
87
98
  is Double -> {
88
99
  putDouble(key, value)
89
100
  }
101
+
102
+ is Float -> {
103
+ putDouble(key, value.toDouble())
104
+ }
105
+
90
106
  is Boolean -> {
91
107
  putBoolean(key, value)
92
108
  }
109
+
93
110
  is List<*> -> {
94
111
  putArray(key, (value as List<String>).toWriteableArray())
95
112
  }
113
+
96
114
  is Map<*, *> -> {
97
115
  putMap(key, (value as Map<String, Any>).toWritableMap())
98
116
  }
117
+
99
118
  null -> {
100
119
  putNull(key)
101
120
  }
121
+
102
122
  else -> {
103
123
  throw Exception(IllegalArgumentException(entry.value?.javaClass.toString()))
104
124
  }