@adadapted/react-native-sdk 3.1.6 → 3.1.9

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.
Files changed (47) hide show
  1. package/android/.project +18 -1
  2. package/android/.settings/org.eclipse.buildship.core.prefs +4 -4
  3. package/android/bin/.project +34 -0
  4. package/android/bin/.settings/org.eclipse.buildship.core.prefs +13 -0
  5. package/android/bin/build.gradle +130 -0
  6. package/android/bin/gradle.properties +4 -0
  7. package/android/bin/src/main/AndroidManifest.xml +4 -0
  8. package/android/bin/src/main/java/com/adadaptedreactnativesdk/AdadaptedReactNativeSdkModule.kt +115 -0
  9. package/android/bin/src/main/java/com/adadaptedreactnativesdk/AdadaptedReactNativeSdkPackage.kt +20 -0
  10. package/android/build.gradle +1 -1
  11. package/android/src/main/java/com/adadaptedreactnativesdk/AdadaptedReactNativeSdkModule.kt +1 -1
  12. package/lib/commonjs/api/adadaptedApiRequests.mock.js +0 -20
  13. package/lib/commonjs/api/adadaptedApiRequests.mock.js.map +1 -1
  14. package/lib/commonjs/api/adadaptedApiTypes.js +0 -5
  15. package/lib/commonjs/api/adadaptedApiTypes.js.map +1 -1
  16. package/lib/commonjs/components/AdZone.js +11 -41
  17. package/lib/commonjs/components/AdZone.js.map +1 -1
  18. package/lib/commonjs/index.js +1 -1
  19. package/lib/commonjs/index.js.map +1 -1
  20. package/lib/module/api/adadaptedApiRequests.mock.js +0 -20
  21. package/lib/module/api/adadaptedApiRequests.mock.js.map +1 -1
  22. package/lib/module/api/adadaptedApiTypes.js +0 -5
  23. package/lib/module/api/adadaptedApiTypes.js.map +1 -1
  24. package/lib/module/components/AdZone.js +11 -40
  25. package/lib/module/components/AdZone.js.map +1 -1
  26. package/lib/module/index.js +1 -1
  27. package/lib/module/index.js.map +1 -1
  28. package/lib/typescript/src/api/adadaptedApiTypes.d.ts +0 -47
  29. package/lib/typescript/src/components/AdZone.d.ts +0 -4
  30. package/lib/typescript/src/index.d.ts +1 -1
  31. package/package.json +12 -13
  32. package/src/api/adadaptedApiRequests.mock.ts +0 -20
  33. package/src/api/adadaptedApiTypes.ts +0 -48
  34. package/src/components/AdZone.tsx +14 -57
  35. package/src/index.tsx +1 -1
  36. package/lib/commonjs/components/AdPopup.js +0 -352
  37. package/lib/commonjs/components/AdPopup.js.map +0 -1
  38. package/lib/commonjs/components/AdPopup.test.js +0 -60
  39. package/lib/commonjs/components/AdPopup.test.js.map +0 -1
  40. package/lib/module/components/AdPopup.js +0 -339
  41. package/lib/module/components/AdPopup.js.map +0 -1
  42. package/lib/module/components/AdPopup.test.js +0 -50
  43. package/lib/module/components/AdPopup.test.js.map +0 -1
  44. package/lib/typescript/src/components/AdPopup.d.ts +0 -75
  45. package/lib/typescript/src/components/AdPopup.test.d.ts +0 -1
  46. package/src/components/AdPopup.test.tsx +0 -60
  47. package/src/components/AdPopup.tsx +0 -471
