@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.
- package/README.md +3 -3
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/mobilesdk/MobileSdkModule.kt +25 -4
- package/android/src/main/java/com/mobilesdk/MobileSdkPackage.kt +1 -1
- package/android/src/main/java/com/mobilesdk/MobileSdkSurveyModule.kt +296 -0
- package/android/src/main/java/com/mobilesdk/module/TriggerCallback.kt +31 -1
- package/android/src/main/java/com/mobilesdk/survey/MobileSdkSurveyManager.kt +23 -0
- package/android/src/main/java/com/mobilesdk/survey/MobileSdkSurveyWrapper.kt +104 -0
- package/ios/MobileSdk.mm +8 -1
- package/ios/MobileSdk.swift +15 -2
- package/ios/MobileSdkSurvey-Bridging-Header.h +2 -0
- package/ios/MobileSdkSurvey.mm +111 -0
- package/ios/MobileSdkSurvey.swift +274 -0
- package/ios/Mobilesdk.xcodeproj/project.pbxproj +0 -2
- package/ios/Module/MobileTriggerCallback.swift +31 -1
- package/ios/Module/SdkEmitter.swift +1 -1
- package/ios/Podfile +1 -1
- package/ios/Podfile.lock +1 -1
- package/ios/Survey/MobileSdkSurveyManager.swift +21 -0
- package/ios/Survey/MobileSdkSurveyWrapper.swift +79 -0
- package/lib/commonjs/confirmitSdk.js +29 -0
- package/lib/commonjs/confirmitSdk.js.map +1 -0
- package/lib/commonjs/index.js +48 -140
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/models.js +24 -0
- package/lib/commonjs/models/models.js.map +1 -1
- package/lib/commonjs/program/triggerCallback.js +9 -21
- package/lib/commonjs/program/triggerCallback.js.map +1 -1
- package/lib/commonjs/serverSdk.js +83 -0
- package/lib/commonjs/serverSdk.js.map +1 -0
- package/lib/commonjs/survey/pageControl.js +72 -0
- package/lib/commonjs/survey/pageControl.js.map +1 -0
- package/lib/commonjs/survey/surveyFrameCallback.js +28 -0
- package/lib/commonjs/survey/surveyFrameCallback.js.map +1 -0
- package/lib/commonjs/surveySdk.js +23 -0
- package/lib/commonjs/surveySdk.js.map +1 -0
- package/lib/commonjs/triggerSdk.js +50 -0
- package/lib/commonjs/triggerSdk.js.map +1 -0
- package/lib/commonjs/views/surveyWebView.js +43 -43
- package/lib/commonjs/views/surveyWebView.js.map +1 -1
- package/lib/module/confirmitSdk.js +23 -0
- package/lib/module/confirmitSdk.js.map +1 -0
- package/lib/module/index.js +7 -113
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/models.js +19 -1
- package/lib/module/models/models.js.map +1 -1
- package/lib/module/program/triggerCallback.js +9 -21
- package/lib/module/program/triggerCallback.js.map +1 -1
- package/lib/module/serverSdk.js +77 -0
- package/lib/module/serverSdk.js.map +1 -0
- package/lib/module/survey/pageControl.js +65 -0
- package/lib/module/survey/pageControl.js.map +1 -0
- package/lib/module/survey/surveyFrameCallback.js +22 -0
- package/lib/module/survey/surveyFrameCallback.js.map +1 -0
- package/lib/module/surveySdk.js +17 -0
- package/lib/module/surveySdk.js.map +1 -0
- package/lib/module/triggerSdk.js +44 -0
- package/lib/module/triggerSdk.js.map +1 -0
- package/lib/module/views/surveyWebView.js +43 -42
- package/lib/module/views/surveyWebView.js.map +1 -1
- package/lib/typescript/confirmitSdk.d.ts +8 -0
- package/lib/typescript/confirmitSdk.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -36
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/models/models.d.ts +91 -0
- package/lib/typescript/models/models.d.ts.map +1 -1
- package/lib/typescript/program/triggerCallback.d.ts +5 -13
- package/lib/typescript/program/triggerCallback.d.ts.map +1 -1
- package/lib/typescript/serverSdk.d.ts +24 -0
- package/lib/typescript/serverSdk.d.ts.map +1 -0
- package/lib/typescript/survey/pageControl.d.ts +27 -0
- package/lib/typescript/survey/pageControl.d.ts.map +1 -0
- package/lib/typescript/survey/surveyFrameCallback.d.ts +15 -0
- package/lib/typescript/survey/surveyFrameCallback.d.ts.map +1 -0
- package/lib/typescript/surveySdk.d.ts +10 -0
- package/lib/typescript/surveySdk.d.ts.map +1 -0
- package/lib/typescript/triggerSdk.d.ts +23 -0
- package/lib/typescript/triggerSdk.d.ts.map +1 -0
- package/lib/typescript/views/surveyWebView.d.ts +4 -13
- package/lib/typescript/views/surveyWebView.d.ts.map +1 -1
- package/package.json +9 -7
- package/react-native-mobilesdk.podspec +1 -1
- package/src/confirmitSdk.ts +34 -0
- package/src/index.tsx +45 -152
- package/src/models/models.ts +96 -0
- package/src/program/triggerCallback.ts +10 -27
- package/src/serverSdk.ts +105 -0
- package/src/survey/pageControl.ts +97 -0
- package/src/survey/surveyFrameCallback.ts +28 -0
- package/src/surveySdk.ts +32 -0
- package/src/triggerSdk.ts +62 -0
- package/src/views/surveyWebView.tsx +46 -44
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Add the SDK dependency to the application level `build.gradle` file.
|
|
|
41
41
|
// build.gradle (Module)
|
|
42
42
|
dependencies {
|
|
43
43
|
...
|
|
44
|
-
implementation 'com.confirmit.mobilesdk:mobilesdk:3.
|
|
44
|
+
implementation 'com.confirmit.mobilesdk:mobilesdk:3.13.0'
|
|
45
45
|
}
|
|
46
46
|
```
|
|
47
47
|
|
|
@@ -83,7 +83,7 @@ import PackageDescription
|
|
|
83
83
|
let package = Package(
|
|
84
84
|
name: "<Your Product Name>",
|
|
85
85
|
dependencies: [
|
|
86
|
-
.package(url: "https://github.com/ForstaGlobal/DigitalFeedbackMobileSDK.git", .upToNextMajor(from: "3.
|
|
86
|
+
.package(url: "https://github.com/ForstaGlobal/DigitalFeedbackMobileSDK.git", .upToNextMajor(from: "3.13.0"))
|
|
87
87
|
],
|
|
88
88
|
targets: [
|
|
89
89
|
.target(
|
|
@@ -108,7 +108,7 @@ platform :ios, '11.0'
|
|
|
108
108
|
# Your target
|
|
109
109
|
target 'MyApp' do
|
|
110
110
|
# ... others pods
|
|
111
|
-
pod 'ConfirmitMobileSDK', '3.
|
|
111
|
+
pod 'ConfirmitMobileSDK', '3.13.0'
|
|
112
112
|
end
|
|
113
113
|
```
|
|
114
114
|
|
package/android/build.gradle
CHANGED
|
@@ -97,7 +97,7 @@ dependencies {
|
|
|
97
97
|
//noinspection GradleDynamicVersion
|
|
98
98
|
implementation "com.facebook.react:react-native:+"
|
|
99
99
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
100
|
-
implementation 'com.confirmit.mobilesdk:mobilesdk:3.
|
|
100
|
+
implementation 'com.confirmit.mobilesdk:mobilesdk:3.13.0'
|
|
101
101
|
implementation project(path: ':react-native-webview')
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -54,10 +54,11 @@ class MobileSdkModule(reactContext: ReactApplicationContext) :
|
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
@ReactMethod
|
|
57
|
-
fun initSdk() {
|
|
57
|
+
fun initSdk(promise: Promise) {
|
|
58
58
|
application?.let {
|
|
59
59
|
ConfirmitSDK.Setup(it).configure()
|
|
60
60
|
}
|
|
61
|
+
promise.resolve(null);
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
@ReactMethod
|
|
@@ -72,7 +73,7 @@ class MobileSdkModule(reactContext: ReactApplicationContext) :
|
|
|
72
73
|
if (response.result) {
|
|
73
74
|
promise.resolve(response.result)
|
|
74
75
|
} else {
|
|
75
|
-
promise.reject(response.exception)
|
|
76
|
+
promise.reject("trigger", "failed to download program", response.exception)
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -85,8 +86,9 @@ class MobileSdkModule(reactContext: ReactApplicationContext) :
|
|
|
85
86
|
) {
|
|
86
87
|
try {
|
|
87
88
|
TriggerSDK.deleteProgram(serverId, programKey, deleteCustomData)
|
|
89
|
+
promise.resolve(null)
|
|
88
90
|
} catch (error: Exception) {
|
|
89
|
-
promise.reject(error)
|
|
91
|
+
promise.reject("trigger", "failed to delete program $programKey", error)
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
94
|
|
|
@@ -94,8 +96,9 @@ class MobileSdkModule(reactContext: ReactApplicationContext) :
|
|
|
94
96
|
fun deleteAll(deleteCustomData: Boolean, promise: Promise) {
|
|
95
97
|
try {
|
|
96
98
|
TriggerSDK.deleteAll(deleteCustomData)
|
|
99
|
+
promise.resolve(null)
|
|
97
100
|
} catch (error: Exception) {
|
|
98
|
-
promise.reject(error)
|
|
101
|
+
promise.reject("trigger", "failed to delete all programs", error)
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
|
|
@@ -136,6 +139,24 @@ class MobileSdkModule(reactContext: ReactApplicationContext) :
|
|
|
136
139
|
TriggerSDK.notifyAppForeground(result)
|
|
137
140
|
}
|
|
138
141
|
|
|
142
|
+
@ReactMethod
|
|
143
|
+
fun addJourneyLog(data: ReadableMap) {
|
|
144
|
+
val result = mutableMapOf<String, String>()
|
|
145
|
+
for (entry in data.entryIterator) {
|
|
146
|
+
result[entry.key] = entry.value.toString()
|
|
147
|
+
}
|
|
148
|
+
TriggerSDK.addJourneyLog(result)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@ReactMethod
|
|
152
|
+
fun addJourneyLogWithServer(serverId: String, programKey: String, data: ReadableMap) {
|
|
153
|
+
val result = mutableMapOf<String, String>()
|
|
154
|
+
for (entry in data.entryIterator) {
|
|
155
|
+
result[entry.key] = entry.value.toString()
|
|
156
|
+
}
|
|
157
|
+
TriggerSDK.addJourneyLog(serverId, programKey, result)
|
|
158
|
+
}
|
|
159
|
+
|
|
139
160
|
// Server
|
|
140
161
|
@ReactMethod
|
|
141
162
|
fun getUs(promise: Promise) {
|
|
@@ -8,7 +8,7 @@ import com.facebook.react.uimanager.ViewManager
|
|
|
8
8
|
|
|
9
9
|
class MobileSdkPackage : ReactPackage {
|
|
10
10
|
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
|
|
11
|
-
return listOf(MobileSdkModule(reactContext))
|
|
11
|
+
return listOf(MobileSdkModule(reactContext), MobileSdkSurveyModule(reactContext))
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
package com.mobilesdk
|
|
2
|
+
|
|
3
|
+
import android.app.Application
|
|
4
|
+
import com.confirmit.mobilesdk.ui.QuestionType
|
|
5
|
+
import com.confirmit.mobilesdk.ui.SurveyFrameActionResult
|
|
6
|
+
import com.confirmit.mobilesdk.ui.questions.DefaultQuestion
|
|
7
|
+
import com.confirmit.mobilesdk.ui.questions.InfoQuestion
|
|
8
|
+
import com.confirmit.mobilesdk.ui.questions.MultiQuestion
|
|
9
|
+
import com.confirmit.mobilesdk.ui.questions.NumericQuestion
|
|
10
|
+
import com.confirmit.mobilesdk.ui.questions.QuestionAnswer
|
|
11
|
+
import com.confirmit.mobilesdk.ui.questions.SingleQuestion
|
|
12
|
+
import com.confirmit.mobilesdk.ui.questions.TextQuestion
|
|
13
|
+
import com.facebook.react.bridge.Arguments
|
|
14
|
+
import com.facebook.react.bridge.Promise
|
|
15
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
16
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
17
|
+
import com.facebook.react.bridge.ReactMethod
|
|
18
|
+
import com.facebook.react.bridge.ReadableMap
|
|
19
|
+
import com.facebook.react.bridge.WritableArray
|
|
20
|
+
import com.mobilesdk.survey.MobileSdkSurveyManager
|
|
21
|
+
import com.mobilesdk.survey.MobileSdkSurveyWrapper
|
|
22
|
+
|
|
23
|
+
class MobileSdkSurveyModule(reactContext: ReactApplicationContext) :
|
|
24
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
25
|
+
|
|
26
|
+
companion object {
|
|
27
|
+
const val NAME = "MobileSdkSurvey"
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private val surveyManager = MobileSdkSurveyManager()
|
|
31
|
+
|
|
32
|
+
override fun getName(): String {
|
|
33
|
+
return NAME
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Survey Page Methods
|
|
37
|
+
@ReactMethod
|
|
38
|
+
fun getTitle(serverId: String, programKey: String, surveyId: String, promise: Promise) {
|
|
39
|
+
promise.resolve(surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.title?.get())
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@ReactMethod
|
|
43
|
+
fun getText(serverId: String, programKey: String, surveyId: String, promise: Promise) {
|
|
44
|
+
promise.resolve(surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.text?.get())
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@ReactMethod
|
|
48
|
+
fun getQuestions(serverId: String, programKey: String, surveyId: String, promise: Promise) {
|
|
49
|
+
val results = Arguments.createArray()
|
|
50
|
+
surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.questions?.let { questions ->
|
|
51
|
+
for (question in questions) {
|
|
52
|
+
val result = Arguments.createMap().apply {
|
|
53
|
+
putString("id", question.id)
|
|
54
|
+
putString("nodeType", question.nodeType.toString())
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
val errors = Arguments.createArray()
|
|
58
|
+
when (question) {
|
|
59
|
+
is InfoQuestion -> {
|
|
60
|
+
result.putString("title", question.title.get())
|
|
61
|
+
result.putString("text", question.text.get())
|
|
62
|
+
result.putString("instruction", question.instruction.get())
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
is TextQuestion -> {
|
|
66
|
+
result.putString("title", question.title.get())
|
|
67
|
+
result.putString("text", question.text.get())
|
|
68
|
+
result.putString("instruction", question.instruction.get())
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
is NumericQuestion -> {
|
|
72
|
+
result.putString("title", question.title.get())
|
|
73
|
+
result.putString("text", question.text.get())
|
|
74
|
+
result.putString("instruction", question.instruction.get())
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
is SingleQuestion -> {
|
|
78
|
+
result.putString("title", question.title.get())
|
|
79
|
+
result.putString("text", question.text.get())
|
|
80
|
+
result.putString("instruction", question.instruction.get())
|
|
81
|
+
result.putInt("appearance", question.appearance.value)
|
|
82
|
+
result.putArray("answers", getAnswers(question.answers))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
is MultiQuestion -> {
|
|
86
|
+
result.putString("title", question.title.get())
|
|
87
|
+
result.putString("text", question.text.get())
|
|
88
|
+
result.putString("instruction", question.instruction.get())
|
|
89
|
+
result.putInt("appearance", question.appearance.value)
|
|
90
|
+
result.putArray("answers", getAnswers(question.answers))
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (question is DefaultQuestion) {
|
|
95
|
+
for (error in question.errors) {
|
|
96
|
+
errors.pushMap(Arguments.createMap().apply {
|
|
97
|
+
putString("code", error.code.name)
|
|
98
|
+
putString("message", error.message)
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
result.putArray("errors", errors);
|
|
104
|
+
results.pushMap(result)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
promise.resolve(results)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private fun getAnswers(questionAnswers: List<QuestionAnswer>): WritableArray {
|
|
111
|
+
val answers = Arguments.createArray()
|
|
112
|
+
for (answer in questionAnswers) {
|
|
113
|
+
val result = Arguments.createMap().apply {
|
|
114
|
+
putString("code", answer.code)
|
|
115
|
+
putString("text", answer.text.get())
|
|
116
|
+
putBoolean("isHeader", answer.isHeader)
|
|
117
|
+
}
|
|
118
|
+
val groupAnswer = Arguments.createArray()
|
|
119
|
+
for (innerAnswer in answer.answers) {
|
|
120
|
+
groupAnswer.pushMap(Arguments.createMap().apply {
|
|
121
|
+
putString("code", innerAnswer.code)
|
|
122
|
+
putString("text", innerAnswer.text.get())
|
|
123
|
+
putBoolean("isHeader", innerAnswer.isHeader)
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
result.putArray("answers", groupAnswer)
|
|
128
|
+
answers.pushMap(result)
|
|
129
|
+
}
|
|
130
|
+
return answers
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Question Control
|
|
134
|
+
@ReactMethod
|
|
135
|
+
fun setText(serverId: String, programKey: String, surveyId: String, questionId: String, answer: String, promise: Promise) {
|
|
136
|
+
surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.questions?.firstOrNull { it.id == questionId }?.let {
|
|
137
|
+
val text = it as? TextQuestion
|
|
138
|
+
text?.setValue(answer)
|
|
139
|
+
}
|
|
140
|
+
promise.resolve(null)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@ReactMethod
|
|
144
|
+
fun getText(serverId: String, programKey: String, surveyId: String, questionId: String, promise: Promise) {
|
|
145
|
+
var result = ""
|
|
146
|
+
surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.questions?.firstOrNull { it.id == questionId }?.let {
|
|
147
|
+
val text = it as? TextQuestion
|
|
148
|
+
result = text?.getValue() ?: ""
|
|
149
|
+
}
|
|
150
|
+
promise.resolve(result)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@ReactMethod
|
|
154
|
+
fun setNumeric(serverId: String, programKey: String, surveyId: String, questionId: String, answer: Double, isDouble: Boolean, promise: Promise) {
|
|
155
|
+
surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.questions?.firstOrNull { it.id == questionId }?.let {
|
|
156
|
+
val text = it as? NumericQuestion
|
|
157
|
+
if (isDouble) {
|
|
158
|
+
text?.setValue(answer)
|
|
159
|
+
} else {
|
|
160
|
+
text?.setValue(answer.toInt())
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
}
|
|
164
|
+
promise.resolve(null)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@ReactMethod
|
|
168
|
+
fun getNumeric(serverId: String, programKey: String, surveyId: String, questionId: String, promise: Promise) {
|
|
169
|
+
var result = ""
|
|
170
|
+
surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.questions?.firstOrNull { it.id == questionId }?.let {
|
|
171
|
+
val text = it as? NumericQuestion
|
|
172
|
+
result = text?.getValue() ?: ""
|
|
173
|
+
}
|
|
174
|
+
promise.resolve(result)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@ReactMethod
|
|
178
|
+
fun setSingle(serverId: String, programKey: String, surveyId: String, questionId: String, code: String, promise: Promise) {
|
|
179
|
+
surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.questions?.firstOrNull { it.id == questionId }?.let {
|
|
180
|
+
val single = it as? SingleQuestion
|
|
181
|
+
val allAnswers = single?.answers?.flatMap { flatAnswer ->
|
|
182
|
+
if (flatAnswer.isHeader) {
|
|
183
|
+
return@flatMap flatAnswer.answers
|
|
184
|
+
}
|
|
185
|
+
return@flatMap listOf(flatAnswer)
|
|
186
|
+
}
|
|
187
|
+
allAnswers?.firstOrNull { findAnswer -> findAnswer.code == code }?.let { questionAnswer ->
|
|
188
|
+
single.select(questionAnswer)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
promise.resolve(null)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
@ReactMethod
|
|
195
|
+
fun getSingle(serverId: String, programKey: String, surveyId: String, questionId: String, promise: Promise) {
|
|
196
|
+
val result = Arguments.createMap()
|
|
197
|
+
surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.questions?.firstOrNull { it.id == questionId }?.let {
|
|
198
|
+
val single = it as? SingleQuestion
|
|
199
|
+
single?.selected()?.let { selected ->
|
|
200
|
+
result.apply {
|
|
201
|
+
putString("code", selected.code)
|
|
202
|
+
putString("text", selected.text.get())
|
|
203
|
+
putBoolean("isHeader", selected.isHeader)
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
promise.resolve(result)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@ReactMethod
|
|
211
|
+
fun setMulti(serverId: String, programKey: String, surveyId: String, questionId: String, code: String, selected: Boolean, promise: Promise) {
|
|
212
|
+
surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.questions?.firstOrNull { it.id == questionId }?.let {
|
|
213
|
+
val multi = it as? MultiQuestion
|
|
214
|
+
val allAnswers = multi?.answers?.flatMap { flatAnswer ->
|
|
215
|
+
if (flatAnswer.isHeader) {
|
|
216
|
+
return@flatMap flatAnswer.answers
|
|
217
|
+
}
|
|
218
|
+
return@flatMap listOf(flatAnswer)
|
|
219
|
+
}
|
|
220
|
+
allAnswers?.firstOrNull { findAnswer -> findAnswer.code == code }?.let { questionAnswer ->
|
|
221
|
+
multi.set(questionAnswer, selected)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
promise.resolve(null)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@ReactMethod
|
|
228
|
+
fun getMulti(serverId: String, programKey: String, surveyId: String, questionId: String, promise: Promise) {
|
|
229
|
+
val result = Arguments.createArray()
|
|
230
|
+
surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.page?.questions?.firstOrNull { it.id == questionId }?.let {
|
|
231
|
+
(it as? MultiQuestion)?.let { multi ->
|
|
232
|
+
val allAnswers = multi.answers.flatMap { flatAnswer ->
|
|
233
|
+
if (flatAnswer.isHeader) {
|
|
234
|
+
return@flatMap flatAnswer.answers
|
|
235
|
+
}
|
|
236
|
+
return@flatMap listOf(flatAnswer)
|
|
237
|
+
}
|
|
238
|
+
for (answer in allAnswers) {
|
|
239
|
+
if (multi.get(answer)) {
|
|
240
|
+
result.pushMap(Arguments.createMap().apply {
|
|
241
|
+
putString("code", answer.code)
|
|
242
|
+
putString("text", answer.text.get())
|
|
243
|
+
putBoolean("isHeader", answer.isHeader)
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
promise.resolve(result)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Survey Control
|
|
253
|
+
@ReactMethod
|
|
254
|
+
fun startSurvey(serverId: String, programKey: String, surveyId: String, data: ReadableMap, respondentValue: ReadableMap, promise: Promise) {
|
|
255
|
+
val dataResult = mutableMapOf<String, String>()
|
|
256
|
+
for (entry in data.entryIterator) {
|
|
257
|
+
dataResult[entry.key] = entry.value.toString()
|
|
258
|
+
}
|
|
259
|
+
val respondentValueResult = mutableMapOf<String, String>()
|
|
260
|
+
for (entry in respondentValue.entryIterator) {
|
|
261
|
+
respondentValueResult[entry.key] = entry.value.toString()
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
val result = surveyManager.getSurvey(serverId, programKey, surveyId)?.startSurvey(dataResult, respondentValueResult)
|
|
265
|
+
surveyActionResult(serverId, programKey, surveyId, promise, result)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
@ReactMethod
|
|
269
|
+
fun next(serverId: String, programKey: String, surveyId: String, promise: Promise) {
|
|
270
|
+
val result = surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.next()
|
|
271
|
+
surveyActionResult(serverId, programKey, surveyId, promise, result)
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@ReactMethod
|
|
275
|
+
fun back(serverId: String, programKey: String, surveyId: String, promise: Promise) {
|
|
276
|
+
val result = surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.back()
|
|
277
|
+
surveyActionResult(serverId, programKey, surveyId, promise, result)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
@ReactMethod
|
|
281
|
+
fun quit(serverId: String, programKey: String, surveyId: String, upload: Boolean, promise: Promise) {
|
|
282
|
+
val result = surveyManager.getSurvey(serverId, programKey, surveyId)?.surveyFrame?.quit(upload)
|
|
283
|
+
surveyActionResult(serverId, programKey, surveyId, promise, result)
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
private fun surveyActionResult(serverId: String, programKey: String, surveyId: String, promise: Promise, result: SurveyFrameActionResult?) {
|
|
287
|
+
if (result == null) {
|
|
288
|
+
promise.reject("survey", "failed to find active survey for ServerId: $serverId ProgramKey: $programKey SurveyId: $surveyId")
|
|
289
|
+
} else {
|
|
290
|
+
promise.resolve(Arguments.createMap().apply {
|
|
291
|
+
putBoolean("success", result.success)
|
|
292
|
+
putString("message", result.message)
|
|
293
|
+
})
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -7,6 +7,8 @@ import com.confirmit.mobilesdk.web.SurveyWebViewFragment
|
|
|
7
7
|
import com.facebook.react.bridge.Arguments
|
|
8
8
|
import com.facebook.react.bridge.ReactContext
|
|
9
9
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
+
import com.mobilesdk.survey.MobileSdkSurveyManager
|
|
11
|
+
import com.mobilesdk.survey.MobileSdkSurveyWrapper
|
|
10
12
|
|
|
11
13
|
class TriggerCallback(
|
|
12
14
|
private val reactContext: ReactContext,
|
|
@@ -42,7 +44,35 @@ class TriggerCallback(
|
|
|
42
44
|
) {
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
override fun onSurveyStart(config: SurveyFrameConfig) {
|
|
47
|
+
override fun onSurveyStart(config: SurveyFrameConfig) {
|
|
48
|
+
MobileSdkSurveyManager().addSurvey(config.serverId, programKey, config.surveyId, MobileSdkSurveyWrapper(reactContext, config))
|
|
49
|
+
|
|
50
|
+
val values = Arguments.createMap().apply {
|
|
51
|
+
putString("serverId", serverId)
|
|
52
|
+
putString("programKey", programKey)
|
|
53
|
+
putString("surveyId", config.surveyId)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
config.languageId?.let {
|
|
57
|
+
values.putInt("languageId", it)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
val customData = Arguments.createMap()
|
|
61
|
+
for (data in config.customData) {
|
|
62
|
+
customData.putString(data.key, data.value)
|
|
63
|
+
}
|
|
64
|
+
values.putMap("customData", customData)
|
|
65
|
+
|
|
66
|
+
val respondentValue = Arguments.createMap()
|
|
67
|
+
for (respondent in config.respondentValues) {
|
|
68
|
+
respondentValue.putString(respondent.key, respondent.value)
|
|
69
|
+
}
|
|
70
|
+
values.putMap("respondentValue", respondentValue)
|
|
71
|
+
|
|
72
|
+
reactContext
|
|
73
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
74
|
+
.emit("__mobileOnSurveyStart", values)
|
|
75
|
+
}
|
|
46
76
|
|
|
47
77
|
override fun onWebSurveyStart(fragment: SurveyWebViewFragment) {
|
|
48
78
|
val result = fragment.getSurveyUrl()
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
package com.mobilesdk.survey
|
|
2
|
+
|
|
3
|
+
class MobileSdkSurveyManager {
|
|
4
|
+
companion object {
|
|
5
|
+
private val activeSurvey: MutableMap<String, MobileSdkSurveyWrapper> = mutableMapOf()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
fun getSurvey(serverId: String, programKey: String, surveyId: String): MobileSdkSurveyWrapper? {
|
|
9
|
+
return activeSurvey[getKey(serverId, programKey, surveyId)]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
fun addSurvey(serverId: String, programKey: String, surveyId: String, survey: MobileSdkSurveyWrapper) {
|
|
13
|
+
activeSurvey[getKey(serverId, programKey, surveyId)] = survey
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
fun removeSurvey(serverId: String, programKey: String, surveyId: String) {
|
|
17
|
+
activeSurvey.remove(getKey(serverId, programKey, surveyId))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private fun getKey(serverId: String, programKey: String, surveyId: String): String {
|
|
21
|
+
return "${serverId}_${programKey}_$surveyId"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
package com.mobilesdk.survey
|
|
2
|
+
|
|
3
|
+
import com.confirmit.mobilesdk.ui.SurveyFrame
|
|
4
|
+
import com.confirmit.mobilesdk.ui.SurveyFrameActionResult
|
|
5
|
+
import com.confirmit.mobilesdk.ui.SurveyFrameConfig
|
|
6
|
+
import com.confirmit.mobilesdk.ui.SurveyFrameLifecycleListener
|
|
7
|
+
import com.confirmit.mobilesdk.ui.SurveyPage
|
|
8
|
+
import com.facebook.react.bridge.Arguments
|
|
9
|
+
import com.facebook.react.bridge.ReactContext
|
|
10
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
11
|
+
import okhttp3.internal.wait
|
|
12
|
+
|
|
13
|
+
class MobileSdkSurveyWrapper(private val reactContext: ReactContext, private val config: SurveyFrameConfig) : SurveyFrameLifecycleListener {
|
|
14
|
+
private val manager = MobileSdkSurveyManager()
|
|
15
|
+
var surveyFrame: SurveyFrame? = SurveyFrame()
|
|
16
|
+
|
|
17
|
+
fun startSurvey(customData: Map<String, String?>, respondentValue: Map<String, String>): SurveyFrameActionResult? {
|
|
18
|
+
for (data in customData) {
|
|
19
|
+
config.customData[data.key] = data.value
|
|
20
|
+
}
|
|
21
|
+
config.respondentValues = respondentValue
|
|
22
|
+
surveyFrame?.surveyFrameLifeCycleListener = this
|
|
23
|
+
surveyFrame?.load(config)
|
|
24
|
+
|
|
25
|
+
return surveyFrame?.start()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
override fun onSurveyErrored(page: SurveyPage, values: Map<String, String?>, exception: Exception) {
|
|
29
|
+
val results = Arguments.createMap()
|
|
30
|
+
for (value in values) {
|
|
31
|
+
results.putString(value.key, value.value)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
reactContext
|
|
35
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
36
|
+
.emit("__mobileOnSurveyErrored", Arguments.createMap().apply {
|
|
37
|
+
putString("forwardText", page.forwardText)
|
|
38
|
+
putString("backwardText", page.backwardText)
|
|
39
|
+
putString("okText", page.okText)
|
|
40
|
+
putBoolean("showForward", page.showForward)
|
|
41
|
+
putBoolean("showBackward", page.showBackward)
|
|
42
|
+
putMap("error", Arguments.createMap().apply {
|
|
43
|
+
putString("message", exception.localizedMessage)
|
|
44
|
+
putString("stack", exception.stackTraceToString())
|
|
45
|
+
})
|
|
46
|
+
putMap("values", results)
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
override fun onSurveyFinished(page: SurveyPage, values: Map<String, String?>) {
|
|
51
|
+
val results = Arguments.createMap()
|
|
52
|
+
for (value in values) {
|
|
53
|
+
results.putString(value.key, value.value)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
reactContext
|
|
57
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
58
|
+
.emit("__mobileOnSurveyFinished", Arguments.createMap().apply {
|
|
59
|
+
putString("forwardText", page.forwardText)
|
|
60
|
+
putString("backwardText", page.backwardText)
|
|
61
|
+
putString("okText", page.okText)
|
|
62
|
+
putBoolean("showForward", page.showForward)
|
|
63
|
+
putBoolean("showBackward", page.showBackward)
|
|
64
|
+
putMap("values", results)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
cleanup()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override fun onSurveyPageReady(page: SurveyPage) {
|
|
71
|
+
reactContext
|
|
72
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
73
|
+
.emit("__mobileOnSurveyPageReady", Arguments.createMap().apply {
|
|
74
|
+
putString("serverId", config.serverId)
|
|
75
|
+
putString("programKey", config.programKey)
|
|
76
|
+
putString("surveyId", config.surveyId)
|
|
77
|
+
putString("forwardText", page.forwardText)
|
|
78
|
+
putString("backwardText", page.backwardText)
|
|
79
|
+
putString("okText", page.okText)
|
|
80
|
+
putBoolean("showForward", page.showForward)
|
|
81
|
+
putBoolean("showBackward", page.showBackward)
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
override fun onSurveyQuit(values: Map<String, String?>) {
|
|
86
|
+
val results = Arguments.createMap()
|
|
87
|
+
for (value in values) {
|
|
88
|
+
results.putString(value.key, value.value)
|
|
89
|
+
}
|
|
90
|
+
reactContext
|
|
91
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
92
|
+
.emit("__mobileOnSurveyQuit", Arguments.createMap().apply {
|
|
93
|
+
putMap("values", results)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
cleanup()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private fun cleanup() {
|
|
100
|
+
surveyFrame?.surveyFrameLifeCycleListener = null
|
|
101
|
+
surveyFrame = null
|
|
102
|
+
manager.removeSurvey(config.serverId, config.programKey ?: "", config.surveyId)
|
|
103
|
+
}
|
|
104
|
+
}
|
package/ios/MobileSdk.mm
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
RCT_EXTERN_METHOD(injectWebView)
|
|
6
6
|
|
|
7
7
|
// Confirmit
|
|
8
|
-
RCT_EXTERN_METHOD(initSdk)
|
|
8
|
+
RCT_EXTERN_METHOD(initSdk:(RCTPromiseResolveBlock)resolve
|
|
9
|
+
withRejecter:(RCTPromiseRejectBlock)reject)
|
|
9
10
|
|
|
10
11
|
RCT_EXTERN_METHOD(enableLog:(BOOL)eanble)
|
|
11
12
|
|
|
@@ -38,6 +39,12 @@ RCT_EXTERN_METHOD(notifyAppForeground:(NSDictionary)data)
|
|
|
38
39
|
RCT_EXTERN_METHOD(notifyEventWithData:(NSString)event
|
|
39
40
|
withData:(NSDictionary)data)
|
|
40
41
|
|
|
42
|
+
RCT_EXTERN_METHOD(addJourney:(NSDictionary)data)
|
|
43
|
+
|
|
44
|
+
RCT_EXTERN_METHOD(addJourneyLogWithServer:(NSString)serverId
|
|
45
|
+
withProgramKey:(NSString)programKey
|
|
46
|
+
withData:(NSDictionary)data)
|
|
47
|
+
|
|
41
48
|
// servers
|
|
42
49
|
RCT_EXTERN_METHOD(getUs:(RCTPromiseResolveBlock)resolve
|
|
43
50
|
withRejecter:(RCTPromiseRejectBlock)reject)
|
package/ios/MobileSdk.swift
CHANGED
|
@@ -9,9 +9,10 @@ class MobileSdk: NSObject {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
// Confirmit
|
|
12
|
-
@objc(initSdk)
|
|
13
|
-
func initSdk() {
|
|
12
|
+
@objc(initSdk:withRejecter:)
|
|
13
|
+
func initSdk(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
|
|
14
14
|
ConfirmitSDK.Setup().configure()
|
|
15
|
+
resolve(nil)
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
@objc(enableLog:)
|
|
@@ -35,6 +36,7 @@ class MobileSdk: NSObject {
|
|
|
35
36
|
func deleteProgram(serverId: String, programKey: String, deleteCustomData: Bool, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
36
37
|
do {
|
|
37
38
|
try TriggerSDK.deleteProgram(serverId: serverId, programKey: programKey, deleteCustomData: deleteCustomData)
|
|
39
|
+
resolve(nil)
|
|
38
40
|
} catch {
|
|
39
41
|
reject("trigger", "failed to delete program \(programKey)", error)
|
|
40
42
|
}
|
|
@@ -44,6 +46,7 @@ class MobileSdk: NSObject {
|
|
|
44
46
|
func deleteAll(deleteCustomData: Bool, resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|
|
45
47
|
do {
|
|
46
48
|
try TriggerSDK.deleteAll(deleteCustomData: deleteCustomData)
|
|
49
|
+
resolve(nil)
|
|
47
50
|
} catch {
|
|
48
51
|
reject("trigger", "failed to delete all programs", error)
|
|
49
52
|
}
|
|
@@ -78,6 +81,16 @@ class MobileSdk: NSObject {
|
|
|
78
81
|
TriggerSDK.notifyAppForeground(data: data.swiftDictionary)
|
|
79
82
|
}
|
|
80
83
|
|
|
84
|
+
@objc(addJourney:)
|
|
85
|
+
func addJourney(data: NSDictionary) {
|
|
86
|
+
TriggerSDK.addJourneyLog(data: data.swiftDictionary)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@objc(addJourneyLogWithServer:withProgramKey:withData:)
|
|
90
|
+
func addJourneyLogWithServer(serverId: String, programKey: String, data: NSDictionary) {
|
|
91
|
+
TriggerSDK.addJourneyLog(serverId: serverId, programKey: programKey, data: data.swiftDictionary)
|
|
92
|
+
}
|
|
93
|
+
|
|
81
94
|
// Servers
|
|
82
95
|
@objc(getUs:withRejecter:)
|
|
83
96
|
func getUs(resolve: RCTPromiseResolveBlock, reject: RCTPromiseRejectBlock) {
|