@screeb/react-native 2.1.3 → 2.1.5
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.
|
@@ -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.5")
|
|
32
32
|
var map: HashMap<String, Any?>? = null
|
|
33
33
|
if (properties != null) {
|
|
34
34
|
map = properties.toHashMap()
|
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.5")
|
|
15
15
|
var map: [String: AnyEncodable?] = [:]
|
|
16
16
|
if (properties_ != nil) {
|
|
17
17
|
map = self.mapToAnyEncodable(map: properties_!)
|
|
@@ -23,7 +23,14 @@ class ScreebModule: RCTEventEmitter {
|
|
|
23
23
|
if (hook.key == "version") {
|
|
24
24
|
mapHooks![hook.key] = hook.value as? String
|
|
25
25
|
} else {
|
|
26
|
-
mapHooks![hook.key] = {(payload:Any) -> () in
|
|
26
|
+
mapHooks![hook.key] = {(payload:Any) -> () in DispatchQueue.main.async {
|
|
27
|
+
guard let data = try? JSONEncoder().encode(self.toAnyEncodable(payload)) else {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let encoded = String(data: data, encoding: .utf8)!
|
|
32
|
+
self.sendEvent(withName: "ScreebEvent", body: ["hookId": hook.value, "payload": encoded])
|
|
33
|
+
}}
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
}
|
|
@@ -90,7 +97,14 @@ class ScreebModule: RCTEventEmitter {
|
|
|
90
97
|
if(hook.key == "version"){
|
|
91
98
|
mapHooks![hook.key] = hook.value as? String
|
|
92
99
|
} else {
|
|
93
|
-
mapHooks![hook.key] = {(payload:Any) -> () in
|
|
100
|
+
mapHooks![hook.key] = {(payload:Any) -> () in DispatchQueue.main.async {
|
|
101
|
+
guard let data = try? JSONEncoder().encode(self.toAnyEncodable(payload)) else {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let encoded = String(data: data, encoding: .utf8)!
|
|
106
|
+
self.sendEvent(withName: "ScreebEvent", body: ["hookId": hook.value, "payload": encoded])
|
|
107
|
+
}}
|
|
94
108
|
}
|
|
95
109
|
}
|
|
96
110
|
}
|
|
@@ -140,7 +154,7 @@ class ScreebModule: RCTEventEmitter {
|
|
|
140
154
|
@objc func onHookResult(_ hookId: String, payload: [String: Any]?) {
|
|
141
155
|
DispatchQueue.main.async {
|
|
142
156
|
if payload != nil {
|
|
143
|
-
let encoded = self.toAnyEncodable(payload["result"]
|
|
157
|
+
let encoded = self.toAnyEncodable(payload!["result"])
|
|
144
158
|
Screeb.onHookResult(hookId, encoded)
|
|
145
159
|
}
|
|
146
160
|
}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -104,16 +104,27 @@ function closeSurvey() {
|
|
|
104
104
|
}
|
|
105
105
|
exports.closeSurvey = closeSurvey;
|
|
106
106
|
function handleEvent(event) {
|
|
107
|
-
console.log(event);
|
|
108
107
|
if (event?.hookId != null) {
|
|
109
108
|
let hook = hooksRegistry.get(event.hookId);
|
|
110
109
|
if (hook != null) {
|
|
111
110
|
const result = hook(event.payload);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const originalHookId = event?.payload?.hook_id;
|
|
111
|
+
const parsedPayload = JSON.parse(event.payload);
|
|
112
|
+
const originalHookId = parsedPayload?.hook_id;
|
|
115
113
|
if (originalHookId) {
|
|
116
|
-
|
|
114
|
+
// result must be a map to fit with react native allowed types
|
|
115
|
+
// Check if hook is a promise/async function
|
|
116
|
+
if (result instanceof Promise) {
|
|
117
|
+
result
|
|
118
|
+
.then((result) => {
|
|
119
|
+
ScreebModule.onHookResult(originalHookId, { result });
|
|
120
|
+
})
|
|
121
|
+
.catch((error) => {
|
|
122
|
+
console.error(error);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
ScreebModule.onHookResult(originalHookId, { result });
|
|
127
|
+
}
|
|
117
128
|
}
|
|
118
129
|
}
|
|
119
130
|
}
|
package/lib/module/index.js
CHANGED
|
@@ -88,16 +88,27 @@ export function closeSurvey() {
|
|
|
88
88
|
return ScreebModule.closeSurvey();
|
|
89
89
|
}
|
|
90
90
|
function handleEvent(event) {
|
|
91
|
-
console.log(event);
|
|
92
91
|
if (event?.hookId != null) {
|
|
93
92
|
let hook = hooksRegistry.get(event.hookId);
|
|
94
93
|
if (hook != null) {
|
|
95
94
|
const result = hook(event.payload);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const originalHookId = event?.payload?.hook_id;
|
|
95
|
+
const parsedPayload = JSON.parse(event.payload);
|
|
96
|
+
const originalHookId = parsedPayload?.hook_id;
|
|
99
97
|
if (originalHookId) {
|
|
100
|
-
|
|
98
|
+
// result must be a map to fit with react native allowed types
|
|
99
|
+
// Check if hook is a promise/async function
|
|
100
|
+
if (result instanceof Promise) {
|
|
101
|
+
result
|
|
102
|
+
.then((result) => {
|
|
103
|
+
ScreebModule.onHookResult(originalHookId, { result });
|
|
104
|
+
})
|
|
105
|
+
.catch((error) => {
|
|
106
|
+
console.error(error);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
ScreebModule.onHookResult(originalHookId, { result });
|
|
111
|
+
}
|
|
101
112
|
}
|
|
102
113
|
}
|
|
103
114
|
}
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -143,10 +143,22 @@ function handleEvent(event: any) {
|
|
|
143
143
|
let hook = hooksRegistry.get(event.hookId);
|
|
144
144
|
if (hook != null) {
|
|
145
145
|
const result = hook(event.payload);
|
|
146
|
-
const
|
|
146
|
+
const parsedPayload = JSON.parse(event.payload);
|
|
147
|
+
const originalHookId = parsedPayload?.hook_id;
|
|
147
148
|
if (originalHookId) {
|
|
148
149
|
// result must be a map to fit with react native allowed types
|
|
149
|
-
|
|
150
|
+
// Check if hook is a promise/async function
|
|
151
|
+
if (result instanceof Promise) {
|
|
152
|
+
result
|
|
153
|
+
.then((result) => {
|
|
154
|
+
ScreebModule.onHookResult(originalHookId, { result });
|
|
155
|
+
})
|
|
156
|
+
.catch((error) => {
|
|
157
|
+
console.error(error);
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
ScreebModule.onHookResult(originalHookId, { result });
|
|
161
|
+
}
|
|
150
162
|
}
|
|
151
163
|
}
|
|
152
164
|
}
|