@primer-io/react-native 0.12.4 → 0.15.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/android/build.gradle +2 -2
- package/android/gradle.properties +1 -1
- package/android/src/main/java/com/primerioreactnative/PrimerRN.kt +191 -152
- package/android/src/main/java/com/primerioreactnative/PrimerRNEventListener.kt +131 -86
- package/android/src/main/java/com/primerioreactnative/datamodels/PrimerErrorRN.kt +3 -2
- package/android/src/main/java/com/primerioreactnative/datamodels/PrimerEventsRN.kt +11 -0
- package/android/src/main/java/com/primerioreactnative/utils/ErrorHelper.kt +11 -0
- package/android/src/main/java/com/primerioreactnative/utils/PrimerImplementedRNCallbacks.kt +14 -0
- package/ios/DataModels/PrimerErrorRN.swift +32 -2
- package/ios/RNTPrimer.m +43 -0
- package/ios/RNTPrimer.swift +394 -0
- package/ios/ReactNative-Bridging-Header.h +1 -9
- package/ios/ReactNative.xcodeproj/project.pbxproj +44 -0
- package/lib/commonjs/Primer.js +221 -209
- package/lib/commonjs/Primer.js.map +1 -1
- package/lib/commonjs/RNPrimer.js +145 -0
- package/lib/commonjs/RNPrimer.js.map +1 -0
- package/lib/commonjs/index.js +1 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/primer-intent.js.map +1 -1
- package/lib/commonjs/models/utils/redirectScheme.js +4 -0
- package/lib/commonjs/models/utils/redirectScheme.js.map +1 -0
- package/lib/module/Primer.js +203 -209
- package/lib/module/Primer.js.map +1 -1
- package/lib/module/RNPrimer.js +136 -0
- package/lib/module/RNPrimer.js.map +1 -0
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/primer-intent.js.map +1 -1
- package/lib/module/models/utils/redirectScheme.js +2 -0
- package/lib/module/models/utils/redirectScheme.js.map +1 -0
- package/lib/typescript/Primer.d.ts +13 -0
- package/lib/typescript/RNPrimer.d.ts +24 -0
- package/lib/typescript/models/primer-callbacks.d.ts +7 -9
- package/lib/typescript/models/primer-config.d.ts +16 -13
- package/lib/typescript/models/primer-intent.d.ts +1 -1
- package/lib/typescript/models/primer-request.d.ts +2 -12
- package/lib/typescript/models/primer-settings.d.ts +3 -5
- package/lib/typescript/models/primer.d.ts +4 -4
- package/lib/typescript/models/utils/redirectScheme.d.ts +3 -0
- package/package.json +4 -1
- package/primer-io-react-native.podspec +2 -3
- package/src/Primer.ts +227 -176
- package/src/RNPrimer.ts +170 -0
- package/src/index.tsx +1 -0
- package/src/models/primer-callbacks.ts +9 -27
- package/src/models/primer-config.ts +23 -20
- package/src/models/primer-intent.ts +1 -1
- package/src/models/primer-request.ts +2 -16
- package/src/models/primer-settings.ts +3 -5
- package/src/models/primer.ts +5 -5
- package/src/models/utils/redirectScheme.ts +5 -0
- package/ios/PrimerRN+PrimerDelegate.swift +0 -147
- package/ios/PrimerRN.swift +0 -166
- package/ios/ReactNative.m +0 -34
package/android/build.gradle
CHANGED
|
@@ -127,6 +127,6 @@ dependencies {
|
|
|
127
127
|
// noinspection GradleDynamicVersion
|
|
128
128
|
api 'com.facebook.react:react-native:+'
|
|
129
129
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
130
|
-
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.
|
|
131
|
-
implementation 'io.primer:android:1.
|
|
130
|
+
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.1"
|
|
131
|
+
implementation 'io.primer:android:1.13.0'
|
|
132
132
|
}
|
|
@@ -1,235 +1,274 @@
|
|
|
1
1
|
package com.primerioreactnative
|
|
2
2
|
|
|
3
|
-
import android.content.Context
|
|
4
3
|
import android.util.Log
|
|
5
|
-
import com.facebook.react.bridge
|
|
6
|
-
import com.facebook.react.
|
|
7
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
8
|
-
import com.facebook.react.bridge.ReactMethod
|
|
4
|
+
import com.facebook.react.bridge.*
|
|
5
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
9
6
|
import com.primerioreactnative.datamodels.*
|
|
7
|
+
import com.primerioreactnative.utils.PrimerImplementedRNCallbacks
|
|
8
|
+
import com.primerioreactnative.utils.errorTo
|
|
9
|
+
import io.primer.android.PaymentMethodIntent
|
|
10
10
|
import io.primer.android.Primer
|
|
11
|
-
import io.primer.android.model.dto
|
|
11
|
+
import io.primer.android.model.dto.PrimerConfig
|
|
12
|
+
import io.primer.android.model.dto.PrimerPaymentMethod
|
|
12
13
|
import kotlinx.serialization.decodeFromString
|
|
13
14
|
import kotlinx.serialization.encodeToString
|
|
14
15
|
import kotlinx.serialization.json.Json
|
|
15
|
-
import
|
|
16
|
+
import org.json.JSONObject
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
class PrimerRN(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) {
|
|
19
20
|
|
|
20
21
|
private var settings: PrimerSettingsRN = PrimerSettingsRN()
|
|
21
22
|
private var theme: PrimerThemeRN = PrimerThemeRN()
|
|
22
|
-
private var intent:
|
|
23
|
+
private var intent: PaymentMethodIntent? = null
|
|
24
|
+
private var paymentMethod: PrimerPaymentMethod? = null
|
|
23
25
|
|
|
24
26
|
private var mListener = PrimerRNEventListener()
|
|
25
27
|
|
|
26
28
|
private var sdkWasInitialised = false
|
|
27
|
-
private var haltExecution = false
|
|
28
29
|
|
|
29
|
-
private val json = Json{ ignoreUnknownKeys = true }
|
|
30
|
+
private val json = Json { ignoreUnknownKeys = true }
|
|
30
31
|
|
|
31
|
-
|
|
32
|
+
init {
|
|
33
|
+
mListener.sendEvent = { eventName, paramsJson -> sendEvent(eventName, paramsJson) }
|
|
34
|
+
mListener.sendError = { paramsJson -> checkoutFailed(paramsJson) }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
override fun getName(): String = "NativePrimer"
|
|
32
38
|
|
|
33
39
|
@ReactMethod
|
|
34
|
-
fun
|
|
40
|
+
fun configureWithSettings(settingsStr: String, promise: Promise) {
|
|
35
41
|
try {
|
|
36
|
-
Log.d("PrimerRN", "settings: $
|
|
37
|
-
val settings = json.decodeFromString<PrimerSettingsRN>(
|
|
42
|
+
Log.d("PrimerRN", "settings: $settingsStr")
|
|
43
|
+
val settings = json.decodeFromString<PrimerSettingsRN>(settingsStr)
|
|
38
44
|
this.settings = settings
|
|
45
|
+
startSdk()
|
|
46
|
+
promise.resolve(null)
|
|
39
47
|
} catch (e: Exception) {
|
|
40
48
|
Log.e("PrimerRN", "configure settings error: $e")
|
|
41
|
-
val exception =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
)
|
|
45
|
-
val encoded = json.encodeToString(exception)
|
|
46
|
-
mListener.onPrimerErrorQueue?.addRequestAndPoll(encoded)
|
|
47
|
-
haltExecution = true
|
|
49
|
+
val exception = ErrorTypeRN.ParseJsonFailed errorTo "failed to parse settings."
|
|
50
|
+
checkoutFailed(exception)
|
|
51
|
+
promise.reject(exception.errorId, exception.errorDescription, e)
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
@ReactMethod
|
|
52
|
-
fun
|
|
56
|
+
fun configureWithTheme(themeStr: String, promise: Promise) {
|
|
53
57
|
try {
|
|
54
|
-
Log.d("PrimerRN", "theme: $
|
|
55
|
-
val theme = json.decodeFromString<PrimerThemeRN>(
|
|
58
|
+
Log.d("PrimerRN", "theme: $themeStr")
|
|
59
|
+
val theme = json.decodeFromString<PrimerThemeRN>(themeStr)
|
|
56
60
|
this.theme = theme
|
|
61
|
+
startSdk()
|
|
62
|
+
promise.resolve(null)
|
|
57
63
|
} catch (e: Exception) {
|
|
58
64
|
Log.e("PrimerRN", "configure theme error: $e")
|
|
59
|
-
val exception =
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
val encoded = json.encodeToString(exception)
|
|
64
|
-
mListener.onPrimerErrorQueue?.addRequestAndPoll(encoded)
|
|
65
|
-
haltExecution = true
|
|
65
|
+
val exception = ErrorTypeRN.ParseJsonFailed errorTo "failed to parse theme."
|
|
66
|
+
checkoutFailed(exception)
|
|
67
|
+
promise.reject(exception.errorId, exception.errorDescription, e)
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
@ReactMethod
|
|
70
|
-
fun
|
|
72
|
+
fun showUniversalCheckout(promise: Promise) {
|
|
73
|
+
val exception = ErrorTypeRN.CheckoutFlowFailed errorTo
|
|
74
|
+
"This method is deprecated. Use the new showUniversalCheckoutWithClientToken method"
|
|
75
|
+
checkoutFailed(exception)
|
|
76
|
+
promise.reject(exception.errorId, exception.errorDescription)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@ReactMethod
|
|
80
|
+
fun showUniversalCheckoutWithClientToken(
|
|
81
|
+
clientToken: String,
|
|
82
|
+
promise: Promise
|
|
83
|
+
) {
|
|
71
84
|
try {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.intent = intent
|
|
85
|
+
Primer.instance.showUniversalCheckout(reactApplicationContext.applicationContext, clientToken)
|
|
86
|
+
promise.resolve(null)
|
|
75
87
|
} catch (e: Exception) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
)
|
|
81
|
-
val encoded = json.encodeToString(exception)
|
|
82
|
-
mListener.onPrimerErrorQueue?.addRequestAndPoll(encoded)
|
|
83
|
-
haltExecution = true
|
|
88
|
+
val exception = ErrorTypeRN.CheckoutFlowFailed errorTo
|
|
89
|
+
"Primer SDK failed: ${e.message}"
|
|
90
|
+
checkoutFailed(exception)
|
|
91
|
+
promise.reject(exception.errorId, exception.errorDescription, e)
|
|
84
92
|
}
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
@ReactMethod
|
|
88
|
-
fun
|
|
89
|
-
|
|
96
|
+
fun showVaultManager(promise: Promise) {
|
|
97
|
+
val exception = ErrorTypeRN.CheckoutFlowFailed errorTo
|
|
98
|
+
"This method is deprecated. Use the new showUniversalCheckoutWithClientToken method"
|
|
99
|
+
checkoutFailed(exception)
|
|
100
|
+
promise.reject(exception.errorId, exception.errorDescription)
|
|
90
101
|
}
|
|
91
102
|
|
|
92
103
|
@ReactMethod
|
|
93
|
-
fun
|
|
94
|
-
|
|
104
|
+
fun showVaultManager(clientToken: String, promise: Promise) {
|
|
105
|
+
try {
|
|
106
|
+
Primer.instance.showVaultManager(reactApplicationContext.applicationContext, clientToken)
|
|
107
|
+
promise.resolve(null)
|
|
108
|
+
} catch (e: Exception) {
|
|
109
|
+
val exception = ErrorTypeRN.CheckoutFlowFailed errorTo
|
|
110
|
+
"Primer SDK failed: ${e.message}"
|
|
111
|
+
checkoutFailed(exception)
|
|
112
|
+
promise.reject(exception.errorId, exception.errorDescription, e)
|
|
113
|
+
}
|
|
95
114
|
}
|
|
96
115
|
|
|
97
116
|
@ReactMethod
|
|
98
|
-
fun
|
|
99
|
-
|
|
117
|
+
fun showPaymentMethod(
|
|
118
|
+
clientToken: String,
|
|
119
|
+
paymentMethodTypeStr: String,
|
|
120
|
+
intentStr: String,
|
|
121
|
+
promise: Promise
|
|
122
|
+
) {
|
|
123
|
+
try {
|
|
124
|
+
this.intent = PaymentMethodIntent.valueOf(intentStr)
|
|
125
|
+
} catch (e: Exception) {
|
|
126
|
+
val exception = ErrorTypeRN.ParseJsonFailed errorTo "failed to parse intent."
|
|
127
|
+
checkoutFailed(exception)
|
|
128
|
+
promise.reject(exception.errorId, exception.errorDescription, e)
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
val paymentMethod = PrimerPaymentMethod.valueOf(paymentMethodTypeStr)
|
|
133
|
+
this.paymentMethod = paymentMethod
|
|
134
|
+
} catch (e: Exception) {
|
|
135
|
+
val exception = ErrorTypeRN.CheckoutFlowFailed errorTo "failed to parse payment method type."
|
|
136
|
+
checkoutFailed(exception)
|
|
137
|
+
promise.reject(exception.errorId, exception.errorDescription, e)
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
val paymentMethod = this.paymentMethod ?: return
|
|
143
|
+
val intent = this.intent ?: return
|
|
144
|
+
Primer.instance.showPaymentMethod(
|
|
145
|
+
reactApplicationContext.applicationContext,
|
|
146
|
+
clientToken,
|
|
147
|
+
paymentMethod,
|
|
148
|
+
intent
|
|
149
|
+
)
|
|
150
|
+
promise.resolve(null)
|
|
151
|
+
} catch (e: Exception) {
|
|
152
|
+
val exception = ErrorTypeRN.CheckoutFlowFailed errorTo
|
|
153
|
+
"Primer SDK failed: ${e.message}"
|
|
154
|
+
checkoutFailed(exception)
|
|
155
|
+
promise.reject(exception.errorId, exception.errorDescription, e)
|
|
156
|
+
}
|
|
100
157
|
}
|
|
101
158
|
|
|
102
159
|
@ReactMethod
|
|
103
|
-
fun
|
|
104
|
-
mListener.
|
|
160
|
+
fun handleNewClientToken(clientToken: String, promise: Promise) {
|
|
161
|
+
mListener.onClientTokenCallback(clientToken, null)
|
|
162
|
+
mListener.onClientSessionActions(clientToken, null)
|
|
163
|
+
mListener.onTokenizeSuccess(clientToken, null)
|
|
164
|
+
mListener.onResumeSuccess(clientToken, null)
|
|
165
|
+
removeCallbacksAndHandlers()
|
|
166
|
+
promise.resolve(null)
|
|
105
167
|
}
|
|
106
168
|
|
|
107
169
|
@ReactMethod
|
|
108
|
-
fun
|
|
109
|
-
|
|
170
|
+
fun handleError(errorStr: String, promise: Promise) {
|
|
171
|
+
try {
|
|
172
|
+
val err = json.decodeFromString<PrimerErrorRN>(errorStr)
|
|
173
|
+
mListener.onClientTokenCallback(null, err)
|
|
174
|
+
mListener.onClientSessionActions(null, err)
|
|
175
|
+
mListener.onTokenizeSuccess(null, err)
|
|
176
|
+
mListener.onResumeSuccess(null, err)
|
|
177
|
+
removeCallbacksAndHandlers()
|
|
178
|
+
promise.resolve(null)
|
|
179
|
+
} catch (e: Exception) {
|
|
180
|
+
val exception = PrimerErrorRN(
|
|
181
|
+
ErrorTypeRN.CheckoutFlowFailed.name,
|
|
182
|
+
"Primer SDK failed: ${e.message}"
|
|
183
|
+
)
|
|
184
|
+
checkoutFailed(exception)
|
|
185
|
+
promise.reject(exception.errorId, exception.errorDescription, e)
|
|
186
|
+
}
|
|
110
187
|
}
|
|
111
188
|
|
|
112
189
|
@ReactMethod
|
|
113
|
-
fun
|
|
114
|
-
|
|
190
|
+
fun handleSuccess(promise: Promise) {
|
|
191
|
+
try {
|
|
192
|
+
mListener.onClientTokenCallback(null, null)
|
|
193
|
+
mListener.onClientSessionActions(null, null)
|
|
194
|
+
mListener.onTokenizeSuccess(null, null)
|
|
195
|
+
mListener.onResumeSuccess(null, null)
|
|
196
|
+
removeCallbacksAndHandlers()
|
|
197
|
+
promise.resolve(null)
|
|
198
|
+
} catch (e: Exception) {
|
|
199
|
+
val exception = ErrorTypeRN.CheckoutFlowFailed errorTo
|
|
200
|
+
"Primer SDK failed: ${e.message}"
|
|
201
|
+
checkoutFailed(exception)
|
|
202
|
+
promise.reject(exception.errorId, exception.errorDescription, e)
|
|
203
|
+
}
|
|
115
204
|
}
|
|
116
205
|
|
|
117
206
|
@ReactMethod
|
|
118
|
-
fun
|
|
119
|
-
|
|
207
|
+
fun setImplementedRNCallbacks(implementedRNCallbacksStr: String, promise: Promise) {
|
|
208
|
+
try {
|
|
209
|
+
Log.d("PrimerRN", "implementedRNCallbacks: $implementedRNCallbacksStr")
|
|
210
|
+
val implementedRNCallbacks =
|
|
211
|
+
json.decodeFromString<PrimerImplementedRNCallbacks>(implementedRNCallbacksStr)
|
|
212
|
+
this.mListener.setImplementedCallbacks(implementedRNCallbacks)
|
|
213
|
+
promise.resolve(null)
|
|
214
|
+
} catch (e: Exception) {
|
|
215
|
+
val exception = ErrorTypeRN.ParseJsonFailed errorTo "Failed to parse implemented callbacks"
|
|
216
|
+
checkoutFailed(exception)
|
|
217
|
+
promise.reject(exception.errorId, exception.errorDescription, e)
|
|
218
|
+
}
|
|
120
219
|
}
|
|
121
220
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
mListener = PrimerRNEventListener()
|
|
221
|
+
private fun removeCallbacksAndHandlers() {
|
|
222
|
+
mListener.removeCallbacksAndHandlers()
|
|
125
223
|
}
|
|
126
224
|
|
|
127
|
-
private fun startSdk(
|
|
225
|
+
private fun startSdk() {
|
|
128
226
|
val theme = theme.format()
|
|
129
227
|
val settings = settings.format()
|
|
130
228
|
val config = PrimerConfig(theme, settings)
|
|
131
229
|
|
|
132
|
-
// todo: refactor with next version
|
|
133
|
-
mListener.completion = { error, clientToken ->
|
|
134
|
-
currentActivity?.let {
|
|
135
|
-
it.runOnUiThread {
|
|
136
|
-
if (error != null) {
|
|
137
|
-
mListener.resumeHandler?.handleError(Error(error))
|
|
138
|
-
} else {
|
|
139
|
-
if (clientToken == null) {
|
|
140
|
-
mListener.resumeHandler?.handleSuccess()
|
|
141
|
-
} else {
|
|
142
|
-
mListener.resumeHandler?.handleNewClientToken(clientToken)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
mListener.actionCompletion = { error, clientToken ->
|
|
150
|
-
currentActivity?.let {
|
|
151
|
-
it.runOnUiThread {
|
|
152
|
-
if (error != null) {
|
|
153
|
-
mListener.actionResumeHandler?.handleError(Error(error))
|
|
154
|
-
} else {
|
|
155
|
-
mListener.actionResumeHandler?.handleClientToken(clientToken)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
230
|
Primer.instance.configure(config, mListener)
|
|
162
231
|
sdkWasInitialised = true
|
|
163
232
|
}
|
|
164
233
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
Log.d("PrimerRN", "init with client token: $token")
|
|
174
|
-
|
|
175
|
-
startSdk(token)
|
|
176
|
-
|
|
177
|
-
val context = currentActivity as Context
|
|
234
|
+
private fun checkoutFailed(exception: PrimerErrorRN) {
|
|
235
|
+
val params = Arguments.createMap()
|
|
236
|
+
val errorJson = JSONObject(Json.encodeToString(exception))
|
|
237
|
+
val data = Arguments.createMap()
|
|
238
|
+
prepareData(data, errorJson)
|
|
239
|
+
params.putMap(Keys.ERROR, data)
|
|
240
|
+
sendEvent(PrimerEventsRN.OnError.string, params)
|
|
241
|
+
}
|
|
178
242
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
} catch (e: Exception) {
|
|
184
|
-
Log.e("PrimerRN", "init error: $e")
|
|
185
|
-
val exception = PrimerErrorRN(
|
|
186
|
-
ErrorTypeRN.InitFailed,
|
|
187
|
-
"failed to initialise Primer SDK, error: $e",
|
|
188
|
-
)
|
|
189
|
-
val encoded = json.encodeToString(exception)
|
|
190
|
-
mListener.onPrimerErrorQueue?.addRequestAndPoll(encoded)
|
|
191
|
-
}
|
|
243
|
+
private fun sendEvent(name: String, params: WritableMap) {
|
|
244
|
+
reactApplicationContext.getJSModule(
|
|
245
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter::class.java
|
|
246
|
+
).emit(name, params)
|
|
192
247
|
}
|
|
193
248
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
} catch (e: Exception) {
|
|
201
|
-
Log.e("PrimerRN", "configure settings error: $e")
|
|
202
|
-
val exception = PrimerErrorRN(
|
|
203
|
-
ErrorTypeRN.ParseJsonFailed,
|
|
204
|
-
"failed to parse settings.",
|
|
205
|
-
)
|
|
206
|
-
val encoded = json.encodeToString(exception)
|
|
207
|
-
mListener.onPrimerErrorQueue?.addRequestAndPoll(encoded)
|
|
208
|
-
haltExecution = true
|
|
209
|
-
}
|
|
249
|
+
private fun sendEvent(name: String, data: JSONObject?) {
|
|
250
|
+
val params = Arguments.createMap()
|
|
251
|
+
prepareData(params, data)
|
|
252
|
+
reactApplicationContext.getJSModule(
|
|
253
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter::class.java
|
|
254
|
+
).emit(name, params)
|
|
210
255
|
}
|
|
211
256
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
it.runOnUiThread {
|
|
222
|
-
if (error != null) {
|
|
223
|
-
mListener.actionResumeHandler?.handleError(Error(error))
|
|
224
|
-
} else {
|
|
225
|
-
mListener.actionResumeHandler?.handleClientToken(clientToken)
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
257
|
+
private fun prepareData(params: WritableMap, data: JSONObject?) {
|
|
258
|
+
data?.keys()?.forEach { key ->
|
|
259
|
+
when (val dataValue = data.opt(key)) {
|
|
260
|
+
is String -> params.putString(key, dataValue)
|
|
261
|
+
is Boolean -> params.putBoolean(key, dataValue)
|
|
262
|
+
is Double -> params.putDouble(key, dataValue)
|
|
263
|
+
is Int -> params.putInt(key, dataValue)
|
|
264
|
+
is JSONObject -> prepareData(params, dataValue)
|
|
265
|
+
else -> params.putNull(key)
|
|
229
266
|
}
|
|
230
|
-
|
|
231
|
-
} catch (e: Exception) {
|
|
232
|
-
Log.e("PrimerRN", "configure settings error: $e")
|
|
233
267
|
}
|
|
234
268
|
}
|
|
235
269
|
}
|
|
270
|
+
|
|
271
|
+
internal object Keys {
|
|
272
|
+
const val ERROR = "error"
|
|
273
|
+
const val RESUME_TOKEN = "resumeToken"
|
|
274
|
+
}
|