@screeb/react-native 2.1.12 → 2.1.13

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.
@@ -29,10 +29,6 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
29
29
  fun initSdk(channelId: String, userId: String?, properties: ReadableMap?, hooks: ReadableMap?, initOptions: ReadableMap?, language: String?) {
30
30
  Log.d("ScreebModule", "Called initSdk : $userId")
31
31
  Screeb.setSecondarySDK("react-native", "2.1.12")
32
- var map: HashMap<String, Any?>? = null
33
- if (properties != null) {
34
- map = properties.toHashMap()
35
- }
36
32
  var mapHooks:HashMap<String, Any>? = null
37
33
  if (hooks != null) {
38
34
  mapHooks = hashMapOf<String, Any>()
@@ -52,93 +48,61 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
52
48
  }
53
49
 
54
50
  Handler(Looper.getMainLooper()).post {
55
- Screeb.pluginInit(channelId, userId, map, mapHooks, language)
51
+ Screeb.pluginInit(channelId, userId, fromReadableMap(properties), mapHooks, language)
56
52
  }
57
53
  }
58
54
 
59
55
  @ReactMethod
60
56
  fun setIdentity(userId: String, properties: ReadableMap?) {
61
57
  Log.d("ScreebModule", "Called setIdentity : $userId")
62
- var map: HashMap<String, Any?>? = null
63
- if (properties != null) {
64
- map = properties.toHashMap()
65
- }
66
-
67
58
  Handler(Looper.getMainLooper()).post {
68
- Screeb.setIdentity(userId, map)
59
+ Screeb.setIdentity(userId, fromReadableMap(properties))
69
60
  }
70
61
  }
71
62
 
72
63
  @ReactMethod
73
64
  fun setProperties(properties: ReadableMap) {
74
- Log.d(
75
- "ScreebModule",
76
- "Called setVisitorProperties with " + properties.toHashMap().size + " properties"
77
- )
78
-
65
+ Log.d("ScreebModule", "Called setProperties")
79
66
  Handler(Looper.getMainLooper()).post {
80
- Screeb.setVisitorProperties(properties.toHashMap())
67
+ Screeb.setVisitorProperties(fromReadableMap(properties))
81
68
  }
82
69
  }
83
70
 
84
71
  @ReactMethod
85
72
  fun assignGroup(type: String? = null, name: String, properties: ReadableMap? = null) {
86
73
  Log.d("ScreebModule", "Called assignGroup : $name")
87
- var map: HashMap<String, Any?>? = null
88
- if (properties != null) {
89
- map = properties.toHashMap()
90
- }
91
-
92
74
  Handler(Looper.getMainLooper()).post {
93
- Screeb.assignGroup(type, name, map)
75
+ Screeb.assignGroup(type, name, fromReadableMap(properties))
94
76
  }
95
77
  }
96
78
 
97
79
  @ReactMethod
98
80
  fun unassignGroup(type: String? = null, name: String, properties: ReadableMap? = null) {
99
81
  Log.d("ScreebModule", "Called unassignGroup : $name")
100
- var map: HashMap<String, Any?>? = null
101
- if (properties != null) {
102
- map = properties.toHashMap()
103
- }
104
-
105
82
  Handler(Looper.getMainLooper()).post {
106
- Screeb.unassignGroup(type, name, map)
83
+ Screeb.unassignGroup(type, name, fromReadableMap(properties))
107
84
  }
108
85
  }
109
86
 
110
87
  @ReactMethod
111
88
  fun trackEvent(eventId: String, properties: ReadableMap?) {
112
89
  Log.d("ScreebModule", "Called trackEvent : $eventId")
113
- var map: HashMap<String, Any?>? = null
114
- if (properties != null) {
115
- map = properties.toHashMap()
116
- }
117
-
118
90
  Handler(Looper.getMainLooper()).post {
119
- Screeb.trackEvent(eventId, map)
91
+ Screeb.trackEvent(eventId, fromReadableMap(properties))
120
92
  }
121
93
  }
122
94
 
123
95
  @ReactMethod
124
96
  fun trackScreen(screen: String, properties: ReadableMap?) {
125
97
  Log.d("ScreebModule", "Called trackScreen : $screen")
126
- var map: HashMap<String, Any?>? = null
127
- if (properties != null) {
128
- map = properties.toHashMap()
129
- }
130
98
  Handler(Looper.getMainLooper()).post {
131
- Screeb.trackScreen(screen, map)
99
+ Screeb.trackScreen(screen, fromReadableMap(properties))
132
100
  }
133
101
  }
134
102
 
135
103
  @ReactMethod
136
104
  fun startSurvey(surveyId: String, allowMultipleResponses: Boolean? = true, hiddenFields: ReadableMap? = null, ignoreSurveyStatus: Boolean? = true, hooks: ReadableMap? = null, language: String? = null) {
137
105
  Log.e("ScreebModule", "Called startSurvey : $surveyId")
138
- var map: HashMap<String, Any?>? = null
139
- if (hiddenFields != null) {
140
- map = hiddenFields.toHashMap()
141
- }
142
106
  var mapHooks:HashMap<String, Any>? = null
143
107
  if (hooks != null) {
144
108
  mapHooks = hashMapOf<String, Any>()
@@ -157,7 +121,7 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
157
121
  }
158
122
  }
159
123
  Handler(Looper.getMainLooper()).post {
160
- Screeb.startSurvey(surveyId, allowMultipleResponses ?: true, map, ignoreSurveyStatus ?: true, mapHooks, language)
124
+ Screeb.startSurvey(surveyId, allowMultipleResponses ?: true, fromReadableMap(hiddenFields), ignoreSurveyStatus ?: true, mapHooks, language)
161
125
  }
162
126
  }
163
127
 
@@ -188,7 +152,7 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
188
152
  @ReactMethod
189
153
  fun onHookResult(hookId: String, payload: ReadableMap?){
190
154
  if (payload != null) {
191
- val result = payload!!.toHashMap()["result"] as Any?
155
+ val result = fromReadableMap(payload!!)!!["result"] as Any?
192
156
  Screeb.onHookResult(hookId, result)
193
157
  }
194
158
  }
@@ -206,4 +170,21 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
206
170
  Screeb.debugTargeting()
207
171
  }
208
172
  }
173
+
174
+ private fun fromReadableMap(readableMap: ReadableMap?): HashMap<String, Any?>? {
175
+ if (readableMap == null) {
176
+ return null
177
+ }
178
+ val map = HashMap<String, Any?>()
179
+ val keys = readableMap.keySetIterator()
180
+ while (keys.hasNextKey()) {
181
+ val key = keys.nextKey()
182
+ when (val value = readableMap.getValue(key)) {
183
+ is ReadableMap -> map[key] = fromReadableMap(value)
184
+ is ReadableArray -> map[key] = fromReadableArray(value)
185
+ else -> map[key] = value
186
+ }
187
+ }
188
+ return map
189
+ }
209
190
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@screeb/react-native",
3
- "version": "2.1.12",
3
+ "version": "2.1.13",
4
4
  "description": "Continuous Product Discovery",
5
5
  "scripts": {
6
6
  "clean": "rm -rf lib/",