@forstaglobal/react-native-mobilesdk 3.9.2-beta.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.
- package/LICENSE +13 -0
- package/README.md +158 -0
- package/android/build.gradle +110 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/mobilesdk/MobileSdkModule.kt +283 -0
- package/android/src/main/java/com/mobilesdk/MobileSdkPackage.kt +17 -0
- package/android/src/main/java/com/mobilesdk/module/MobileBridge.kt +15 -0
- package/android/src/main/java/com/mobilesdk/module/TriggerCallback.kt +60 -0
- package/ios/MobileSdk-Bridging-Header.h +2 -0
- package/ios/MobileSdk.mm +118 -0
- package/ios/MobileSdk.swift +257 -0
- package/ios/Mobilesdk.xcodeproj/project.pbxproj +351 -0
- package/ios/Mobilesdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
- package/ios/Mobilesdk.xcworkspace/contents.xcworkspacedata +10 -0
- package/ios/Mobilesdk.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/Module/Exts.swift +16 -0
- package/ios/Module/MobileTriggerCallback.swift +49 -0
- package/ios/Module/SdkEmitter.mm +5 -0
- package/ios/Module/SdkEmitter.swift +26 -0
- package/ios/Podfile +7 -0
- package/ios/Podfile.lock +16 -0
- package/lib/commonjs/index.js +161 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/models/models.js +2 -0
- package/lib/commonjs/models/models.js.map +1 -0
- package/lib/commonjs/program/triggerCallback.js +38 -0
- package/lib/commonjs/program/triggerCallback.js.map +1 -0
- package/lib/commonjs/views/surveyWebView.js +60 -0
- package/lib/commonjs/views/surveyWebView.js.map +1 -0
- package/lib/module/index.js +116 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/models/models.js +2 -0
- package/lib/module/models/models.js.map +1 -0
- package/lib/module/program/triggerCallback.js +31 -0
- package/lib/module/program/triggerCallback.js.map +1 -0
- package/lib/module/views/surveyWebView.js +50 -0
- package/lib/module/views/surveyWebView.js.map +1 -0
- package/lib/typescript/index.d.ts +39 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/models/models.d.ts +15 -0
- package/lib/typescript/models/models.d.ts.map +1 -0
- package/lib/typescript/program/triggerCallback.d.ts +20 -0
- package/lib/typescript/program/triggerCallback.d.ts.map +1 -0
- package/lib/typescript/views/surveyWebView.d.ts +17 -0
- package/lib/typescript/views/surveyWebView.d.ts.map +1 -0
- package/package.json +137 -0
- package/react-native-mobilesdk.podspec +43 -0
- package/src/index.tsx +202 -0
- package/src/models/models.ts +16 -0
- package/src/program/triggerCallback.ts +51 -0
- package/src/views/surveyWebView.tsx +69 -0
package/src/index.tsx
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { NativeModules, Platform } from 'react-native';
|
|
2
|
+
import type {
|
|
3
|
+
IServerModel,
|
|
4
|
+
IWebSurveyModel,
|
|
5
|
+
IScenarioCallback,
|
|
6
|
+
} from './models/models';
|
|
7
|
+
import SurveyWebView from './views/surveyWebView';
|
|
8
|
+
import type { ISdkListener } from './program/triggerCallback';
|
|
9
|
+
import { TriggerManager } from './program/triggerCallback';
|
|
10
|
+
|
|
11
|
+
const LINKING_ERROR =
|
|
12
|
+
`The package 'react-native-mobilesdk' doesn't seem to be linked. Make sure: \n\n` +
|
|
13
|
+
Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
|
|
14
|
+
'- You rebuilt the app after installing the package\n' +
|
|
15
|
+
'- You are not using Expo Go\n';
|
|
16
|
+
|
|
17
|
+
const MobileSdk = NativeModules.MobileSdk
|
|
18
|
+
? NativeModules.MobileSdk
|
|
19
|
+
: new Proxy(
|
|
20
|
+
{},
|
|
21
|
+
{
|
|
22
|
+
get() {
|
|
23
|
+
throw new Error(LINKING_ERROR);
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export type {
|
|
29
|
+
IScenarioCallback,
|
|
30
|
+
IServerModel,
|
|
31
|
+
IWebSurveyModel,
|
|
32
|
+
ISdkListener,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { SurveyWebView, TriggerManager };
|
|
36
|
+
|
|
37
|
+
export function injectWebView() {
|
|
38
|
+
MobileSdk.injectWebView();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Confirmit
|
|
42
|
+
export function initSdk() {
|
|
43
|
+
return MobileSdk.initSdk();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function enableLog(enable: Boolean) {
|
|
47
|
+
MobileSdk.enableLog(enable);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Trigger
|
|
51
|
+
export function notifyEvent(event: String) {
|
|
52
|
+
MobileSdk.notifyEvent(event);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function notifyAppForeground(data: { [Name: string]: string }) {
|
|
56
|
+
MobileSdk.notifyAppForeground(data);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function deleteProgram(
|
|
60
|
+
serverId: string,
|
|
61
|
+
programKey: string,
|
|
62
|
+
deleteCustomData: boolean
|
|
63
|
+
): Promise<void> {
|
|
64
|
+
return MobileSdk.deleteProgram(serverId, programKey, deleteCustomData);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function deleteAll(deleteCustomData: boolean): Promise<void> {
|
|
68
|
+
return MobileSdk.deleteAll(deleteCustomData);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function setCallback(serverId: string, programKey: string) {
|
|
72
|
+
MobileSdk.setCallback(serverId, programKey);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function removeCallback(serverId: string, programKey: string) {
|
|
76
|
+
MobileSdk.removeCallback(serverId, programKey);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function triggerDownload(
|
|
80
|
+
serverId: string,
|
|
81
|
+
programKey: string
|
|
82
|
+
): Promise<boolean> {
|
|
83
|
+
return MobileSdk.triggerDownload(serverId, programKey);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function notifyEventWithData(
|
|
87
|
+
event: string,
|
|
88
|
+
data: { [Name: string]: string }
|
|
89
|
+
) {
|
|
90
|
+
MobileSdk.notifyEventWithData(event, data);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Server
|
|
94
|
+
export async function getUs(): Promise<IServerModel> {
|
|
95
|
+
return transformServer(await MobileSdk.getUs());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function getUk(): Promise<IServerModel> {
|
|
99
|
+
return transformServer(await MobileSdk.getUk());
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export async function getAustralia(): Promise<IServerModel> {
|
|
103
|
+
return transformServer(await MobileSdk.getAustralia());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function getCanada(): Promise<IServerModel> {
|
|
107
|
+
return transformServer(await MobileSdk.getCanada());
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export async function getGermany(): Promise<IServerModel> {
|
|
111
|
+
return transformServer(await MobileSdk.getGermany());
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function getHxPlatform(): Promise<IServerModel> {
|
|
115
|
+
return transformServer(await MobileSdk.getHxPlatform());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export async function getHxAustralia(): Promise<IServerModel> {
|
|
119
|
+
return transformServer(await MobileSdk.getHxAustralia());
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export async function configureUs(
|
|
123
|
+
clientId: string,
|
|
124
|
+
clientSecret: string
|
|
125
|
+
): Promise<void> {
|
|
126
|
+
return await MobileSdk.configureUs(clientId, clientSecret);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export async function configureUk(
|
|
130
|
+
clientId: string,
|
|
131
|
+
clientSecret: string
|
|
132
|
+
): Promise<void> {
|
|
133
|
+
return await MobileSdk.configureUk(clientId, clientSecret);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export async function configureAustralia(
|
|
137
|
+
clientId: string,
|
|
138
|
+
clientSecret: string
|
|
139
|
+
): Promise<void> {
|
|
140
|
+
return await MobileSdk.configureAustralia(clientId, clientSecret);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export async function configureCanada(
|
|
144
|
+
clientId: string,
|
|
145
|
+
clientSecret: string
|
|
146
|
+
): Promise<void> {
|
|
147
|
+
return await MobileSdk.configureCanada(clientId, clientSecret);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function configureGermany(
|
|
151
|
+
clientId: string,
|
|
152
|
+
clientSecret: string
|
|
153
|
+
): Promise<void> {
|
|
154
|
+
return await MobileSdk.configureGermany(clientId, clientSecret);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export async function configureHxPlatform(
|
|
158
|
+
clientId: string,
|
|
159
|
+
clientSecret: string
|
|
160
|
+
): Promise<void> {
|
|
161
|
+
return await MobileSdk.configureHxPlatform(clientId, clientSecret);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export async function configureHxAustralia(
|
|
165
|
+
clientId: string,
|
|
166
|
+
clientSecret: string
|
|
167
|
+
): Promise<void> {
|
|
168
|
+
return await MobileSdk.configureHxAustralia(clientId, clientSecret);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export async function configureServer(
|
|
172
|
+
name: string,
|
|
173
|
+
host: string,
|
|
174
|
+
clientId: string,
|
|
175
|
+
clientSecret: string
|
|
176
|
+
): Promise<IServerModel> {
|
|
177
|
+
return transformServer(
|
|
178
|
+
await MobileSdk.configureServer(name, host, clientId, clientSecret)
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export async function getServer(serverId: string): Promise<IServerModel> {
|
|
183
|
+
return transformServer(await MobileSdk.getServer(serverId));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export async function getServers(): Promise<IServerModel[]> {
|
|
187
|
+
const result = await MobileSdk.getServers();
|
|
188
|
+
const servers = [];
|
|
189
|
+
for (const server of result) {
|
|
190
|
+
servers.push(transformServer(server));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return servers;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function transformServer(result: any): IServerModel {
|
|
197
|
+
return {
|
|
198
|
+
host: result.host,
|
|
199
|
+
name: result.name,
|
|
200
|
+
serverId: result.serverId,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface IServerModel {
|
|
2
|
+
serverId: string;
|
|
3
|
+
name: string;
|
|
4
|
+
host: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface IWebSurveyModel {
|
|
8
|
+
token: string;
|
|
9
|
+
url: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface IScenarioCallback {
|
|
13
|
+
serverId: string;
|
|
14
|
+
programKey: string;
|
|
15
|
+
error: string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { IScenarioCallback, IWebSurveyModel } from '../models/models';
|
|
2
|
+
import { NativeEventEmitter, NativeModules } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface ISdkListener {
|
|
5
|
+
onSurveyWebview(model: IWebSurveyModel): void;
|
|
6
|
+
onScenarioLoad(model: IScenarioCallback): void;
|
|
7
|
+
onScenarioError(model: IScenarioCallback): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class Manager {
|
|
11
|
+
private listener: ISdkListener | null = null;
|
|
12
|
+
private sdkEmitter = NativeModules.SdkEmitter;
|
|
13
|
+
private triggerManagerEmitter = new NativeEventEmitter(this.sdkEmitter);
|
|
14
|
+
|
|
15
|
+
constructor() {
|
|
16
|
+
this.triggerManagerEmitter.addListener(
|
|
17
|
+
'__mobileOnWebSurveyStart',
|
|
18
|
+
this.onWebSurveyStart
|
|
19
|
+
);
|
|
20
|
+
this.triggerManagerEmitter.addListener(
|
|
21
|
+
'__mobileOnScenarioLoad',
|
|
22
|
+
this.onScenarioLoad
|
|
23
|
+
);
|
|
24
|
+
this.triggerManagerEmitter.addListener(
|
|
25
|
+
'__mobileOnScenarioError',
|
|
26
|
+
this.onScenarioError
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public setSdkListener(callbackListener: ISdkListener) {
|
|
31
|
+
this.listener = callbackListener;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public removeSdkListener() {
|
|
35
|
+
this.listener = null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private onWebSurveyStart = (event: IWebSurveyModel) => {
|
|
39
|
+
this.listener?.onSurveyWebview(event);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
private onScenarioLoad = (event: IScenarioCallback) => {
|
|
43
|
+
this.listener?.onScenarioLoad(event);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
private onScenarioError = (event: IScenarioCallback) => {
|
|
47
|
+
this.listener?.onScenarioError(event);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const TriggerManager = new Manager();
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import WebView from 'react-native-webview';
|
|
2
|
+
import type {
|
|
3
|
+
WebViewMessageEvent,
|
|
4
|
+
WebViewProps,
|
|
5
|
+
} from 'react-native-webview';
|
|
6
|
+
import React, { Component } from 'react';
|
|
7
|
+
import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
|
|
8
|
+
import { injectWebView } from '../index';
|
|
9
|
+
|
|
10
|
+
interface SurveyWebViewProps extends WebViewProps {
|
|
11
|
+
onSurveyClosed?: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default class SurveyWebView extends Component<SurveyWebViewProps> {
|
|
15
|
+
private sdkEmitter = NativeModules.SdkEmitter;
|
|
16
|
+
private triggerManagerEmitter = new NativeEventEmitter(this.sdkEmitter);
|
|
17
|
+
|
|
18
|
+
private loaded = false;
|
|
19
|
+
|
|
20
|
+
constructor(props: SurveyWebViewProps) {
|
|
21
|
+
super(props);
|
|
22
|
+
|
|
23
|
+
this.triggerManagerEmitter.addListener(
|
|
24
|
+
'__mobileOnSurveyClosed',
|
|
25
|
+
this.__onSurveyClosed
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private __onSurveyClosed = () => {
|
|
30
|
+
this.props.onSurveyClosed?.();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
load() {
|
|
34
|
+
if (!this.loaded) {
|
|
35
|
+
injectWebView();
|
|
36
|
+
this.loaded = true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private onMessage = (event: WebViewMessageEvent) => {
|
|
41
|
+
this.__onSurveyClosed();
|
|
42
|
+
this.props.onMessage?.(event);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
render() {
|
|
46
|
+
let { injectedJavaScriptBeforeContentLoaded } = this.props;
|
|
47
|
+
|
|
48
|
+
if (Platform.OS === 'ios') {
|
|
49
|
+
injectedJavaScriptBeforeContentLoaded += ` \nwindow['mobileBridge'] = { onSurveyEnd: function() { window.ReactNativeWebView?.postMessage(''); } };`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<WebView
|
|
54
|
+
nativeID={'surveyWebViews'}
|
|
55
|
+
{...this.props}
|
|
56
|
+
domStorageEnabled={true}
|
|
57
|
+
javaScriptEnabled={true}
|
|
58
|
+
onLoad={() => {
|
|
59
|
+
this.load();
|
|
60
|
+
}}
|
|
61
|
+
injectedJavaScriptForMainFrameOnly={false}
|
|
62
|
+
injectedJavaScriptBeforeContentLoaded={
|
|
63
|
+
injectedJavaScriptBeforeContentLoaded
|
|
64
|
+
}
|
|
65
|
+
onMessage={this.onMessage}
|
|
66
|
+
/>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|