react-native-firework-sdk 1.9.0-beta.3 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/fireworksdk/bridge/utils/FWLanguageUtil.kt +47 -14
- package/ios/Components/StoryBlock.swift +28 -1
- package/ios/Components/StoryBlockManager.m +32 -0
- package/ios/Components/VideoFeed.swift +1 -24
- package/ios/Components/VideoFeedManager.m +11 -6
- package/ios/FireworkSdk-Bridging-Header.h +0 -6
- package/ios/FireworkSdk.xcodeproj/project.pbxproj +4 -0
- package/ios/Models/NativeToRN/FireworkEventName.swift +2 -1
- package/ios/Models/RNToNative/RCTConvert+Shopping.swift +21 -0
- package/ios/Models/RNToNative/RCTConvert+VideoFeed.swift +27 -0
- package/ios/Modules/FWNavigatorModule/FWNavigatorModule.swift +4 -4
- package/ios/Modules/FireworkSDKModule/FireworkSDKModule.m +1 -1
- package/ios/Modules/FireworkSDKModule/FireworkSDKModule.swift +4 -4
- package/ios/Modules/Shopping/ProductInfoViewConfiguration.swift +13 -0
- package/ios/Modules/Shopping/ShoppingCTAResult.swift +16 -0
- package/ios/Modules/Shopping/ShoppingModule.m +2 -1
- package/ios/Modules/Shopping/ShoppingModule.swift +103 -30
- package/ios/Support/MultiHostStreaming/FWMultiHostStreaming.podspec +24 -0
- package/ios/Support/MultiHostStreaming/src/MultiHostStreamingSDK.swift +17 -0
- package/ios/Utils/AppLanguage/FWAppLanguageManager.swift +23 -2
- package/ios/Utils/AppLanguage/FWLanguageUtil.swift +5 -1
- package/ios/Utils/AppLanguage/UIImageView+FWSwizzle.swift +3 -3
- package/ios/Utils/FWSwizzleLoader.m +5 -0
- package/ios/scripts/react_native_firework_sdk_pods.rb +31 -0
- package/lib/commonjs/FWNavigator.js +2 -2
- package/lib/commonjs/FWNavigator.js.map +1 -1
- package/lib/commonjs/FireworkSDK.js +14 -1
- package/lib/commonjs/FireworkSDK.js.map +1 -1
- package/lib/commonjs/VideoShopping.js +71 -22
- package/lib/commonjs/VideoShopping.js.map +1 -1
- package/lib/commonjs/components/StoryBlock.js +156 -106
- package/lib/commonjs/components/StoryBlock.js.map +1 -1
- package/lib/commonjs/components/VideoFeed.js +29 -15
- package/lib/commonjs/components/VideoFeed.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/FWEventName.js +1 -0
- package/lib/commonjs/models/FWEventName.js.map +1 -1
- package/lib/commonjs/models/ShoppingCTAResult.js +2 -0
- package/lib/commonjs/models/ShoppingCTAResult.js.map +1 -0
- package/lib/commonjs/modules/FireworkSDKModule.js.map +1 -1
- package/lib/commonjs/modules/ShoppingModule.js.map +1 -1
- package/lib/module/FWNavigator.js +5 -2
- package/lib/module/FWNavigator.js.map +1 -1
- package/lib/module/FireworkSDK.js +14 -1
- package/lib/module/FireworkSDK.js.map +1 -1
- package/lib/module/VideoShopping.js +70 -23
- package/lib/module/VideoShopping.js.map +1 -1
- package/lib/module/components/StoryBlock.js +146 -103
- package/lib/module/components/StoryBlock.js.map +1 -1
- package/lib/module/components/VideoFeed.js +36 -12
- package/lib/module/components/VideoFeed.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/FWEventName.js +1 -0
- package/lib/module/models/FWEventName.js.map +1 -1
- package/lib/module/models/ShoppingCTAResult.js +2 -0
- package/lib/module/models/ShoppingCTAResult.js.map +1 -0
- package/lib/module/modules/FireworkSDKModule.js.map +1 -1
- package/lib/module/modules/ShoppingModule.js.map +1 -1
- package/lib/typescript/FWNavigator.d.ts +5 -2
- package/lib/typescript/FireworkSDK.d.ts +14 -3
- package/lib/typescript/VideoShopping.d.ts +26 -5
- package/lib/typescript/components/StoryBlock.d.ts +21 -11
- package/lib/typescript/components/VideoFeed.d.ts +20 -4
- package/lib/typescript/index.d.ts +6 -5
- package/lib/typescript/models/AddToCartResult.d.ts +4 -0
- package/lib/typescript/models/FWEventName.d.ts +1 -0
- package/lib/typescript/models/FWEvents.d.ts +27 -0
- package/lib/typescript/models/ProductInfoViewConfiguration.d.ts +35 -0
- package/lib/typescript/models/ShoppingCTAResult.d.ts +11 -0
- package/lib/typescript/models/VideoFeedConfiguration.d.ts +2 -1
- package/lib/typescript/models/VideoPlayerConfiguration.d.ts +2 -0
- package/lib/typescript/modules/FireworkSDKModule.d.ts +1 -2
- package/lib/typescript/modules/ShoppingModule.d.ts +2 -0
- package/package.json +5 -4
- package/react-native-firework-sdk.podspec +14 -9
- package/src/FWNavigator.ts +5 -2
- package/src/FireworkSDK.ts +15 -4
- package/src/VideoShopping.ts +107 -32
- package/src/components/StoryBlock.tsx +158 -84
- package/src/components/VideoFeed.tsx +28 -11
- package/src/index.ts +15 -1
- package/src/models/AddToCartResult.ts +4 -0
- package/src/models/FWEventName.ts +1 -0
- package/src/models/FWEvents.ts +28 -0
- package/src/models/ProductInfoViewConfiguration.ts +37 -0
- package/src/models/ShoppingCTAResult.ts +11 -0
- package/src/models/VideoFeedConfiguration.ts +2 -1
- package/src/models/VideoPlayerConfiguration.ts +2 -0
- package/src/modules/FireworkSDKModule.ts +1 -2
- package/src/modules/ShoppingModule.ts +6 -1
- package/ios/scripts/firework_sdk_pods.rb +0 -3
|
@@ -14,6 +14,12 @@ class VideoShopping {
|
|
|
14
14
|
*
|
|
15
15
|
* The host apps can return an AddToCartResult object to tell FireworkSDK the result of adding to cart.
|
|
16
16
|
* If the host apps want to customize the processing logic of clicking "Add to cart" button, they could return null or undefined in the callback.
|
|
17
|
+
* @deprecated The callback will be deprecated since RN SDK V2.1.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* This callback is triggered when the user clicks the "Add to cart" or "Shop now" button.
|
|
22
|
+
* The host app can return a ShoppingCTAResult object to tell SDK how to handle the result.
|
|
17
23
|
*/
|
|
18
24
|
|
|
19
25
|
/**
|
|
@@ -21,6 +27,8 @@ class VideoShopping {
|
|
|
21
27
|
*
|
|
22
28
|
* The host app can return NewNativeContainerProps object
|
|
23
29
|
* and we will push a new native container with the props.
|
|
30
|
+
*
|
|
31
|
+
* @deprecated The property will be deprecated since RN SDK V2.0.
|
|
24
32
|
*/
|
|
25
33
|
|
|
26
34
|
/**
|
|
@@ -55,8 +63,9 @@ class VideoShopping {
|
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
/**
|
|
58
|
-
* The
|
|
59
|
-
*
|
|
66
|
+
* The configuration of product info view.
|
|
67
|
+
* Please refer to {@link ProductInfoViewConfiguration} for more details.
|
|
68
|
+
* Only supported on iOS.
|
|
60
69
|
*/
|
|
61
70
|
get productInfoViewConfiguration() {
|
|
62
71
|
return this._productInfoViewConfiguration;
|
|
@@ -83,10 +92,7 @@ class VideoShopping {
|
|
|
83
92
|
|
|
84
93
|
set onCustomClickLinkButton(value) {
|
|
85
94
|
this._onCustomClickLinkButton = value;
|
|
86
|
-
|
|
87
|
-
if (Platform.OS === 'android') {
|
|
88
|
-
ShoppingModule.setCustomClickLinkButtonEnabled(!!value);
|
|
89
|
-
}
|
|
95
|
+
ShoppingModule.setCustomClickLinkButtonEnabled(!!value);
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
get eventEmitter() {
|
|
@@ -106,6 +112,8 @@ class VideoShopping {
|
|
|
106
112
|
constructor() {
|
|
107
113
|
_defineProperty(this, "onAddToCart", void 0);
|
|
108
114
|
|
|
115
|
+
_defineProperty(this, "onShoppingCTA", void 0);
|
|
116
|
+
|
|
109
117
|
_defineProperty(this, "onClickCartIcon", void 0);
|
|
110
118
|
|
|
111
119
|
_defineProperty(this, "_onCustomClickCartIcon", void 0);
|
|
@@ -120,10 +128,20 @@ class VideoShopping {
|
|
|
120
128
|
|
|
121
129
|
_defineProperty(this, "_onCustomClickLinkButton", void 0);
|
|
122
130
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
131
|
+
if (Platform.OS === 'android') {
|
|
132
|
+
this.eventEmitter.addListener(FWEventName.AddToCart, event => {
|
|
133
|
+
FWLoggerUtil.log(`Receive AddToCart event productId: ${event === null || event === void 0 ? void 0 : event.productId} unitId: ${event === null || event === void 0 ? void 0 : event.unitId}`);
|
|
134
|
+
this.handleShoppingCTAEvent(event);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (Platform.OS === 'ios') {
|
|
139
|
+
this.eventEmitter.addListener(FWEventName.ShoppingCTAButtonClick, event => {
|
|
140
|
+
FWLoggerUtil.log(`Receive ShoppingCTA event productId: ${event === null || event === void 0 ? void 0 : event.productId} unitId: ${event === null || event === void 0 ? void 0 : event.unitId} url: ${event === null || event === void 0 ? void 0 : event.url}`);
|
|
141
|
+
this.handleShoppingCTAEvent(event);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
127
145
|
this.eventEmitter.addListener(FWEventName.ClickCartIcon, event => {
|
|
128
146
|
FWLoggerUtil.log('Receive ClickCartIcon event');
|
|
129
147
|
this.handleClickCartIconEvent(event);
|
|
@@ -137,13 +155,10 @@ class VideoShopping {
|
|
|
137
155
|
this.handleWillDisplayProductEvent(event);
|
|
138
156
|
});
|
|
139
157
|
this.eventEmitter.addListener(FWEventName.LogMessage, () => {});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
this.
|
|
143
|
-
|
|
144
|
-
this.handleCustomLinkButtonClickEvent(event);
|
|
145
|
-
});
|
|
146
|
-
}
|
|
158
|
+
this.eventEmitter.addListener(FWEventName.CustomLinkButtonClick, event => {
|
|
159
|
+
FWLoggerUtil.log(`Receive CustomLinkButtonClick event url: ${event === null || event === void 0 ? void 0 : event.url}`);
|
|
160
|
+
this.handleCustomLinkButtonClickEvent(event);
|
|
161
|
+
});
|
|
147
162
|
}
|
|
148
163
|
/**
|
|
149
164
|
*
|
|
@@ -159,28 +174,60 @@ class VideoShopping {
|
|
|
159
174
|
ShoppingModule.setCartItemCount(count);
|
|
160
175
|
}
|
|
161
176
|
|
|
162
|
-
async
|
|
177
|
+
async handleShoppingCTAEvent(event) {
|
|
178
|
+
var _this$productInfoView, _this$productInfoView2;
|
|
179
|
+
|
|
163
180
|
const callbackId = event.callbackId;
|
|
164
181
|
delete event.callbackId;
|
|
182
|
+
let isShopNowCTA = false;
|
|
183
|
+
|
|
184
|
+
if (Platform.OS === 'ios' && ((_this$productInfoView = this.productInfoViewConfiguration) === null || _this$productInfoView === void 0 ? void 0 : (_this$productInfoView2 = _this$productInfoView.ctaButton) === null || _this$productInfoView2 === void 0 ? void 0 : _this$productInfoView2.text) === 'shopNow') {
|
|
185
|
+
isShopNowCTA = true;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (this.onShoppingCTA) {
|
|
189
|
+
const result = await this.onShoppingCTA(event);
|
|
190
|
+
|
|
191
|
+
if (callbackId) {
|
|
192
|
+
if (Platform.OS === 'ios') {
|
|
193
|
+
ShoppingModule.updateShoppingCTAResult(result, callbackId);
|
|
194
|
+
} else {
|
|
195
|
+
if (result.tips) {
|
|
196
|
+
ShoppingModule.updateAddToCartStatus(result.res, result.tips, callbackId);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
} else if (this.onAddToCart && !isShopNowCTA) {
|
|
201
|
+
if (event.url) {
|
|
202
|
+
delete event.url;
|
|
203
|
+
}
|
|
165
204
|
|
|
166
|
-
if (this.onAddToCart) {
|
|
167
205
|
const result = await this.onAddToCart(event);
|
|
168
206
|
|
|
169
207
|
if (result) {
|
|
170
208
|
if (callbackId) {
|
|
171
|
-
|
|
209
|
+
if (Platform.OS === 'ios') {
|
|
210
|
+
ShoppingModule.updateShoppingCTAResult({
|
|
211
|
+
res: result.res,
|
|
212
|
+
tips: result.tips
|
|
213
|
+
}, callbackId);
|
|
214
|
+
} else {
|
|
215
|
+
var _result$tips;
|
|
216
|
+
|
|
217
|
+
ShoppingModule.updateAddToCartStatus(result.res, (_result$tips = result.tips) !== null && _result$tips !== void 0 ? _result$tips : '', callbackId);
|
|
218
|
+
}
|
|
172
219
|
}
|
|
173
220
|
} else {
|
|
174
221
|
if (callbackId) {
|
|
175
222
|
if (Platform.OS === 'ios') {
|
|
176
|
-
ShoppingModule.clearCallbackId(callbackId, FWEventName.
|
|
223
|
+
ShoppingModule.clearCallbackId(callbackId, FWEventName.ShoppingCTAButtonClick);
|
|
177
224
|
}
|
|
178
225
|
}
|
|
179
226
|
}
|
|
180
227
|
} else {
|
|
181
228
|
if (callbackId) {
|
|
182
229
|
if (Platform.OS === 'ios') {
|
|
183
|
-
ShoppingModule.clearCallbackId(callbackId, FWEventName.
|
|
230
|
+
ShoppingModule.clearCallbackId(callbackId, FWEventName.ShoppingCTAButtonClick);
|
|
184
231
|
}
|
|
185
232
|
}
|
|
186
233
|
}
|
|
@@ -242,7 +289,7 @@ class VideoShopping {
|
|
|
242
289
|
const config = await this.onWillDisplayProduct(event);
|
|
243
290
|
|
|
244
291
|
if (config) {
|
|
245
|
-
|
|
292
|
+
this.productInfoViewConfiguration = config;
|
|
246
293
|
}
|
|
247
294
|
}
|
|
248
295
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["VideoShopping.ts"],"names":["Platform","FWEventName","ShoppingModule","ShoppingModuleEventEmitter","FWLoggerUtil","VideoShopping","onCustomClickCartIcon","_onCustomClickCartIcon","value","OS","setCustomClickCartIconEnabled","cartIconVisible","_cartIconVisible","setCartIconVisible","productInfoViewConfiguration","_productInfoViewConfiguration","setProductInfoViewConfiguration","onCustomClickLinkButton","_onCustomClickLinkButton","setCustomClickLinkButtonEnabled","eventEmitter","getInstance","log","_instance","constructor","addListener","AddToCart","event","productId","unitId","handleAddToCartEvent","ClickCartIcon","handleClickCartIconEvent","UpdateProductDetails","productIds","handleUpdateProductDetailsEvent","WillDisplayProduct","videoId","handleWillDisplayProductEvent","LogMessage","CustomLinkButtonClick","url","handleCustomLinkButtonClickEvent","setCartItemCount","count","callbackId","onAddToCart","result","updateAddToCartStatus","res","tips","clearCallbackId","onClickCartIcon","props","jumpToCartPage","onUpdateProductDetails","productList","map","product","length","updateVideoProducts","onWillDisplayProduct","config"],"mappings":";;AAAA,SAA6BA,QAA7B,QAA6C,cAA7C;AASA,SAASC,WAAT,QAA4B,sBAA5B;AAGA,OAAOC,cAAP,IACEC,0BADF,QAEO,0BAFP;AAIA,OAAOC,YAAP,MAAyB,sBAAzB;;AAwBA;AACA;AACA;AACA,MAAMC,aAAN,CAAoB;AAGlB;AACF;AACA;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;AACA;AACkC,MAArBC,qBAAqB,GAA4C;AAC1E,WAAO,KAAKC,sBAAZ;AACD;;AAC+B,MAArBD,qBAAqB,CAC9BE,KAD8B,EAE9B;AACA,SAAKD,sBAAL,GAA8BC,KAA9B;;AACA,QAAIR,QAAQ,CAACS,EAAT,KAAgB,KAApB,EAA2B;AACzBP,MAAAA,cAAc,CAACQ,6BAAf,CAA6C,CAAC,CAACF,KAA/C;AACD;AACF;;AAiBD;AACF;AACA;AACA;AAC4B,MAAfG,eAAe,GAAY;AACpC,WAAO,KAAKC,gBAAZ;AACD;;AACyB,MAAfD,eAAe,CAACH,KAAD,EAAiB;AACzC,SAAKI,gBAAL,GAAwBJ,KAAxB;AACAN,IAAAA,cAAc,CAACW,kBAAf,CAAkCL,KAAlC;AACD;;AAGD;AACF;AACA;AACA;AACyC,MAA5BM,4BAA4B,GAEzB;AACZ,WAAO,KAAKC,6BAAZ;AACD;;AAEsC,MAA5BD,4BAA4B,CACrCN,KADqC,EAErC;AACA,SAAKO,6BAAL,GAAqCP,KAArC;;AACA,QAAIR,QAAQ,CAACS,EAAT,KAAgB,KAApB,EAA2B;AACzBP,MAAAA,cAAc,CAACc,+BAAf,CAA+CR,KAA/C,aAA+CA,KAA/C,cAA+CA,KAA/C,GAAwD,EAAxD;AACD;AACF;;AAMD;AACF;AACA;AACA;AACA;AACA;AACA;AACoC,MAAvBS,uBAAuB,GAEpB;AACZ,WAAO,KAA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';\n\nimport type AddToCartResult from './models/AddToCartResult';\nimport type {\n AddToCartEvent,\n CustomClickLinkButtonEvent,\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';\nimport FWLoggerUtil from './utils/FWLoggerUtil';\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\nexport type CustomClickLinkButtonCallback = (\n event: CustomClickLinkButtonEvent\n) => Promise<void>;\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 apps can return an AddToCartResult object to tell FireworkSDK the result of adding to cart.\n * If the host apps want to customize the processing logic of clicking \"Add to cart\" button, they could return null or undefined in the callback.\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\n * 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 click event processing logic of\n * 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 * Please use productInfoViewConfiguration property. Only supported on iOS.\n *\n * @deprecated The property will be deprecated since RN SDK V2.\n */\n public onWillDisplayProduct?: WillDisplayProductCallback;\n\n /**\n * Defaults to true.\n * 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 /**\n * The host app can use this property to configure \"Add to cart\" button style\n * and hide the link button next to \"Add to cart\" button. Only supported on iOS.\n */\n public get productInfoViewConfiguration():\n | ProductInfoViewConfiguration\n | undefined {\n return this._productInfoViewConfiguration;\n }\n\n public set productInfoViewConfiguration(\n value: ProductInfoViewConfiguration | undefined\n ) {\n this._productInfoViewConfiguration = value;\n if (Platform.OS === 'ios') {\n ShoppingModule.setProductInfoViewConfiguration(value ?? {});\n }\n }\n\n private _productInfoViewConfiguration?:\n | ProductInfoViewConfiguration\n | undefined;\n\n /**\n * This callback is triggered when the user clicks\n * the link button next to Add to cart button. Only supported on Android.\n *\n * The host app can customize the click event processing logic of\n * the link button by setting the callback.\n */\n public get onCustomClickLinkButton():\n | CustomClickLinkButtonCallback\n | undefined {\n return this._onCustomClickLinkButton;\n }\n public set onCustomClickLinkButton(\n value: CustomClickLinkButtonCallback | undefined\n ) {\n this._onCustomClickLinkButton = value;\n if (Platform.OS === 'android') {\n ShoppingModule.setCustomClickLinkButtonEnabled(!!value);\n }\n }\n private _onCustomClickLinkButton?: CustomClickLinkButtonCallback | undefined;\n\n private get eventEmitter(): NativeEventEmitter {\n return ShoppingModuleEventEmitter;\n }\n\n public static getInstance() {\n FWLoggerUtil.log('VideoShopping constructor');\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 FWLoggerUtil.log(\n `Receive AddToCart event productId: ${event?.productId} unitId: ${event?.unitId}`\n );\n this.handleAddToCartEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.ClickCartIcon, (event) => {\n FWLoggerUtil.log('Receive ClickCartIcon event');\n this.handleClickCartIconEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.UpdateProductDetails, (event) => {\n FWLoggerUtil.log(\n `Receive UpdateProductDetails event productIds: ${event?.productIds}`\n );\n this.handleUpdateProductDetailsEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.WillDisplayProduct, (event) => {\n FWLoggerUtil.log(\n `Receive WillDisplayProduct event videoId: ${event?.videoId}`\n );\n this.handleWillDisplayProductEvent(event);\n });\n this.eventEmitter.addListener(FWEventName.LogMessage, () => {});\n\n if (Platform.OS === 'android') {\n this.eventEmitter.addListener(\n FWEventName.CustomLinkButtonClick,\n (event) => {\n FWLoggerUtil.log(\n `Receive CustomLinkButtonClick event url: ${event?.url}`\n );\n this.handleCustomLinkButtonClickEvent(event);\n }\n );\n }\n }\n\n /**\n *\n * @param {number} count The number of items in the host app cart.\n * The count should be greater than or equal to 0.\n * We just use count to show or hide red indicator on the cart icon.\n * If cound > 0, we will show the red indicator on the cart icon.\n * Otherwise, we will hide the red indicator on the cart icon.\n */\n public setCartItemCount(count: number) {\n ShoppingModule.setCartItemCount(count);\n }\n\n private async handleAddToCartEvent(event: any) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n if (this.onAddToCart) {\n const result = await this.onAddToCart(event as AddToCartEvent);\n if (result) {\n if (callbackId) {\n ShoppingModule.updateAddToCartStatus(\n result.res,\n result.tips,\n callbackId\n );\n }\n } else {\n if (callbackId) {\n if (Platform.OS === 'ios') {\n ShoppingModule.clearCallbackId(callbackId, FWEventName.AddToCart);\n }\n }\n }\n } else {\n if (callbackId) {\n if (Platform.OS === 'ios') {\n ShoppingModule.clearCallbackId(callbackId, FWEventName.AddToCart);\n }\n }\n }\n }\n\n private async handleClickCartIconEvent(event: any) {\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(event: any) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n if (this.onUpdateProductDetails) {\n FWLoggerUtil.log(\n `Call onUpdateProductDetails callback productIds: ${event.productIds} callbackId: ${callbackId}`\n );\n const productList = await this.onUpdateProductDetails(\n event as UpdateProductDetailsEvent\n );\n\n const productIds = (productList || []).map(\n (product) => product.productId ?? ''\n );\n\n FWLoggerUtil.log(\n `Get result from onUpdateProductDetails callback productIds: ${productIds} productListLength: ${\n (productList || []).length\n }`\n );\n\n if (productList) {\n if (callbackId) {\n ShoppingModule.updateVideoProducts(productList, callbackId);\n }\n } else {\n if (callbackId) {\n if (Platform.OS === 'ios') {\n ShoppingModule.clearCallbackId(\n callbackId,\n FWEventName.UpdateProductDetails\n );\n }\n }\n }\n } else {\n FWLoggerUtil.log('onUpdateProductDetails callback is not set.');\n if (callbackId) {\n if (Platform.OS === 'ios') {\n ShoppingModule.clearCallbackId(\n callbackId,\n FWEventName.UpdateProductDetails\n );\n }\n }\n }\n }\n\n private async handleWillDisplayProductEvent(event: any) {\n if (this.onWillDisplayProduct) {\n delete event.callbackId;\n const config = await this.onWillDisplayProduct(\n event as WillDisplayProductEvent\n );\n if (config) {\n ShoppingModule.setProductInfoViewConfiguration(config);\n }\n }\n }\n\n private async handleCustomLinkButtonClickEvent(\n event: CustomClickLinkButtonEvent\n ) {\n if (this.onCustomClickLinkButton) {\n this.onCustomClickLinkButton(event);\n }\n }\n}\n\nexport default VideoShopping;\n"]}
|
|
1
|
+
{"version":3,"sources":["VideoShopping.ts"],"names":["Platform","FWEventName","ShoppingModule","ShoppingModuleEventEmitter","FWLoggerUtil","VideoShopping","onCustomClickCartIcon","_onCustomClickCartIcon","value","OS","setCustomClickCartIconEnabled","cartIconVisible","_cartIconVisible","setCartIconVisible","productInfoViewConfiguration","_productInfoViewConfiguration","setProductInfoViewConfiguration","onCustomClickLinkButton","_onCustomClickLinkButton","setCustomClickLinkButtonEnabled","eventEmitter","getInstance","log","_instance","constructor","addListener","AddToCart","event","productId","unitId","handleShoppingCTAEvent","ShoppingCTAButtonClick","url","ClickCartIcon","handleClickCartIconEvent","UpdateProductDetails","productIds","handleUpdateProductDetailsEvent","WillDisplayProduct","videoId","handleWillDisplayProductEvent","LogMessage","CustomLinkButtonClick","handleCustomLinkButtonClickEvent","setCartItemCount","count","callbackId","isShopNowCTA","ctaButton","text","onShoppingCTA","result","updateShoppingCTAResult","tips","updateAddToCartStatus","res","onAddToCart","clearCallbackId","onClickCartIcon","props","jumpToCartPage","onUpdateProductDetails","productList","map","product","length","updateVideoProducts","onWillDisplayProduct","config"],"mappings":";;AAAA,SAA6BA,QAA7B,QAA6C,cAA7C;AAUA,SAASC,WAAT,QAA4B,sBAA5B;AAGA,OAAOC,cAAP,IACEC,0BADF,QAEO,0BAFP;AAIA,OAAOC,YAAP,MAAyB,sBAAzB;;AAsCA;AACA;AACA;AACA,MAAMC,aAAN,CAAoB;AAGlB;AACF;AACA;AACA;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;AACA;AACA;AACA;;AAGE;AACF;AACA;AACA;AACA;AACA;AACkC,MAArBC,qBAAqB,GAA4C;AAC1E,WAAO,KAAKC,sBAAZ;AACD;;AAC+B,MAArBD,qBAAqB,CAC9BE,KAD8B,EAE9B;AACA,SAAKD,sBAAL,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AQ,CAACS,EAAT,KAAgB,KAApB,EAA2B;AACzBP,YAAAA,cAAc,CAACuD,eAAf,CACEX,UADF,EAEE7C,WAAW,CAACkC,oBAFd;AAID;AACF;AACF;AACF,KAhCD,MAgCO;AACL/B,MAAAA,YAAY,CAACkB,GAAb,CAAiB,6CAAjB;;AACA,UAAIwB,UAAJ,EAAgB;AACd,YAAI9C,QAAQ,CAACS,EAAT,KAAgB,KAApB,EAA2B;AACzBP,UAAAA,cAAc,CAACuD,eAAf,CACEX,UADF,EAEE7C,WAAW,CAACkC,oBAFd;AAID;AACF;AACF;AACF;;AAE0C,QAA7BK,6BAA6B,CAACb,KAAD,EAAa;AACtD,QAAI,KAAKwC,oBAAT,EAA+B;AAC7B,aAAOxC,KAAK,CAACmB,UAAb;AACA,YAAMsB,MAAM,GAAG,MAAM,KAAKD,oBAAL,CACnBxC,KADmB,CAArB;;AAGA,UAAIyC,MAAJ,EAAY;AACV,aAAKtD,4BAAL,GAAoCsD,MAApC;AACD;AACF;AACF;;AAE6C,QAAhCzB,gCAAgC,CAC5ChB,KAD4C,EAE5C;AACA,QAAI,KAAKV,uBAAT,EAAkC;AAChC,WAAKA,uBAAL,CAA6BU,KAA7B;AACD;AACF;;AAxViB;;gBAAdtB,a;;AA2VN,eAAeA,aAAf","sourcesContent":["import { NativeEventEmitter, Platform } from 'react-native';\n\nimport type AddToCartResult from './models/AddToCartResult';\nimport type {\n AddToCartEvent,\n CustomClickLinkButtonEvent,\n ShoppingCTAEvent,\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';\nimport FWLoggerUtil from './utils/FWLoggerUtil';\nimport type ShoppingCTAResult from './models/ShoppingCTAResult';\n\n/**\n * @deprecated The type will be deprecated since RN SDK V2.1.\n */\nexport type AddToCartCallback = (\n event: AddToCartEvent\n) => Promise<AddToCartResult | undefined | null>;\n\nexport type ShoppingCTACallback = (\n event: ShoppingCTAEvent\n) => Promise<ShoppingCTAResult>;\n\n/**\n * @deprecated The type will be deprecated since RN SDK V2.0.\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\n/**\n * @deprecated The type will be deprecated since RN SDK V2.0.\n */\nexport type WillDisplayProductCallback = (\n event: WillDisplayProductEvent\n) => Promise<ProductInfoViewConfiguration | undefined | null>;\n\nexport type CustomClickLinkButtonCallback = (\n event: CustomClickLinkButtonEvent\n) => Promise<void>;\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 apps can return an AddToCartResult object to tell FireworkSDK the result of adding to cart.\n * If the host apps want to customize the processing logic of clicking \"Add to cart\" button, they could return null or undefined in the callback.\n * @deprecated The callback will be deprecated since RN SDK V2.1.\n */\n public onAddToCart?: AddToCartCallback;\n\n /**\n * This callback is triggered when the user clicks the \"Add to cart\" or \"Shop now\" button.\n * The host app can return a ShoppingCTAResult object to tell SDK how to handle the result.\n */\n public onShoppingCTA?: ShoppingCTACallback;\n\n /**\n * This callback is triggered when the user clicks the shopping cart icon.\n *\n * The host app can return NewNativeContainerProps object\n * and we will push a new native container with the props.\n *\n * @deprecated The property will be deprecated since RN SDK V2.0.\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 click event processing logic of\n * 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 * Please use productInfoViewConfiguration property. Only supported on iOS.\n *\n * @deprecated The property will be deprecated since RN SDK V2.0.\n * Use {@link productInfoViewConfiguration} instead.\n */\n public onWillDisplayProduct?: WillDisplayProductCallback;\n\n /**\n * Defaults to true.\n * 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 /**\n * The configuration of product info view.\n * Please refer to {@link ProductInfoViewConfiguration} for more details.\n * Only supported on iOS.\n */\n public get productInfoViewConfiguration():\n | ProductInfoViewConfiguration\n | undefined {\n return this._productInfoViewConfiguration;\n }\n\n public set productInfoViewConfiguration(\n value: ProductInfoViewConfiguration | undefined\n ) {\n this._productInfoViewConfiguration = value;\n if (Platform.OS === 'ios') {\n ShoppingModule.setProductInfoViewConfiguration(value ?? {});\n }\n }\n\n private _productInfoViewConfiguration?:\n | ProductInfoViewConfiguration\n | undefined;\n\n /**\n * This callback is triggered when the user clicks\n * the link button next to Add to cart button. Only supported on Android.\n *\n * The host app can customize the click event processing logic of\n * the link button by setting the callback.\n */\n public get onCustomClickLinkButton():\n | CustomClickLinkButtonCallback\n | undefined {\n return this._onCustomClickLinkButton;\n }\n public set onCustomClickLinkButton(\n value: CustomClickLinkButtonCallback | undefined\n ) {\n this._onCustomClickLinkButton = value;\n ShoppingModule.setCustomClickLinkButtonEnabled(!!value);\n }\n private _onCustomClickLinkButton?: CustomClickLinkButtonCallback | undefined;\n\n private get eventEmitter(): NativeEventEmitter {\n return ShoppingModuleEventEmitter;\n }\n\n public static getInstance() {\n FWLoggerUtil.log('VideoShopping constructor');\n if (!VideoShopping._instance) {\n VideoShopping._instance = new VideoShopping();\n }\n\n return VideoShopping._instance!;\n }\n\n private constructor() {\n if (Platform.OS === 'android') {\n this.eventEmitter.addListener(FWEventName.AddToCart, (event) => {\n FWLoggerUtil.log(\n `Receive AddToCart event productId: ${event?.productId} unitId: ${event?.unitId}`\n );\n this.handleShoppingCTAEvent(event);\n });\n }\n\n if (Platform.OS === 'ios') {\n this.eventEmitter.addListener(\n FWEventName.ShoppingCTAButtonClick,\n (event) => {\n FWLoggerUtil.log(\n `Receive ShoppingCTA event productId: ${event?.productId} unitId: ${event?.unitId} url: ${event?.url}`\n );\n this.handleShoppingCTAEvent(event);\n }\n );\n }\n\n this.eventEmitter.addListener(FWEventName.ClickCartIcon, (event) => {\n FWLoggerUtil.log('Receive ClickCartIcon event');\n this.handleClickCartIconEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.UpdateProductDetails, (event) => {\n FWLoggerUtil.log(\n `Receive UpdateProductDetails event productIds: ${event?.productIds}`\n );\n this.handleUpdateProductDetailsEvent(event);\n });\n\n this.eventEmitter.addListener(FWEventName.WillDisplayProduct, (event) => {\n FWLoggerUtil.log(\n `Receive WillDisplayProduct event videoId: ${event?.videoId}`\n );\n this.handleWillDisplayProductEvent(event);\n });\n this.eventEmitter.addListener(FWEventName.LogMessage, () => {});\n\n this.eventEmitter.addListener(\n FWEventName.CustomLinkButtonClick,\n (event) => {\n FWLoggerUtil.log(\n `Receive CustomLinkButtonClick event url: ${event?.url}`\n );\n this.handleCustomLinkButtonClickEvent(event);\n }\n );\n }\n\n /**\n *\n * @param {number} count The number of items in the host app cart.\n * The count should be greater than or equal to 0.\n * We just use count to show or hide red indicator on the cart icon.\n * If cound > 0, we will show the red indicator on the cart icon.\n * Otherwise, we will hide the red indicator on the cart icon.\n */\n public setCartItemCount(count: number) {\n ShoppingModule.setCartItemCount(count);\n }\n\n private async handleShoppingCTAEvent(event: any) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n let isShopNowCTA = false;\n if (\n Platform.OS === 'ios' &&\n this.productInfoViewConfiguration?.ctaButton?.text === 'shopNow'\n ) {\n isShopNowCTA = true;\n }\n\n if (this.onShoppingCTA) {\n const result = await this.onShoppingCTA(event as ShoppingCTAEvent);\n if (callbackId) {\n if (Platform.OS === 'ios') {\n ShoppingModule.updateShoppingCTAResult(result, callbackId);\n } else {\n if (result.tips) {\n ShoppingModule.updateAddToCartStatus(\n result.res,\n result.tips,\n callbackId\n );\n }\n }\n }\n } else if (this.onAddToCart && !isShopNowCTA) {\n if (event.url) {\n delete event.url;\n }\n const result = await this.onAddToCart(event as AddToCartEvent);\n if (result) {\n if (callbackId) {\n if (Platform.OS === 'ios') {\n ShoppingModule.updateShoppingCTAResult(\n { res: result.res, tips: result.tips },\n callbackId\n );\n } else {\n ShoppingModule.updateAddToCartStatus(\n result.res,\n result.tips ?? '',\n callbackId\n );\n }\n }\n } else {\n if (callbackId) {\n if (Platform.OS === 'ios') {\n ShoppingModule.clearCallbackId(\n callbackId,\n FWEventName.ShoppingCTAButtonClick\n );\n }\n }\n }\n } else {\n if (callbackId) {\n if (Platform.OS === 'ios') {\n ShoppingModule.clearCallbackId(\n callbackId,\n FWEventName.ShoppingCTAButtonClick\n );\n }\n }\n }\n }\n\n private async handleClickCartIconEvent(event: any) {\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(event: any) {\n const callbackId = event.callbackId;\n delete event.callbackId;\n if (this.onUpdateProductDetails) {\n FWLoggerUtil.log(\n `Call onUpdateProductDetails callback productIds: ${event.productIds} callbackId: ${callbackId}`\n );\n const productList = await this.onUpdateProductDetails(\n event as UpdateProductDetailsEvent\n );\n\n const productIds = (productList || []).map(\n (product) => product.productId ?? ''\n );\n\n FWLoggerUtil.log(\n `Get result from onUpdateProductDetails callback productIds: ${productIds} productListLength: ${\n (productList || []).length\n }`\n );\n\n if (productList) {\n if (callbackId) {\n ShoppingModule.updateVideoProducts(productList, callbackId);\n }\n } else {\n if (callbackId) {\n if (Platform.OS === 'ios') {\n ShoppingModule.clearCallbackId(\n callbackId,\n FWEventName.UpdateProductDetails\n );\n }\n }\n }\n } else {\n FWLoggerUtil.log('onUpdateProductDetails callback is not set.');\n if (callbackId) {\n if (Platform.OS === 'ios') {\n ShoppingModule.clearCallbackId(\n callbackId,\n FWEventName.UpdateProductDetails\n );\n }\n }\n }\n }\n\n private async handleWillDisplayProductEvent(event: any) {\n if (this.onWillDisplayProduct) {\n delete event.callbackId;\n const config = await this.onWillDisplayProduct(\n event as WillDisplayProductEvent\n );\n if (config) {\n this.productInfoViewConfiguration = config;\n }\n }\n }\n\n private async handleCustomLinkButtonClickEvent(\n event: CustomClickLinkButtonEvent\n ) {\n if (this.onCustomClickLinkButton) {\n this.onCustomClickLinkButton(event);\n }\n }\n}\n\nexport default VideoShopping;\n"]}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import React from 'react';
|
|
3
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useReducer, useRef } from 'react';
|
|
6
4
|
import { findNodeHandle, Platform, UIManager } from 'react-native';
|
|
7
5
|
import FireworkSDK from '../FireworkSDK';
|
|
8
6
|
import { FWEventName } from '../models/FWEventName';
|
|
@@ -11,121 +9,89 @@ import FWLoggerUtil from '../utils/FWLoggerUtil';
|
|
|
11
9
|
import FWStoryBlock from './FWStoryBlock';
|
|
12
10
|
const NativeComponentName = 'FWStoryBlock';
|
|
13
11
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
const StoryBlock = (props, forwardedRef) => {
|
|
13
|
+
const nativeComponentRef = useRef(null);
|
|
14
|
+
const [, forceUpdate] = useReducer(x => x + 1, 0);
|
|
15
|
+
useImperativeHandle(forwardedRef, () => {
|
|
16
|
+
const sendCommand = command => {
|
|
17
|
+
const nativeNodeHandle = findNodeHandle(nativeComponentRef.current);
|
|
18
|
+
let commandId = UIManager.getViewManagerConfig(NativeComponentName).Commands[command];
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
super(...arguments);
|
|
23
|
-
|
|
24
|
-
_defineProperty(this, "nativeComponentRef", /*#__PURE__*/React.createRef());
|
|
25
|
-
|
|
26
|
-
_defineProperty(this, "subscriptions", []);
|
|
27
|
-
|
|
28
|
-
_defineProperty(this, "_onStoryBlockLoadFinished", event => {
|
|
29
|
-
FWLoggerUtil.log(`StoryBlock _onStoryBlockLoadFinished ${event.nativeEvent.name}`);
|
|
30
|
-
const {
|
|
31
|
-
onStoryBlockLoadFinished
|
|
32
|
-
} = this.props;
|
|
33
|
-
const {
|
|
34
|
-
name,
|
|
35
|
-
reason
|
|
36
|
-
} = event.nativeEvent;
|
|
37
|
-
|
|
38
|
-
if (onStoryBlockLoadFinished) {
|
|
39
|
-
if (name) {
|
|
40
|
-
if (reason) {
|
|
41
|
-
onStoryBlockLoadFinished({
|
|
42
|
-
name,
|
|
43
|
-
reason
|
|
44
|
-
});
|
|
45
|
-
} else {
|
|
46
|
-
onStoryBlockLoadFinished({
|
|
47
|
-
name
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
onStoryBlockLoadFinished();
|
|
52
|
-
}
|
|
20
|
+
if (Platform.OS === 'android') {
|
|
21
|
+
commandId = commandId.toString();
|
|
53
22
|
}
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
23
|
|
|
57
|
-
|
|
24
|
+
UIManager.dispatchViewManagerCommand(findNodeHandle(nativeNodeHandle), commandId, []);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
play: () => {
|
|
29
|
+
sendCommand('play');
|
|
30
|
+
},
|
|
31
|
+
pause: () => {
|
|
32
|
+
sendCommand('pause');
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}, []);
|
|
36
|
+
useEffect(() => {
|
|
58
37
|
const subscriptionOfShareBaseURLUpdated = FireworkSDKModuleEventEmitter.addListener(FWEventName.ShareBaseURLUpdated, () => {
|
|
59
|
-
|
|
38
|
+
FWLoggerUtil.log('Receive FWEventName.ShareBaseURLUpdated');
|
|
39
|
+
forceUpdate();
|
|
60
40
|
});
|
|
61
|
-
this.subscriptions.push(subscriptionOfShareBaseURLUpdated);
|
|
62
41
|
const subscriptionOfAdBadgeConfigurationUpdated = FireworkSDKModuleEventEmitter.addListener(FWEventName.AdBadgeConfigurationUpdated, () => {
|
|
63
|
-
|
|
42
|
+
FWLoggerUtil.log('Receive FWEventName.AdBadgeConfigurationUpdated');
|
|
43
|
+
forceUpdate();
|
|
44
|
+
});
|
|
45
|
+
const subscriptionOfAppLanguageUpdated = FireworkSDKModuleEventEmitter.addListener(FWEventName.AppLanguageUpdated, () => {
|
|
46
|
+
FWLoggerUtil.log('Receive FWEventName.AppLanguageUpdated');
|
|
47
|
+
forceUpdate();
|
|
64
48
|
});
|
|
65
|
-
this.subscriptions.push(subscriptionOfAdBadgeConfigurationUpdated);
|
|
66
49
|
|
|
67
50
|
if (Platform.OS === 'android') {
|
|
68
|
-
const viewId = findNodeHandle(
|
|
69
|
-
FWLoggerUtil.log(`StoryBlock
|
|
70
|
-
|
|
51
|
+
const viewId = findNodeHandle(nativeComponentRef.current);
|
|
52
|
+
FWLoggerUtil.log(`StoryBlock createFragment viewId: ${viewId}`);
|
|
53
|
+
UIManager.dispatchViewManagerCommand(viewId, UIManager.getViewManagerConfig(NativeComponentName).Commands.create.toString(), [viewId]);
|
|
71
54
|
}
|
|
72
|
-
}
|
|
73
55
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
56
|
+
return () => {
|
|
57
|
+
subscriptionOfShareBaseURLUpdated.remove();
|
|
58
|
+
subscriptionOfAdBadgeConfigurationUpdated.remove();
|
|
59
|
+
subscriptionOfAppLanguageUpdated.remove();
|
|
60
|
+
};
|
|
61
|
+
}, []);
|
|
80
62
|
|
|
81
|
-
|
|
63
|
+
const handleStoryBlockLoadFinished = event => {
|
|
64
|
+
FWLoggerUtil.log(`StoryBlock handleStoryBlockLoadFinished ${event.nativeEvent.name}`);
|
|
82
65
|
const {
|
|
83
|
-
|
|
84
|
-
} =
|
|
85
|
-
return /*#__PURE__*/React.createElement(FWStoryBlock, _extends({
|
|
86
|
-
ref: this.nativeComponentRef,
|
|
87
|
-
key: this._generateKey()
|
|
88
|
-
}, this.props, {
|
|
89
|
-
onStoryBlockLoadFinished: this._onStoryBlockLoadFinished,
|
|
90
|
-
style: Object.assign({}, style, {
|
|
91
|
-
zIndex: -1
|
|
92
|
-
})
|
|
93
|
-
}));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
_generateKey() {
|
|
97
|
-
var _FireworkSDK$getInsta, _FireworkSDK$getInsta2, _adBadgeConfiguration, _adBadgeConfiguration2, _adBadgeConfiguration3;
|
|
98
|
-
|
|
66
|
+
onStoryBlockLoadFinished
|
|
67
|
+
} = props;
|
|
99
68
|
const {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
key += `_enablePictureInPicture:${enablePictureInPicture}`;
|
|
122
|
-
return key;
|
|
123
|
-
}
|
|
69
|
+
name,
|
|
70
|
+
reason
|
|
71
|
+
} = event.nativeEvent;
|
|
72
|
+
|
|
73
|
+
if (onStoryBlockLoadFinished) {
|
|
74
|
+
if (name) {
|
|
75
|
+
if (reason) {
|
|
76
|
+
onStoryBlockLoadFinished({
|
|
77
|
+
name,
|
|
78
|
+
reason
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
onStoryBlockLoadFinished({
|
|
82
|
+
name
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
onStoryBlockLoadFinished();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
124
90
|
|
|
125
|
-
|
|
91
|
+
const generateDynamicContentParametersString = () => {
|
|
126
92
|
const {
|
|
127
93
|
dynamicContentParameters
|
|
128
|
-
} =
|
|
94
|
+
} = props;
|
|
129
95
|
|
|
130
96
|
if (!dynamicContentParameters) {
|
|
131
97
|
return '';
|
|
@@ -146,7 +112,84 @@ export default class StoryBlock extends React.Component {
|
|
|
146
112
|
}
|
|
147
113
|
|
|
148
114
|
return resultString;
|
|
149
|
-
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const generateVastAttributesString = () => {
|
|
118
|
+
var _adConfiguration$vast;
|
|
119
|
+
|
|
120
|
+
const {
|
|
121
|
+
adConfiguration
|
|
122
|
+
} = props;
|
|
123
|
+
const vastAttributes = (_adConfiguration$vast = adConfiguration === null || adConfiguration === void 0 ? void 0 : adConfiguration.vastAttributes) !== null && _adConfiguration$vast !== void 0 ? _adConfiguration$vast : '';
|
|
124
|
+
|
|
125
|
+
if (!vastAttributes) {
|
|
126
|
+
return '';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let resultString = '';
|
|
130
|
+
|
|
131
|
+
for (const attribute of vastAttributes) {
|
|
132
|
+
var _attribute$name;
|
|
133
|
+
|
|
134
|
+
if (resultString.length > 0) {
|
|
135
|
+
resultString += '_';
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
resultString += `${(_attribute$name = attribute.name) !== null && _attribute$name !== void 0 ? _attribute$name : ''}:${attribute.value}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return resultString;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const generateKey = () => {
|
|
145
|
+
var _FireworkSDK$getInsta, _FireworkSDK$getInsta2, _adBadgeConfiguration, _adBadgeConfiguration2, _adBadgeConfiguration3, _FireworkSDK$getInsta3, _adConfiguration$requ, _adConfiguration$adsF;
|
|
146
|
+
|
|
147
|
+
const {
|
|
148
|
+
source,
|
|
149
|
+
channel = '',
|
|
150
|
+
playlist = '',
|
|
151
|
+
enablePictureInPicture = false,
|
|
152
|
+
adConfiguration
|
|
153
|
+
} = props;
|
|
154
|
+
const shareBaseURL = (_FireworkSDK$getInsta = FireworkSDK.getInstance().shareBaseURL) !== null && _FireworkSDK$getInsta !== void 0 ? _FireworkSDK$getInsta : '';
|
|
155
|
+
const adBadgeConfiguration = (_FireworkSDK$getInsta2 = FireworkSDK.getInstance().adBadgeConfiguration) !== null && _FireworkSDK$getInsta2 !== void 0 ? _FireworkSDK$getInsta2 : {};
|
|
156
|
+
const adBadgeTextType = (_adBadgeConfiguration = adBadgeConfiguration.badgeTextType) !== null && _adBadgeConfiguration !== void 0 ? _adBadgeConfiguration : '';
|
|
157
|
+
const backgroundColorOfAdBadge = (_adBadgeConfiguration2 = adBadgeConfiguration.backgroundColor) !== null && _adBadgeConfiguration2 !== void 0 ? _adBadgeConfiguration2 : '';
|
|
158
|
+
const textColorOfAdBadge = (_adBadgeConfiguration3 = adBadgeConfiguration.textColor) !== null && _adBadgeConfiguration3 !== void 0 ? _adBadgeConfiguration3 : '';
|
|
159
|
+
const dynamicContentParametersString = generateDynamicContentParametersString();
|
|
160
|
+
const appLanguage = (_FireworkSDK$getInsta3 = FireworkSDK.getInstance().appLanguage) !== null && _FireworkSDK$getInsta3 !== void 0 ? _FireworkSDK$getInsta3 : '';
|
|
161
|
+
const requiresAds = (_adConfiguration$requ = adConfiguration === null || adConfiguration === void 0 ? void 0 : adConfiguration.requiresAds) !== null && _adConfiguration$requ !== void 0 ? _adConfiguration$requ : false;
|
|
162
|
+
const adsFetchTimeout = (_adConfiguration$adsF = adConfiguration === null || adConfiguration === void 0 ? void 0 : adConfiguration.adsFetchTimeout) !== null && _adConfiguration$adsF !== void 0 ? _adConfiguration$adsF : 10;
|
|
163
|
+
const vastAttributesString = generateVastAttributesString();
|
|
164
|
+
let key = `source:${source}`;
|
|
165
|
+
key += `_channel:${channel}`;
|
|
166
|
+
key += `_playlist:${playlist}`;
|
|
167
|
+
key += `_shareBaseURL:${shareBaseURL}`;
|
|
168
|
+
key += `_adBadgeTextType:${adBadgeTextType}`;
|
|
169
|
+
key += `_backgroundColorOfAdBadge:${backgroundColorOfAdBadge}`;
|
|
170
|
+
key += `_textColorOfAdBadge:${textColorOfAdBadge}`;
|
|
171
|
+
key += `_dynamicContentParameters:${dynamicContentParametersString}`;
|
|
172
|
+
key += `_enablePictureInPicture:${enablePictureInPicture}`;
|
|
173
|
+
key += `_appLanguage:${appLanguage}`;
|
|
174
|
+
key += `_requiresAds:${requiresAds}`;
|
|
175
|
+
key += `_adsFetchTimeout:${adsFetchTimeout}`;
|
|
176
|
+
key += `_vastAttributes:${vastAttributesString}`;
|
|
177
|
+
return key;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const {
|
|
181
|
+
style
|
|
182
|
+
} = props;
|
|
183
|
+
return /*#__PURE__*/React.createElement(FWStoryBlock, _extends({
|
|
184
|
+
ref: nativeComponentRef,
|
|
185
|
+
key: generateKey()
|
|
186
|
+
}, props, {
|
|
187
|
+
onStoryBlockLoadFinished: handleStoryBlockLoadFinished,
|
|
188
|
+
style: Object.assign({}, style, {
|
|
189
|
+
zIndex: -1
|
|
190
|
+
})
|
|
191
|
+
}));
|
|
192
|
+
};
|
|
150
193
|
|
|
151
|
-
|
|
194
|
+
export default /*#__PURE__*/forwardRef(StoryBlock);
|
|
152
195
|
//# sourceMappingURL=StoryBlock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["StoryBlock.tsx"],"names":["React","findNodeHandle","Platform","UIManager","FireworkSDK","FWEventName","FireworkSDKModuleEventEmitter","FWLoggerUtil","FWStoryBlock","NativeComponentName","createFragment","viewId","OS","dispatchViewManagerCommand","getViewManagerConfig","Commands","create","toString","StoryBlock","Component","createRef","event","log","nativeEvent","name","onStoryBlockLoadFinished","props","reason","componentDidMount","subscriptionOfShareBaseURLUpdated","addListener","ShareBaseURLUpdated","setState","subscriptions","push","subscriptionOfAdBadgeConfigurationUpdated","AdBadgeConfigurationUpdated","nativeComponentRef","current","componentWillUnmount","forEach","value","remove","render","style","_generateKey","_onStoryBlockLoadFinished","Object","assign","zIndex","source","channel","playlist","enablePictureInPicture","shareBaseURL","getInstance","adBadgeConfiguration","adBadgeTextType","badgeTextType","backgroundColorOfAdBadge","backgroundColor","textColorOfAdBadge","textColor","dynamicContentParametersString","_generateDynamicContentParametersString","key","dynamicContentParameters","resultString","sortedKeyList","keys","sort","valueString","join","length"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAQA,SAASC,cAAT,EAAyBC,QAAzB,EAAmCC,SAAnC,QAAoD,cAApD;AAEA,OAAOC,WAAP,MAAwB,gBAAxB;AAEA,SAASC,WAAT,QAA4B,uBAA5B;AAEA,SAASC,6BAAT,QAA8C,8BAA9C;AACA,OAAOC,YAAP,MAAyB,uBAAzB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AAEA,MAAMC,mBAAmB,GAAG,cAA5B;;AAEA,MAAMC,cAAc,GAAIC,MAAD,IAAiB;AACtC,MAAIT,QAAQ,CAACU,EAAT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EDA,MAAAA,YAAY,IAAK,GAAEF,GAAI,IAAGM,WAAY,EAAtC;AACD;;AAED,WAAOJ,YAAP;AACD;;AA7HuE","sourcesContent":["import React from 'react';\n\nimport type {\n EmitterSubscription,\n NativeSyntheticEvent,\n StyleProp,\n ViewStyle,\n} from 'react-native';\nimport { findNodeHandle, Platform, UIManager } from 'react-native';\n\nimport FireworkSDK from '../FireworkSDK';\nimport type FWError from '../models/FWError';\nimport { FWEventName } from '../models/FWEventName';\nimport type { StoryBlockSource } from '../models/StoryBlockSource';\nimport { FireworkSDKModuleEventEmitter } from '../modules/FireworkSDKModule';\nimport FWLoggerUtil from '../utils/FWLoggerUtil';\nimport FWStoryBlock from './FWStoryBlock';\n\nconst NativeComponentName = 'FWStoryBlock';\n\nconst createFragment = (viewId: any) => {\n if (Platform.OS === 'android') {\n UIManager.dispatchViewManagerCommand(\n viewId,\n UIManager.getViewManagerConfig(\n NativeComponentName\n ).Commands.create.toString(),\n [viewId]\n );\n }\n};\n\nexport interface IStoryBlockProps {\n /**\n * Standard React Native View Style.\n */\n style?: StyleProp<ViewStyle>;\n /**\n * One of four available story block sources.\n */\n source: StoryBlockSource;\n /**\n * Channel id of the story block. Required when the source is set as channel or playlist or dynamicContent.\n */\n channel?: string;\n /**\n * Playlist id of the story block. Please note channel id is necessary. Required when the source is set as playlist.\n */\n playlist?: string;\n /**\n * The dynamic content parameters of the story block. Required when the source is set as dynamicContent.\n */\n dynamicContentParameters?: { [key: string]: string[] };\n /**\n * Specifies if Picture in Picture is enabled. Only supported on iOS.\n */\n enablePictureInPicture?: boolean;\n /**\n * The feed loading result callback. It means loading successfully when error equals to undefined.\n */\n onStoryBlockLoadFinished?: (error?: FWError) => void;\n}\n\nexport default class StoryBlock extends React.Component<IStoryBlockProps> {\n nativeComponentRef = React.createRef<any>();\n\n subscriptions: EmitterSubscription[] = [];\n componentDidMount() {\n const subscriptionOfShareBaseURLUpdated =\n FireworkSDKModuleEventEmitter.addListener(\n FWEventName.ShareBaseURLUpdated,\n () => {\n this.setState({});\n }\n );\n this.subscriptions.push(subscriptionOfShareBaseURLUpdated);\n\n const subscriptionOfAdBadgeConfigurationUpdated =\n FireworkSDKModuleEventEmitter.addListener(\n FWEventName.AdBadgeConfigurationUpdated,\n () => {\n this.setState({});\n }\n );\n this.subscriptions.push(subscriptionOfAdBadgeConfigurationUpdated);\n\n if (Platform.OS === 'android') {\n const viewId = findNodeHandle(this.nativeComponentRef.current);\n FWLoggerUtil.log(\n `StoryBlock componentDidMount createFragment viewId: ${viewId}`\n );\n createFragment(viewId);\n }\n }\n\n componentWillUnmount() {\n this.subscriptions.forEach((value) => {\n value.remove();\n });\n\n this.subscriptions = [];\n }\n\n render() {\n const { style } = this.props;\n\n return (\n <FWStoryBlock\n ref={this.nativeComponentRef}\n key={this._generateKey()}\n {...this.props}\n onStoryBlockLoadFinished={this._onStoryBlockLoadFinished}\n style={Object.assign({}, style, { zIndex: -1 })}\n />\n );\n }\n\n private _onStoryBlockLoadFinished = (event: NativeSyntheticEvent<any>) => {\n FWLoggerUtil.log(\n `StoryBlock _onStoryBlockLoadFinished ${event.nativeEvent.name}`\n );\n\n const { onStoryBlockLoadFinished } = this.props;\n const { name, reason } = event.nativeEvent;\n\n if (onStoryBlockLoadFinished) {\n if (name) {\n if (reason) {\n onStoryBlockLoadFinished({ name, reason });\n } else {\n onStoryBlockLoadFinished({ name });\n }\n } else {\n onStoryBlockLoadFinished();\n }\n }\n };\n\n private _generateKey(): string {\n const {\n source,\n channel = '',\n playlist = '',\n enablePictureInPicture = false,\n } = this.props;\n\n const shareBaseURL = FireworkSDK.getInstance().shareBaseURL ?? '';\n const adBadgeConfiguration =\n FireworkSDK.getInstance().adBadgeConfiguration ?? {};\n const adBadgeTextType = adBadgeConfiguration.badgeTextType ?? '';\n const backgroundColorOfAdBadge = adBadgeConfiguration.backgroundColor ?? '';\n const textColorOfAdBadge = adBadgeConfiguration.textColor ?? '';\n const dynamicContentParametersString =\n this._generateDynamicContentParametersString();\n\n let key = `source:${source}`;\n key += `_channel:${channel}`;\n key += `_playlist:${playlist}`;\n key += `_shareBaseURL:${shareBaseURL}`;\n key += `_adBadgeTextType:${adBadgeTextType}`;\n key += `_backgroundColorOfAdBadge:${backgroundColorOfAdBadge}`;\n key += `_textColorOfAdBadge:${textColorOfAdBadge}`;\n key += `_dynamicContentParameters:${dynamicContentParametersString}`;\n key += `_enablePictureInPicture:${enablePictureInPicture}`;\n\n return key;\n }\n\n private _generateDynamicContentParametersString(): string {\n const { dynamicContentParameters } = this.props;\n\n if (!dynamicContentParameters) {\n return '';\n }\n\n let resultString = '';\n const sortedKeyList = Object.keys(dynamicContentParameters).sort();\n for (const key of sortedKeyList) {\n const value = dynamicContentParameters[key];\n const valueString = value.join(',');\n if (resultString.length > 0) {\n resultString += '_';\n }\n\n resultString += `${key}:${valueString}`;\n }\n\n return resultString;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["StoryBlock.tsx"],"names":["React","forwardRef","useEffect","useImperativeHandle","useReducer","useRef","findNodeHandle","Platform","UIManager","FireworkSDK","FWEventName","FireworkSDKModuleEventEmitter","FWLoggerUtil","FWStoryBlock","NativeComponentName","StoryBlock","props","forwardedRef","nativeComponentRef","forceUpdate","x","sendCommand","command","nativeNodeHandle","current","commandId","getViewManagerConfig","Commands","OS","toString","dispatchViewManagerCommand","play","pause","subscriptionOfShareBaseURLUpdated","addListener","ShareBaseURLUpdated","log","subscriptionOfAdBadgeConfigurationUpdated","AdBadgeConfigurationUpdated","subscriptionOfAppLanguageUpdated","AppLanguageUpdated","viewId","create","remove","handleStoryBlockLoadFinished","event","nativeEvent","name","onStoryBlockLoadFinished","reason","generateDynamicContentParametersString","dynamicContentParameters","resultString","sortedKeyList","Object","keys","sort","key","value","valueString","join","length","generateVastAttributesString","adConfiguration","vastAttributes","attribute","generateKey","source","channel","playlist","enablePictureInPicture","shareBaseURL","getInstance","adBadgeConfiguration","adBadgeTextType","badgeTextType","backgroundColorOfAdBadge","backgroundColor","textColorOfAdBadge","textColor","dynamicContentParametersString","appLanguage","requiresAds","adsFetchTimeout","vastAttributesString","style","assign","zIndex"],"mappings":";;AAAA,OAAOA,KAAP,IACEC,UADF,EAEEC,SAFF,EAGEC,mBAHF,EAIEC,UAJF,EAKEC,MALF,QAMO,OANP;AASA,SAASC,cAAT,EAAyBC,QAAzB,EAAmCC,SAAnC,QAAoD,cAApD;AACA,OAAOC,WAAP,MAAwB,gBAAxB;AAEA,SAASC,WAAT,QAA4B,uBAA5B;AAEA,SAASC,6BAAT,QAA8C,8BAA9C;AACA,OAAOC,YAAP,MAAyB,uBAAzB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AAGA,MAAMC,mBAAmB,GAAG,cAA5B;;AAmDA,MAAMC,UAGL,GAAG,CAACC,KAAD,EAA0BC,YAA1B,KAA2C;AAC7C,QAAMC,kBAAkB,GAAGb,MAAM,CAAC,IAAD,CAAjC;AACA,QAAM,GAAGc,WAAH,IAAkBf,UAAU,CAAEgB,CAAD,IAAOA,CAAC,GAAG,CAAZ,EAAe,CAAf,CAAlC;AACAjB,EAAAA,mBAAmB,CACjBc,YADiB,EAEjB,MAAM;AACJ,UAAMI,WAAW,GAAIC,OAAD,IAAqB;AACvC,YAAMC,gBAAgB,GAAGjB,cAAc,CAACY,kBAAkB,CAACM,OAApB,CAAvC;AAEA,UAAIC,SAA0B,GAC5BjB,SAAS,CAACkB,oBAAV,CAA+BZ,mBAA/B,EAAoDa,QAApD,CAA6DL,OAA7D,CADF;;AAEA,UAAIf,QAAQ,CAACqB,EAAT,KAAgB,SAApB,EAA+B;AAC7BH,QAAAA,SAAS,GAAGA,SAAS,CAACI,QAAV,EAAZ;AACD;;AAEDrB,MAAAA,SAAS,CAACsB,0BAAV,CACExB,cAAc,CAACiB,gBAAD,CADhB,EAEEE,SAFF,EAGE,EAHF;AAKD,KAdD;;AAeA,WAAO;AACLM,MAAAA,IAAI,EAAE,MAAM;AACVV,QAAAA,WAAW,CAAC,MAAD,CAA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,UAAU,CAACc,UAAD,CAAzB","sourcesContent":["import React, {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useReducer,\n useRef,\n} from 'react';\nimport type { ForwardRefRenderFunction } from 'react';\nimport type { NativeSyntheticEvent, StyleProp, ViewStyle } from 'react-native';\nimport { findNodeHandle, Platform, UIManager } from 'react-native';\nimport FireworkSDK from '../FireworkSDK';\nimport type FWError from '../models/FWError';\nimport { FWEventName } from '../models/FWEventName';\nimport type { StoryBlockSource } from '../models/StoryBlockSource';\nimport { FireworkSDKModuleEventEmitter } from '../modules/FireworkSDKModule';\nimport FWLoggerUtil from '../utils/FWLoggerUtil';\nimport FWStoryBlock from './FWStoryBlock';\nimport type AdConfiguration from '../models/AdConfiguration';\n\nconst NativeComponentName = 'FWStoryBlock';\n\nexport interface IStoryBlockMethods {\n /**\n * Play the story block.\n */\n play: () => void;\n /**\n * Pause the story block.\n */\n pause: () => void;\n}\n\n/**\n * The props type of StoryBlock component.\n */\nexport interface IStoryBlockProps {\n /**\n * Standard React Native View Style.\n */\n style?: StyleProp<ViewStyle>;\n /**\n * One of four available story block sources.\n */\n source: StoryBlockSource;\n /**\n * Channel id of the story block. Required when the source is set as channel or playlist or dynamicContent.\n */\n channel?: string;\n /**\n * Playlist id of the story block. Please note channel id is necessary. Required when the source is set as playlist.\n */\n playlist?: string;\n /**\n * The dynamic content parameters of the story block. Required when the source is set as dynamicContent.\n */\n dynamicContentParameters?: { [key: string]: string[] };\n /**\n * Specifies if Picture in Picture is enabled. Only supported on iOS.\n */\n enablePictureInPicture?: boolean;\n /**\n * Ad configuration of the feed. Only supported on iOS.\n */\n adConfiguration?: AdConfiguration;\n /**\n * The feed loading result callback. It means loading successfully when error equals to undefined.\n */\n onStoryBlockLoadFinished?: (error?: FWError) => void;\n}\n\nconst StoryBlock: ForwardRefRenderFunction<\n IStoryBlockMethods,\n IStoryBlockProps\n> = (props: IStoryBlockProps, forwardedRef) => {\n const nativeComponentRef = useRef(null);\n const [, forceUpdate] = useReducer((x) => x + 1, 0);\n useImperativeHandle(\n forwardedRef,\n () => {\n const sendCommand = (command: string) => {\n const nativeNodeHandle = findNodeHandle(nativeComponentRef.current);\n\n let commandId: string | number =\n UIManager.getViewManagerConfig(NativeComponentName).Commands[command];\n if (Platform.OS === 'android') {\n commandId = commandId.toString();\n }\n\n UIManager.dispatchViewManagerCommand(\n findNodeHandle(nativeNodeHandle),\n commandId,\n []\n );\n };\n return {\n play: () => {\n sendCommand('play');\n },\n pause: () => {\n sendCommand('pause');\n },\n };\n },\n []\n );\n useEffect(() => {\n const subscriptionOfShareBaseURLUpdated =\n FireworkSDKModuleEventEmitter.addListener(\n FWEventName.ShareBaseURLUpdated,\n () => {\n FWLoggerUtil.log('Receive FWEventName.ShareBaseURLUpdated');\n forceUpdate();\n }\n );\n const subscriptionOfAdBadgeConfigurationUpdated =\n FireworkSDKModuleEventEmitter.addListener(\n FWEventName.AdBadgeConfigurationUpdated,\n () => {\n FWLoggerUtil.log('Receive FWEventName.AdBadgeConfigurationUpdated');\n forceUpdate();\n }\n );\n\n const subscriptionOfAppLanguageUpdated =\n FireworkSDKModuleEventEmitter.addListener(\n FWEventName.AppLanguageUpdated,\n () => {\n FWLoggerUtil.log('Receive FWEventName.AppLanguageUpdated');\n forceUpdate();\n }\n );\n\n if (Platform.OS === 'android') {\n const viewId = findNodeHandle(nativeComponentRef.current);\n FWLoggerUtil.log(`StoryBlock createFragment viewId: ${viewId}`);\n UIManager.dispatchViewManagerCommand(\n viewId,\n UIManager.getViewManagerConfig(\n NativeComponentName\n ).Commands.create.toString(),\n [viewId]\n );\n }\n\n return () => {\n subscriptionOfShareBaseURLUpdated.remove();\n subscriptionOfAdBadgeConfigurationUpdated.remove();\n subscriptionOfAppLanguageUpdated.remove();\n };\n }, []);\n\n const handleStoryBlockLoadFinished = (event: NativeSyntheticEvent<any>) => {\n FWLoggerUtil.log(\n `StoryBlock handleStoryBlockLoadFinished ${event.nativeEvent.name}`\n );\n\n const { onStoryBlockLoadFinished } = props;\n const { name, reason } = event.nativeEvent;\n\n if (onStoryBlockLoadFinished) {\n if (name) {\n if (reason) {\n onStoryBlockLoadFinished({ name, reason });\n } else {\n onStoryBlockLoadFinished({ name });\n }\n } else {\n onStoryBlockLoadFinished();\n }\n }\n };\n\n const generateDynamicContentParametersString = (): string => {\n const { dynamicContentParameters } = props;\n\n if (!dynamicContentParameters) {\n return '';\n }\n\n let resultString = '';\n const sortedKeyList = Object.keys(dynamicContentParameters).sort();\n for (const key of sortedKeyList) {\n const value = dynamicContentParameters[key];\n const valueString = value.join(',');\n if (resultString.length > 0) {\n resultString += '_';\n }\n\n resultString += `${key}:${valueString}`;\n }\n\n return resultString;\n };\n\n const generateVastAttributesString = () => {\n const { adConfiguration } = props;\n const vastAttributes = adConfiguration?.vastAttributes ?? '';\n if (!vastAttributes) {\n return '';\n }\n\n let resultString = '';\n for (const attribute of vastAttributes) {\n if (resultString.length > 0) {\n resultString += '_';\n }\n resultString += `${attribute.name ?? ''}:${attribute.value}`;\n }\n\n return resultString;\n };\n\n const generateKey = (): string => {\n const {\n source,\n channel = '',\n playlist = '',\n enablePictureInPicture = false,\n adConfiguration,\n } = props;\n\n const shareBaseURL = FireworkSDK.getInstance().shareBaseURL ?? '';\n const adBadgeConfiguration =\n FireworkSDK.getInstance().adBadgeConfiguration ?? {};\n const adBadgeTextType = adBadgeConfiguration.badgeTextType ?? '';\n const backgroundColorOfAdBadge = adBadgeConfiguration.backgroundColor ?? '';\n const textColorOfAdBadge = adBadgeConfiguration.textColor ?? '';\n const dynamicContentParametersString =\n generateDynamicContentParametersString();\n const appLanguage = FireworkSDK.getInstance().appLanguage ?? '';\n const requiresAds = adConfiguration?.requiresAds ?? false;\n const adsFetchTimeout = adConfiguration?.adsFetchTimeout ?? 10;\n const vastAttributesString = generateVastAttributesString();\n\n let key = `source:${source}`;\n key += `_channel:${channel}`;\n key += `_playlist:${playlist}`;\n key += `_shareBaseURL:${shareBaseURL}`;\n key += `_adBadgeTextType:${adBadgeTextType}`;\n key += `_backgroundColorOfAdBadge:${backgroundColorOfAdBadge}`;\n key += `_textColorOfAdBadge:${textColorOfAdBadge}`;\n key += `_dynamicContentParameters:${dynamicContentParametersString}`;\n key += `_enablePictureInPicture:${enablePictureInPicture}`;\n key += `_appLanguage:${appLanguage}`;\n key += `_requiresAds:${requiresAds}`;\n key += `_adsFetchTimeout:${adsFetchTimeout}`;\n key += `_vastAttributes:${vastAttributesString}`;\n\n return key;\n };\n\n const { style } = props;\n return (\n <FWStoryBlock\n ref={nativeComponentRef}\n key={generateKey()}\n {...props}\n onStoryBlockLoadFinished={handleStoryBlockLoadFinished}\n style={Object.assign({}, style, { zIndex: -1 })}\n />\n );\n};\n\nexport default forwardRef(StoryBlock);\n"]}
|