react-native-firework-sdk 1.2.7 → 1.2.8

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.
@@ -12,8 +12,8 @@
12
12
  android:theme="@style/Theme.AppCompat.Light.NoActionBar"
13
13
  />
14
14
  <provider
15
- android:authorities="com.fireworksdk.bridge.reactnative"
16
- android:name=".reactnative.FWInitializationProvider"
15
+ android:authorities="${applicationId}.fwBridgeProvider"
16
+ android:name="com.fireworksdk.bridge.FWInitializationProvider"
17
17
  android:exported="false"
18
18
  />
19
19
  <meta-data
@@ -1,4 +1,4 @@
1
- package com.fireworksdk.bridge.reactnative
1
+ package com.fireworksdk.bridge
2
2
 
3
3
  import android.app.Activity
4
4
  import android.app.Application
@@ -2,7 +2,7 @@ package com.fireworksdk.bridge.reactnative.module
2
2
 
3
3
  import android.app.Activity
4
4
  import com.facebook.react.bridge.*
5
- import com.fireworksdk.bridge.reactnative.FWInitializationProvider
5
+ import com.fireworksdk.bridge.FWInitializationProvider
6
6
  import com.fireworksdk.bridge.reactnative.models.FWNavigatorInterface
7
7
  import com.fireworksdk.bridge.reactnative.utils.FWEventUtils
8
8
  import com.fireworksdk.bridge.utils.FWLogUtils
@@ -11,7 +11,7 @@ import com.fireworksdk.bridge.utils.*
11
11
  import org.json.JSONObject
12
12
  import com.facebook.react.bridge.ReactMethod
13
13
  import com.fireworksdk.bridge.models.FWAdBadgeConfigModel
14
- import com.fireworksdk.bridge.reactnative.FWInitializationProvider
14
+ import com.fireworksdk.bridge.FWInitializationProvider
15
15
  import com.fireworksdk.bridge.reactnative.models.FireworkSDKInterface
16
16
  import com.fireworksdk.bridge.reactnative.pages.FWContainerActivity
17
17
  import com.fireworksdk.bridge.reactnative.utils.FWEventUtils
@@ -5,11 +5,10 @@ import com.facebook.react.bridge.*
5
5
  import com.facebook.react.modules.core.DeviceEventManagerModule
6
6
  import com.facebook.react.uimanager.events.RCTEventEmitter
7
7
  import com.fireworksdk.bridge.models.*
8
- import com.fireworksdk.bridge.reactnative.FWInitializationProvider
8
+ import com.fireworksdk.bridge.FWInitializationProvider
9
9
  import com.fireworksdk.bridge.reactnative.module.FireworkSDKModule
10
10
  import com.fireworksdk.bridge.reactnative.pages.FWContainerActivity
11
11
  import com.fireworksdk.bridge.utils.FWDateUtils
12
- import com.fireworksdk.bridge.utils.FWJsonUtils
13
12
  import com.fireworksdk.bridge.utils.FWLogUtils
14
13
  import com.loopnow.fireworklibrary.data.Product
15
14
  import java.util.*
@@ -20,7 +19,7 @@ object FWEventUtils {
20
19
  FWLogUtils.d { "FWNavigatorModule pushNativeContainer: $props" }
21
20
  val activity = FWInitializationProvider.INSTANCE.resumedActivity
22
21
 
23
- if (activity == null) {
22
+ if (activity == null || FireworkSDKModule.appComponentName.isNullOrBlank()) {
24
23
  promise?.resolve(false)
25
24
  return
26
25
  }
@@ -81,15 +81,20 @@ class CartViewController: UIViewController, CartViewRepresentable {
81
81
  indicator.centerYAnchor.constraint(equalTo: view.centerYAnchor)
82
82
  ])
83
83
 
84
- indicator.startAnimating()
84
+ // indicator.startAnimating()
85
85
 
86
86
  self.indicator = indicator
87
87
  }
88
88
 
