@appboxo/react-native-sdk 1.0.36 → 1.0.37

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.
@@ -19,15 +19,18 @@ package com.appboxo;
19
19
  import android.app.Application;
20
20
  import android.os.Handler;
21
21
  import android.os.Looper;
22
+ import android.util.Log;
22
23
 
23
24
  import androidx.annotation.NonNull;
24
25
 
26
+ import com.appboxo.data.models.MiniappData;
25
27
  import com.appboxo.js.params.CustomEvent;
26
28
  import com.appboxo.js.params.PaymentData;
27
29
  import com.appboxo.sdk.Appboxo;
28
30
  import com.appboxo.sdk.Config;
29
31
  import com.appboxo.sdk.Miniapp;
30
32
  import com.appboxo.sdk.MiniappConfig;
33
+ import com.appboxo.sdk.MiniappListCallback;
31
34
  import com.appboxo.ui.main.AppboxoActivity;
32
35
  import com.appboxo.utils.MapUtil;
33
36
  import com.facebook.react.bridge.Arguments;
@@ -40,13 +43,16 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
40
43
 
41
44
  import org.jetbrains.annotations.NotNull;
42
45
 
46
+ import java.sql.ClientInfoStatus;
43
47
  import java.util.HashMap;
48
+ import java.util.List;
44
49
  import java.util.Map;
45
50
 
46
51
  public class RnappboxosdkModule extends ReactContextBaseJavaModule
47
52
  implements Miniapp.LifecycleListener, Miniapp.CustomEventListener, Miniapp.AuthListener, Miniapp.PaymentEventListener {
48
53
  private static final String CUSTOM_EVENTS_EVENT_NAME = "appboxo_custom_events";
49
54
  private static final String PAYMENT_EVENTS_EVENT_NAME = "appboxo_payment_events";
55
+ private static final String MINIAPP_LIST_EVENT_NAME = "appboxo_miniapp_list";
50
56
  private static final String MINIAPP_LIFECYCLE_EVENT_NAME = "appboxo_miniapp_lifecycle";
51
57
 
52
58
  private final ReactApplicationContext reactContext;
@@ -261,6 +267,40 @@ public class RnappboxosdkModule extends ReactContextBaseJavaModule
261
267
  }
262
268
  }
263
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
+
264
304
  @ReactMethod
265
305
  void hideMiniapps() {
266
306
  Appboxo.INSTANCE.hideMiniapps();
package/index.d.ts CHANGED
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
16
 
17
- import { AppboxoCustomEvent, LifecycleHooksCallbacks } from './types'
17
+ import { AppboxoCustomEvent, LifecycleHooksCallbacks, MiniappDataListCallback } from './types'
18
18
 
19
19
  declare module '@appboxo/react-native-sdk' {
20
20
 
@@ -80,6 +80,8 @@ declare module '@appboxo/react-native-sdk' {
80
80
  * Appboxo Miniapp lifecycle hooks listener
81
81
  * */
82
82
  export function lifecycleHooksListener(callbacks: Partial<LifecycleHooksCallbacks>): () => void
83
+
84
+ export function getMiniapps(): void
83
85
  }
84
86
 
85
- export * from './types'
87
+ export * from './types'
package/index.js CHANGED
@@ -18,11 +18,13 @@ import { NativeModules } from 'react-native'
18
18
 
19
19
  import lifecycleHooksListener from './js/lifecycleHooks'
20
20
  import customEvents from './js/customEvents'
21
+ import miniapps from './js/miniapps'
21
22
  import mOpenMiniapp from './js/mOpenMiniapp'
23
+ import mGetMiniapps from './js/mGetMiniapps'
22
24
  import mSetConfig from './js/mSetConfig'
23
25
  import mSetAuthCode from './js/mSetAuthCode'
24
26
  import paymentEvents from './js/paymentEvents'
25
27
 
26
- const { Rnappboxosdk: { sendCustomEvent, sendPaymentEvent, openMiniapp, setConfig, ...methods } } = NativeModules
28
+ const { Rnappboxosdk: { sendCustomEvent, sendPaymentEvent, openMiniapp, setConfig, getMiniapps, ...methods } } = NativeModules
27
29
 
28
- export default { ...methods, lifecycleHooksListener, openMiniapp: mOpenMiniapp, setConfig: mSetConfig, customEvents, paymentEvents }
30
+ export default { ...methods, lifecycleHooksListener, openMiniapp: mOpenMiniapp, setConfig: mSetConfig, getMiniapps:mGetMiniapps, customEvents, paymentEvents, miniapps}
@@ -25,6 +25,7 @@ limitations under the License.
25
25
  #define APPBOXO_CUSTOM_EVENT @"appboxo_custom_events"
26
26
  #define APPBOXO_PAYMENT_EVENT @"appboxo_payment_events"
27
27
  #define APPBOXO_MINIAPP_LIFECYCLE_EVENT @"appboxo_miniapp_lifecycle"
28
+ #define APPBOXO_MINIAPP_LIST_EVENT @"appboxo_miniapp_list"
28
29
 
29
30
  @implementation Rnappboxosdk
30
31
 
@@ -132,10 +133,34 @@ RCT_EXPORT_METHOD(sendPaymentEvent:(NSDictionary<NSString *,id> * _Nonnull)param
132
133
  });
133
134
  }
