@btsd/aitu-bridge 0.2.15 → 0.2.18

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/src/index.ts CHANGED
@@ -18,6 +18,7 @@ type GetItemType = (keyName: string) => Promise<string | null>;
18
18
  type ClearType = () => Promise<void>;
19
19
 
20
20
  type HeaderMenuItemClickHandlerType = (id: string) => Promise<void>;
21
+ type BackArrowClickHandlerType = () => Promise<void>;
21
22
 
22
23
  interface GetPhoneResponse {
23
24
  phone: string;
@@ -67,6 +68,8 @@ interface GetUserProfileResponse {
67
68
  avatarThumb?: string;
68
69
  }
69
70
 
71
+ const MAX_HEADER_MENU_ITEMS_COUNT = 3;
72
+
70
73
  export enum HeaderMenuIcon {
71
74
  Search = "Search",
72
75
  ShoppingCart = "ShoppingCart",
@@ -132,6 +135,10 @@ interface AituBridge {
132
135
  disableScreenCapture: () => Promise<{}>;
133
136
  setHeaderMenuItems: (items: Array<HeaderMenuItem>) => Promise<ResponseType>;
134
137
  setHeaderMenuItemClickHandler: (handler: HeaderMenuItemClickHandlerType) => void;
138
+ setCustomBackArrowMode: (enabled: boolean) => Promise<ResponseType>;
139
+ getCustomBackArrowMode: () => Promise<boolean>;
140
+ setCustomBackArrowVisible: (visible: boolean) => Promise<ResponseType>;
141
+ setCustomBackArrowOnClickHandler: (handler: BackArrowClickHandlerType) => void;
135
142
  }
136
143
 
137
144
  const invokeMethod = 'invoke';
@@ -154,6 +161,10 @@ const disableScreenCaptureMethod = 'disableScreenCapture';
154
161
  const setTabActiveHandlerMethod = 'setTabActiveHandler';
155
162
  const setHeaderMenuItemsMethod = 'setHeaderMenuItems';
156
163
  const setHeaderMenuItemClickHandlerMethod = 'setHeaderMenuItemClickHandler';
164
+ const setCustomBackArrowModeMethod = 'setCustomBackArrowMode';
165
+ const getCustomBackArrowModeMethod = 'getCustomBackArrowMode';
166
+ const setCustomBackArrowVisibleMethod = 'setCustomBackArrowVisible';
167
+ const setCustomBackArrowOnClickHandlerMethod = 'setCustomBackArrowOnClickHandler';
157
168
 
158
169
  const android = typeof window !== 'undefined' && (window as any).AndroidBridge;
159
170
  const ios = typeof window !== 'undefined' && (window as any).webkit && (window as any).webkit.messageHandlers;
@@ -475,14 +486,21 @@ const buildBridge = (): AituBridge => {
475
486
  subs.push(listener);
476
487
  }
477
488
 
478
- const setHeaderMenuItems = (items: Array<HeaderMenuItem>) => {
489
+ const setHeaderMenuItems = (reqId, items: Array<HeaderMenuItem>) => {
490
+ if (items.length > MAX_HEADER_MENU_ITEMS_COUNT) {
491
+ console.error('SetHeaderMenuItems: items count should not be more than ' + MAX_HEADER_MENU_ITEMS_COUNT);
492
+ return;
493
+ }
494
+
479
495
  const isAndroid = android && android[setHeaderMenuItemsMethod];
480
496
  const isIos = ios && ios[setHeaderMenuItemsMethod];
481
497
 
498
+ const itemsJsonArray = JSON.stringify(items);
499
+
482
500
  if (isAndroid) {
483
- android[setHeaderMenuItemsMethod](items);
501
+ android[setHeaderMenuItemsMethod](reqId, itemsJsonArray);
484
502
  } else if (isIos) {
485
- ios[setHeaderMenuItemsMethod].postMessage({ items });
503
+ ios[setHeaderMenuItemsMethod].postMessage({ reqId, itemsJsonArray });
486
504
  } else if (typeof window !== 'undefined') {
487
505
  console.log('--setHeaderMenuItems-isWeb');
488
506
  }
@@ -499,6 +517,56 @@ const buildBridge = (): AituBridge => {
499
517
  }
500
518
  }
501
519
 
520
+ const setCustomBackArrowMode = (reqId, enabled: boolean) => {
521
+ const isAndroid = android && android[setCustomBackArrowModeMethod];
522
+ const isIos = ios && ios[setCustomBackArrowModeMethod];
523
+
524
+ if (isAndroid) {
525
+ android[setHeaderMenuItemsMethod](reqId, enabled);
526
+ } else if (isIos) {
527
+ ios[setHeaderMenuItemsMethod].postMessage({ reqId, enabled });
528
+ } else if (typeof window !== 'undefined') {
529
+ console.log('--setCustomBackArrowMode-isWeb');
530
+ }
531
+ }
532
+
533
+ const getCustomBackArrowMode = (reqId) => {
534
+ const isAndroid = android && android[getCustomBackArrowModeMethod];
535
+ const isIos = ios && ios[getCustomBackArrowModeMethod];
536
+
537
+ if (isAndroid) {
538
+ android[setHeaderMenuItemsMethod](reqId);
539
+ } else if (isIos) {
540
+ ios[setHeaderMenuItemsMethod].postMessage({ reqId });
541
+ } else if (typeof window !== 'undefined') {
542
+ console.log('--getCustomBackArrowMode-isWeb');
543
+ }
544
+ }
545
+
546
+ const setCustomBackArrowVisible = (reqId, visible: boolean) => {
547
+ const isAndroid = android && android[setCustomBackArrowVisibleMethod];
548
+ const isIos = ios && ios[setCustomBackArrowVisibleMethod];
549
+
550
+ if (isAndroid) {
551
+ android[setHeaderMenuItemsMethod](reqId, visible);
552
+ } else if (isIos) {
553
+ ios[setHeaderMenuItemsMethod].postMessage({ reqId, visible });
554
+ } else if (typeof window !== 'undefined') {
555
+ console.log('--setCustomBackArrowVisible-isWeb');
556
+ }
557
+ }
558
+
559
+ const setCustomBackArrowOnClickHandler = (handler: BackArrowClickHandlerType) => {
560
+ const isAndroid = android && android[setCustomBackArrowOnClickHandlerMethod];
561
+ const isIos = ios && ios[setCustomBackArrowOnClickHandlerMethod];
562
+
563
+ if (isAndroid || isIos) {
564
+ (window as any).onAituBridgeBackArrowClick = handler;
565
+ } else if (typeof window !== 'undefined') {
566
+ console.log('--setCustomBackArrowOnClickHandler-isWeb');
567
+ }
568
+ }
569
+
502
570
  const invokePromise = promisifyInvoke(invoke, sub);
503
571
  const storagePromise = promisifyStorage(storage, sub);
504
572
  const getGeoPromise = promisifyMethod(getGeo, sub);
@@ -516,6 +584,9 @@ const buildBridge = (): AituBridge => {
516
584
  const enableScreenCapturePromise = promisifyMethod(enableScreenCapture, sub);
517
585
  const disableScreenCapturePromise = promisifyMethod(disableScreenCapture, sub);
518
586
  const setHeaderMenuItemsPromise = promisifyMethod(setHeaderMenuItems, sub);
587
+ const setCustomBackArrowModePromise = promisifyMethod(setCustomBackArrowMode, sub);
588
+ const getCustomBackArrowModePromise = promisifyMethod(getCustomBackArrowMode, sub);
589
+ const setCustomBackArrowVisiblePromise = promisifyMethod(setCustomBackArrowVisible, sub);
519
590
 
520
591
  return {
521
592
  version: String(LIB_VERSION),
@@ -547,7 +618,11 @@ const buildBridge = (): AituBridge => {
547
618
  enableScreenCapture: enableScreenCapturePromise,
548
619
  disableScreenCapture: disableScreenCapturePromise,
549
620
  setHeaderMenuItems: setHeaderMenuItemsPromise,
550
- setHeaderMenuItemClickHandler
621
+ setHeaderMenuItemClickHandler,
622
+ setCustomBackArrowMode: setCustomBackArrowModePromise,
623
+ getCustomBackArrowMode: getCustomBackArrowModePromise,
624
+ setCustomBackArrowVisible: setCustomBackArrowVisiblePromise,
625
+ setCustomBackArrowOnClickHandler,
551
626
  }
552
627
  }
553
628
 
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const LIB_VERSION = "0.2.15";
1
+ export const LIB_VERSION = "0.2.18";