89
89
  private func directShowCustomCartView() {
90
90
  indicator?.stopAnimating()
91
-
92
- let rctRootView = RCTRootView.init(bridge: RCTBridge.current(), moduleName: gAppComponentName ?? "", initialProperties: properties)
91
+ guard let appComponentName = gAppComponentName else {
92
+ return
93
+ }
94
+ let rctRootView = RCTRootView.init(
95
+ bridge: RCTBridge.current(),
96
+ moduleName: appComponentName,
97
+ initialProperties: properties)
93
98
  view.addSubview(rctRootView)
94
99
  rctRootView.translatesAutoresizingMaskIntoConstraints = false
95
100
 
@@ -16,5 +16,5 @@ RCT_EXTERN_METHOD(updateVideoProducts:(NSArray *)products cbId:(nonnull NSNumber
16
16
  RCT_EXTERN_METHOD(updateProductViewConfig:(NSDictionary *)config cbId:(nonnull NSNumber *)cbid)
17
17
  RCT_EXTERN_METHOD(updateAddToCartStatus:(NSString *)res tips:(nullable NSString *)tips cbId:(nonnull NSNumber *)cbid)
18
18
  RCT_EXTERN_METHOD(jumpToCartPage:(nonnull NSNumber *)cbid props:(NSDictionary *)props)
19
-
19
+ RCT_EXTERN_METHOD(setCustomClickCartIconEnabled:(BOOL)enabled resolver: (RCTPromiseResolveBlock)resolver rejecter:(RCTPromiseRejectBlock)rejecter)
20
20
  @end
@@ -19,6 +19,7 @@ class ShoppingModule: RCTEventEmitter, FireworkVideoShoppingDelegate, CartViewCo
19
19
  private var cartViewController: CartViewController?
20
20
  private var cartIconVisible = true
21
21
  private var itemCounts = 0
22
+ private var customClickCartIconEnabled = false
22
23
 
23
24
  override func supportedEvents() -> [String]! {
24
25
  ShoppingEventName.allCases.map { $0.rawValue }
@@ -124,6 +125,12 @@ class ShoppingModule: RCTEventEmitter, FireworkVideoShoppingDelegate, CartViewCo
124
125
  NotificationCenter.default.post(noti)
125
126
  }
126
127
  }
128
+
129
+ @objc
130
+ func setCustomClickCartIconEnabled(_ enabled: Bool, resolver: @escaping RCTPromiseResolveBlock, rejecter: @escaping RCTPromiseRejectBlock) {
131
+ customClickCartIconEnabled = enabled
132
+ resolver([:])
133
+ }
127
134
 
128
135
  // MARK: - FireworkVideoShoppingDelegate
129
136
  func fireworkShopping(_ fireworkShopping: FireworkVideoShopping, willDisplayProductInfo productInfoViewConfigurator: ProductInfoViewConfigurable, forVideo video: VideoDetails) {
@@ -152,8 +159,11 @@ class ShoppingModule: RCTEventEmitter, FireworkVideoShoppingDelegate, CartViewCo
152
159
  let callbackId = ShoppingModule.generateCallbackId()
153
160
  sendEvent(withName: ShoppingEventName.ClickCartIcon.rawValue, body: ["callbackId": callbackId])
154
161
 
155
- gCartViewController = CartViewController(callbackId: callbackId)
156
- return gCartViewController!
162
+ let cartVC = CartViewController(callbackId: callbackId)
163
+ if !customClickCartIconEnabled {
164
+ gCartViewController = cartVC
165
+ }
166
+ return cartVC
157
167
  }
158
168
  }
159
169
 
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
+ var _reactNative = require("react-native");
9
+
8
10
  var _FWEventName = require("./models/FWEventName");
9
11
 
10
12
  var _ShoppingModule = _interopRequireWildcard(require("./modules/ShoppingModule"));
@@ -28,20 +30,25 @@ class VideoShopping {
28
30
  /**
29
31
  * This callback is triggered when the user clicks the shopping cart icon.
30
32
  *
31
- * The host app can return a React.Node to integrate custom cart page to shopping flow.
33
+ * The host app can return NewNativeContainerProps object and we will push a new native container with the props.
32
34
  */
33
35
 
34
36
  /**
35
- * This callback is triggered when the video will be shown.
37
+ * This callback is triggered when the user clicks the shopping cart icon.
36
38
  *
37
- * The host app can return a Product list to update the latest product information.
39
+ * The host app can customize the processing logic of clicking the shopping cart icon by setting the callback.
38
40
  */
41
+ get onCustomClickCartIcon() {
42
+ return this._onCustomClickCartIcon;
43
+ }
39
44
 
40
- /**
41
- * This callback is triggered when the product will be shown.
42
- *
43
- * The host app can return a ProductInfoViewConfiguration object to configure "Add to cart" button style and cart icon style.
44
- */
45
+ set onCustomClickCartIcon(value) {
46
+ this._onCustomClickCartIcon = value;
47
+
48
+ if (_reactNative.Platform.OS === 'ios') {
49
+ _ShoppingModule.default.setCustomClickCartIconEnabled(!!value);
50
+ }
51
+ }
45
52
 
46
53
  /**
47
54
  * Defaults to true. You can hide the cart icon by setting this property to false.
@@ -73,6 +80,8 @@ class VideoShopping {
73
80
 
74
81
  _defineProperty(this, "onClickCartIcon", void 0);
75
82
 
83
+ _defineProperty(this, "_onCustomClickCartIcon", void 0);
84
+
76
85
  _defineProperty(this, "onUpdateProductDetails", void 0);
77
86
 
78
87
  _defineProperty(this, "onWillDisplayProduct", void 0);
@@ -115,7 +124,9 @@ class VideoShopping {
115
124
  }
116
125
 
117
126
  async handleClickCartIconEvent(event) {
118
- if (this.onClickCartIcon) {
127
+ if (this.onCustomClickCartIcon) {
128
+ this.onCustomClickCartIcon();
129
+ } else if (this.onClickCartIcon) {
119
130
  const callbackId = event.callbackId;
120
131
  delete event.callbackId;
121
132
  const props = await this.onClickCartIcon();
@@ -1 +1 @@
1
- {"version":3,"sources":["VideoShopping.ts"],"names":["VideoShopping","cartIconVisible","_cartIconVisible","value","ShoppingModule","setCartIconVisible","eventEmitter","ShoppingModuleEventEmitter","getInstance","_instance","constructor","addListener","FWEventName","AddToCart","event","handleAddToCartEvent","ClickCartIcon","handleClickCartIconEvent","UpdateProductDetails","handleUpdateProductDetailsEvent","WillDisplayProduct","handleWillDisplayProductEvent","setCartItemCount","count","onAddToCart","callbackId","result","updateAddToCartStatus","res","tips","onClickCartIcon","props","jumpToCartPage","onUpdateProductDetails","productList","updateVideoProducts","onWillDisplayProduct","config","updateProductViewConfig"],"mappings":";;;;;;;AAQA;;AAGA;;;;;;;;AAuBA;AACA;AACA;AACA,MAAMA,aAAN,CAAoB;AAGlB;AACF;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;;AAGE;AACF;AACA;AAC4B,MAAfC,eAAe,GAAY;AACpC,WAAO,KAAKC,gBAAZ;AACD;;AACyB,MAAfD,eAAe,CAACE,KAAD,EAAiB;AACzC,SAAKD,gBAAL,GAAwBC,KAAxB;;AACAC,4BAAeC,kBAAf,CAAkCF,KAAlC;AACD;;AAGuB,MAAZG,YAAY,GAAuB;AAC7C,WAAOC,0CAAP;AACD;;AAEwB,SAAXC,WAAW,GAAG;AAC1B,QAAI,CAACR,aAAa,CAACS,SAAnB,EAA8B;AAC5BT,MAAAA,aAAa,CAACS,SAAd,GAA0B,IAAIT,aAAJ,EAA1B;AACD;;AAED,WAAOA,aAAa,CAACS,SAArB;AACD;;AAEOC,EAAAA,WAAW,GAAG;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,8CAdc,IAcd;;AACpB,SAAKJ,YAAL,CAAkBK,WAAlB,CAA8BC,yBAAYC,SAA1C,EAAsDC,KAAD,IAAW;AAC9D,W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C,QAA/BZ,+BAA+B,CAC3CL,KAD2C,EAE3C;AACA,QAAI,KAAKmB,sBAAT,EAAiC;AAC/B,YAAMR,UAAU,GAAGX,KAAK,CAACW,UAAzB;AACA,aAAOX,KAAK,CAACW,UAAb;AACA,YAAMS,WAAW,GAAG,MAAM,KAAKD,sBAAL,CACxBnB,KADwB,CAA1B;;AAGA,UAAIoB,WAAJ,EAAiB;AACf9B,gCAAe+B,mBAAf,CAAmCD,WAAnC,EAAgDT,UAAhD;AACD;AACF;AACF;;AAE0C,QAA7BJ,6BAA6B,CACzCP,KADyC,EAEzC;AACA,QAAI,KAAKsB,oBAAT,EAA+B;AAC7B,YAAMX,UAAU,GAAGX,KAAK,CAACW,UAAzB;AACA,aAAOX,KAAK,CAACW,UAAb;AACA,YAAMY,MAAM,GAAG,MAAM,KAAKD,oBAAL,CACnBtB,KADmB,CAArB;;AAGA,UAAIuB,MAAJ,EAAY;AACVjC,gCAAekC,uBAAf,CAAuCD,MAAvC,EAA+CZ,UAA/C;AACD;AACF;AACF;;AAvIiB;;gBAAdzB,a;;eA0ISA,a","sourcesContent":["import type { NativeEventEmitter } from 'react-native';\n\nimport type AddToCartResult from './models/AddToCartResult';\nimport type {\n AddToCartEvent,\n UpdateProductDetailsEvent,\n WillDisplayProductEvent,\n} from './models/FWEvents';\nimport { FWEventName } from './models/FWEventName';\nimport type Product from './models/Product';\nimport type ProductInfoViewConfiguration from './models/ProductInfoViewConfiguration';\nimport ShoppingModule, {\n ShoppingModuleEventEmitter,\n} from './modules/ShoppingModule';\nimport type { NewNativeContainerProps } from './models/NewNativeContainerProps';\n\nexport type AddToCartCallback = (\n event: AddToCartEvent\n) => Promise<AddToCartResult | undefined | null>;\n\nexport type ClickCartIconCallback = () => Promise<\n NewNativeContainerProps | undefined | null\n>;\n\nexport type UpdateProductDetailsCallback = (\n event: UpdateProductDetailsEvent\n) => Promise<Product[] | undefined | null>;\n\nexport type WillDisplayProductCallback = (\n event: WillDisplayProductEvent\n) => Promise<ProductInfoViewConfiguration | undefined | null>;\n\ntype CallbackInfo = { callbackId?: number | string };\n\n/**\n * The entry class of video shopping.\n */\nclass VideoShopping {\n private static _instance?: VideoShopping;\n\n /**\n * This callback is triggered when the user clicks the \"Add to cart\" button.\n *\n * The host app can return an AddToCartResult object to tell FireworkSDK the result of adding to cart.\n */\n public onAddToCart?: AddToCartCallback;\n\n /**\n * This callback is triggered when the user clicks the shopping cart icon.\n *\n * The host app can return a React.Node to integrate custom cart page to shopping flow.\n */\n public onClickCartIcon?: ClickCartIconCallback;\n\n /**\n * This callback is triggered when the video will be shown.\n *\n * The host app can return a Product list to update the latest product information.\n */\n public onUpdateProductDetails?: UpdateProductDetailsCallback;\n\n /**\n * This callback is triggered when the product will be shown.\n *\n * The host app can return a ProductInfoViewConfiguration object to configure \"Add to cart\" button style and cart icon style.\n */\n public onWillDisplayProduct?: WillDisplayProductCallback;\n\n /**\n * Defaults to true. You can hide the cart icon by setting this property to false.\n */\n public get cartIconVisible(): boolean {\n return this._cartIconVisible;\n }\n public set cartIconVisible(value: boolean) {\n this._cartIconVisible = value;\n ShoppingModule.setCartIconVisible(value);\n }\n private _cartIconVisible: boolean = true;\n\n private get eventEmitter(): NativeEventEmitter {\n return ShoppingModuleEventEmitter;\n }\n\n public static getInstance() {\n if (!VideoShopping._instance) {\n VideoShopping._instance = new VideoShopping();\n }\n\n return VideoShopping._instance!;\n }\n\n private constructor() {\n this.eventEmitter.addListener(FWEventName.AddToCart, (event) => {\n this.handleAddToCartEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.ClickCartIcon, (event) => {\n this.handleClickCartIconEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.UpdateProductDetails, (event) => {\n this.handleUpdateProductDetailsEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.WillDisplayProduct, (event) => {\n this.handleWillDisplayProductEvent(event);\n });\n }\n\n /**\n *\n * @param {number} count The number of items in the host app cart\n */\n public setCartItemCount(count: number) {\n ShoppingModule.setCartItemCount(count);\n }\n\n private async handleAddToCartEvent(event: AddToCartEvent & CallbackInfo) {\n if (this.onAddToCart) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const result = await this.onAddToCart(event as AddToCartEvent);\n if (result) {\n ShoppingModule.updateAddToCartStatus(\n result.res,\n result.tips,\n callbackId!\n );\n }\n }\n }\n\n private async handleClickCartIconEvent(event: CallbackInfo) {\n if (this.onClickCartIcon) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const props = await this.onClickCartIcon();\n if (callbackId) {\n ShoppingModule.jumpToCartPage(callbackId, props ?? {});\n }\n }\n }\n\n private async handleUpdateProductDetailsEvent(\n event: UpdateProductDetailsEvent & CallbackInfo\n ) {\n if (this.onUpdateProductDetails) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const productList = await this.onUpdateProductDetails(\n event as UpdateProductDetailsEvent\n );\n if (productList) {\n ShoppingModule.updateVideoProducts(productList, callbackId!);\n }\n }\n }\n\n private async handleWillDisplayProductEvent(\n event: WillDisplayProductEvent & CallbackInfo\n ) {\n if (this.onWillDisplayProduct) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const config = await this.onWillDisplayProduct(\n event as WillDisplayProductEvent\n );\n if (config) {\n ShoppingModule.updateProductViewConfig(config, callbackId!);\n }\n }\n }\n}\n\nexport default VideoShopping;\n"]}
1
+ {"version":3,"sources":["VideoShopping.ts"],"names":["VideoShopping","onCustomClickCartIcon","_onCustomClickCartIcon","value","Platform","OS","ShoppingModule","setCustomClickCartIconEnabled","cartIconVisible","_cartIconVisible","setCartIconVisible","eventEmitter","ShoppingModuleEventEmitter","getInstance","_instance","constructor","addListener","FWEventName","AddToCart","event","handleAddToCartEvent","ClickCartIcon","handleClickCartIconEvent","UpdateProductDetails","handleUpdateProductDetailsEvent","WillDisplayProduct","handleWillDisplayProductEvent","setCartItemCount","count","onAddToCart","callbackId","result","updateAddToCartStatus","res","tips","onClickCartIcon","props","jumpToCartPage","onUpdateProductDetails","productList","updateVide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K,CAACW,UAAzB;AACA,aAAOX,KAAK,CAACW,UAAb;AACA,YAAMS,WAAW,GAAG,MAAM,KAAKD,sBAAL,CACxBnB,KADwB,CAA1B;;AAGA,UAAIoB,WAAJ,EAAiB;AACfjC,gCAAekC,mBAAf,CAAmCD,WAAnC,EAAgDT,UAAhD;AACD;AACF;AACF;;AAE0C,QAA7BJ,6BAA6B,CACzCP,KADyC,EAEzC;AACA,QAAI,KAAKsB,oBAAT,EAA+B;AAC7B,YAAMX,UAAU,GAAGX,KAAK,CAACW,UAAzB;AACA,aAAOX,KAAK,CAACW,UAAb;AACA,YAAMY,MAAM,GAAG,MAAM,KAAKD,oBAAL,CACnBtB,KADmB,CAArB;;AAGA,UAAIuB,MAAJ,EAAY;AACVpC,gCAAeqC,uBAAf,CAAuCD,MAAvC,EAA+CZ,UAA/C;AACD;AACF;AACF;;AA3JiB;;gBAAd9B,a;;eA8JSA,a","sourcesContent":["import { NativeEventEmitter, Platform } from 'react-native';\n\nimport type AddToCartResult from './models/AddToCartResult';\nimport type {\n AddToCartEvent,\n UpdateProductDetailsEvent,\n WillDisplayProductEvent,\n} from './models/FWEvents';\nimport { FWEventName } from './models/FWEventName';\nimport type Product from './models/Product';\nimport type ProductInfoViewConfiguration from './models/ProductInfoViewConfiguration';\nimport ShoppingModule, {\n ShoppingModuleEventEmitter,\n} from './modules/ShoppingModule';\nimport type { NewNativeContainerProps } from './models/NewNativeContainerProps';\n\nexport type AddToCartCallback = (\n event: AddToCartEvent\n) => Promise<AddToCartResult | undefined | null>;\n\nexport type ClickCartIconCallback = () => Promise<\n NewNativeContainerProps | undefined | null\n>;\n\nexport type CustomClickCartIconCallback = () => Promise<void>;\n\nexport type UpdateProductDetailsCallback = (\n event: UpdateProductDetailsEvent\n) => Promise<Product[] | undefined | null>;\n\nexport type WillDisplayProductCallback = (\n event: WillDisplayProductEvent\n) => Promise<ProductInfoViewConfiguration | undefined | null>;\n\ntype CallbackInfo = { callbackId?: number | string };\n\n/**\n * The entry class of video shopping.\n */\nclass VideoShopping {\n private static _instance?: VideoShopping;\n\n /**\n * This callback is triggered when the user clicks the \"Add to cart\" button.\n *\n * The host app can return an AddToCartResult object to tell FireworkSDK the result of adding to cart.\n */\n public onAddToCart?: AddToCartCallback;\n\n /**\n * This callback is triggered when the user clicks the shopping cart icon.\n *\n * The host app can return NewNativeContainerProps object and we will push a new native container with the props.\n */\n public onClickCartIcon?: ClickCartIconCallback;\n\n /**\n * This callback is triggered when the user clicks the shopping cart icon.\n *\n * The host app can customize the processing logic of clicking the shopping cart icon by setting the callback.\n */\n public get onCustomClickCartIcon(): CustomClickCartIconCallback | undefined {\n return this._onCustomClickCartIcon;\n }\n public set onCustomClickCartIcon(\n value: CustomClickCartIconCallback | undefined\n ) {\n this._onCustomClickCartIcon = value;\n if (Platform.OS === 'ios') {\n ShoppingModule.setCustomClickCartIconEnabled(!!value);\n }\n }\n private _onCustomClickCartIcon?: CustomClickCartIconCallback | undefined;\n\n /**\n * This callback is triggered when the video will be shown.\n *\n * The host app can return a Product list to update the latest product information.\n */\n public onUpdateProductDetails?: UpdateProductDetailsCallback;\n\n /**\n * This callback is triggered when the product will be shown.\n *\n * The host app can return a ProductInfoViewConfiguration object to configure \"Add to cart\" button style and cart icon style.\n */\n public onWillDisplayProduct?: WillDisplayProductCallback;\n\n /**\n * Defaults to true. You can hide the cart icon by setting this property to false.\n */\n public get cartIconVisible(): boolean {\n return this._cartIconVisible;\n }\n public set cartIconVisible(value: boolean) {\n this._cartIconVisible = value;\n ShoppingModule.setCartIconVisible(value);\n }\n private _cartIconVisible: boolean = true;\n\n private get eventEmitter(): NativeEventEmitter {\n return ShoppingModuleEventEmitter;\n }\n\n public static getInstance() {\n if (!VideoShopping._instance) {\n VideoShopping._instance = new VideoShopping();\n }\n\n return VideoShopping._instance!;\n }\n\n private constructor() {\n this.eventEmitter.addListener(FWEventName.AddToCart, (event) => {\n this.handleAddToCartEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.ClickCartIcon, (event) => {\n this.handleClickCartIconEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.UpdateProductDetails, (event) => {\n this.handleUpdateProductDetailsEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.WillDisplayProduct, (event) => {\n this.handleWillDisplayProductEvent(event);\n });\n }\n\n /**\n *\n * @param {number} count The number of items in the host app cart\n */\n public setCartItemCount(count: number) {\n ShoppingModule.setCartItemCount(count);\n }\n\n private async handleAddToCartEvent(event: AddToCartEvent & CallbackInfo) {\n if (this.onAddToCart) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const result = await this.onAddToCart(event as AddToCartEvent);\n if (result) {\n ShoppingModule.updateAddToCartStatus(\n result.res,\n result.tips,\n callbackId!\n );\n }\n }\n }\n\n private async handleClickCartIconEvent(event: CallbackInfo) {\n if (this.onCustomClickCartIcon) {\n this.onCustomClickCartIcon();\n } else if (this.onClickCartIcon) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const props = await this.onClickCartIcon();\n if (callbackId) {\n ShoppingModule.jumpToCartPage(callbackId, props ?? {});\n }\n }\n }\n\n private async handleUpdateProductDetailsEvent(\n event: UpdateProductDetailsEvent & CallbackInfo\n ) {\n if (this.onUpdateProductDetails) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const productList = await this.onUpdateProductDetails(\n event as UpdateProductDetailsEvent\n );\n if (productList) {\n ShoppingModule.updateVideoProducts(productList, callbackId!);\n }\n }\n }\n\n private async handleWillDisplayProductEvent(\n event: WillDisplayProductEvent & CallbackInfo\n ) {\n if (this.onWillDisplayProduct) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const config = await this.onWillDisplayProduct(\n event as WillDisplayProductEvent\n );\n if (config) {\n ShoppingModule.updateProductViewConfig(config, callbackId!);\n }\n }\n }\n}\n\nexport default VideoShopping;\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["ShoppingModule.ts"],"names":["ShoppingModule","NativeModules","Proxy","get","Error","LINKING_ERROR","ShoppingModuleEventEmitter","NativeEventEmitter"],"mappings":";;;;;;;AAAA;;AAGA;;AAGA,MAAMA,cAAc,GAAGC,2BAAcD,cAAd,GACnBC,2BAAcD,cADK,GAEnB,IAAIE,KAAJ,CACE,EADF,EAEE;AACEC,EAAAA,GAAG,GAAG;AACJ,UAAM,IAAIC,KAAJ,CAAUC,6BAAV,CAAN;AACD;;AAHH,CAFF,CAFJ;AA+BA,MAAMC,0BAA0B,GAAG,IAAIC,+BAAJ,CAAuBP,cAAvB,CAAnC;;eAGeA,c","sourcesContent":["import { NativeEventEmitter, NativeModule, NativeModules } from 'react-native';\nimport type Product from '../models/Product';\nimport type ProductInfoViewConfiguration from '../models/ProductInfoViewConfiguration';\nimport { LINKING_ERROR } from '../constants/FWErrorMessage';\nimport type { NewNativeContainerProps } from 'src/models/NewNativeContainerProps';\n\nconst ShoppingModule = NativeModules.ShoppingModule\n ? NativeModules.ShoppingModule\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\ninterface IShoppingModule extends NativeModule {\n init(): void;\n updateVideoProducts(products: Product[], callbackId: number | string): void;\n updateProductViewConfig(\n config: ProductInfoViewConfiguration,\n callbackId: number | string\n ): void;\n updateAddToCartStatus(\n res: string,\n tips: string,\n callbackId: number | string\n ): void;\n jumpToCartPage(\n callbackId: number | string,\n props: NewNativeContainerProps\n ): void;\n setCartIconVisible(visible: boolean): void;\n setCartItemCount(count: number): void;\n}\n\nconst ShoppingModuleEventEmitter = new NativeEventEmitter(ShoppingModule);\nexport { ShoppingModuleEventEmitter };\n\nexport default ShoppingModule as IShoppingModule;\n"]}
1
+ {"version":3,"sources":["ShoppingModule.ts"],"names":["ShoppingModule","NativeModules","Proxy","get","Error","LINKING_ERROR","ShoppingModuleEventEmitter","NativeEventEmitter"],"mappings":";;;;;;;AAAA;;AAGA;;AAGA,MAAMA,cAAc,GAAGC,2BAAcD,cAAd,GACnBC,2BAAcD,cADK,GAEnB,IAAIE,KAAJ,CACE,EADF,EAEE;AACEC,EAAAA,GAAG,GAAG;AACJ,UAAM,IAAIC,KAAJ,CAAUC,6BAAV,CAAN;AACD;;AAHH,CAFF,CAFJ;AAgCA,MAAMC,0BAA0B,GAAG,IAAIC,+BAAJ,CAAuBP,cAAvB,CAAnC;;eAGeA,c","sourcesContent":["import { NativeEventEmitter, NativeModule, NativeModules } from 'react-native';\nimport type Product from '../models/Product';\nimport type ProductInfoViewConfiguration from '../models/ProductInfoViewConfiguration';\nimport { LINKING_ERROR } from '../constants/FWErrorMessage';\nimport type { NewNativeContainerProps } from 'src/models/NewNativeContainerProps';\n\nconst ShoppingModule = NativeModules.ShoppingModule\n ? NativeModules.ShoppingModule\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\ninterface IShoppingModule extends NativeModule {\n init(): void;\n updateVideoProducts(products: Product[], callbackId: number | string): void;\n updateProductViewConfig(\n config: ProductInfoViewConfiguration,\n callbackId: number | string\n ): void;\n updateAddToCartStatus(\n res: string,\n tips: string,\n callbackId: number | string\n ): void;\n jumpToCartPage(\n callbackId: number | string,\n props: NewNativeContainerProps\n ): void;\n setCartIconVisible(visible: boolean): void;\n setCartItemCount(count: number): void;\n setCustomClickCartIconEnabled(enabled: boolean): Promise<void>; // Only supported on iOS\n}\n\nconst ShoppingModuleEventEmitter = new NativeEventEmitter(ShoppingModule);\nexport { ShoppingModuleEventEmitter };\n\nexport default ShoppingModule as IShoppingModule;\n"]}
@@ -1,5 +1,6 @@
1
1
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
 
3
+ import { Platform } from 'react-native';
3
4
  import { FWEventName } from './models/FWEventName';
4
5
  import ShoppingModule, { ShoppingModuleEventEmitter } from './modules/ShoppingModule';
5
6
 
@@ -16,20 +17,25 @@ class VideoShopping {
16
17
  /**
17
18
  * This callback is triggered when the user clicks the shopping cart icon.
18
19
  *
19
- * The host app can return a React.Node to integrate custom cart page to shopping flow.
20
+ * The host app can return NewNativeContainerProps object and we will push a new native container with the props.
20
21
  */
21
22
 
22
23
  /**
23
- * This callback is triggered when the video will be shown.
24
+ * This callback is triggered when the user clicks the shopping cart icon.
24
25
  *
25
- * The host app can return a Product list to update the latest product information.
26
+ * The host app can customize the processing logic of clicking the shopping cart icon by setting the callback.
26
27
  */
28
+ get onCustomClickCartIcon() {
29
+ return this._onCustomClickCartIcon;
30
+ }
27
31
 
28
- /**
29
- * This callback is triggered when the product will be shown.
30
- *
31
- * The host app can return a ProductInfoViewConfiguration object to configure "Add to cart" button style and cart icon style.
32
- */
32
+ set onCustomClickCartIcon(value) {
33
+ this._onCustomClickCartIcon = value;
34
+
35
+ if (Platform.OS === 'ios') {
36
+ ShoppingModule.setCustomClickCartIconEnabled(!!value);
37
+ }
38
+ }
33
39
 
34
40
  /**
35
41
  * Defaults to true. You can hide the cart icon by setting this property to false.
@@ -60,6 +66,8 @@ class VideoShopping {
60
66
 
61
67
  _defineProperty(this, "onClickCartIcon", void 0);
62
68
 
69
+ _defineProperty(this, "_onCustomClickCartIcon", void 0);
70
+
63
71
  _defineProperty(this, "onUpdateProductDetails", void 0);
64
72
 
65
73
  _defineProperty(this, "onWillDisplayProduct", void 0);
@@ -102,7 +110,9 @@ class VideoShopping {
102
110
  }
103
111
 
104
112
  async handleClickCartIconEvent(event) {
105
- if (this.onClickCartIcon) {
113
+ if (this.onCustomClickCartIcon) {
114
+ this.onCustomClickCartIcon();
115
+ } else if (this.onClickCartIcon) {
106
116
  const callbackId = event.callbackId;
107
117
  delete event.callbackId;
108
118
  const props = await this.onClickCartIcon();
@@ -1 +1 @@
1
- {"version":3,"sources":["VideoShopping.ts"],"names":["FWEventName","ShoppingModule","ShoppingModuleEventEmitter","VideoShopping","cartIconVisible","_cartIconVisible","value","setCartIconVisible","eventEmitter","getInstance","_instance","constructor","addListener","AddToCart","event","handleAddToCartEvent","ClickCartIcon","handleClickCartIconEvent","UpdateProductDetails","handleUpdateProductDetailsEvent","WillDisplayProduct","handleWillDisplayProductEvent","setCartItemCount","count","onAddToCart","callbackId","result","updateAddToCartStatus","res","tips","onClickCartIcon","props","jumpToCartPage","onUpdateProductDetails","productList","updateVideoProducts","onWillDisplayProduct","config","updateProductViewConfig"],"mappings":";;AAQA,SAASA,WAAT,QAA4B,sBAA5B;AAGA,OAAOC,cAAP,IACEC,0BADF,QAEO,0BAFP;;AAuBA;AACA;AACA;AACA,MAAMC,aAAN,CAAoB;AAGlB;AACF;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;;AAGE;AACF;AACA;AAC4B,MAAfC,eAAe,GAAY;AACpC,WAAO,KAAKC,gBAAZ;AACD;;AACyB,MAAfD,eAAe,CAACE,KAAD,EAAiB;AACzC,SAAKD,gBAAL,GAAwBC,KAAxB;AACAL,IAAAA,cAAc,CAACM,kBAAf,CAAkCD,KAAlC;AACD;;AAGuB,MAAZE,YAAY,GAAuB;AAC7C,WAAON,0BAAP;AACD;;AAEwB,SAAXO,WAAW,GAAG;AAC1B,QAAI,CAACN,aAAa,CAACO,SAAnB,EAA8B;AAC5BP,MAAAA,aAAa,CAACO,SAAd,GAA0B,IAAIP,aAAJ,EAA1B;AACD;;AAED,WAAOA,aAAa,CAACO,SAArB;AACD;;AAEOC,EAAAA,WAAW,GAAG;AAAA;;AAAA;;AAAA;;AAAA;;AAAA,8CAdc,IAcd;;AACpB,SAAKH,YAAL,CAAkBI,WAAlB,CAA8BZ,WAAW,CAACa,SAA1C,EAAsDC,KAAD,IAAW;AAC9D,WAAKC,oBAAL,CAA0BD,KAA1B;AACD,KAFD;AAIA,SAAKN,YAAL,CAAkBI,WAAlB,CAA8BZ,WAAW,CAACgB,aAA1C,EAA0DF,KAAD,IAAW;AAClE,WAAKG,wBAAL,CAA8BH,KAA9B;AACD,KAFD;AAIA,SAAKN,YAAL,CAAkBI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W,UAAb;AACA,YAAMS,WAAW,GAAG,MAAM,KAAKD,sBAAL,CACxBnB,KADwB,CAA1B;;AAGA,UAAIoB,WAAJ,EAAiB;AACfjC,QAAAA,cAAc,CAACkC,mBAAf,CAAmCD,WAAnC,EAAgDT,UAAhD;AACD;AACF;AACF;;AAE0C,QAA7BJ,6BAA6B,CACzCP,KADyC,EAEzC;AACA,QAAI,KAAKsB,oBAAT,EAA+B;AAC7B,YAAMX,UAAU,GAAGX,KAAK,CAACW,UAAzB;AACA,aAAOX,KAAK,CAACW,UAAb;AACA,YAAMY,MAAM,GAAG,MAAM,KAAKD,oBAAL,CACnBtB,KADmB,CAArB;;AAGA,UAAIuB,MAAJ,EAAY;AACVpC,QAAAA,cAAc,CAACqC,uBAAf,CAAuCD,MAAvC,EAA+CZ,UAA/C;AACD;AACF;AACF;;AAvIiB;;gBAAdtB,a;;AA0IN,eAAeA,aAAf","sourcesContent":["import type { NativeEventEmitter } from 'react-native';\n\nimport type AddToCartResult from './models/AddToCartResult';\nimport type {\n AddToCartEvent,\n UpdateProductDetailsEvent,\n WillDisplayProductEvent,\n} from './models/FWEvents';\nimport { FWEventName } from './models/FWEventName';\nimport type Product from './models/Product';\nimport type ProductInfoViewConfiguration from './models/ProductInfoViewConfiguration';\nimport ShoppingModule, {\n ShoppingModuleEventEmitter,\n} from './modules/ShoppingModule';\nimport type { NewNativeContainerProps } from './models/NewNativeContainerProps';\n\nexport type AddToCartCallback = (\n event: AddToCartEvent\n) => Promise<AddToCartResult | undefined | null>;\n\nexport type ClickCartIconCallback = () => Promise<\n NewNativeContainerProps | undefined | null\n>;\n\nexport type UpdateProductDetailsCallback = (\n event: UpdateProductDetailsEvent\n) => Promise<Product[] | undefined | null>;\n\nexport type WillDisplayProductCallback = (\n event: WillDisplayProductEvent\n) => Promise<ProductInfoViewConfiguration | undefined | null>;\n\ntype CallbackInfo = { callbackId?: number | string };\n\n/**\n * The entry class of video shopping.\n */\nclass VideoShopping {\n private static _instance?: VideoShopping;\n\n /**\n * This callback is triggered when the user clicks the \"Add to cart\" button.\n *\n * The host app can return an AddToCartResult object to tell FireworkSDK the result of adding to cart.\n */\n public onAddToCart?: AddToCartCallback;\n\n /**\n * This callback is triggered when the user clicks the shopping cart icon.\n *\n * The host app can return a React.Node to integrate custom cart page to shopping flow.\n */\n public onClickCartIcon?: ClickCartIconCallback;\n\n /**\n * This callback is triggered when the video will be shown.\n *\n * The host app can return a Product list to update the latest product information.\n */\n public onUpdateProductDetails?: UpdateProductDetailsCallback;\n\n /**\n * This callback is triggered when the product will be shown.\n *\n * The host app can return a ProductInfoViewConfiguration object to configure \"Add to cart\" button style and cart icon style.\n */\n public onWillDisplayProduct?: WillDisplayProductCallback;\n\n /**\n * Defaults to true. You can hide the cart icon by setting this property to false.\n */\n public get cartIconVisible(): boolean {\n return this._cartIconVisible;\n }\n public set cartIconVisible(value: boolean) {\n this._cartIconVisible = value;\n ShoppingModule.setCartIconVisible(value);\n }\n private _cartIconVisible: boolean = true;\n\n private get eventEmitter(): NativeEventEmitter {\n return ShoppingModuleEventEmitter;\n }\n\n public static getInstance() {\n if (!VideoShopping._instance) {\n VideoShopping._instance = new VideoShopping();\n }\n\n return VideoShopping._instance!;\n }\n\n private constructor() {\n this.eventEmitter.addListener(FWEventName.AddToCart, (event) => {\n this.handleAddToCartEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.ClickCartIcon, (event) => {\n this.handleClickCartIconEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.UpdateProductDetails, (event) => {\n this.handleUpdateProductDetailsEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.WillDisplayProduct, (event) => {\n this.handleWillDisplayProductEvent(event);\n });\n }\n\n /**\n *\n * @param {number} count The number of items in the host app cart\n */\n public setCartItemCount(count: number) {\n ShoppingModule.setCartItemCount(count);\n }\n\n private async handleAddToCartEvent(event: AddToCartEvent & CallbackInfo) {\n if (this.onAddToCart) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const result = await this.onAddToCart(event as AddToCartEvent);\n if (result) {\n ShoppingModule.updateAddToCartStatus(\n result.res,\n result.tips,\n callbackId!\n );\n }\n }\n }\n\n private async handleClickCartIconEvent(event: CallbackInfo) {\n if (this.onClickCartIcon) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const props = await this.onClickCartIcon();\n if (callbackId) {\n ShoppingModule.jumpToCartPage(callbackId, props ?? {});\n }\n }\n }\n\n private async handleUpdateProductDetailsEvent(\n event: UpdateProductDetailsEvent & CallbackInfo\n ) {\n if (this.onUpdateProductDetails) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const productList = await this.onUpdateProductDetails(\n event as UpdateProductDetailsEvent\n );\n if (productList) {\n ShoppingModule.updateVideoProducts(productList, callbackId!);\n }\n }\n }\n\n private async handleWillDisplayProductEvent(\n event: WillDisplayProductEvent & CallbackInfo\n ) {\n if (this.onWillDisplayProduct) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const config = await this.onWillDisplayProduct(\n event as WillDisplayProductEvent\n );\n if (config) {\n ShoppingModule.updateProductViewConfig(config, callbackId!);\n }\n }\n }\n}\n\nexport default VideoShopping;\n"]}
1
+ {"version":3,"sources":["VideoShopping.ts"],"names":["Platform","FWEventName","ShoppingModule","ShoppingModuleEventEmitter","VideoShopping","onCustomClickCartIcon","_onCustomClickCartIcon","value","OS","setCustomClickCartIconEnabled","cartIconVisible","_cartIconVisible","setCartIconVisible","eventEmitter","getInstance","_instance","constructor","addListener","AddToCart","event","handleAddToCartEvent","ClickCartIcon","handleClickCartIconEvent","UpdateProductDetails","handleUpdateProductDetailsEvent","WillDisplayProduct","handleWillDisplayProductEvent","setCartItemCount","count","onAddToCart","callbackId","result","updateAddToCartStatus","res","tips","onClickCartIcon","props","jumpToCartPage","onUpdateProductDetails","productList","updateVideoProducts","onWillDisplayProduct","config","updateProductViewConfig"],"mappings":";;AAAA,SAA6BA,QAA7B,QAA6C,cAA7C;AAQA,SAASC,WAAT,QAA4B,sBAA5B;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B,sBAAT,EAAiC;AAC/B,YAAMR,UAAU,GAAGX,KAAK,CAACW,UAAzB;AACA,aAAOX,KAAK,CAACW,UAAb;AACA,YAAMS,WAAW,GAAG,MAAM,KAAKD,sBAAL,CACxBnB,KADwB,CAA1B;;AAGA,UAAIoB,WAAJ,EAAiB;AACfrC,QAAAA,cAAc,CAACsC,mBAAf,CAAmCD,WAAnC,EAAgDT,UAAhD;AACD;AACF;AACF;;AAE0C,QAA7BJ,6BAA6B,CACzCP,KADyC,EAEzC;AACA,QAAI,KAAKsB,oBAAT,EAA+B;AAC7B,YAAMX,UAAU,GAAGX,KAAK,CAACW,UAAzB;AACA,aAAOX,KAAK,CAACW,UAAb;AACA,YAAMY,MAAM,GAAG,MAAM,KAAKD,oBAAL,CACnBtB,KADmB,CAArB;;AAGA,UAAIuB,MAAJ,EAAY;AACVxC,QAAAA,cAAc,CAACyC,uBAAf,CAAuCD,MAAvC,EAA+CZ,UAA/C;AACD;AACF;AACF;;AA3JiB;;gBAAd1B,a;;AA8JN,eAAeA,aAAf","sourcesContent":["import { NativeEventEmitter, Platform } from 'react-native';\n\nimport type AddToCartResult from './models/AddToCartResult';\nimport type {\n AddToCartEvent,\n UpdateProductDetailsEvent,\n WillDisplayProductEvent,\n} from './models/FWEvents';\nimport { FWEventName } from './models/FWEventName';\nimport type Product from './models/Product';\nimport type ProductInfoViewConfiguration from './models/ProductInfoViewConfiguration';\nimport ShoppingModule, {\n ShoppingModuleEventEmitter,\n} from './modules/ShoppingModule';\nimport type { NewNativeContainerProps } from './models/NewNativeContainerProps';\n\nexport type AddToCartCallback = (\n event: AddToCartEvent\n) => Promise<AddToCartResult | undefined | null>;\n\nexport type ClickCartIconCallback = () => Promise<\n NewNativeContainerProps | undefined | null\n>;\n\nexport type CustomClickCartIconCallback = () => Promise<void>;\n\nexport type UpdateProductDetailsCallback = (\n event: UpdateProductDetailsEvent\n) => Promise<Product[] | undefined | null>;\n\nexport type WillDisplayProductCallback = (\n event: WillDisplayProductEvent\n) => Promise<ProductInfoViewConfiguration | undefined | null>;\n\ntype CallbackInfo = { callbackId?: number | string };\n\n/**\n * The entry class of video shopping.\n */\nclass VideoShopping {\n private static _instance?: VideoShopping;\n\n /**\n * This callback is triggered when the user clicks the \"Add to cart\" button.\n *\n * The host app can return an AddToCartResult object to tell FireworkSDK the result of adding to cart.\n */\n public onAddToCart?: AddToCartCallback;\n\n /**\n * This callback is triggered when the user clicks the shopping cart icon.\n *\n * The host app can return NewNativeContainerProps object and we will push a new native container with the props.\n */\n public onClickCartIcon?: ClickCartIconCallback;\n\n /**\n * This callback is triggered when the user clicks the shopping cart icon.\n *\n * The host app can customize the processing logic of clicking the shopping cart icon by setting the callback.\n */\n public get onCustomClickCartIcon(): CustomClickCartIconCallback | undefined {\n return this._onCustomClickCartIcon;\n }\n public set onCustomClickCartIcon(\n value: CustomClickCartIconCallback | undefined\n ) {\n this._onCustomClickCartIcon = value;\n if (Platform.OS === 'ios') {\n ShoppingModule.setCustomClickCartIconEnabled(!!value);\n }\n }\n private _onCustomClickCartIcon?: CustomClickCartIconCallback | undefined;\n\n /**\n * This callback is triggered when the video will be shown.\n *\n * The host app can return a Product list to update the latest product information.\n */\n public onUpdateProductDetails?: UpdateProductDetailsCallback;\n\n /**\n * This callback is triggered when the product will be shown.\n *\n * The host app can return a ProductInfoViewConfiguration object to configure \"Add to cart\" button style and cart icon style.\n */\n public onWillDisplayProduct?: WillDisplayProductCallback;\n\n /**\n * Defaults to true. You can hide the cart icon by setting this property to false.\n */\n public get cartIconVisible(): boolean {\n return this._cartIconVisible;\n }\n public set cartIconVisible(value: boolean) {\n this._cartIconVisible = value;\n ShoppingModule.setCartIconVisible(value);\n }\n private _cartIconVisible: boolean = true;\n\n private get eventEmitter(): NativeEventEmitter {\n return ShoppingModuleEventEmitter;\n }\n\n public static getInstance() {\n if (!VideoShopping._instance) {\n VideoShopping._instance = new VideoShopping();\n }\n\n return VideoShopping._instance!;\n }\n\n private constructor() {\n this.eventEmitter.addListener(FWEventName.AddToCart, (event) => {\n this.handleAddToCartEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.ClickCartIcon, (event) => {\n this.handleClickCartIconEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.UpdateProductDetails, (event) => {\n this.handleUpdateProductDetailsEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.WillDisplayProduct, (event) => {\n this.handleWillDisplayProductEvent(event);\n });\n }\n\n /**\n *\n * @param {number} count The number of items in the host app cart\n */\n public setCartItemCount(count: number) {\n ShoppingModule.setCartItemCount(count);\n }\n\n private async handleAddToCartEvent(event: AddToCartEvent & CallbackInfo) {\n if (this.onAddToCart) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const result = await this.onAddToCart(event as AddToCartEvent);\n if (result) {\n ShoppingModule.updateAddToCartStatus(\n result.res,\n result.tips,\n callbackId!\n );\n }\n }\n }\n\n private async handleClickCartIconEvent(event: CallbackInfo) {\n if (this.onCustomClickCartIcon) {\n this.onCustomClickCartIcon();\n } else if (this.onClickCartIcon) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const props = await this.onClickCartIcon();\n if (callbackId) {\n ShoppingModule.jumpToCartPage(callbackId, props ?? {});\n }\n }\n }\n\n private async handleUpdateProductDetailsEvent(\n event: UpdateProductDetailsEvent & CallbackInfo\n ) {\n if (this.onUpdateProductDetails) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const productList = await this.onUpdateProductDetails(\n event as UpdateProductDetailsEvent\n );\n if (productList) {\n ShoppingModule.updateVideoProducts(productList, callbackId!);\n }\n }\n }\n\n private async handleWillDisplayProductEvent(\n event: WillDisplayProductEvent & CallbackInfo\n ) {\n if (this.onWillDisplayProduct) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n const config = await this.onWillDisplayProduct(\n event as WillDisplayProductEvent\n );\n if (config) {\n ShoppingModule.updateProductViewConfig(config, callbackId!);\n }\n }\n }\n}\n\nexport default VideoShopping;\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["ShoppingModule.ts"],"names":["NativeEventEmitter","NativeModules","LINKING_ERROR","ShoppingModule","Proxy","get","Error","ShoppingModuleEventEmitter"],"mappings":"AAAA,SAASA,kBAAT,EAA2CC,aAA3C,QAAgE,cAAhE;AAGA,SAASC,aAAT,QAA8B,6BAA9B;AAGA,MAAMC,cAAc,GAAGF,aAAa,CAACE,cAAd,GACnBF,aAAa,CAACE,cADK,GAEnB,IAAIC,KAAJ,CACE,EADF,EAEE;AACEC,EAAAA,GAAG,GAAG;AACJ,UAAM,IAAIC,KAAJ,CAAUJ,aAAV,CAAN;AACD;;AAHH,CAFF,CAFJ;AA+BA,MAAMK,0BAA0B,GAAG,IAAIP,kBAAJ,CAAuBG,cAAvB,CAAnC;AACA,SAASI,0BAAT;AAEA,eAAeJ,cAAf","sourcesContent":["import { NativeEventEmitter, NativeModule, NativeModules } from 'react-native';\nimport type Product from '../models/Product';\nimport type ProductInfoViewConfiguration from '../models/ProductInfoViewConfiguration';\nimport { LINKING_ERROR } from '../constants/FWErrorMessage';\nimport type { NewNativeContainerProps } from 'src/models/NewNativeContainerProps';\n\nconst ShoppingModule = NativeModules.ShoppingModule\n ? NativeModules.ShoppingModule\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\ninterface IShoppingModule extends NativeModule {\n init(): void;\n updateVideoProducts(products: Product[], callbackId: number | string): void;\n updateProductViewConfig(\n config: ProductInfoViewConfiguration,\n callbackId: number | string\n ): void;\n updateAddToCartStatus(\n res: string,\n tips: string,\n callbackId: number | string\n ): void;\n jumpToCartPage(\n callbackId: number | string,\n props: NewNativeContainerProps\n ): void;\n setCartIconVisible(visible: boolean): void;\n setCartItemCount(count: number): void;\n}\n\nconst ShoppingModuleEventEmitter = new NativeEventEmitter(ShoppingModule);\nexport { ShoppingModuleEventEmitter };\n\nexport default ShoppingModule as IShoppingModule;\n"]}
1
+ {"version":3,"sources":["ShoppingModule.ts"],"names":["NativeEventEmitter","NativeModules","LINKING_ERROR","ShoppingModule","Proxy","get","Error","ShoppingModuleEventEmitter"],"mappings":"AAAA,SAASA,kBAAT,EAA2CC,aAA3C,QAAgE,cAAhE;AAGA,SAASC,aAAT,QAA8B,6BAA9B;AAGA,MAAMC,cAAc,GAAGF,aAAa,CAACE,cAAd,GACnBF,aAAa,CAACE,cADK,GAEnB,IAAIC,KAAJ,CACE,EADF,EAEE;AACEC,EAAAA,GAAG,GAAG;AACJ,UAAM,IAAIC,KAAJ,CAAUJ,aAAV,CAAN;AACD;;AAHH,CAFF,CAFJ;AAgCA,MAAMK,0BAA0B,GAAG,IAAIP,kBAAJ,CAAuBG,cAAvB,CAAnC;AACA,SAASI,0BAAT;AAEA,eAAeJ,cAAf","sourcesContent":["import { NativeEventEmitter, NativeModule, NativeModules } from 'react-native';\nimport type Product from '../models/Product';\nimport type ProductInfoViewConfiguration from '../models/ProductInfoViewConfiguration';\nimport { LINKING_ERROR } from '../constants/FWErrorMessage';\nimport type { NewNativeContainerProps } from 'src/models/NewNativeContainerProps';\n\nconst ShoppingModule = NativeModules.ShoppingModule\n ? NativeModules.ShoppingModule\n : new Proxy(\n {},\n {\n get() {\n throw new Error(LINKING_ERROR);\n },\n }\n );\n\ninterface IShoppingModule extends NativeModule {\n init(): void;\n updateVideoProducts(products: Product[], callbackId: number | string): void;\n updateProductViewConfig(\n config: ProductInfoViewConfiguration,\n callbackId: number | string\n ): void;\n updateAddToCartStatus(\n res: string,\n tips: string,\n callbackId: number | string\n ): void;\n jumpToCartPage(\n callbackId: number | string,\n props: NewNativeContainerProps\n ): void;\n setCartIconVisible(visible: boolean): void;\n setCartItemCount(count: number): void;\n setCustomClickCartIconEnabled(enabled: boolean): Promise<void>; // Only supported on iOS\n}\n\nconst ShoppingModuleEventEmitter = new NativeEventEmitter(ShoppingModule);\nexport { ShoppingModuleEventEmitter };\n\nexport default ShoppingModule as IShoppingModule;\n"]}
@@ -5,6 +5,7 @@ import type ProductInfoViewConfiguration from './models/ProductInfoViewConfigura
5
5
  import type { NewNativeContainerProps } from './models/NewNativeContainerProps';
6
6
  export declare type AddToCartCallback = (event: AddToCartEvent) => Promise<AddToCartResult | undefined | null>;
7
7
  export declare type ClickCartIconCallback = () => Promise<NewNativeContainerProps | undefined | null>;
8
+ export declare type CustomClickCartIconCallback = () => Promise<void>;
8
9
  export declare type UpdateProductDetailsCallback = (event: UpdateProductDetailsEvent) => Promise<Product[] | undefined | null>;
9
10
  export declare type WillDisplayProductCallback = (event: WillDisplayProductEvent) => Promise<ProductInfoViewConfiguration | undefined | null>;
10
11
  /**
@@ -21,9 +22,17 @@ declare class VideoShopping {
21
22
  /**
22
23
  * This callback is triggered when the user clicks the shopping cart icon.
23
24
  *
24
- * The host app can return a React.Node to integrate custom cart page to shopping flow.
25
+ * The host app can return NewNativeContainerProps object and we will push a new native container with the props.
25
26
  */
26
27
  onClickCartIcon?: ClickCartIconCallback;
28
+ /**
29
+ * This callback is triggered when the user clicks the shopping cart icon.
30
+ *
31
+ * The host app can customize the processing logic of clicking the shopping cart icon by setting the callback.
32
+ */
33
+ get onCustomClickCartIcon(): CustomClickCartIconCallback | undefined;
34
+ set onCustomClickCartIcon(value: CustomClickCartIconCallback | undefined);
35
+ private _onCustomClickCartIcon?;
27
36
  /**
28
37
  * This callback is triggered when the video will be shown.
29
38
  *
@@ -10,6 +10,7 @@ interface IShoppingModule extends NativeModule {
10
10
  jumpToCartPage(callbackId: number | string, props: NewNativeContainerProps): void;
11
11
  setCartIconVisible(visible: boolean): void;
12
12
  setCartItemCount(count: number): void;
13
+ setCustomClickCartIconEnabled(enabled: boolean): Promise<void>;
13
14
  }
14
15
  declare const ShoppingModuleEventEmitter: NativeEventEmitter;
15
16
  export { ShoppingModuleEventEmitter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-firework-sdk",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "Firework React Native SDK",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -1,4 +1,4 @@
1
- import type { NativeEventEmitter } from 'react-native';
1
+ import { NativeEventEmitter, Platform } from 'react-native';
2
2
 
3
3
  import type AddToCartResult from './models/AddToCartResult';
4
4
  import type {
@@ -22,6 +22,8 @@ export type ClickCartIconCallback = () => Promise<
22
22
  NewNativeContainerProps | undefined | null
23
23
  >;
24
24
 
25
+ export type CustomClickCartIconCallback = () => Promise<void>;
26
+
25
27
  export type UpdateProductDetailsCallback = (
26
28
  event: UpdateProductDetailsEvent
27
29
  ) => Promise<Product[] | undefined | null>;
@@ -48,10 +50,28 @@ class VideoShopping {
48
50
  /**
49
51
  * This callback is triggered when the user clicks the shopping cart icon.
50
52
  *
51
- * The host app can return a React.Node to integrate custom cart page to shopping flow.
53
+ * The host app can return NewNativeContainerProps object and we will push a new native container with the props.
52
54
  */
53
55
  public onClickCartIcon?: ClickCartIconCallback;
54
56
 
57
+ /**
58
+ * This callback is triggered when the user clicks the shopping cart icon.
59
+ *
60
+ * The host app can customize the processing logic of clicking the shopping cart icon by setting the callback.
61
+ */
62
+ public get onCustomClickCartIcon(): CustomClickCartIconCallback | undefined {
63
+ return this._onCustomClickCartIcon;
64
+ }
65
+ public set onCustomClickCartIcon(
66
+ value: CustomClickCartIconCallback | undefined
67
+ ) {
68
+ this._onCustomClickCartIcon = value;
69
+ if (Platform.OS === 'ios') {
70
+ ShoppingModule.setCustomClickCartIconEnabled(!!value);
71
+ }
72
+ }
73
+ private _onCustomClickCartIcon?: CustomClickCartIconCallback | undefined;
74
+
55
75
  /**
56
76
  * This callback is triggered when the video will be shown.
57
77
  *
@@ -132,7 +152,9 @@ class VideoShopping {
132
152
  }
133
153
 
134
154
  private async handleClickCartIconEvent(event: CallbackInfo) {
135
- if (this.onClickCartIcon) {
155
+ if (this.onCustomClickCartIcon) {
156
+ this.onCustomClickCartIcon();
157
+ } else if (this.onClickCartIcon) {
136
158
  const callbackId = event.callbackId;
137
159
  delete event.callbackId;
138
160
  const props = await this.onClickCartIcon();
@@ -33,6 +33,7 @@ interface IShoppingModule extends NativeModule {
33
33
  ): void;
34
34
  setCartIconVisible(visible: boolean): void;
35
35
  setCartItemCount(count: number): void;
36
+ setCustomClickCartIconEnabled(enabled: boolean): Promise<void>; // Only supported on iOS
36
37
  }
37
38
 
38
39
  const ShoppingModuleEventEmitter = new NativeEventEmitter(ShoppingModule);