134
135
 
136
+ RCT_EXPORT_METHOD(getMiniapps)
137
+ {
138
+ dispatch_async(dispatch_get_main_queue(), ^{
139
+ [[Appboxo shared] getMiniapps:^(NSArray<MiniappData *> * _Nonnull list, NSString * _Nullable error) {
140
+ if (error != NULL) {
141
+ [self sendEventWithName:APPBOXO_MINIAPP_LIST_EVENT body:@{@"error": error}];
142
+ } else {
143
+ NSMutableArray *array = [NSMutableArray new];
144
+ for (int i = 0; i < list.count; i++) {
145
+ MiniappData *miniappData = list[i];
146
+ NSMutableDictionary *data = [NSMutableDictionary new];
147
+ data[@"app_id"] = miniappData.appId;
148
+ data[@"name"] = miniappData.name;
149
+ data[@"category"] = miniappData.category;
150
+ data[@"logo"] = miniappData.logo;
151
+ data[@"description"] = miniappData.longDescription;
152
+ array[i] = data;
153
+ }
154
+
155
+ [self sendEventWithName:APPBOXO_MINIAPP_LIST_EVENT body:@{@"miniapps": array}];
156
+ }
157
+ }];
158
+ });
159
+ }
135
160
 
136
161
  - (NSArray<NSString *> *)supportedEvents
137
162
  {
138
- return @[APPBOXO_CUSTOM_EVENT, APPBOXO_PAYMENT_EVENT, APPBOXO_MINIAPP_LIFECYCLE_EVENT];
163
+ return @[APPBOXO_CUSTOM_EVENT, APPBOXO_PAYMENT_EVENT, APPBOXO_MINIAPP_LIFECYCLE_EVENT, APPBOXO_MINIAPP_LIST_EVENT];
139
164
  }
140
165
 
141
166
  - (void)didReceiveCustomEvent:(Miniapp *)miniapp customEvent:(CustomEvent *)customEvent {
@@ -0,0 +1,23 @@
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
+ import { NativeEventEmitter, NativeModules } from 'react-native'
18
+
19
+ const mGetMiniapps = () => {
20
+ NativeModules.Rnappboxosdk.getMiniapps()
21
+ }
22
+
23
+ export default mGetMiniapps
package/js/miniapps.js ADDED
@@ -0,0 +1,30 @@
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
+ import { NativeEventEmitter, NativeModules } from 'react-native'
18
+
19
+ const miniapps = {
20
+ subscribe: (eventHandler, errorHandler) => {
21
+ const appboxoEventEmitter = new NativeEventEmitter(NativeModules.Rnappboxosdk)
22
+ const appboxoEventListener =
23
+ appboxoEventEmitter.addListener('appboxo_miniapp_list', event =>
24
+ event.miniapps ? eventHandler(event.miniapps) : errorHandler && errorHandler(event.error),
25
+ )
26
+ return () => appboxoEventListener.remove()
27
+ },
28
+ }
29
+
30
+ export default miniapps
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.36",
4
+ "version": "1.0.37",
5
5
  "description": "Appboxo react native sdk",
6
6
  "main": "index.js",
7
7
  "files": [
package/types.ts CHANGED
@@ -69,3 +69,15 @@ export interface LifecycleHooksCallbacks {
69
69
  onAuth: (appId: string) => void
70
70
  onError: (appId: string, error: string) => void
71
71
  }
72
+
73
+ /**
74
+ * miniapp data body
75
+ * */
76
+ export interface MiniappData{
77
+ app_id: string
78
+ name: string
79
+ description: string
80
+ category: string
81
+ logo?: string
82
+ }
83
+