@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.
- package/PluginEngagementReactNative.podspec +1 -1
- package/android/src/main/java/com/amplitude/pluginengagementreactnative/PluginEngagementReactNativeModule.kt +251 -201
- package/android/src/main/java/com/amplitude/pluginengagementreactnative/PluginEngagementReactNativePackage.kt +27 -19
- package/android/src/main/java/com/amplitude/pluginengagementreactnative/Util.kt +35 -36
- package/lib/module/build-version-android.json +1 -1
- package/lib/module/build-version-ios.json +1 -1
- package/package.json +3 -2
- package/src/build-version-android.json +1 -1
- package/src/build-version-ios.json +1 -1
|
@@ -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
|
|
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
|
-
|
|
26
|
+
NativePluginEngagementReactNativeSpec(reactContext) {
|
|
27
|
+
private data class InstanceInfo(val apiKey: String, val instance: AmplitudeEngagement)
|
|
27
28
|
|
|
28
|
-
|
|
29
|
+
private var instances = ConcurrentHashMap<Double, InstanceInfo>()
|
|
30
|
+
private var nextId: Double = 0.0
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
160
|
-
|
|
186
|
+
override fun setThemeMode(
|
|
187
|
+
id: Double,
|
|
188
|
+
themeMode: String?,
|
|
189
|
+
) {
|
|
190
|
+
val instance = instances[id]?.instance ?: return
|
|
161
191
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
192
|
+
runBlocking(Dispatchers.Main) {
|
|
193
|
+
if (themeMode != null) {
|
|
194
|
+
instance.setThemeMode(ThemeMode.valueOf(themeMode))
|
|
195
|
+
}
|
|
196
|
+
}
|
|
166
197
|
}
|
|
167
|
-
}
|
|
168
198
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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
|
-
|
|
248
|
-
|
|
295
|
+
override fun handleURL(
|
|
296
|
+
id: Double,
|
|
297
|
+
url: String,
|
|
298
|
+
): Boolean {
|
|
299
|
+
val instance = instances[id]?.instance ?: return false
|
|
249
300
|
|
|
250
|
-
|
|
251
|
-
|
|
301
|
+
val uri = url.toUri()
|
|
302
|
+
val intent = Intent(Intent.ACTION_VIEW, uri)
|
|
252
303
|
|
|
253
|
-
|
|
254
|
-
|
|
304
|
+
return runBlocking(Dispatchers.Main) {
|
|
305
|
+
instance.handlePreviewLinkIntent(intent)
|
|
306
|
+
}
|
|
255
307
|
}
|
|
256
|
-
}
|
|
257
308
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
26
|
+
return writableArray
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
30
29
|
fun Map<String, *>.toWritableMap(): WritableMap {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
49
|
+
return writableMap
|
|
51
50
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/plugin-engagement-react-native",
|
|
3
|
-
"version": "3.
|
|
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 \"
|
|
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"
|