@forstaglobal/react-native-mobilesdk 3.11.0 → 3.13.0

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.
Files changed (92) hide show
  1. package/README.md +3 -3
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/mobilesdk/MobileSdkModule.kt +25 -4
  4. package/android/src/main/java/com/mobilesdk/MobileSdkPackage.kt +1 -1
  5. package/android/src/main/java/com/mobilesdk/MobileSdkSurveyModule.kt +296 -0
  6. package/android/src/main/java/com/mobilesdk/module/TriggerCallback.kt +31 -1
  7. package/android/src/main/java/com/mobilesdk/survey/MobileSdkSurveyManager.kt +23 -0
  8. package/android/src/main/java/com/mobilesdk/survey/MobileSdkSurveyWrapper.kt +104 -0
  9. package/ios/MobileSdk.mm +8 -1
  10. package/ios/MobileSdk.swift +15 -2
  11. package/ios/MobileSdkSurvey-Bridging-Header.h +2 -0
  12. package/ios/MobileSdkSurvey.mm +111 -0
  13. package/ios/MobileSdkSurvey.swift +274 -0
  14. package/ios/Mobilesdk.xcodeproj/project.pbxproj +0 -2
  15. package/ios/Module/MobileTriggerCallback.swift +31 -1
  16. package/ios/Module/SdkEmitter.swift +1 -1
  17. package/ios/Podfile +1 -1
  18. package/ios/Podfile.lock +1 -1
  19. package/ios/Survey/MobileSdkSurveyManager.swift +21 -0
  20. package/ios/Survey/MobileSdkSurveyWrapper.swift +79 -0
  21. package/lib/commonjs/confirmitSdk.js +29 -0
  22. package/lib/commonjs/confirmitSdk.js.map +1 -0
  23. package/lib/commonjs/index.js +48 -140
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/models/models.js +24 -0
  26. package/lib/commonjs/models/models.js.map +1 -1
  27. package/lib/commonjs/program/triggerCallback.js +9 -21
  28. package/lib/commonjs/program/triggerCallback.js.map +1 -1
  29. package/lib/commonjs/serverSdk.js +83 -0
  30. package/lib/commonjs/serverSdk.js.map +1 -0
  31. package/lib/commonjs/survey/pageControl.js +72 -0
  32. package/lib/commonjs/survey/pageControl.js.map +1 -0
  33. package/lib/commonjs/survey/surveyFrameCallback.js +28 -0
  34. package/lib/commonjs/survey/surveyFrameCallback.js.map +1 -0
  35. package/lib/commonjs/surveySdk.js +23 -0
  36. package/lib/commonjs/surveySdk.js.map +1 -0
  37. package/lib/commonjs/triggerSdk.js +50 -0
  38. package/lib/commonjs/triggerSdk.js.map +1 -0
  39. package/lib/commonjs/views/surveyWebView.js +43 -43
  40. package/lib/commonjs/views/surveyWebView.js.map +1 -1
  41. package/lib/module/confirmitSdk.js +23 -0
  42. package/lib/module/confirmitSdk.js.map +1 -0
  43. package/lib/module/index.js +7 -113
  44. package/lib/module/index.js.map +1 -1
  45. package/lib/module/models/models.js +19 -1
  46. package/lib/module/models/models.js.map +1 -1
  47. package/lib/module/program/triggerCallback.js +9 -21
  48. package/lib/module/program/triggerCallback.js.map +1 -1
  49. package/lib/module/serverSdk.js +77 -0
  50. package/lib/module/serverSdk.js.map +1 -0
  51. package/lib/module/survey/pageControl.js +65 -0
  52. package/lib/module/survey/pageControl.js.map +1 -0
  53. package/lib/module/survey/surveyFrameCallback.js +22 -0
  54. package/lib/module/survey/surveyFrameCallback.js.map +1 -0
  55. package/lib/module/surveySdk.js +17 -0
  56. package/lib/module/surveySdk.js.map +1 -0
  57. package/lib/module/triggerSdk.js +44 -0
  58. package/lib/module/triggerSdk.js.map +1 -0
  59. package/lib/module/views/surveyWebView.js +43 -42
  60. package/lib/module/views/surveyWebView.js.map +1 -1
  61. package/lib/typescript/confirmitSdk.d.ts +8 -0
  62. package/lib/typescript/confirmitSdk.d.ts.map +1 -0
  63. package/lib/typescript/index.d.ts +8 -36
  64. package/lib/typescript/index.d.ts.map +1 -1
  65. package/lib/typescript/models/models.d.ts +91 -0
  66. package/lib/typescript/models/models.d.ts.map +1 -1
  67. package/lib/typescript/program/triggerCallback.d.ts +5 -13
  68. package/lib/typescript/program/triggerCallback.d.ts.map +1 -1
  69. package/lib/typescript/serverSdk.d.ts +24 -0
  70. package/lib/typescript/serverSdk.d.ts.map +1 -0
  71. package/lib/typescript/survey/pageControl.d.ts +27 -0
  72. package/lib/typescript/survey/pageControl.d.ts.map +1 -0
  73. package/lib/typescript/survey/surveyFrameCallback.d.ts +15 -0
  74. package/lib/typescript/survey/surveyFrameCallback.d.ts.map +1 -0
  75. package/lib/typescript/surveySdk.d.ts +10 -0
  76. package/lib/typescript/surveySdk.d.ts.map +1 -0
  77. package/lib/typescript/triggerSdk.d.ts +23 -0
  78. package/lib/typescript/triggerSdk.d.ts.map +1 -0
  79. package/lib/typescript/views/surveyWebView.d.ts +4 -13
  80. package/lib/typescript/views/surveyWebView.d.ts.map +1 -1
  81. package/package.json +9 -7
  82. package/react-native-mobilesdk.podspec +1 -1
  83. package/src/confirmitSdk.ts +34 -0
  84. package/src/index.tsx +45 -152
  85. package/src/models/models.ts +96 -0
  86. package/src/program/triggerCallback.ts +10 -27
  87. package/src/serverSdk.ts +105 -0
  88. package/src/survey/pageControl.ts +97 -0
  89. package/src/survey/surveyFrameCallback.ts +28 -0
  90. package/src/surveySdk.ts +32 -0
  91. package/src/triggerSdk.ts +62 -0
  92. package/src/views/surveyWebView.tsx +46 -44
