@appboxo/react-native-sdk 1.0.37 → 1.0.38

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.
@@ -1,22 +1,26 @@
1
1
  def DEFAULT_COMPILE_SDK_VERSION = 33
2
2
  def DEFAULT_MIN_SDK_VERSION = 21
3
3
  def DEFAULT_TARGET_SDK_VERSION = 33
4
-
5
4
  def safeExtGet(prop, fallback) {
6
5
  rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
7
6
  }
8
7
 
9
8
  buildscript {
9
+ ext{
10
+ kotlin_version = '1.8.10'
11
+ }
10
12
  repositories {
11
13
  google()
12
14
  jcenter()
13
15
  }
14
16
  dependencies {
15
17
  classpath "com.android.tools.build:gradle:7.4.2"
18
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
16
19
  }
17
20
  }
18
21
 
19
22
  apply plugin: 'com.android.library'
23
+ apply plugin: 'kotlin-android'
20
24
 
21
25
  android {
22
26
  compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
@@ -125,6 +129,7 @@ rootProject.allprojects {
125
129
  }
126
130
 
127
131
  dependencies {
132
+ implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
128
133
  //noinspection GradleDynamicVersion
129
134
  implementation 'com.facebook.react:react-native:+' // From node_modules
130
135
  implementation 'com.appboxo:sdk:1.4.19'
@@ -0,0 +1,331 @@
1
+ /*
2
+ Copyright 2020 Appboxo pte. ltd.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+ package com.appboxo
17
+
18
+ import android.app.Application
19
+ import android.os.Handler
20
+ import android.os.Looper
21
+ import com.appboxo.data.models.MiniappData
22
+ import com.appboxo.js.params.CustomEvent
23
+ import com.appboxo.js.params.PaymentData
24
+ import com.appboxo.sdk.Appboxo
25
+ import com.appboxo.sdk.Config
26
+ import com.appboxo.sdk.Miniapp
27
+ import com.appboxo.sdk.MiniappConfig
28
+ import com.appboxo.sdk.MiniappListCallback
29
+ import com.appboxo.ui.main.AppboxoActivity
30
+ import com.appboxo.utils.MapUtil
31
+ import com.facebook.react.bridge.Arguments
32
+ import com.facebook.react.bridge.ReactApplicationContext
33
+ import com.facebook.react.bridge.ReactContextBaseJavaModule
34
+ import com.facebook.react.bridge.ReactMethod
35
+ import com.facebook.react.bridge.ReadableMap
36
+ import com.facebook.react.bridge.WritableMap
37
+ import com.facebook.react.modules.core.DeviceEventManagerModule
38
+
39
+ class RnappboxosdkModule(reactContext: ReactApplicationContext) :
40
+ ReactContextBaseJavaModule(reactContext), Miniapp.LifecycleListener,
41
+ Miniapp.CustomEventListener, Miniapp.AuthListener,
42
+ Miniapp.PaymentEventListener {
43
+ private val reactContext: ReactApplicationContext
44
+ private val handler: Handler
45
+
46
+ init {
47
+ this.reactContext = reactContext
48
+ Appboxo.init(reactContext.getBaseContext() as Application)
49
+ handler = Handler(Looper.getMainLooper())
50
+ }
51
+
52
+ override fun getName(): String = "Rnappboxosdk"
53
+
54
+ @ReactMethod
55
+ fun setConfig(
56
+ clientId: String,
57
+ sandboxMode: Boolean,
58
+ enableMultitaskMode: Boolean,
59
+ theme: String?,
60
+ isDebug: Boolean,
61
+ showPermissionsPage: Boolean,
62
+ showClearCache: Boolean
63
+ ) {
64
+ val globalTheme: Config.Theme = when (theme) {
65
+ "light" -> Config.Theme.LIGHT
66
+ "dark" -> Config.Theme.DARK
67
+ else -> Config.Theme.SYSTEM
68
+ }
69
+ Appboxo
70
+ .setConfig(
71
+ Config.Builder()
72
+ .setClientId(clientId)
73
+ .sandboxMode(sandboxMode)
74
+ .multitaskMode(enableMultitaskMode)
75
+ .setTheme(globalTheme)
76
+ .permissionsPage(showPermissionsPage)
77
+ .showClearCache(showClearCache)
78
+ .debug(isDebug)
79
+ .build()
80
+ )
81
+ }
82
+
83
+ @ReactMethod
84
+ fun openMiniapp(
85
+ appId: String,
86
+ data: ReadableMap?,
87
+ theme: String?,
88
+ extraUrlParams: ReadableMap?,
89
+ urlSuffix: String?,
90
+ colors: ReadableMap?
91
+ ) {
92
+ val miniapp: Miniapp = Appboxo.getMiniapp(appId)
93
+ .setCustomEventListener(this)
94
+ .setPaymentEventListener(this)
95
+ .setAuthListener(this)
96
+ .setLifecycleListener(this)
97
+ if (data != null) miniapp.setData(MapUtil.toMap(data))
98
+ val configBuilder = MiniappConfig.Builder()
99
+ if (theme != null) {
100
+ val miniappTheme: Config.Theme? = when (theme) {
101
+ "light" -> Config.Theme.LIGHT
102
+ "dark" -> Config.Theme.DARK
103
+ "system" -> Config.Theme.SYSTEM
104
+ else -> null
105
+ }
106
+ if (miniappTheme != null) {
107
+ configBuilder.setTheme(miniappTheme)
108
+ }
109
+ }
110
+ if (extraUrlParams != null) {
111
+ val map: Map<String, Any> = MapUtil.toMap(extraUrlParams)
112
+ val stringMap: MutableMap<String, String> = HashMap()
113
+ for ((key, value) in map) stringMap[key] = value.toString()
114
+ configBuilder.setExtraUrlParams(stringMap)
115
+ }
116
+ urlSuffix?.also { suffix -> configBuilder.setUrlSuffix(suffix) }
117
+ if (colors != null) {
118
+ configBuilder.setColors(
119
+ colors.getString("primaryColor") ?: "",
120
+ colors.getString("secondaryColor") ?: "",
121
+ colors.getString("tertiaryColor") ?: "",
122
+ )
123
+ }
124
+ miniapp.setConfig(configBuilder.build())
125
+ miniapp.open(reactContext)
126
+ }
127
+
128
+ @ReactMethod
129
+ fun setAuthCode(appId: String, authCode: String) {
130
+ Appboxo.getMiniapp(appId)
131
+ .setAuthCode(authCode)
132
+ }
133
+
134
+ @ReactMethod
135
+ fun closeMiniapp(appId: String) {
136
+ handler.post { Appboxo.getExistingMiniapp(appId)?.close() }
137
+ }
138
+
139
+ override fun handle(
140
+ miniAppActivity: AppboxoActivity,
141
+ miniapp: Miniapp,
142
+ customEvent: CustomEvent
143
+ ) {
144
+ val params: WritableMap = Arguments.createMap()
145
+ params.putString("app_id", miniapp.appId)
146
+ val event: WritableMap = Arguments.createMap()
147
+ try {
148
+ event.putInt("request_id", customEvent.requestId ?: 0)
149
+ event.putString("type", customEvent.type)
150
+ event.putString("error_type", customEvent.errorType)
151
+ event.putMap(
152
+ "payload",
153
+ MapUtil.toWritableMap(customEvent.payload)
154
+ )
155
+ params.putMap("custom_event", event)
156
+ sendEvent(CUSTOM_EVENTS_EVENT_NAME, params)
157
+ } catch (e: Exception) {
158
+ e.printStackTrace()
159
+ }
160
+ }
161
+
162
+ override fun onLaunch(miniapp: Miniapp) {
163
+ val params: WritableMap = Arguments.createMap()
164
+ params.putString("app_id", miniapp.appId)
165
+ params.putString("lifecycle", "onLaunch")
166
+ sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params)
167
+ }
168
+
169
+ override fun onResume(miniapp: Miniapp) {
170
+ val params: WritableMap = Arguments.createMap()
171
+ params.putString("app_id", miniapp.appId)
172
+ params.putString("lifecycle", "onResume")
173
+ sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params)
174
+ }
175
+
176
+ override fun onPause(miniapp: Miniapp) {
177
+ val params: WritableMap = Arguments.createMap()
178
+ params.putString("app_id", miniapp.appId)
179
+ params.putString("lifecycle", "onPause")
180
+ sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params)
181
+ }
182
+
183
+ override fun onClose(miniapp: Miniapp) {
184
+ val params: WritableMap = Arguments.createMap()
185
+ params.putString("app_id", miniapp.appId)
186
+ params.putString("lifecycle", "onClose")
187
+ sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params)
188
+ }
189
+
190
+ override fun onError(miniapp: Miniapp, message: String) {
191
+ val params: WritableMap = Arguments.createMap()
192
+ params.putString("app_id", miniapp.appId)
193
+ params.putString("lifecycle", "onError")
194
+ params.putString("error", message)
195
+ sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params)
196
+ }
197
+
198
+ override fun onUserInteraction(miniapp: Miniapp) {
199
+ val params: WritableMap = Arguments.createMap()
200
+ params.putString("app_id", miniapp.appId)
201
+ params.putString("lifecycle", "onUserInteraction")
202
+ sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params)
203
+ }
204
+
205
+ override fun onAuth(appboxoActivity: AppboxoActivity, miniapp: Miniapp) {
206
+ val params: WritableMap = Arguments.createMap()
207
+ params.putString("app_id", miniapp.appId)
208
+ params.putString("lifecycle", "onAuth")
209
+ sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params)
210
+ }
211
+
212
+ @ReactMethod
213
+ fun sendCustomEvent(map: ReadableMap) {
214
+ try {
215
+ val appId: String = map.getString("app_id")!!
216
+ val customEventMap: ReadableMap = map.getMap("custom_event")!!
217
+ val event = CustomEvent(
218
+ customEventMap.getInt("request_id"),
219
+ customEventMap.getString("type")!!,
220
+ if (customEventMap.hasKey("error_type")) customEventMap.getString("error_type") else null,
221
+ MapUtil.toMap(customEventMap.getMap("payload"))
222
+ )
223
+ handler.post { Appboxo.getExistingMiniapp(appId)?.sendEvent(event) }
224
+ } catch (e: Exception) {
225
+ e.printStackTrace()
226
+ }
227
+ }
228
+
229
+ @ReactMethod
230
+ fun sendPaymentEvent(map: ReadableMap) {
231
+ try {
232
+ val appId: String = map.getString("app_id")!!
233
+ val paymentEvent: ReadableMap = map.getMap("payment_event")!!
234
+ val data = PaymentData(
235
+ paymentEvent.getString("transaction_token") ?: "",
236
+ paymentEvent.getString("miniapp_order_id") ?: "",
237
+ paymentEvent.getDouble("amount"),
238
+ paymentEvent.getString("currency") ?: "",
239
+ paymentEvent.getString("status") ?: "",
240
+ paymentEvent.getString("hostapp_order_id") ?: "",
241
+ MapUtil.toMap(paymentEvent.getMap("extra_params"))
242
+ )
243
+ handler.post { Appboxo.getExistingMiniapp(appId)?.sendPaymentResult(data) }
244
+ } catch (e: Exception) {
245
+ e.printStackTrace()
246
+ }
247
+ }
248
+
249
+ @ReactMethod
250
+ fun getMiniapps() {
251
+ Appboxo.getMiniapps(object : MiniappListCallback {
252
+ override fun onSuccess(miniapps: List<MiniappData>) {
253
+ try {
254
+ val array: Array<Map<*, *>?> = arrayOfNulls(miniapps.size)
255
+ for (i in miniapps.indices) {
256
+ val miniappData: MiniappData = miniapps[i]
257
+ val data: MutableMap<String, Any> = HashMap()
258
+ data["app_id"] = miniappData.appId
259
+ data["name"] = miniappData.name
260
+ data["category"] = miniappData.category
261
+ data["logo"] = miniappData.logo
262
+ data["description"] = miniappData.description
263
+ array[i] = data
264
+ }
265
+ val params: MutableMap<String, Any> = HashMap()
266
+ params["miniapps"] = array
267
+ sendEvent(
268
+ MINIAPP_LIST_EVENT_NAME,
269
+ MapUtil.toWritableMap(params as Map<String, Any>)
270
+ )
271
+ } catch (e: Exception) {
272
+ e.printStackTrace()
273
+ }
274
+ }
275
+
276
+ override fun onFailure(e: Exception) {
277
+ val result: WritableMap = Arguments.createMap()
278
+ result.putString("error", e.message)
279
+ sendEvent(MINIAPP_LIST_EVENT_NAME, result)
280
+ }
281
+ })
282
+ }
283
+
284
+ @ReactMethod
285
+ fun hideMiniapps() {
286
+ Appboxo.hideMiniapps()
287
+ }
288
+
289
+ @ReactMethod
290
+ fun logout() {
291
+ Appboxo.logout()
292
+ }
293
+
294
+ private fun sendEvent(name: String, params: WritableMap) {
295
+ reactContext
296
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
297
+ .emit(name, params)
298
+ }
299
+
300
+ override fun handle(
301
+ miniAppActivity: AppboxoActivity,
302
+ miniapp: Miniapp,
303
+ paymentData: PaymentData
304
+ ) {
305
+ val params: WritableMap = Arguments.createMap()
306
+ params.putString("app_id", miniapp.appId)
307
+ val event: WritableMap = Arguments.createMap()
308
+ try {
309
+ event.putString("transaction_token", paymentData.transactionToken)
310
+ event.putString("miniapp_order_id", paymentData.miniappOrderId)
311
+ event.putDouble("amount", paymentData.amount)
312
+ event.putString("currency", paymentData.currency)
313
+ event.putString("status", paymentData.status)
314
+ event.putString("hostapp_order_id", paymentData.hostappOrderId)
315
+ if (paymentData.extraParams != null) {
316
+ event.putMap("extra_params", MapUtil.toWritableMap(paymentData.extraParams))
317
+ }
318
+ params.putMap("payment_event", event)
319
+ sendEvent(PAYMENT_EVENTS_EVENT_NAME, params)
320
+ } catch (e: Exception) {
321
+ e.printStackTrace()
322
+ }
323
+ }
324
+
325
+ companion object {
326
+ private const val CUSTOM_EVENTS_EVENT_NAME = "appboxo_custom_events"
327
+ private const val PAYMENT_EVENTS_EVENT_NAME = "appboxo_payment_events"
328
+ private const val MINIAPP_LIST_EVENT_NAME = "appboxo_miniapp_list"
329
+ private const val MINIAPP_LIFECYCLE_EVENT_NAME = "appboxo_miniapp_lifecycle"
330
+ }
331
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+ Copyright 2020 Appboxo pte. ltd.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+ package com.appboxo
17
+
18
+ import android.view.View
19
+ import com.facebook.react.ReactPackage
20
+ import com.facebook.react.bridge.NativeModule
21
+ import com.facebook.react.bridge.ReactApplicationContext
22
+ import com.facebook.react.uimanager.ReactShadowNode
23
+ import com.facebook.react.uimanager.ViewManager
24
+
25
+ class RnappboxosdkPackage : ReactPackage {
26
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
27
+ return listOf(RnappboxosdkModule(reactContext))
28
+ }
29
+
30
+ override fun createViewManagers(reactContext: ReactApplicationContext): MutableList<ViewManager<out View, out ReactShadowNode<*>>> {
31
+ return mutableListOf()
32
+ }
33
+ }
package/index.d.ts CHANGED
@@ -21,16 +21,27 @@ declare module '@appboxo/react-native-sdk' {
21
21
  /**
22
22
  * Set Appboxo clientId
23
23
  * @param {string} clientId Appboxo clientId
24
- * @param {boolean} sandboxMode (by default false)
25
- * @param {boolean} enableMultitaskMode Enable multiscreen mode (by default true)
26
- * @param {'dark' | 'light'} theme Miniapp theme (by default 'system')
24
+ * @param {object} options - Appboxo global config
25
+ * sandboxMode (by default false)
26
+ * enableMultitaskMode Enable multiscreen mode (by default true)
27
+ * theme {'dark' | 'light'} theme Miniapp theme (by default 'system')
27
28
  * */
28
- export function setConfig(clientId: string, sandboxMode?: boolean, enableMultitaskMode?: boolean, theme?: 'dark' | 'light'): void
29
+ export function setConfig(
30
+ clientId: string,
31
+ options?: {
32
+ sandboxMode?: boolean,
33
+ enableMultitaskMode?: boolean,
34
+ theme?: 'dark' | 'light',
35
+ isDebug?: boolean,
36
+ showPermissionsPage? : boolean,
37
+ showClearCache?: boolean
38
+ }
39
+ ): void
29
40
 
30
41
  /**
31
42
  * Launch miniapp by id with payload and custom data
32
43
  * @param {string} miniAppId Appboxo miniAppId
33
- * @param {{ data?: object, theme?: 'dark' | 'light' | 'system', extraUrlParams?: object }} options Appboxo options: data for send to miniapp,
44
+ * @param {object} options Appboxo options: data for send to miniapp,
34
45
  * theme Miniapp theme (by default is value of "theme" argument in setConfig function)
35
46
  * */
36
47
 
@@ -39,10 +50,14 @@ declare module '@appboxo/react-native-sdk' {
39
50
  options?: {
40
51
  data?: object,
41
52
  theme?: 'dark' | 'light' | 'system',
42
- extraUrlParams?: { [key: string]: string }
53
+ extraUrlParams?: { [key: string]: string },
54
+ urlSuffix?: string
55
+ colors?: { primaryColor: string, secondaryColor: string, tertiaryColor: string }
43
56
  },
44
57
  ): void
45
58
 
59
+ export function closeMiniapp(appId: string): void
60
+
46
61
  /**
47
62
  * Appboxo custom events system for handle events from miniapp and send to miniapp.
48
63
  * */
@@ -69,7 +84,7 @@ declare module '@appboxo/react-native-sdk' {
69
84
  /**
70
85
  * Hide all miniapps
71
86
  * */
72
- export function hideAllMiniapps(): void
87
+ export function hideMiniapps(): void
73
88
 
74
89
  /**
75
90
  * On logout from your app, call this method to clear all miniapps data.
package/index.js CHANGED
@@ -20,11 +20,12 @@ import lifecycleHooksListener from './js/lifecycleHooks'
20
20
  import customEvents from './js/customEvents'
21
21
  import miniapps from './js/miniapps'
22
22
  import mOpenMiniapp from './js/mOpenMiniapp'
23
+ import mCloseMiniapp from './js/mCloseMiniapp'
23
24
  import mGetMiniapps from './js/mGetMiniapps'
24
25
  import mSetConfig from './js/mSetConfig'
25
26
  import mSetAuthCode from './js/mSetAuthCode'
26
27
  import paymentEvents from './js/paymentEvents'
27
28
 
28
- const { Rnappboxosdk: { sendCustomEvent, sendPaymentEvent, openMiniapp, setConfig, getMiniapps, ...methods } } = NativeModules
29
+ const { Rnappboxosdk: { sendCustomEvent, sendPaymentEvent, openMiniapp, closeMiniapp, setConfig, getMiniapps, ...methods } } = NativeModules
29
30
 
30
- export default { ...methods, lifecycleHooksListener, openMiniapp: mOpenMiniapp, setConfig: mSetConfig, getMiniapps:mGetMiniapps, customEvents, paymentEvents, miniapps}
31
+ export default { ...methods, lifecycleHooksListener, openMiniapp: mOpenMiniapp, closeMiniapp: mCloseMiniapp, setConfig: mSetConfig, getMiniapps:mGetMiniapps, customEvents, paymentEvents, miniapps}
@@ -32,7 +32,7 @@ limitations under the License.
32
32
  RCT_EXPORT_MODULE()
33
33
 
34
34
 
35
- RCT_EXPORT_METHOD(setConfig:(NSString *)clientId sandboxMode:(BOOL)sandboxMode multitaskMode:(BOOL)multitaskMode theme:(NSString *)theme)
35
+ RCT_EXPORT_METHOD(setConfig:(NSString *)clientId sandboxMode:(BOOL)sandboxMode multitaskMode:(BOOL)multitaskMode theme:(NSString *)theme isDebug:(BOOL)isDebug showPermissionsPage:(BOOL)showPermissionsPage showClearCache:(BOOL)showClearCache)
36
36
  {
37
37
  NSArray *themes = @[@"dark", @"light", @"system"];
38
38
 
@@ -44,11 +44,13 @@ RCT_EXPORT_METHOD(setConfig:(NSString *)clientId sandboxMode:(BOOL)sandboxMode m
44
44
 
45
45
  Config *config = [[Config alloc] initWithClientId: clientId theme: globalTheme];
46
46
  config.sandboxMode = sandboxMode;
47
+ config.permissionsPage = showPermissionsPage;
48
+ config.showClearCache = showClearCache;
47
49
 
48
50
  [[Appboxo shared] setConfig: config];
49
51
  }
50
52
 
51
- RCT_EXPORT_METHOD(openMiniapp:(NSString *)appId data:(nullable NSDictionary<NSString *,id> *)data theme:(nullable NSString *)theme customUrlParams:(nullable NSDictionary<NSString *,id> *)customUrlParams)
53
+ RCT_EXPORT_METHOD(openMiniapp:(NSString *)appId data:(nullable NSDictionary<NSString *,id> *)data theme:(nullable NSString *)theme extraUrlParams:(nullable NSDictionary<NSString *,id> *)extraUrlParams urlSuffix:(nullable NSString *)urlSuffix colors:(nullable NSDictionary<NSString *,id> *)colors)
52
54
  {
53
55
  dispatch_async(dispatch_get_main_queue(), ^{
54
56
  Miniapp *miniapp = [[Appboxo shared] getMiniappWithAppId: appId];
@@ -56,7 +58,7 @@ RCT_EXPORT_METHOD(openMiniapp:(NSString *)appId data:(nullable NSDictionary<NSSt
56
58
  [miniapp setDelegate:self];
57
59
 
58
60
  MiniappConfig *miniappConfig = [[MiniappConfig alloc] initWithTheme: ThemeSystem];
59
- [miniappConfig setExtraParams:customUrlParams];
61
+ [miniappConfig setExtraParams:extraUrlParams];
60
62
 
61
63
  if (theme != NULL) {
62
64
  NSArray *themes = @[@"dark", @"light", @"system"];
@@ -64,12 +66,29 @@ RCT_EXPORT_METHOD(openMiniapp:(NSString *)appId data:(nullable NSDictionary<NSSt
64
66
  [miniappConfig setTheme:(Theme) [themes indexOfObject:theme]];
65
67
  }
66
68
  }
69
+
70
+ if (colors != NULL) {
71
+ NSString *primaryColor = colors[@"primaryColor"] != NULL ? (NSString *) colors[@"primaryColor"] : @"";
72
+ NSString *secondaryColor = colors[@"secondaryColor"] != NULL ? (NSString *) colors[@"secondaryColor"] : @"";
73
+ NSString *tertiaryColor = colors[@"tertiaryColor"] != NULL ? (NSString *) colors[@"tertiaryColor"] : @"";
74
+
75
+ MiniappColor *color = [[MiniappColor alloc] initWithPrimary: primaryColor secondary: secondaryColor tertiary: tertiaryColor];
76
+ [miniappConfig setColor: color];
77
+ }
67
78
 
68
- [miniapp setConfig:miniappConfig];
79
+ [miniapp setConfig: miniappConfig];
69
80
  [miniapp openWithViewController: [UIApplication sharedApplication].delegate.window.rootViewController];
70
81
  });
71
82
  }
72
83
 
84
+ RCT_EXPORT_METHOD(closeMiniapp:(NSString *)appId)
85
+ {
86
+ dispatch_async(dispatch_get_main_queue(), ^{
87
+ Miniapp *miniapp = [[Appboxo shared] getMiniappWithAppId: appId];
88
+ [miniapp close];
89
+ });
90
+ }
91
+
73
92
  RCT_EXPORT_METHOD(setAuthCode:(NSString *)appId code:(NSString *)code)
74
93
  {
75
94
  dispatch_async(dispatch_get_main_queue(), ^{
@@ -78,7 +97,7 @@ RCT_EXPORT_METHOD(setAuthCode:(NSString *)appId code:(NSString *)code)
78
97
  });
79
98
  }
80
99
 
81
- RCT_EXPORT_METHOD(hideAllMiniApps)
100
+ RCT_EXPORT_METHOD(hideMiniapps)
82
101
  {
83
102
  dispatch_async(dispatch_get_main_queue(), ^{
84
103
  [[Appboxo shared] hideMiniapps];
@@ -0,0 +1,10 @@
1
+ import { NativeModules } from 'react-native'
2
+
3
+ /**
4
+ * Close miniapp by id
5
+ * */
6
+ const mCloseMiniapp = (appId) => {
7
+ NativeModules.Rnappboxosdk.closeMiniapp(appId)
8
+ }
9
+
10
+ export default mCloseMiniapp
@@ -9,6 +9,8 @@ const mOpenMiniapp = (miniAppId, options) => {
9
9
  options?.data,
10
10
  options?.theme === 'dark' || options?.theme === 'light' || options?.theme === 'system' ? options.theme : null,
11
11
  options?.extraUrlParams,
12
+ options?.urlSuffix,
13
+ options?.colors
12
14
  )
13
15
  }
14
16
 
package/js/mSetConfig.js CHANGED
@@ -3,8 +3,16 @@ import { NativeModules } from 'react-native'
3
3
  /**
4
4
  * Miniapp theme (by default 'system')
5
5
  * */
6
- const mSetConfig = (clientId, sandboxMode = false, enableMultitaskMode = true, theme = 'system') => {
7
- NativeModules.Rnappboxosdk.setConfig(clientId, sandboxMode, enableMultitaskMode, theme === 'dark' || theme === 'light' ? theme : 'system')
6
+ const mSetConfig = (clientId, options) => {
7
+ NativeModules.Rnappboxosdk.setConfig(
8
+ clientId,
9
+ options?.sandboxMode ?? false,
10
+ options?.enableMultitaskMode ?? false,
11
+ options?.theme === 'dark' || options?.theme === 'light' ? options?.theme : 'system',
12
+ options?.isDebug ?? false,
13
+ options?.showPermissionsPage ?? true,
14
+ options?.showClearCache ?? true
15
+ )
8
16
  }
9
17
 
10
18
  export default mSetConfig
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@appboxo/react-native-sdk",
3
3
  "title": "Appboxo react native sdk",
4
- "version": "1.0.37",
4
+ "version": "1.0.38",
5
5
  "description": "Appboxo react native sdk",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -1,342 +0,0 @@
1
- /*
2
- Copyright 2020 Appboxo pte. ltd.
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- package com.appboxo;
18
-
19
- import android.app.Application;
20
- import android.os.Handler;
21
- import android.os.Looper;
22
- import android.util.Log;
23
-
24
- import androidx.annotation.NonNull;
25
-
26
- import com.appboxo.data.models.MiniappData;
27
- import com.appboxo.js.params.CustomEvent;
28
- import com.appboxo.js.params.PaymentData;
29
- import com.appboxo.sdk.Appboxo;
30
- import com.appboxo.sdk.Config;
31
- import com.appboxo.sdk.Miniapp;
32
- import com.appboxo.sdk.MiniappConfig;
33
- import com.appboxo.sdk.MiniappListCallback;
34
- import com.appboxo.ui.main.AppboxoActivity;
35
- import com.appboxo.utils.MapUtil;
36
- import com.facebook.react.bridge.Arguments;
37
- import com.facebook.react.bridge.ReactApplicationContext;
38
- import com.facebook.react.bridge.ReactContextBaseJavaModule;
39
- import com.facebook.react.bridge.ReactMethod;
40
- import com.facebook.react.bridge.ReadableMap;
41
- import com.facebook.react.bridge.WritableMap;
42
- import com.facebook.react.modules.core.DeviceEventManagerModule;
43
-
44
- import org.jetbrains.annotations.NotNull;
45
-
46
- import java.sql.ClientInfoStatus;
47
- import java.util.HashMap;
48
- import java.util.List;
49
- import java.util.Map;
50
-
51
- public class RnappboxosdkModule extends ReactContextBaseJavaModule
52
- implements Miniapp.LifecycleListener, Miniapp.CustomEventListener, Miniapp.AuthListener, Miniapp.PaymentEventListener {
53
- private static final String CUSTOM_EVENTS_EVENT_NAME = "appboxo_custom_events";
54
- private static final String PAYMENT_EVENTS_EVENT_NAME = "appboxo_payment_events";
55
- private static final String MINIAPP_LIST_EVENT_NAME = "appboxo_miniapp_list";
56
- private static final String MINIAPP_LIFECYCLE_EVENT_NAME = "appboxo_miniapp_lifecycle";
57
-
58
- private final ReactApplicationContext reactContext;
59
- private final Handler handler;
60
-
61
- public RnappboxosdkModule(ReactApplicationContext reactContext) {
62
- super(reactContext);
63
- this.reactContext = reactContext;
64
- Appboxo.INSTANCE.init((Application) reactContext.getBaseContext());
65
- handler = new Handler(Looper.getMainLooper());
66
- }
67
-
68
- @Override
69
- public String getName() {
70
- return "Rnappboxosdk";
71
- }
72
-
73
- @ReactMethod
74
- public void setConfig(String clientId, boolean sandboxMode, boolean enableMultitaskMode, String theme) {
75
- Config.Theme globalTheme;
76
- switch (theme) {
77
- case "light":
78
- globalTheme = Config.Theme.LIGHT;
79
- break;
80
- case "dark":
81
- globalTheme = Config.Theme.DARK;
82
- break;
83
- default:
84
- globalTheme = Config.Theme.SYSTEM;
85
- }
86
- Appboxo.INSTANCE
87
- .setConfig(new Config.Builder()
88
- .setClientId(clientId)
89
- .sandboxMode(sandboxMode)
90
- .multitaskMode(enableMultitaskMode)
91
- .setTheme(globalTheme)
92
- .build());
93
- }
94
-
95
- @ReactMethod
96
- public void openMiniapp(String appId, ReadableMap data, String theme, ReadableMap customUrlParams) {
97
- Miniapp miniapp = Appboxo.INSTANCE.getMiniapp(appId)
98
- .setCustomEventListener(this)
99
- .setPaymentEventListener(this)
100
- .setAuthListener(this)
101
- .setLifecycleListener(this);
102
-
103
- MiniappConfig.Builder configBuilder = new MiniappConfig.Builder();
104
- if (theme != null) {
105
- Config.Theme miniappTheme;
106
-
107
- switch (theme) {
108
- case "light":
109
- miniappTheme = Config.Theme.LIGHT;
110
- break;
111
- case "dark":
112
- miniappTheme = Config.Theme.DARK;
113
- break;
114
- case "system":
115
- miniappTheme = Config.Theme.SYSTEM;
116
- break;
117
- default:
118
- miniappTheme = null;
119
- }
120
-
121
- if (miniappTheme != null) {
122
- configBuilder.setTheme(miniappTheme);
123
- }
124
- }
125
-
126
- if (customUrlParams != null) {
127
- Map<String, Object> map = MapUtil.toMap(customUrlParams);
128
- Map<String, String> stringMap = new HashMap<String, String>();
129
- for (Map.Entry<String, Object> entry : map.entrySet())
130
- stringMap.put(entry.getKey(), String.valueOf(entry.getValue()));
131
- configBuilder.setExtraUrlParams(stringMap);
132
- }
133
-
134
- miniapp.setConfig(configBuilder.build());
135
-
136
- miniapp.open(reactContext);
137
- }
138
-
139
- @ReactMethod
140
- public void setAuthCode(String appId, String authCode) {
141
- Appboxo.INSTANCE.getMiniapp(appId)
142
- .setAuthCode(authCode);
143
- }
144
-
145
- @Override
146
- public void handle(@NotNull AppboxoActivity appboxoActivity, @NotNull Miniapp miniApp, @NotNull CustomEvent customEvent) {
147
- WritableMap params = Arguments.createMap();
148
- params.putString("app_id", miniApp.getAppId());
149
- WritableMap event = Arguments.createMap();
150
- try {
151
- event.putInt("request_id", customEvent.getRequestId());
152
- event.putString("type", customEvent.getType());
153
- event.putString("error_type", customEvent.getErrorType());
154
- event.putMap("payload", MapUtil.toWritableMap((Map<String, Object>) customEvent.getPayload()));
155
-
156
- params.putMap("custom_event", event);
157
- sendEvent(CUSTOM_EVENTS_EVENT_NAME, params);
158
- } catch (Exception e) {
159
- e.printStackTrace();
160
- }
161
- }
162
-
163
- @Override
164
- public void onLaunch(@NotNull Miniapp miniapp) {
165
- WritableMap params = Arguments.createMap();
166
- params.putString("app_id", miniapp.getAppId());
167
- params.putString("lifecycle", "onLaunch");
168
- sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params);
169
- }
170
-
171
- @Override
172
- public void onResume(@NotNull Miniapp miniapp) {
173
- WritableMap params = Arguments.createMap();
174
- params.putString("app_id", miniapp.getAppId());
175
- params.putString("lifecycle", "onResume");
176
- sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params);
177
- }
178
-
179
- @Override
180
- public void onPause(@NotNull Miniapp miniapp) {
181
- WritableMap params = Arguments.createMap();
182
- params.putString("app_id", miniapp.getAppId());
183
- params.putString("lifecycle", "onPause");
184
- sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params);
185
- }
186
-
187
- @Override
188
- public void onClose(@NotNull Miniapp miniapp) {
189
- WritableMap params = Arguments.createMap();
190
- params.putString("app_id", miniapp.getAppId());
191
- params.putString("lifecycle", "onClose");
192
- sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params);
193
- }
194
-
195
- @Override
196
- public void onError(@NotNull Miniapp miniapp, @NotNull String s) {
197
- WritableMap params = Arguments.createMap();
198
- params.putString("app_id", miniapp.getAppId());
199
- params.putString("lifecycle", "onError");
200
- params.putString("error", s);
201
- sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params);
202
- }
203
-
204
- @Override
205
- public void onUserInteraction(@NonNull Miniapp miniapp) {
206
- WritableMap params = Arguments.createMap();
207
- params.putString("app_id", miniapp.getAppId());
208
- params.putString("lifecycle", "onUserInteraction");
209
- sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params);
210
- }
211
-
212
- @Override
213
- public void onAuth(@NotNull AppboxoActivity appboxoActivity, @NonNull Miniapp miniapp) {
214
- WritableMap params = Arguments.createMap();
215
- params.putString("app_id", miniapp.getAppId());
216
- params.putString("lifecycle", "onAuth");
217
- sendEvent(MINIAPP_LIFECYCLE_EVENT_NAME, params);
218
- }
219
-
220
- @ReactMethod
221
- public void sendCustomEvent(ReadableMap map) {
222
- try {
223
- String appId = map.getString("app_id");
224
- ReadableMap customEventMap = map.getMap("custom_event");
225
- final CustomEvent event = new CustomEvent(customEventMap.getInt("request_id"),
226
- customEventMap.getString("type"),
227
- customEventMap.hasKey("error_type") ? customEventMap.getString("error_type") : null,
228
- MapUtil.toMap(customEventMap.getMap("payload")));
229
- final Miniapp miniapp = Appboxo.INSTANCE.getMiniapp(appId);
230
- handler.post(new Runnable() {
231
- @Override
232
- public void run() {
233
- if (miniapp != null) {
234
- miniapp.sendEvent(event);
235
- }
236
- }
237
- });
238
- } catch (Exception e) {
239
- e.printStackTrace();
240
- }
241
- }
242
-
243
- @ReactMethod
244
- public void sendPaymentEvent(ReadableMap map) {
245
- try {
246
- String appId = map.getString("app_id");
247
- ReadableMap paymentEvent = map.getMap("payment_event");
248
- final PaymentData data = new PaymentData(
249
- paymentEvent.getString("transaction_token"),
250
- paymentEvent.getString("miniapp_order_id"),
251
- paymentEvent.getDouble("amount"),
252
- paymentEvent.getString("currency"),
253
- paymentEvent.getString("status"),
254
- paymentEvent.getString("hostapp_order_id"),
255
- MapUtil.toMap(paymentEvent.getMap("extra_params")));
256
- final Miniapp miniapp = Appboxo.INSTANCE.getMiniapp(appId);
257
- handler.post(new Runnable() {
258
- @Override
259
- public void run() {
260
- if (miniapp != null) {
261
- miniapp.sendPaymentResult(data);
262
- }
263
- }
264
- });
265
- } catch (Exception e) {
266
- e.printStackTrace();
267
- }
268
- }
269
-
270
- @ReactMethod
271
- void getMiniapps() {
272
- Appboxo.INSTANCE.getMiniapps(new MiniappListCallback() {
273
- @Override
274
- public void onSuccess(List<MiniappData> list) {
275
- try {
276
- Map[] array = new Map[list.size()];
277
- for (int i = 0; i < list.size(); i++) {
278
- MiniappData miniappData = list.get(i);
279
- Map<String, Object> data = new HashMap<String, Object>();
280
- data.put("app_id", miniappData.getAppId());
281
- data.put("name", miniappData.getName());
282
- data.put("category", miniappData.getCategory());
283
- data.put("logo", miniappData.getLogo());
284
- data.put("description", miniappData.getDescription());
285
- array[i] = data;
286
- }
287
- Map<String, Object> params = new HashMap<String, Object>();
288
- params.put("miniapps", array);
289
- sendEvent(MINIAPP_LIST_EVENT_NAME, MapUtil.toWritableMap((Map<String, Object>) params));
290
- } catch (Exception e) {
291
- e.printStackTrace();
292
- }
293
- }
294
-
295
- @Override
296
- public void onFailure(Exception e) {
297
- WritableMap result = Arguments.createMap();
298
- result.putString("error", e.getMessage());
299
- sendEvent(MINIAPP_LIST_EVENT_NAME, result);
300
- }
301
- });
302
- }
303
-
304
- @ReactMethod
305
- void hideMiniapps() {
306
- Appboxo.INSTANCE.hideMiniapps();
307
- }
308
-
309
- @ReactMethod
310
- void logout() {
311
- Appboxo.INSTANCE.logout();
312
- }
313
-
314
- private void sendEvent(String name, WritableMap params) {
315
- reactContext
316
- .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
317
- .emit(name, params);
318
- }
319
-
320
- @Override
321
- public void handle(AppboxoActivity appboxoActivity, Miniapp miniapp, PaymentData paymentData) {
322
- WritableMap params = Arguments.createMap();
323
- params.putString("app_id", miniapp.getAppId());
324
- WritableMap event = Arguments.createMap();
325
- try {
326
- event.putString("transaction_token", paymentData.getTransactionToken());
327
- event.putString("miniapp_order_id", paymentData.getMiniappOrderId());
328
- event.putDouble("amount", paymentData.getAmount());
329
- event.putString("currency", paymentData.getCurrency());
330
- event.putString("status", paymentData.getStatus());
331
- event.putString("hostapp_order_id", paymentData.getHostappOrderId());
332
- if (paymentData.getExtraParams() != null) {
333
- event.putMap("extra_params", MapUtil.toWritableMap(paymentData.getExtraParams()));
334
- }
335
-
336
- params.putMap("payment_event", event);
337
- sendEvent(PAYMENT_EVENTS_EVENT_NAME, params);
338
- } catch (Exception e) {
339
- e.printStackTrace();
340
- }
341
- }
342
- }
@@ -1,38 +0,0 @@
1
- /*
2
- Copyright 2020 Appboxo pte. ltd.
3
-
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
7
-
8
- http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
15
- */
16
-
17
- package com.appboxo;
18
-
19
- import java.util.Arrays;
20
- import java.util.Collections;
21
- import java.util.List;
22
-
23
- import com.facebook.react.ReactPackage;
24
- import com.facebook.react.bridge.NativeModule;
25
- import com.facebook.react.bridge.ReactApplicationContext;
26
- import com.facebook.react.uimanager.ViewManager;
27
-
28
- public class RnappboxosdkPackage implements ReactPackage {
29
- @Override
30
- public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
31
- return Arrays.<NativeModule>asList(new RnappboxosdkModule(reactContext));
32
- }
33
-
34
- @Override
35
- public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
36
- return Collections.emptyList();
37
- }
38
- }