@amplitude/plugin-engagement-react-native 3.4.0 → 3.5.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.
@@ -33,7 +33,7 @@ Pod::Spec.new do |s|
33
33
  'ios/Frameworks/AmplitudeEngagementSwift.xcframework',
34
34
  'ios/Frameworks/CQuickJS.xcframework',
35
35
  ]
36
- s.dependency 'AmplitudeCore', '>=1.0.12', '<2.0.0'
36
+ s.dependency 'AmplitudeCore', '>=1.3.0', '<2.0.0'
37
37
  else
38
38
  s.dependency "AmplitudeEngagementSwift", engagement_version
39
39
  end
@@ -23,240 +23,290 @@ import com.amplitude.android.engagement.AmplitudeLogLevel
23
23
 
24
24
  @ReactModule(name = PluginEngagementReactNativeModule.NAME)
25
25
  class PluginEngagementReactNativeModule(val reactContext: ReactApplicationContext) :
26
- NativePluginEngagementReactNativeSpec(reactContext) {
26
+ NativePluginEngagementReactNativeSpec(reactContext) {
27
+ private data class InstanceInfo(val apiKey: String, val instance: AmplitudeEngagement)
27
28
 
28
- private data class InstanceInfo(val apiKey: String, val instance: AmplitudeEngagement)
29
+ private var instances = ConcurrentHashMap<Double, InstanceInfo>()
30
+ private var nextId: Double = 0.0
29
31
 
30
- private var instances = ConcurrentHashMap<Double, InstanceInfo>()
31
- private var _id: Double = 0.0
32
-
33
- override fun getName(): String {
34
- return NAME
35
- }
36
-
37
- override fun newInstance(apiKey: String, options: ReadableMap?): Double {
38
- // --- remove this comment ---
39
- val existingId = instances.entries.firstOrNull { it.value.apiKey == apiKey }?.key
40
- if (existingId != null) {
41
- return existingId
32
+ override fun getName(): String {
33
+ return NAME
42
34
  }
43
35
 
44
- return synchronized(this) {
45
- runBlocking(Dispatchers.Main) {
46
- val serverZone = options?.getString("serverZone")?.let {
47
- runCatching { AmplitudeServerZone.valueOf(it) }.getOrNull()
48
- } ?: AmplitudeServerZone.US
49
-
50
- val logLevel = options?.getString("logLevel")?.let { level ->
51
- runCatching { AmplitudeLogLevel.valueOf(level.uppercase()) }.getOrNull()
52
- } ?: AmplitudeLogLevel.WARN
53
-
54
- val locale = if (options?.hasKey("locale") == true) options.getString("locale") else null
55
- val ignoreAnalyticsAutomaticScreenTracking = if (options?.hasKey("ignoreAnalyticsAutomaticScreenTracking") == true) options.getBoolean("ignoreAnalyticsAutomaticScreenTracking") else null
56
-
57
- val serverUrl = if (options?.hasKey("serverUrl") == true) options.getString("serverUrl") else null
58
- val cdnUrl = if (options?.hasKey("cdnUrl") == true) options.getString("cdnUrl") else null
59
- val mediaUrl = if (options?.hasKey("mediaUrl") == true) options.getString("mediaUrl") else null
60
-
61
-
62
- var initOptions = AmplitudeInitOptions(
63
- serverZone = serverZone,
64
- serverUrl = serverUrl,
65
- cdnUrl = cdnUrl,
66
- mediaUrl = mediaUrl,
67
- logLevel = logLevel
68
- )
69
-
70
- if(locale != null) {
71
- // this way, we get the default value for `locale` from AmplitudeInitOptions
72
- // UNLESS a locale is specified
73
- initOptions = initOptions.copy(locale = locale)
36
+ override fun newInstance(
37
+ apiKey: String,
38
+ options: ReadableMap?,
39
+ ): Double {
40
+ // --- remove this comment ---
41
+ val existingId = instances.entries.firstOrNull { it.value.apiKey == apiKey }?.key
42
+ if (existingId != null) {
43
+ return existingId
74
44
  }
75
45
 
76
- if(ignoreAnalyticsAutomaticScreenTracking != null) {
77
- // this way, we get the default value for `ignoreAnalyticsAutomaticScreenTracking`
78
- // from AmplitudeInitOptions UNLESS a value is specified
79
- initOptions = initOptions.copy(ignoreAnalyticsAutomaticScreenTracking = ignoreAnalyticsAutomaticScreenTracking)
46
+ return synchronized(this) {
47
+ runBlocking(Dispatchers.Main) {
48
+ val serverZone =
49
+ options?.getString("serverZone")?.let {
50
+ runCatching { AmplitudeServerZone.valueOf(it) }.getOrNull()
51
+ } ?: AmplitudeServerZone.US
52
+
53
+ val logLevel =
54
+ options?.getString("logLevel")?.let { level ->
55
+ runCatching { AmplitudeLogLevel.valueOf(level.uppercase()) }.getOrNull()
56
+ } ?: AmplitudeLogLevel.WARN
57
+
58
+ val locale = if (options?.hasKey("locale") == true) options.getString("locale") else null
59
+ val ignoreAnalyticsAutomaticScreenTracking =
60
+ if (options?.hasKey("ignoreAnalyticsAutomaticScreenTracking") == true) {
61
+ options.getBoolean(
62
+ "ignoreAnalyticsAutomaticScreenTracking",
63
+ )
64
+ } else {
65
+ null
66
+ }
67
+
68
+ val serverUrl = if (options?.hasKey("serverUrl") == true) options.getString("serverUrl") else null
69
+ val cdnUrl = if (options?.hasKey("cdnUrl") == true) options.getString("cdnUrl") else null
70
+ val mediaUrl = if (options?.hasKey("mediaUrl") == true) options.getString("mediaUrl") else null
71
+
72
+ var initOptions =
73
+ AmplitudeInitOptions(
74
+ serverZone = serverZone,
75
+ serverUrl = serverUrl,
76
+ cdnUrl = cdnUrl,
77
+ mediaUrl = mediaUrl,
78
+ logLevel = logLevel,
79
+ )
80
+
81
+ if (locale != null) {
82
+ // this way, we get the default value for `locale` from AmplitudeInitOptions
83
+ // UNLESS a locale is specified
84
+ initOptions = initOptions.copy(locale = locale)
85
+ }
86
+
87
+ if (ignoreAnalyticsAutomaticScreenTracking != null) {
88
+ // this way, we get the default value for `ignoreAnalyticsAutomaticScreenTracking`
89
+ // from AmplitudeInitOptions UNLESS a value is specified
90
+ initOptions = initOptions.copy(ignoreAnalyticsAutomaticScreenTracking = ignoreAnalyticsAutomaticScreenTracking)
91
+ }
92
+
93
+ val platformVersion = options?.getString("platformVersion") ?: ""
94
+
95
+ Log.d("PluginEngagementReactNativeModule", "newInstance apiKey=$apiKey, options=$options, initOptions=$initOptions")
96
+ val amplitudeEngagement = __ReactNative__AESDK(reactContext, apiKey, initOptions, platformVersion = platformVersion)
97
+
98
+ // The React Native environment seems to have a different activity management lifecycle;
99
+ // so we need to register our own listener to get the current activity.
100
+ amplitudeEngagement.setCurrentActivity(reactContext.currentActivity)
101
+ val lifecycleEventListener: LifecycleEventListener =
102
+ object : LifecycleEventListener {
103
+ override fun onHostResume() {
104
+ amplitudeEngagement.setCurrentActivity(reactContext.currentActivity)
105
+ }
106
+
107
+ override fun onHostPause() {
108
+ }
109
+
110
+ override fun onHostDestroy() {
111
+ }
112
+ }
113
+
114
+ reactContext.addLifecycleEventListener(lifecycleEventListener)
115
+
116
+ nextId++
117
+ val id = nextId
118
+ Log.d("PluginEngagementReactNativeModule", "newInstance id=$id")
119
+ instances[id] =
120
+ InstanceInfo(
121
+ apiKey,
122
+ amplitudeEngagement,
123
+ )
124
+
125
+ id
126
+ }
80
127
  }
128
+ }
81
129
 
82
- val platformVersion = options?.getString("platformVersion") ?: ""
83
-
84
- Log.d("PluginEngagementReactNativeModule", "newInstance apiKey=${apiKey}, options=${options}, initOptions=${initOptions}")
85
- val amplitudeEngagement = __ReactNative__AESDK(reactContext, apiKey, initOptions, platformVersion = platformVersion)
86
-
87
- // The React Native environment seems to have a different activity management lifecycle;
88
- // so we need to register our own listener to get the current activity.
89
- amplitudeEngagement.setCurrentActivity(reactContext.currentActivity)
90
- val lifecycleEventListener: LifecycleEventListener = object : LifecycleEventListener {
91
- override fun onHostResume() {
92
- amplitudeEngagement.setCurrentActivity(reactContext.currentActivity)
93
- }
94
-
95
- override fun onHostPause() {
96
- }
97
-
98
- override fun onHostDestroy() {
99
- }
130
+ override fun boot(
131
+ id: Double,
132
+ userId: String?,
133
+ deviceId: String?,
134
+ userProperties: ReadableMap?,
135
+ ) {
136
+ val instance = instances[id]?.instance ?: return
137
+ val self = this
138
+ runBlocking(Dispatchers.Main) {
139
+ Log.d("PluginEngagementReactNativeModule", "boot: $userId, $deviceId, $userProperties")
140
+ val options =
141
+ AmplitudeBootOptions(
142
+ userId = userId,
143
+ deviceId = deviceId,
144
+ userProperties = userProperties?.toHashMap() ?: emptyMap(),
145
+ integrations =
146
+ arrayOf(
147
+ { event: BaseEvent ->
148
+ try {
149
+ val serializedEvent =
150
+ mapOf(
151
+ "event_type" to event.eventType,
152
+ "event_properties" to event.eventProperties,
153
+ ).toWritableMap()
154
+ self.emitOnTrackEvent(serializedEvent)
155
+ } catch (e: Exception) {
156
+ Log.e("PluginEngagementReactNativeModule", "Error tracking Event", e)
157
+ }
158
+ },
159
+ ),
160
+ )
161
+ instance.boot(options)
100
162
  }
101
-
102
- reactContext.addLifecycleEventListener(lifecycleEventListener)
103
-
104
- _id++
105
- val id = _id
106
- Log.d("PluginEngagementReactNativeModule", "newInstance id=${id}")
107
- instances[id] = InstanceInfo(
108
- apiKey,
109
- amplitudeEngagement
110
- )
111
-
112
- id
113
- }
114
163
  }
115
- }
116
-
117
- override fun boot(id: Double, userId: String?, deviceId: String?, userProperties: ReadableMap?) {
118
- val instance = instances[id]?.instance ?: return
119
- val self = this
120
- runBlocking(Dispatchers.Main) {
121
- Log.d("PluginEngagementReactNativeModule", "boot: $userId, $deviceId, $userProperties")
122
- val options = AmplitudeBootOptions(userId = userId, deviceId = deviceId, userProperties = userProperties?.toHashMap() ?: emptyMap(), integrations = arrayOf(
123
- { event: BaseEvent ->
124
- try {
125
- val serializedEvent = mapOf(
126
- "event_type" to event.eventType,
127
- "event_properties" to event.eventProperties
128
- ).toWritableMap()
129
- self.emitOnTrackEvent(serializedEvent)
130
- } catch (e: Exception) {
131
- Log.e("PluginEngagementReactNativeModule", "Error tracking Event", e)
132
- }
164
+
165
+ override fun enable(id: Double) {
166
+ val instance = instances[id]?.instance ?: return
167
+ runBlocking(Dispatchers.Main) {
168
+ instance.enable()
133
169
  }
134
- ))
135
- instance.boot(options)
136
170
  }
137
- }
138
171
 
139
- override fun enable(id: Double) {
140
- val instance = instances[id]?.instance ?: return
141
- runBlocking(Dispatchers.Main) {
142
- instance.enable()
172
+ override fun disable(id: Double) {
173
+ val instance = instances[id]?.instance ?: return
174
+ runBlocking(Dispatchers.Main) {
175
+ instance.disable()
176
+ }
143
177
  }
144
- }
145
178
 
146
- override fun disable(id: Double) {
147
- val instance = instances[id]?.instance ?: return
148
- runBlocking(Dispatchers.Main) {
149
- instance.disable()
150
- }
151
- }
152
- override fun shutdown(id: Double) {
153
- val instance = instances[id]?.instance ?: return
154
- runBlocking(Dispatchers.Main) {
155
- instance.shutdown()
179
+ override fun shutdown(id: Double) {
180
+ val instance = instances[id]?.instance ?: return
181
+ runBlocking(Dispatchers.Main) {
182
+ instance.shutdown()
183
+ }
156
184
  }
157
- }
158
185
 
159
- override fun setThemeMode(id: Double, themeMode: String?) {
160
- val instance = instances[id]?.instance ?: return
186
+ override fun setThemeMode(
187
+ id: Double,
188
+ themeMode: String?,
189
+ ) {
190
+ val instance = instances[id]?.instance ?: return
161
191
 
162
- runBlocking(Dispatchers.Main) {
163
- if (themeMode != null) {
164
- instance.setThemeMode(ThemeMode.valueOf(themeMode))
165
- }
192
+ runBlocking(Dispatchers.Main) {
193
+ if (themeMode != null) {
194
+ instance.setThemeMode(ThemeMode.valueOf(themeMode))
195
+ }
196
+ }
166
197
  }
167
- }
168
198
 
169
- override fun reset(id: Double, key: String, stepIndex: Double) {
170
- val instance = instances[id]?.instance ?: return
171
- runBlocking(Dispatchers.Main) {
172
- instance.reset(key, stepIndex.toInt())
199
+ override fun reset(
200
+ id: Double,
201
+ key: String,
202
+ stepIndex: Double,
203
+ ) {
204
+ val instance = instances[id]?.instance ?: return
205
+ runBlocking(Dispatchers.Main) {
206
+ instance.reset(key, stepIndex.toInt())
207
+ }
173
208
  }
174
- }
175
-
176
- override fun list(id: Double): WritableArray {
177
- val writableArray = Arguments.createArray()
178
- val instance = instances[id]?.instance ?: return writableArray
179
- runBlocking(Dispatchers.Main) {
180
- val guidesAndSurveysList = instance.list()
181
- guidesAndSurveysList.forEach { guide ->
182
- Log.d("PluginEngagementReactNativeModule", "list: $guide")
183
- val map = Arguments.createMap();
184
- map.putInt("id", guide.id);
185
- map.putString("title", guide.title);
186
- map.putString("status", guide.status);
187
- map.putInt("step", guide.step);
188
- writableArray.pushMap(map);
189
- }
209
+
210
+ override fun list(id: Double): WritableArray {
211
+ val writableArray = Arguments.createArray()
212
+ val instance = instances[id]?.instance ?: return writableArray
213
+ runBlocking(Dispatchers.Main) {
214
+ val guidesAndSurveysList = instance.list()
215
+ guidesAndSurveysList.forEach { guide ->
216
+ Log.d("PluginEngagementReactNativeModule", "list: $guide")
217
+ val map = Arguments.createMap()
218
+ map.putInt("id", guide.id)
219
+ map.putString("title", guide.title)
220
+ map.putString("status", guide.status)
221
+ map.putInt("step", guide.step)
222
+ writableArray.pushMap(map)
223
+ }
224
+ }
225
+ return writableArray
190
226
  }
191
- return writableArray
192
- }
193
227
 
194
- override fun show(id: Double, key: String, stepIndex: Double) {
195
- val instance = instances[id]?.instance ?: return
196
- runBlocking(Dispatchers.Main) {
197
- instance.show(key, stepIndex.toInt())
228
+ override fun show(
229
+ id: Double,
230
+ key: String,
231
+ stepIndex: Double,
232
+ ) {
233
+ val instance = instances[id]?.instance ?: return
234
+ runBlocking(Dispatchers.Main) {
235
+ instance.show(key, stepIndex.toInt())
236
+ }
198
237
  }
199
- }
200
238
 
201
- override fun screen(id: Double, screenName: String) {
202
- val instance = instances[id]?.instance ?: return
203
- runBlocking(Dispatchers.Main) {
204
- instance.screen(screenName)
239
+ override fun screen(
240
+ id: Double,
241
+ screenName: String,
242
+ ) {
243
+ val instance = instances[id]?.instance ?: return
244
+ runBlocking(Dispatchers.Main) {
245
+ instance.screen(screenName)
246
+ }
205
247
  }
206
- }
207
248
 
208
- override fun closeAll(id: Double) {
209
- val instance = instances[id]?.instance ?: return
210
- runBlocking(Dispatchers.Main) {
211
- instance.closeAll()
249
+ override fun closeAll(id: Double) {
250
+ val instance = instances[id]?.instance ?: return
251
+ runBlocking(Dispatchers.Main) {
252
+ instance.closeAll()
253
+ }
212
254
  }
213
- }
214
-
215
- override fun forwardEvent(id: Double, event: ReadableMap) {
216
- val instance = instances[id]?.instance ?: return
217
- val baseEvent = BaseEvent()
218
- baseEvent.eventType = event.getString("event_type") ?: return
219
- baseEvent.eventId = event.getDouble("event_id").toLong()
220
- baseEvent.platform = event.getString("platform")
221
- baseEvent.osName = event.getString("os_name")
222
- baseEvent.osVersion = event.getString("os_version")
223
- baseEvent.eventProperties = event.getMap("event_properties")?.toHashMap()?.toMutableMap()
224
- baseEvent.groupProperties = event.getMap("group_properties")?.toHashMap()?.toMutableMap()
225
- baseEvent.groups = event.getMap("groups")?.toHashMap()?.toMutableMap()
226
- baseEvent.userProperties = event.getMap("user_properties")?.toHashMap()?.toMutableMap()
227
- Log.d("PluginEngagementReactNativeModule", "forwardEvent: $baseEvent")
228
- runBlocking(Dispatchers.Main) {
229
- instance.forwardEvent(baseEvent)
255
+
256
+ override fun forwardEvent(
257
+ id: Double,
258
+ event: ReadableMap,
259
+ ) {
260
+ val instance = instances[id]?.instance ?: return
261
+ val baseEvent = BaseEvent()
262
+ baseEvent.eventType = event.getString("event_type") ?: return
263
+ baseEvent.eventId = event.getDouble("event_id").toLong()
264
+ baseEvent.platform = event.getString("platform")
265
+ baseEvent.osName = event.getString("os_name")
266
+ baseEvent.osVersion = event.getString("os_version")
267
+ baseEvent.eventProperties = event.getMap("event_properties")?.toHashMap()?.toMutableMap()
268
+ baseEvent.groupProperties = event.getMap("group_properties")?.toHashMap()?.toMutableMap()
269
+ baseEvent.groups = event.getMap("groups")?.toHashMap()?.toMutableMap()
270
+ baseEvent.userProperties = event.getMap("user_properties")?.toHashMap()?.toMutableMap()
271
+ Log.d("PluginEngagementReactNativeModule", "forwardEvent: $baseEvent")
272
+ runBlocking(Dispatchers.Main) {
273
+ instance.forwardEvent(baseEvent)
274
+ }
230
275
  }
231
- }
232
-
233
- override fun addCallback(id: Double, key: String) {
234
- val instance = instances[id]?.instance ?: return
235
- val self = this
236
- runBlocking(Dispatchers.Main) {
237
- instance.addCallback(key) {
238
- val serializedEvent = mapOf(
239
- "id" to id,
240
- "key" to key
241
- ).toWritableMap()
242
- self.emitOnInvokeCallback(serializedEvent)
243
- }
276
+
277
+ override fun addCallback(
278
+ id: Double,
279
+ key: String,
280
+ ) {
281
+ val instance = instances[id]?.instance ?: return
282
+ val self = this
283
+ runBlocking(Dispatchers.Main) {
284
+ instance.addCallback(key) {
285
+ val serializedEvent =
286
+ mapOf(
287
+ "id" to id,
288
+ "key" to key,
289
+ ).toWritableMap()
290
+ self.emitOnInvokeCallback(serializedEvent)
291
+ }
292
+ }
244
293
  }
245
- }
246
294
 
247
- override fun handleURL(id: Double, url: String): Boolean {
248
- val instance = instances[id]?.instance ?: return false
295
+ override fun handleURL(
296
+ id: Double,
297
+ url: String,
298
+ ): Boolean {
299
+ val instance = instances[id]?.instance ?: return false
249
300
 
250
- val uri = url.toUri()
251
- val intent = Intent(Intent.ACTION_VIEW, uri)
301
+ val uri = url.toUri()
302
+ val intent = Intent(Intent.ACTION_VIEW, uri)
252
303
 
253
- return runBlocking(Dispatchers.Main) {
254
- instance.handlePreviewLinkIntent(intent)
304
+ return runBlocking(Dispatchers.Main) {
305
+ instance.handlePreviewLinkIntent(intent)
306
+ }
255
307
  }
256
- }
257
308
 
258
-
259
- companion object {
260
- const val NAME = "PluginEngagementReactNative"
261
- }
309
+ companion object {
310
+ const val NAME = "PluginEngagementReactNative"
311
+ }
262
312
  }
@@ -8,26 +8,34 @@ import com.facebook.react.module.model.ReactModuleInfoProvider
8
8
  import java.util.HashMap
9
9
 
10
10
  class PluginEngagementReactNativePackage : BaseReactPackage() {
11
- override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
12
- return if (name == PluginEngagementReactNativeModule.NAME) {
13
- PluginEngagementReactNativeModule(reactContext)
14
- } else {
15
- null
11
+ override fun getModule(
12
+ name: String,
13
+ reactContext: ReactApplicationContext,
14
+ ): NativeModule? {
15
+ return if (name == PluginEngagementReactNativeModule.NAME) {
16
+ PluginEngagementReactNativeModule(reactContext)
17
+ } else {
18
+ null
19
+ }
16
20
  }
17
- }
18
21
 
19
- override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
20
- return ReactModuleInfoProvider {
21
- val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
22
- moduleInfos[PluginEngagementReactNativeModule.NAME] = ReactModuleInfo(
23
- PluginEngagementReactNativeModule.NAME,
24
- PluginEngagementReactNativeModule.NAME,
25
- false, // canOverrideExistingModule
26
- false, // needsEagerInit
27
- false, // isCxxModule
28
- true // isTurboModule
29
- )
30
- moduleInfos
22
+ override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
23
+ return ReactModuleInfoProvider {
24
+ val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
25
+ moduleInfos[PluginEngagementReactNativeModule.NAME] =
26
+ ReactModuleInfo(
27
+ PluginEngagementReactNativeModule.NAME,
28
+ PluginEngagementReactNativeModule.NAME,
29
+ // canOverrideExistingModule
30
+ false,
31
+ // needsEagerInit
32
+ false,
33
+ // isCxxModule
34
+ false,
35
+ // isTurboModule
36
+ true,
37
+ )
38
+ moduleInfos
39
+ }
31
40
  }
32
- }
33
41
  }
@@ -5,47 +5,46 @@ import com.facebook.react.bridge.WritableArray
5
5
  import com.facebook.react.bridge.WritableMap
6
6
 
7
7
  fun Iterable<*>.toWritableArray(): WritableArray {
8
- val iter = this.iterator()
9
-
10
- val writableArray: WritableArray = Arguments.createArray()
11
-
12
- while (iter.hasNext()) {
13
- val value = iter.next()
14
-
15
- when (value) {
16
- null -> writableArray.pushNull()
17
- is Boolean -> writableArray.pushBoolean(value)
18
- is Double -> writableArray.pushDouble(value)
19
- is Int -> writableArray.pushInt(value)
20
- is String -> writableArray.pushString(value)
21
- is Map<*, *> -> writableArray.pushMap((value as Map<String, Any?>).toWritableMap())
22
- else -> throw IllegalArgumentException("Cannot convert value of type ${value.javaClass.simpleName}")
8
+ val iter = this.iterator()
9
+
10
+ val writableArray: WritableArray = Arguments.createArray()
11
+
12
+ while (iter.hasNext()) {
13
+ val value = iter.next()
14
+
15
+ when (value) {
16
+ null -> writableArray.pushNull()
17
+ is Boolean -> writableArray.pushBoolean(value)
18
+ is Double -> writableArray.pushDouble(value)
19
+ is Int -> writableArray.pushInt(value)
20
+ is String -> writableArray.pushString(value)
21
+ is Map<*, *> -> writableArray.pushMap((value as Map<String, Any?>).toWritableMap())
22
+ else -> throw IllegalArgumentException("Cannot convert value of type ${value.javaClass.simpleName}")
23
+ }
23
24
  }
24
- }
25
25
 
26
- return writableArray
26
+ return writableArray
27
27
  }
28
28
 
29
-
30
29
  fun Map<String, *>.toWritableMap(): WritableMap {
31
- val writableMap: WritableMap = Arguments.createMap()
32
- val iterator = entries.iterator()
33
-
34
- while (iterator.hasNext()) {
35
- val pair = iterator.next()
36
- val value = pair.value
37
-
38
- when {
39
- value == null -> writableMap.putNull(pair.key)
40
- value is Boolean -> writableMap.putBoolean(pair.key, value)
41
- value is Double -> writableMap.putDouble(pair.key, value)
42
- value is Int -> writableMap.putInt(pair.key, value)
43
- value is String -> writableMap.putString(pair.key, value)
44
- value is Map<*, *> -> writableMap.putMap(pair.key, (value as Map<String, *>).toWritableMap())
45
- value is Iterable<*> -> writableMap.putArray(pair.key, value.toWritableArray())
46
- else -> throw IllegalArgumentException("Cannot convert value of type ${value.javaClass.simpleName}")
30
+ val writableMap: WritableMap = Arguments.createMap()
31
+ val iterator = entries.iterator()
32
+
33
+ while (iterator.hasNext()) {
34
+ val pair = iterator.next()
35
+ val value = pair.value
36
+
37
+ when {
38
+ value == null -> writableMap.putNull(pair.key)
39
+ value is Boolean -> writableMap.putBoolean(pair.key, value)
40
+ value is Double -> writableMap.putDouble(pair.key, value)
41
+ value is Int -> writableMap.putInt(pair.key, value)
42
+ value is String -> writableMap.putString(pair.key, value)
43
+ value is Map<*, *> -> writableMap.putMap(pair.key, (value as Map<String, *>).toWritableMap())
44
+ value is Iterable<*> -> writableMap.putArray(pair.key, value.toWritableArray())
45
+ else -> throw IllegalArgumentException("Cannot convert value of type ${value.javaClass.simpleName}")
46
+ }
47
47
  }
48
- }
49
48
 
50
- return writableMap
49
+ return writableMap
51
50
  }
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "3.4.0"
2
+ "version": "3.5.0"
3
3
  }
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "3.4.0"
2
+ "version": "3.5.0"
3
3
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/plugin-engagement-react-native",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": "Amplitude Engagement plugin for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -38,7 +38,8 @@
38
38
  "e2e:android": "scripts/prepare-e2e-tests.sh && cd testproject && yarn e2e:android",
39
39
  "e2e:android:headless": "scripts/prepare-e2e-tests.sh && cd testproject && yarn e2e:android:headless",
40
40
  "typecheck": "tsc",
41
- "lint": "eslint \"**/*.{js,ts,tsx}\"",
41
+ "lint": "eslint \"src/**/*.{js,ts,tsx}\"",
42
+ "lint:fix": "eslint --fix \"src/**/*.{js,ts,tsx}\"",
42
43
  "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
43
44
  "prepare": "bob build",
44
45
  "release": "npm publish --tag latest --ddd"
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "3.4.0"
2
+ "version": "3.5.0"
3
3
  }
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "3.4.0"
2
+ "version": "3.5.0"
3
3
  }