@screeb/react-native 2.1.2 → 2.1.4

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.
@@ -187,8 +187,10 @@ class ScreebModuleModule(reactContext: ReactApplicationContext) :
187
187
 
188
188
  @ReactMethod
189
189
  fun onHookResult(hookId: String, payload: ReadableMap?){
190
- val result = payload?.toHashMap()["result"] as Any?
191
- Screeb.onHookResult(hookId, result)
190
+ if (payload != null) {
191
+ val result = payload!!.toHashMap()["result"] as Any?
192
+ Screeb.onHookResult(hookId, result)
193
+ }
192
194
  }
193
195
 
194
196
  @ReactMethod
@@ -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 self.sendEvent(withName: "ScreebEvent", body: ["hookId":hook.value,"payload":String(describing: payload)]) }
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 self.sendEvent(withName: "ScreebEvent", body: ["hookId":hook.value,"payload":String(describing: payload)]) }
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
  }
@@ -104,16 +104,15 @@ 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
- console.log("Hook result: ", result);
113
- console.log(event.payload);
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
- ScreebModule.onHookResult(originalHookId, result);
114
+ // result must be a map to fit with react native allowed types
115
+ ScreebModule.onHookResult(originalHookId, { result });
117
116
  }
118
117
  }
119
118
  }
@@ -88,16 +88,15 @@ 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
- console.log("Hook result: ", result);
97
- console.log(event.payload);
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
- ScreebModule.onHookResult(originalHookId, result);
98
+ // result must be a map to fit with react native allowed types
99
+ ScreebModule.onHookResult(originalHookId, { result });
101
100
  }
102
101
  }
103
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@screeb/react-native",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "description": "Continuous Product Discovery",
5
5
  "scripts": {
6
6
  "clean": "rm -rf lib/",
package/src/index.tsx CHANGED
@@ -143,7 +143,8 @@ 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 originalHookId = event?.payload?.hook_id;
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
  ScreebModule.onHookResult(originalHookId, { result });