@@ -0,0 +1,62 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ const LINKING_ERROR =
4
+ `The package 'react-native-mobilesdk' doesn't seem to be linked. Make sure: \n\n${Platform.select({
5
+ ios: "- You have run 'pod install'\n",
6
+ default: ''
7
+ })}- You rebuilt the app after installing the package\n` + '- You are not using Expo Go\n';
8
+
9
+ const MobileSdk = NativeModules.MobileSdk
10
+ ? NativeModules.MobileSdk
11
+ : new Proxy(
12
+ {},
13
+ {
14
+ get() {
15
+ throw new Error(LINKING_ERROR);
16
+ }
17
+ }
18
+ );
19
+
20
+ class Manager {
21
+ public notifyEvent(event: string) {
22
+ MobileSdk.notifyEvent(event);
23
+ }
24
+
25
+ public notifyAppForeground(data: { [Name: string]: string }) {
26
+ MobileSdk.notifyAppForeground(data);
27
+ }
28
+
29
+ public async deleteProgram(serverId: string, programKey: string, deleteCustomData: boolean): Promise<void> {
30
+ return MobileSdk.deleteProgram(serverId, programKey, deleteCustomData);
31
+ }
32
+
33
+ public async deleteAll(deleteCustomData: boolean): Promise<void> {
34
+ return MobileSdk.deleteAll(deleteCustomData);
35
+ }
36
+
37
+ public setCallback(serverId: string, programKey: string) {
38
+ MobileSdk.setCallback(serverId, programKey);
39
+ }
40
+
41
+ public removeCallback(serverId: string, programKey: string) {
42
+ MobileSdk.removeCallback(serverId, programKey);
43
+ }
44
+
45
+ public async triggerDownload(serverId: string, programKey: string): Promise<boolean> {
46
+ return MobileSdk.triggerDownload(serverId, programKey);
47
+ }
48
+
49
+ public notifyEventWithData(event: string, data: { [Name: string]: string }) {
50
+ MobileSdk.notifyEventWithData(event, data);
51
+ }
52
+
53
+ public addJourneyLog(data: { [Name: string]: string }) {
54
+ MobileSdk.addJourneyLog(data);
55
+ }
56
+
57
+ public addJourneyLogWithServer(serverId: string, programKey: string, data: { [Name: string]: string }) {
58
+ MobileSdk.addJourneyLogWithServer(serverId, programKey, data);
59
+ }
60
+ }
61
+
62
+ export const TriggerSdk = new Manager();
@@ -1,61 +1,63 @@
1
- import React, { Component } from 'react';
2
- import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
1
+ import React, { useEffect } from 'react';
2
+ import { EmitterSubscription, NativeEventEmitter, NativeModules, Platform } from 'react-native';
3
3
  import type { WebViewMessageEvent, WebViewProps } from 'react-native-webview';