@@ -1,471 +0,0 @@
1
- /**
2
- * Component for creating an {@link AdPopup}.
3
- * @module
4
- */
5
- import * as React from "react";
6
- import { WebView } from "react-native-webview";
7
- import Modal from "react-native-modal";
8
- import {
9
- ActivityIndicator,
10
- Image,
11
- ImageStyle,
12
- SafeAreaView,
13
- StyleSheet,
14
- Text,
15
- TextStyle,
16
- TouchableOpacity,
17
- View,
18
- ViewStyle,
19
- } from "react-native";
20
- import { Ad, AdActionType, DetailedListItem } from "../api/adadaptedApiTypes";
21
- import { safeInvoke } from "../util";
22
-
23
- /**
24
- * Props interface for {@link AdPopup}.
25
- */
26
- interface Props {
27
- /**
28
- * The add to display in the popup.
29
- */
30
- ad: Ad;
31
- /**
32
- * If true, the ad popup is displayed.
33
- */
34
- isOpen?: boolean;
35
- /**
36
- * Triggered when the popup is closing.
37
- */
38
- onClose?(): void;
39
- /**
40
- * Triggered when an ad circular item is clicked and
41
- * the item should be "added to list".
42
- * @param item - The item to add to list.
43
- */
44
- onAddToListItemClicked(item: DetailedListItem): void;
45
- }
46
-
47
- /**
48
- * State interface for {@link AdPopup}.
49
- */
50
- interface State {
51
- /**
52
- * If true, the popup web view can navigate back.
53
- */
54
- canGoBack: boolean;
55
- /**
56
- * If true, the popup web view can navigate forward.
57
- */
58
- canGoForward: boolean;
59
- /**
60
- * If true, the webview is loading a new page.
61
- */
62
- isPageLoading: boolean;
63
- }
64
-
65
- /**
66
- * Defines the style typing for the component.
67
- */
68
- interface StyleDef {
69
- /**
70
- * Styles for the main View element.
71
- */
72
- mainView: ViewStyle;
73
- /**
74
- * Styles for the WebView element.
75
- */
76
- webView: ViewStyle;
77
- /**
78
- * Styles for the close button View element.
79
- */
80
- closeButtonView: ViewStyle;
81
- /**
82
- * Styles for the navigation header View element.
83
- */
84
- navHeaderView: ViewStyle;
85
- /**
86
- * Styles for the nav arrow buttons view.
87
- */
88
- navArrowsContainer: ViewStyle;
89
- /**
90
- * Styles for the navigation left arrow button.
91
- */
92
- navLeftArrow: ImageStyle;
93
- /**
94
- * Styles for the navigation right arrow button.
95
- */
96
- navRightArrow: ImageStyle;
97
- /**
98
- * Styles for the nav bar title container.
99
- */
100
- navBarTitleView: ViewStyle;
101
- /**
102
- * Styles for the title text.
103
- */
104
- titleText: TextStyle;
105
- /**
106
- * Styles for the loading indicator container.
107
- */
108
- loadingIndicatorContainer: ViewStyle;
109
- /**
110
- * Styles for the close button opacity container.
111
- */
112
- closeButtonContainer: ViewStyle;
113
- /**
114
- * Styles for the button text.
115
- */
116
- closeButtonText: TextStyle;
117
- }
118
-
119
- /**
120
- * Creates the AdPopup component.
121
- */
122
- export class AdPopup extends React.Component<Props, State> {
123
- /**
124
- * The web view element reference.
125
- */
126
- private webViewElementRef: WebView | null = null;
127
-
128
- /**
129
- * @inheritDoc
130
- */
131
- constructor(props: Props, context?: any) {
132
- super(props, context);
133
-
134
- this.state = {
135
- canGoBack: false,
136
- canGoForward: false,
137
- isPageLoading: true,
138
- };
139
- }
140
-
141
- /**
142
- * @inheritDoc
143
- */
144
- public render(): JSX.Element {
145
- // Generate the styles each render in case the ad is updated with
146
- // new settings that need to be reflected in the styles of the view.
147
- const styles = this.generateStyles();
148
-
149
- return (
150
- <Modal
151
- style={styles.mainView}
152
- isVisible={this.props.isOpen}
153
- hasBackdrop={false}
154
- coverScreen={true}
155
- >
156
- <SafeAreaView style={{ flex: 1 }}>
157
- <SafeAreaView style={styles.navHeaderView}>
158
- <View style={styles.navArrowsContainer}>
159
- <View
160
- onTouchStart={() => {
161
- if (
162
- this.webViewElementRef &&
163
- this.state.canGoBack
164
- ) {
165
- this.webViewElementRef.goBack();
166
- }
167
- }}
168
- >
169
- <Image
170
- source={{
171
- uri:
172
- "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAABpUlEQVRoQ+2YvUrFQBBGZ59Hq8QXsLcVLCwsFBQUFBQUlHsFBQUFBQUFLSwsBB9C+/2m0ifxAUYCCinM5i47c83Cpgy7yznzzZAfR5lfLnN+KgL/nWBJoCSQWIHSQokFTN5eEogtYVVVY+fcAhF9icg7M49jz2ivn2oCP/CjFsAngNksBP6Ab7gBYG7wAh3wJCLHg2+hLngiOgJwklL9Zq/pDATgDwCcpcKbCgTg9wBcaMCbCQR6foeZr7TgTQS64J1zW977G014dYFA22wAuNOGVxUIwK8BeLCAVxMIwK8AeLKCVxEIDOwyMz9bwqsI1HX9QUQzbVARWWLmF2t4LQFPRHW2Atm3UFP5rIf4t3UCD7BV7/2j1TyovswFJNa99/cWEqoCoXYSkU1mvtWWUBfomYltANeaEiYCPRK7AC61JMwEeiT2AZxrSJgKhCScc4fe+9NUCXOBnsEe/kd9z3Min/9CHUm8AZhPaaOptFAbsKqqkXNusbknIq+D/y+UUt1J9k49gUmgYtYUgZhqWawtCVhUNebMkkBMtSzWlgQsqhpz5jfHSasx85A3NgAAAABJRU5ErkJggg==",
173
- }}
174
- style={styles.navLeftArrow}
175
- />
176
- </View>
177
- <View
178
- onTouchStart={() => {
179
- if (
180
- this.webViewElementRef &&
181
- this.state.canGoForward
182
- ) {
183
- this.webViewElementRef.goForward();
184
- }
185
- }}
186
- >
187
- <Image
188
- source={{
189
- uri:
190
- "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAABnklEQVRoQ+3YsUoEMRAG4H8ewCfRKpNeH0KwsLBQUFBQUFBQ8ERBQUFBQUELCwsLS3tfwFylzzOykAVZmz0yM+dCrs7O/d9Mwu2FMPAPDTw/KmDaE6wTqBMo7EDdQoUNLH68TiCEMCKieQAzIvI+Ho9HxW2doEDxBJj5C8Bs+50icuKJ0AB8AuDfTfNEFAPyFjruTt0LUQxogjPzEYDTaSBUABlxAODcG6EGyIg9AJeeCFVAEzyEsENE114IdUATPMa4JSK3HggTQN5OGwDurRFmgIxYA/BoiTAFZMQKgGcrhDkgH+xlInqxQLgAMmKJiF47iO+U0twE725/lk4bkFJK8d8DQgjD3ULMPNxDHGNcFZEni8Pb1jQ7AzHGdRF5sAzf1DYBhBA2iejOOrwJgJm3Adx4hFcHMPMugCuv8KoAZt4HcOEZXg0QYzwUkTPv8CqAwf+p794LNV3xupFQmQAzfwBYaLePZ3gVQN5Ci7nzb563ciqAkjdJjWdNfok1gvWtUQF9O2W1rk7AqrN969YJ9O2U1bo6AavO9q37A5jF5jGXG4ruAAAAAElFTkSuQmCC",
191
- }}
192
- style={styles.navRightArrow}
193
- />
194
- </View>
195
- </View>
196
- <View style={styles.navBarTitleView}>
197
- <Text
198
- style={styles.titleText}
199
- numberOfLines={1}
200
- ellipsizeMode={"tail"}
201
- >
202
- {this.props.ad.popup.title_text}
203
- </Text>
204
- </View>
205
- <View style={styles.loadingIndicatorContainer}>
206
- {this.state.isPageLoading ? (
207
- <ActivityIndicator
208
- size="large"
209
- color="#2969a0"
210
- />
211
- ) : undefined}
212
- </View>
213
- </SafeAreaView>
214
- <WebView
215
- source={{
216
- uri: this.props.ad.action_path,
217
- }}
218
- ref={(ref) => {
219
- this.webViewElementRef = ref;
220
- }}
221
- androidHardwareAccelerationDisabled={true}
222
- automaticallyAdjustContentInsets={false}
223
- allowFileAccess={true}
224
- style={styles.webView}
225
- javaScriptEnabled={true}
226
- injectedJavaScript={
227
- this.props.ad.action_type === AdActionType.POPUP ||
228
- this.props.ad.action_type === AdActionType.LINK
229
- ? this.getAddToListCircularJavascript()
230
- : ""
231
- }
232
- onMessage={(event) => {
233
- const responseObj: DetailedListItem = JSON.parse(
234
- event.nativeEvent.data
235
- );
236
-
237
- safeInvoke(
238
- this.props.onAddToListItemClicked,
239
- responseObj
240
- );
241
- }}
242
- onNavigationStateChange={(navState) => {
243
- this.setState({
244
- canGoBack: navState.canGoBack,
245
- canGoForward: navState.canGoForward,
246
- });
247
- }}
248
- onLoadStart={() => {
249
- this.setState({
250
- isPageLoading: true,
251
- });
252
- }}
253
- onLoadEnd={() => {
254
- this.setState({
255
- isPageLoading: false,
256
- });
257
- }}
258
- />
259
- <SafeAreaView style={styles.closeButtonView}>
260
- <TouchableOpacity
261
- style={styles.closeButtonContainer}
262
- onPress={() => {
263
- safeInvoke(this.props.onClose);
264
- }}
265
- >
266
- <Text style={styles.closeButtonText}>Close</Text>
267
- </TouchableOpacity>
268
- </SafeAreaView>
269
- </SafeAreaView>
270
- </Modal>
271
- );
272
- }
273
-
274
- /**
275
- * Generates the javascript to pass down to the Web View that extracts the
276
- * clicked product information based on the circular ad design.
277
- * @returns the javascript string to pass to the Web View.
278
- */
279
- private getAddToListCircularJavascript(): string {
280
- // TODO: This method should ultimately be removed. We shouldn't have to
281
- // hack the web view's javascript just to get the correct data to
282
- // return. When the circular templates get reworked, we should
283
- // build in an onMessage response within the circulars page so we
284
- // don't have to do it this way.
285
- return `
286
- const adButtons = document.getElementsByTagName("button");
287
-
288
- if (adButtons.length > 0) {
289
- if (adButtons.length > 1 && adButtons[1].getAttribute("data-payload-id")) {
290
- for (let x = 0; x < adButtons.length; x++) {
291
- if (adButtons[x].getAttribute("data-payload-id")) {
292
- adButtons[x].addEventListener("click", (event) => {
293
- window.ReactNativeWebView.postMessage(
294
- JSON.stringify(
295
- window.AdAdapted.payloads[adButtons[x].getAttribute("data-payload-id")]
296
- )
297
- );
298
- });
299
- }
300
- }
301
- } else {
302
- const onDataPostMessage = (imgSrc) => {
303
- const valueAfterLastSlash = imgSrc.match(/(?:[^\\/](?!(\\/)))+$/g).toString();
304
- const upcValueWithLeadingZeros = valueAfterLastSlash.match(/[^.]*/).toString();
305
- const finalUpcValue = parseInt(upcValueWithLeadingZeros, 10);
306
- const itemData = window.__NUXT__.data[0].items;
307
- let clickedItem = {};
308
-
309
- for (let i = 0; i < itemData.length; i++) {
310
- if (itemData[i].upc == finalUpcValue) {
311
- clickedItem = itemData[i];
312
- }
313
- }
314
-
315
- window.ReactNativeWebView.postMessage(
316
- JSON.stringify({
317
- product_barcode: clickedItem.upc,
318
- product_brand: clickedItem.brand,
319
- product_category: clickedItem.category,
320
- product_discount: clickedItem.sale_price,
321
- product_image: clickedItem.image,
322
- product_sku: clickedItem.retailer_sku,
323
- product_title: clickedItem.title
324
- })
325
- );
326
- };
327
-
328
- const onItemDialogLoad = () => {
329
- setTimeout(() => {
330
- document.getElementsByClassName("modal-body")[0].getElementsByTagName("button")[0].addEventListener("click", (event) => {
331
- onDataPostMessage(
332
- event.target.parentElement.getElementsByTagName("img")[0].getAttribute("src")
333
- );
334
- });
335
- }, 100);
336
- };
337
-
338
- const adItemImages = document.querySelectorAll(".item img");
339
- const adItemPromotionDivs = document.querySelectorAll(".item .promotion");
340
- const adItemTitleDivs = document.querySelectorAll(".item .title");
341
- const adItemPricingDivs = document.querySelectorAll(".item .pricing");
342
-
343
- for (let x = 0; x < adItemImages.length; x++) {
344
- adItemImages[x].addEventListener("click", (event) => {
345
- onItemDialogLoad();
346
- });
347
- }
348
-
349
- for (let x = 0; x < adItemPromotionDivs.length; x++) {
350
- adItemPromotionDivs[x].addEventListener("click", (event) => {
351
- onItemDialogLoad();
352
- });
353
- }
354
-
355
- for (let x = 0; x < adItemTitleDivs.length; x++) {
356
- adItemTitleDivs[x].addEventListener("click", (event) => {
357
- onItemDialogLoad();
358
- });
359
- }
360
-
361
- for (let x = 0; x < adItemPricingDivs.length; x++) {
362
- adItemPricingDivs[x].addEventListener("click", (event) => {
363
- onItemDialogLoad();
364
- });
365
- }
366
-
367
- for (let x = 0; x < adButtons.length; x++) {
368
- adButtons[x].addEventListener("click", (event) => {
369
- onDataPostMessage(
370
- event.target.parentElement.getElementsByTagName("img")[0].getAttribute("src")
371
- );
372
- });
373
- }
374
- }
375
- }
376
- `;
377
- }
378
-
379
- /**
380
- * Generates all component related styles.
381
- * @returns the styles needed for the component.
382
- */
383
- private generateStyles(): StyleDef {
384
- const backButtonOpacity = this.state.canGoBack ? 1 : 0.3;
385
- const forwardButtonOpacity = this.state.canGoForward ? 1 : 0.3;
386
-
387
- return StyleSheet.create({
388
- mainView: {
389
- display: "flex",
390
- flexDirection: "column",
391
- position: "relative",
392
- margin: 0,
393
- width: "100%",
394
- height: "100%",
395
- },
396
- navHeaderView: {
397
- display: "flex",
398
- flexDirection: "row",
399
- height: 60,
400
- width: "100%",
401
- backgroundColor: "#dadada",
402
- zIndex: 1,
403
- },
404
- navArrowsContainer: {
405
- display: "flex",
406
- flexDirection: "row",
407
- justifyContent: "center",
408
- alignItems: "center",
409
- },
410
- navLeftArrow: {
411
- width: 48,
412
- height: 48,
413
- marginRight: 5,
414
- marginLeft: 10,
415
- opacity: backButtonOpacity,
416
- },
417
- navRightArrow: {
418
- width: 48,
419
- height: 48,
420
- marginRight: 10,
421
- marginLeft: 5,
422
- opacity: forwardButtonOpacity,
423
- },
424
- navBarTitleView: {
425
- display: "flex",
426
- flexDirection: "row",
427
- alignItems: "center",
428
- flex: 1,
429
- },
430
- titleText: {
431
- color: "#333333",
432
- fontWeight: "bold",
433
- fontSize: 18,
434
- overflow: "hidden",
435
- flexWrap: "nowrap",
436
- },
437
- loadingIndicatorContainer: {
438
- display: "flex",
439
- flexDirection: "row",
440
- justifyContent: "center",
441
- alignItems: "center",
442
- marginLeft: 10,
443
- marginRight: 10,
444
- },
445
- webView: {
446
- width: "100%",
447
- height: "100%",
448
- zIndex: 0,
449
- },
450
- closeButtonView: {
451
- height: 60,
452
- width: "100%",
453
- backgroundColor: "#dadada",
454
- zIndex: 1,
455
- },
456
- closeButtonContainer: {
457
- display: "flex",
458
- justifyContent: "center",
459
- width: "100%",
460
- height: "100%",
461
- },
462
- closeButtonText: {
463
- width: "100%",
464
- color: "#2969a0",
465
- margin: "auto",
466
- fontSize: 18,
467
- textAlign: "center",
468
- },
469
- });
470
- }
471
- }