@screeb/react-native 2.1.0 → 2.1.2
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/android/build.gradle +1 -1
- package/android/src/main/java/com/screebmodule/ScreebModuleModule.kt +21 -18
- package/ios/ScreebModule.m +1 -0
- package/ios/ScreebModule.swift +46 -33
- package/lib/commonjs/index.js +10 -5
- package/lib/module/index.js +10 -5
- package/package.json +3 -3
- package/screeb-module.podspec +1 -1
- package/src/index.tsx +8 -5
package/android/build.gradle
CHANGED
|
@@ -123,6 +123,6 @@ def kotlin_version = getExtOrDefault('kotlinVersion')
|
|
|
123
123
|
dependencies {
|
|
124
124
|
// noinspection GradleDynamicVersion
|
|
125
125
|
api 'com.facebook.react:react-native:+'
|
|
126
|
-
implementation "app.screeb.sdk:survey:2.
|
|
126
|
+
implementation "app.screeb.sdk:survey:2.1.2"
|
|
127
127
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22"
|
|
128
128
|
}
|
|
@@ -28,7 +28,7 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
|
|
|
28
28
|
@ReactMethod
|
|
29
29
|
fun initSdk(channelId: String, userId: String?, properties: ReadableMap?, hooks: ReadableMap?, initOptions: ReadableMap?) {
|
|
30
30
|
Log.d("ScreebModule", "Called initSdk : $userId")
|
|
31
|
-
Screeb.setSecondarySDK("react-native", "2.1.
|
|
31
|
+
Screeb.setSecondarySDK("react-native", "2.1.1")
|
|
32
32
|
var map: HashMap<String, Any?>? = null
|
|
33
33
|
if (properties != null) {
|
|
34
34
|
map = properties.toHashMap()
|
|
@@ -51,9 +51,6 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
|
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
// TODO: pass to pluginInit
|
|
55
|
-
var initOptions = InitOptions()
|
|
56
|
-
|
|
57
54
|
Handler(Looper.getMainLooper()).post {
|
|
58
55
|
Screeb.pluginInit(channelId, userId, map, mapHooks)
|
|
59
56
|
}
|
|
@@ -164,20 +161,6 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
|
|
|
164
161
|
}
|
|
165
162
|
}
|
|
166
163
|
|
|
167
|
-
@ReactMethod
|
|
168
|
-
fun debug(){
|
|
169
|
-
Log.d("ScreebModule","Called debug")
|
|
170
|
-
Screeb.debug()
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
@ReactMethod
|
|
174
|
-
fun debugTargeting(){
|
|
175
|
-
Log.d("ScreebModule","Called debugTargeting")
|
|
176
|
-
Handler(Looper.getMainLooper()).post {
|
|
177
|
-
Screeb.debugTargeting()
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
164
|
@ReactMethod
|
|
182
165
|
fun resetIdentity(){
|
|
183
166
|
Log.d("ScreebModule","Called resetIdentity")
|
|
@@ -201,4 +184,24 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
|
|
|
201
184
|
Screeb.closeSurvey()
|
|
202
185
|
}
|
|
203
186
|
}
|
|
187
|
+
|
|
188
|
+
@ReactMethod
|
|
189
|
+
fun onHookResult(hookId: String, payload: ReadableMap?){
|
|
190
|
+
val result = payload?.toHashMap()["result"] as Any?
|
|
191
|
+
Screeb.onHookResult(hookId, result)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@ReactMethod
|
|
195
|
+
fun debug(){
|
|
196
|
+
Log.d("ScreebModule","Called debug")
|
|
197
|
+
Screeb.debug()
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
@ReactMethod
|
|
201
|
+
fun debugTargeting(){
|
|
202
|
+
Log.d("ScreebModule","Called debugTargeting")
|
|
203
|
+
Handler(Looper.getMainLooper()).post {
|
|
204
|
+
Screeb.debugTargeting()
|
|
205
|
+
}
|
|
206
|
+
}
|
|
204
207
|
}
|
package/ios/ScreebModule.m
CHANGED
|
@@ -11,6 +11,7 @@ RCT_EXTERN_METHOD(unassignGroup:(NSString *)type name:(NSString *)name_ properti
|
|
|
11
11
|
RCT_EXTERN_METHOD(trackEvent:(NSString *)eventId properties:(NSDictionary<NSString *, id> *)properties_)
|
|
12
12
|
RCT_EXTERN_METHOD(trackScreen:(NSString *)screen properties:(NSDictionary<NSString *, id> *)properties_)
|
|
13
13
|
RCT_EXTERN_METHOD(startSurvey:(NSString *)surveyId allowMultipleResponses:(BOOL)allowMultipleResponses_ hiddenFields:(NSDictionary<NSString *, id> *)hiddenFields_ ignoreSurveyStatus:(BOOL)ignoreSurveyStatus_ hooks:(NSDictionary<NSString *, id> *)hooks_)
|
|
14
|
+
RCT_EXTERN_METHOD(onHookResult:(NSString *)hookId payload:(NSDictionary<NSString *, id> *)payload_)
|
|
14
15
|
RCT_EXTERN_METHOD(debug)
|
|
15
16
|
RCT_EXTERN_METHOD(debugTargeting)
|
|
16
17
|
RCT_EXTERN_METHOD(closeSdk)
|
package/ios/ScreebModule.swift
CHANGED
|
@@ -11,7 +11,7 @@ class ScreebModule: RCTEventEmitter {
|
|
|
11
11
|
properties properties_: [String: Any]?,
|
|
12
12
|
hooks hooks_: [String: Any]?,
|
|
13
13
|
initOptions initOptions_: [String: Any]?) {
|
|
14
|
-
Screeb.setSecondarySDK(name: "react-native", version: "2.1.
|
|
14
|
+
Screeb.setSecondarySDK(name: "react-native", version: "2.1.1")
|
|
15
15
|
var map: [String: AnyEncodable?] = [:]
|
|
16
16
|
if (properties_ != nil) {
|
|
17
17
|
map = self.mapToAnyEncodable(map: properties_!)
|
|
@@ -119,60 +119,73 @@ class ScreebModule: RCTEventEmitter {
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
@objc func
|
|
122
|
+
@objc func resetIdentity(){
|
|
123
123
|
DispatchQueue.main.async {
|
|
124
|
-
Screeb.
|
|
124
|
+
Screeb.resetIdentity()
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
@objc func
|
|
128
|
+
@objc func closeSdk(){
|
|
129
129
|
DispatchQueue.main.async {
|
|
130
|
-
Screeb.
|
|
130
|
+
Screeb.closeSdk()
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
@objc func
|
|
134
|
+
@objc func closeSurvey(){
|
|
135
135
|
DispatchQueue.main.async {
|
|
136
|
-
Screeb.
|
|
136
|
+
Screeb.closeSurvey()
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
@objc func
|
|
140
|
+
@objc func onHookResult(_ hookId: String, payload: [String: Any]?) {
|
|
141
141
|
DispatchQueue.main.async {
|
|
142
|
-
|
|
142
|
+
if payload != nil {
|
|
143
|
+
let encoded = self.toAnyEncodable(payload["result"]
|
|
144
|
+
Screeb.onHookResult(hookId, encoded)
|
|
145
|
+
}
|
|
143
146
|
}
|
|
144
147
|
}
|
|
145
148
|
|
|
146
|
-
@objc func
|
|
149
|
+
@objc func debug(){
|
|
147
150
|
DispatchQueue.main.async {
|
|
148
|
-
Screeb.
|
|
151
|
+
Screeb.debug()
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
anyEncodableMap[key] = AnyEncodable(value)
|
|
169
|
-
} else if let value = value as? [String: Any?] {
|
|
170
|
-
anyEncodableMap[key] = AnyEncodable(self.mapToAnyEncodable(map: value))
|
|
155
|
+
@objc func debugTargeting(){
|
|
156
|
+
DispatchQueue.main.async {
|
|
157
|
+
Screeb.debugTargeting()
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private func toAnyEncodable(_ value: Any?) -> AnyEncodable? {
|
|
162
|
+
if let nsValue = value as? NSNumber {
|
|
163
|
+
if CFBooleanGetTypeID() == CFGetTypeID(nsValue) {
|
|
164
|
+
return AnyEncodable(nsValue.boolValue)
|
|
165
|
+
} else if let value = value as? Int {
|
|
166
|
+
return AnyEncodable(value)
|
|
167
|
+
} else if let value = value as? Double {
|
|
168
|
+
return AnyEncodable(value)
|
|
169
|
+
} else if let value = value as? Float {
|
|
170
|
+
return AnyEncodable(value)
|
|
171
171
|
} else {
|
|
172
|
-
|
|
172
|
+
return nil
|
|
173
173
|
}
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
} else if let value = value as? String {
|
|
175
|
+
return AnyEncodable(value)
|
|
176
|
+
} else if let value = value as? [String: Any?] {
|
|
177
|
+
return AnyEncodable(self.mapToAnyEncodable(map: value))
|
|
178
|
+
} else {
|
|
179
|
+
return nil
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
private func mapToAnyEncodable(map: [String: Any?]?) -> [String: AnyEncodable?] {
|
|
184
|
+
var anyEncodableMap: [String: AnyEncodable?] = [:]
|
|
185
|
+
map?.forEach { key, value in
|
|
186
|
+
anyEncodableMap[key] = self.toAnyEncodable(value)
|
|
187
|
+
}
|
|
188
|
+
return anyEncodableMap
|
|
176
189
|
}
|
|
177
190
|
|
|
178
191
|
override func supportedEvents() -> [String]! {
|
package/lib/commonjs/index.js
CHANGED
|
@@ -27,8 +27,7 @@ function initSdk(androidChannelId, iosChannelId, userId, properties, hooks, isDe
|
|
|
27
27
|
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
|
-
|
|
31
|
-
let uuid = Date.now().toString() + Math.random().toString();
|
|
30
|
+
let uuid = Date.now().toString() + Math.random().toString() + key;
|
|
32
31
|
hooksRegistry.set(uuid, hooks[key]);
|
|
33
32
|
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
34
33
|
}
|
|
@@ -75,8 +74,7 @@ function startSurvey(surveyId, allowMultipleResponses, hiddenFields, ignoreSurve
|
|
|
75
74
|
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
76
75
|
}
|
|
77
76
|
else {
|
|
78
|
-
|
|
79
|
-
let uuid = Date.now().toString() + Math.random().toString();
|
|
77
|
+
let uuid = Date.now().toString() + Math.random().toString() + key;
|
|
80
78
|
hooksRegistry.set(uuid, hooks[key]);
|
|
81
79
|
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
82
80
|
}
|
|
@@ -106,10 +104,17 @@ function closeSurvey() {
|
|
|
106
104
|
}
|
|
107
105
|
exports.closeSurvey = closeSurvey;
|
|
108
106
|
function handleEvent(event) {
|
|
107
|
+
console.log(event);
|
|
109
108
|
if (event?.hookId != null) {
|
|
110
109
|
let hook = hooksRegistry.get(event.hookId);
|
|
111
110
|
if (hook != null) {
|
|
112
|
-
hook(event.payload);
|
|
111
|
+
const result = hook(event.payload);
|
|
112
|
+
console.log("Hook result: ", result);
|
|
113
|
+
console.log(event.payload);
|
|
114
|
+
const originalHookId = event?.payload?.hook_id;
|
|
115
|
+
if (originalHookId) {
|
|
116
|
+
ScreebModule.onHookResult(originalHookId, result);
|
|
117
|
+
}
|
|
113
118
|
}
|
|
114
119
|
}
|
|
115
120
|
}
|
package/lib/module/index.js
CHANGED
|
@@ -24,8 +24,7 @@ export function initSdk(androidChannelId, iosChannelId, userId, properties, hook
|
|
|
24
24
|
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
25
25
|
}
|
|
26
26
|
else {
|
|
27
|
-
|
|
28
|
-
let uuid = Date.now().toString() + Math.random().toString();
|
|
27
|
+
let uuid = Date.now().toString() + Math.random().toString() + key;
|
|
29
28
|
hooksRegistry.set(uuid, hooks[key]);
|
|
30
29
|
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
31
30
|
}
|
|
@@ -65,8 +64,7 @@ export function startSurvey(surveyId, allowMultipleResponses, hiddenFields, igno
|
|
|
65
64
|
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
66
65
|
}
|
|
67
66
|
else {
|
|
68
|
-
|
|
69
|
-
let uuid = Date.now().toString() + Math.random().toString();
|
|
67
|
+
let uuid = Date.now().toString() + Math.random().toString() + key;
|
|
70
68
|
hooksRegistry.set(uuid, hooks[key]);
|
|
71
69
|
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
72
70
|
}
|
|
@@ -90,10 +88,17 @@ export function closeSurvey() {
|
|
|
90
88
|
return ScreebModule.closeSurvey();
|
|
91
89
|
}
|
|
92
90
|
function handleEvent(event) {
|
|
91
|
+
console.log(event);
|
|
93
92
|
if (event?.hookId != null) {
|
|
94
93
|
let hook = hooksRegistry.get(event.hookId);
|
|
95
94
|
if (hook != null) {
|
|
96
|
-
hook(event.payload);
|
|
95
|
+
const result = hook(event.payload);
|
|
96
|
+
console.log("Hook result: ", result);
|
|
97
|
+
console.log(event.payload);
|
|
98
|
+
const originalHookId = event?.payload?.hook_id;
|
|
99
|
+
if (originalHookId) {
|
|
100
|
+
ScreebModule.onHookResult(originalHookId, result);
|
|
101
|
+
}
|
|
97
102
|
}
|
|
98
103
|
}
|
|
99
104
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@screeb/react-native",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "Continuous Product Discovery",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"clean": "rm -rf lib/",
|
|
7
7
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
8
8
|
"build": "npm run clean ; tsc -p tsconfig.build.json && tsc -p tsconfig.build.cjs.json"
|
|
9
9
|
},
|
|
10
|
-
"react-native": "src/index",
|
|
10
|
+
"react-native": "src/index.tsx",
|
|
11
11
|
"main": "lib/commonjs/index.js",
|
|
12
12
|
"module": "lib/module/index.js",
|
|
13
|
-
"source": "src/index",
|
|
13
|
+
"source": "src/index.tsx",
|
|
14
14
|
"keywords": [
|
|
15
15
|
"react-native",
|
|
16
16
|
"ios",
|
package/screeb-module.podspec
CHANGED
package/src/index.tsx
CHANGED
|
@@ -44,8 +44,7 @@ export function initSdk(
|
|
|
44
44
|
if (key == "version") {
|
|
45
45
|
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
46
46
|
} else {
|
|
47
|
-
|
|
48
|
-
let uuid = Date.now().toString() + Math.random().toString();
|
|
47
|
+
let uuid = Date.now().toString() + Math.random().toString() + key;
|
|
49
48
|
hooksRegistry.set(uuid, hooks[key]);
|
|
50
49
|
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
51
50
|
}
|
|
@@ -109,8 +108,7 @@ export function startSurvey(
|
|
|
109
108
|
if (key == "version") {
|
|
110
109
|
mapHooksId = { ...mapHooksId, version: hooks[key] };
|
|
111
110
|
} else {
|
|
112
|
-
|
|
113
|
-
let uuid = Date.now().toString() + Math.random().toString();
|
|
111
|
+
let uuid = Date.now().toString() + Math.random().toString() + key;
|
|
114
112
|
hooksRegistry.set(uuid, hooks[key]);
|
|
115
113
|
mapHooksId = { ...mapHooksId, [key]: uuid };
|
|
116
114
|
}
|
|
@@ -144,7 +142,12 @@ function handleEvent(event: any) {
|
|
|
144
142
|
if (event?.hookId != null) {
|
|
145
143
|
let hook = hooksRegistry.get(event.hookId);
|
|
146
144
|
if (hook != null) {
|
|
147
|
-
hook(event.payload);
|
|
145
|
+
const result = hook(event.payload);
|
|
146
|
+
const originalHookId = event?.payload?.hook_id;
|
|
147
|
+
if (originalHookId) {
|
|
148
|
+
// result must be a map to fit with react native allowed types
|
|
149
|
+
ScreebModule.onHookResult(originalHookId, { result });
|
|
150
|
+
}
|
|
148
151
|
}
|
|
149
152
|
}
|
|
150
153
|
}
|