surveysparrow-ionic-plugin 0.0.2 → 0.0.3

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.
@@ -21,7 +21,7 @@ public class SurveySparrowIonicPluginPlugin extends Plugin {
21
21
  public void loadFullScreenSurvey(PluginCall call) {
22
22
  String domain = call.getString("domain");
23
23
  String token = call.getString("token");
24
- CustomParam[] params = parseParams(call.getArray("params"));
24
+ CustomParam[] params = parseParams(call.getObject("params"));
25
25
  HashMap<String, String> properties = parseProperties(call.getObject("properties"));
26
26
 
27
27
  implementation.loadFullScreenSurvey(domain, token, params, properties);
@@ -32,28 +32,28 @@ public class SurveySparrowIonicPluginPlugin extends Plugin {
32
32
  public void loadFullScreenSurveyWithValidation(PluginCall call) {
33
33
  String domain = call.getString("domain");
34
34
  String token = call.getString("token");
35
- CustomParam[] params = parseParams(call.getArray("params"));
35
+ CustomParam[] params = parseParams(call.getObject("params"));
36
36
  HashMap<String, String> properties = parseProperties(call.getObject("properties"));
37
37
 
38
38
  implementation.loadFullScreenSurveyWithValidation(domain, token, params, properties);
39
39
  call.resolve();
40
40
  }
41
41
 
42
- private CustomParam[] parseParams(JSArray jsParams) {
43
- if (jsParams == null || jsParams.length() == 0) {
42
+ private CustomParam[] parseParams(JSObject jsParams) {
43
+ if (jsParams == null || jsParams.keys().length == 0) {
44
44
  return new CustomParam[0];
45
45
  }
46
-
47
- CustomParam[] params = new CustomParam[jsParams.length()];
48
-
49
- for (int i = 0; i < jsParams.length(); i++) {
46
+
47
+ String[] keys = jsParams.keys();
48
+ CustomParam[] params = new CustomParam[keys.length];
49
+
50
+ for (int i = 0; i < keys.length; i++) {
50
51
  try {
51
- JSObject paramObj = (JSObject) jsParams.get(i);
52
- String key = paramObj.getString("key");
53
- String value = paramObj.getString("value");
52
+ String key = keys[i];
53
+ String value = jsParams.getString(key);
54
54
  params[i] = new CustomParam(key, value);
55
55
  } catch (JSONException e) {
56
- throw new RuntimeException("Invalid parameter at index " + i, e);
56
+ throw new RuntimeException("Invalid parameter for key: " + keys[i], e);
57
57
  }
58
58
  }
59
59
 
@@ -5,7 +5,19 @@ import SwiftUI
5
5
  @objc public class SurveySparrowIonicPlugin: NSObject {
6
6
 
7
7
  @objc public func loadFullScreenSurvey(domain: String, token: String, params: [String: String], properties: [String: Any]) {
8
- FullScreenSurveyView(domain: domain, token: token, params: params, properties: properties)
8
+ DispatchQueue.main.async {
9
+ let ssSurveyViewController = SsSurveyViewController()
10
+ ssSurveyViewController.domain = domain
11
+ ssSurveyViewController.token = token
12
+ ssSurveyViewController.params = params
13
+ ssSurveyViewController.properties = properties
14
+ ssSurveyViewController.getSurveyLoadedResponse = true
15
+ ssSurveyViewController.surveyDelegate = SsDelegate()
16
+
17
+ if let topViewController = UIApplication.shared.windows.first?.rootViewController {
18
+ topViewController.present(ssSurveyViewController, animated: true, completion: nil)
19
+ }
20
+ }
9
21
  }
10
22
 
11
23
  @objc public func loadFullScreenSurveyWithValidation(domain: String, token: String, params: [String: String], properties: [String: Any]) {
@@ -13,30 +25,6 @@ import SwiftUI
13
25
  }
14
26
  }
15
27
 
16
- struct FullScreenSurveyView: UIViewControllerRepresentable {
17
-
18
- var domain: String
19
- var token: String
20
- let params: [String: String]
21
- let properties: [String: Any]
22
-
23
- @State private var isSurveyLoaded: Bool = false
24
-
25
- func makeUIViewController(context: Context) -> SsSurveyViewController{
26
- let ssSurveyViewController = SsSurveyViewController()
27
- ssSurveyViewController.domain = domain
28
- ssSurveyViewController.token = token
29
- ssSurveyViewController.params = params
30
- ssSurveyViewController.properties = properties
31
- ssSurveyViewController.getSurveyLoadedResponse = true
32
- ssSurveyViewController.surveyDelegate = SsDelegate()
33
- return ssSurveyViewController
34
- }
35
-
36
- func updateUIViewController(_ uiViewController: SsSurveyViewController, context: Context) {}
37
-
38
- }
39
-
40
28
  struct FullScreenSurveyWithValidation {
41
29
 
42
30
  let domain: String?
@@ -7,7 +7,8 @@ public class SurveySparrowIonicPluginPlugin: CAPPlugin, CAPBridgedPlugin {
7
7
  public let identifier = "SurveySparrowIonicPluginPlugin"
8
8
  public let jsName = "SurveySparrowIonicPlugin"
9
9
  public let pluginMethods: [CAPPluginMethod] = [
10
- CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise)
10
+ CAPPluginMethod(name: "loadFullScreenSurvey", returnType: CAPPluginReturnNone),
11
+ CAPPluginMethod(name: "loadFullScreenSurveyWithValidation", returnType: CAPPluginReturnNone)
11
12
  ]
12
13
 
13
14
  private let implementation = SurveySparrowIonicPlugin()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "surveysparrow-ionic-plugin",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "SurveySparrow SDK enables you to collect feedback from your mobile app. Embed the Classic, Chat & NPS surveys in your ionic application seamlessly with few lines of code.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",