4
4
  import { WebView } from 'react-native-webview';
5
- import { injectWebView } from '../index';
5
+ import { ConfirmitSdk } from '../confirmitSdk';
6
6
 
7
- interface SurveyWebViewProps extends WebViewProps {
7
+ interface ISurveyWebViewProps extends WebViewProps {
8
8
  onSurveyClosed?: () => void;
9
9
  }
10
10
 
11
- export default class SurveyWebView extends Component<SurveyWebViewProps> {
12
- private sdkEmitter = NativeModules.SdkEmitter;
13
- private triggerManagerEmitter = new NativeEventEmitter(this.sdkEmitter);
11
+ const sdkEmitter = NativeModules.SdkEmitter;
12
+ const triggerManagerEmitter = new NativeEventEmitter(sdkEmitter);
14
13
 
15
- private loaded = false;
14
+ const SurveyWebView = (props: ISurveyWebViewProps) => {
15
+ let loaded = false;
16
16
 
17
- public constructor(props: SurveyWebViewProps) {
18
- super(props);
17
+ useEffect(() => {
18
+ const pageReady: EmitterSubscription = triggerManagerEmitter.addListener('__mobileOnSurveyClosed', onSurveyClosed);
19
19
 
20
- this.triggerManagerEmitter.addListener('__mobileOnSurveyClosed', this.__onSurveyClosed);
21
- }
20
+ return () => {
21
+ pageReady.remove();
22
+ };
23
+ });
22
24
 
23
- private __onSurveyClosed = () => {
24
- this.props.onSurveyClosed?.();
25
+ const onSurveyClosed = () => {
26
+ props.onSurveyClosed?.();
25
27
  };
26
28
 
27
- private load() {
28
- if (!this.loaded) {
29
- injectWebView();
30
- this.loaded = true;
31
- }
32
- }
33
-
34
- private onMessage = (event: WebViewMessageEvent) => {
35
- this.__onSurveyClosed();
36
- this.props.onMessage?.(event);
29
+ const onMessage = (event: WebViewMessageEvent) => {
30
+ onSurveyClosed();
31
+ props.onMessage?.(event);
37
32
  };
38
33
 
39
- public render() {
40
- let { injectedJavaScriptBeforeContentLoaded } = this.props;
41
-
42
- if (Platform.OS === 'ios') {
43
- injectedJavaScriptBeforeContentLoaded += ` \nwindow['mobileBridge'] = { onSurveyEnd: function() { window.ReactNativeWebView?.postMessage(''); } };`;
34
+ const load = () => {
35
+ if (!loaded) {
36
+ ConfirmitSdk.injectWebView();
37
+ loaded = true;
44
38
  }
39
+ };
40
+
41
+ let { injectedJavaScriptBeforeContentLoaded } = props;
45
42
 
46
- return (
47
- <WebView
48
- nativeID={'surveyWebViews'}
49
- {...this.props}
50
- domStorageEnabled={true}
51
- javaScriptEnabled={true}
52
- onLoad={() => {
53
- this.load();
54
- }}
55
- injectedJavaScriptForMainFrameOnly={false}
56
- injectedJavaScriptBeforeContentLoaded={injectedJavaScriptBeforeContentLoaded}
57
- onMessage={this.onMessage}
58
- />
59
- );
43
+ if (Platform.OS === 'ios') {
44
+ injectedJavaScriptBeforeContentLoaded += " \nwindow['mobileBridge'] = { onSurveyEnd: function() { window.ReactNativeWebView?.postMessage(''); } };";
60
45
  }
61
- }
46
+
47
+ return (
48
+ <WebView
49
+ nativeID={'surveyWebViews'}
50
+ {...props}
51
+ domStorageEnabled={true}
52
+ javaScriptEnabled={true}
53
+ onLoad={() => {
54
+ load();
55
+ }}
56
+ injectedJavaScriptForMainFrameOnly={false}
57
+ injectedJavaScriptBeforeContentLoaded={injectedJavaScriptBeforeContentLoaded}
58
+ onMessage={onMessage}
59
+ />
60
+ );
61
+ };
62
+
63
+ export default SurveyWebView;