@adadapted/react-native-sdk 3.4.0 → 3.5.1

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 (75) hide show
  1. package/adadapted-react-native-sdk.podspec +1 -1
  2. package/lib/commonjs/api/adadaptedApiRequests.js +10 -11
  3. package/lib/commonjs/api/adadaptedApiRequests.js.map +1 -1
  4. package/lib/commonjs/api/adadaptedApiTypes.js +57 -0
  5. package/lib/commonjs/api/adadaptedApiTypes.js.map +1 -1
  6. package/lib/commonjs/componentTypes/AdZone.js +11 -0
  7. package/lib/commonjs/componentTypes/AdZone.js.map +1 -0
  8. package/lib/commonjs/componentTypes/Device.js +28 -0
  9. package/lib/commonjs/componentTypes/Device.js.map +1 -0
  10. package/lib/commonjs/componentTypes/Environment.js +61 -0
  11. package/lib/commonjs/componentTypes/Environment.js.map +1 -0
  12. package/lib/commonjs/components/AdZone.js +12 -17
  13. package/lib/commonjs/components/AdZone.js.map +1 -1
  14. package/lib/commonjs/components/ReportAdButton.js +1 -2
  15. package/lib/commonjs/components/ReportAdButton.js.map +1 -1
  16. package/lib/commonjs/index.js +97 -118
  17. package/lib/commonjs/index.js.map +1 -1
  18. package/lib/commonjs/util.js +0 -1
  19. package/lib/commonjs/util.js.map +1 -1
  20. package/lib/module/api/adadaptedApiRequests.js +9 -9
  21. package/lib/module/api/adadaptedApiRequests.js.map +1 -1
  22. package/lib/module/api/adadaptedApiTypes.js +57 -0
  23. package/lib/module/api/adadaptedApiTypes.js.map +1 -1
  24. package/lib/module/componentTypes/AdZone.js +7 -0
  25. package/lib/module/componentTypes/AdZone.js.map +1 -0
  26. package/lib/module/componentTypes/Device.js +24 -0
  27. package/lib/module/componentTypes/Device.js.map +1 -0
  28. package/lib/module/componentTypes/Environment.js +57 -0
  29. package/lib/module/componentTypes/Environment.js.map +1 -0
  30. package/lib/module/components/AdZone.js +11 -15
  31. package/lib/module/components/AdZone.js.map +1 -1
  32. package/lib/module/index.js +92 -122
  33. package/lib/module/index.js.map +1 -1
  34. package/lib/module/util.js +0 -1
  35. package/lib/module/util.js.map +1 -1
  36. package/lib/typescript/index.d.ts +2 -0
  37. package/lib/typescript/index.d.ts.map +1 -0
  38. package/lib/typescript/jest.setup.d.ts +6 -0
  39. package/lib/typescript/jest.setup.d.ts.map +1 -0
  40. package/lib/typescript/src/api/adadaptedApiRequests.d.ts +10 -9
  41. package/lib/typescript/src/api/adadaptedApiRequests.d.ts.map +1 -1
  42. package/lib/typescript/src/api/adadaptedApiTypes.d.ts +11 -4
  43. package/lib/typescript/src/api/adadaptedApiTypes.d.ts.map +1 -1
  44. package/lib/typescript/src/componentTypes/AdZone.d.ts +95 -0
  45. package/lib/typescript/src/componentTypes/AdZone.d.ts.map +1 -0
  46. package/lib/typescript/src/componentTypes/Device.d.ts +80 -0
  47. package/lib/typescript/src/componentTypes/Device.d.ts.map +1 -0
  48. package/lib/typescript/src/componentTypes/Environment.d.ts +57 -0
  49. package/lib/typescript/src/componentTypes/Environment.d.ts.map +1 -0
  50. package/lib/typescript/src/components/AdZone.d.ts +2 -55
  51. package/lib/typescript/src/components/AdZone.d.ts.map +1 -1
  52. package/lib/typescript/src/index.d.ts +38 -142
  53. package/lib/typescript/src/index.d.ts.map +1 -1
  54. package/lib/typescript/src/types.d.ts.map +1 -1
  55. package/package.json +43 -34
  56. package/src/api/adadaptedApiRequests.mock.ts +2 -2
  57. package/src/api/adadaptedApiRequests.ts +27 -26
  58. package/src/api/adadaptedApiTypes.ts +11 -5
  59. package/src/componentTypes/AdZone.ts +97 -0
  60. package/src/componentTypes/Device.ts +79 -0
  61. package/src/componentTypes/Environment.ts +58 -0
  62. package/src/components/AdZone.tsx +42 -120
  63. package/src/index.tsx +189 -287
  64. package/src/types.tsx +6 -5
  65. package/src/util.ts +6 -7
  66. package/android/.project +0 -34
  67. package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
  68. package/android/bin/.project +0 -34
  69. package/android/bin/.settings/org.eclipse.buildship.core.prefs +0 -13
  70. package/android/bin/build.gradle +0 -132
  71. package/android/bin/gradle.properties +0 -4
  72. package/android/bin/src/main/AndroidManifest.xml +0 -4
  73. package/android/bin/src/main/java/com/adadaptedreactnativesdk/AdadaptedReactNativeSdkModule.kt +0 -115
  74. package/android/bin/src/main/java/com/adadaptedreactnativesdk/AdadaptedReactNativeSdkPackage.kt +0 -20
  75. package/lib/module/package.json +0 -1
@@ -3,109 +3,14 @@
3
3
  * @module
4
4
  */
5
5
  import React, { useEffect, useState } from "react";
6
- import {
7
- DeviceEventEmitter,
8
- Linking,
9
- StyleSheet,
10
- View,
11
- ViewStyle,
12
- } from "react-native";
6
+ import { DeviceEventEmitter, Linking, StyleSheet, View } from "react-native";
13
7
  import * as adadaptedApiRequests from "../api/adadaptedApiRequests";
14
- import {
15
- Ad,
16
- AdActionType,
17
- DetailedListItem,
18
- ReportedEventType,
19
- Zone,
20
- } from "../api/adadaptedApiTypes";
8
+ import { Ad, AdActionType, ReportedEventType } from "../api/adadaptedApiTypes";
21
9
  import { WebView } from "react-native-webview";
22
- import { ApiEnv, DeviceOS } from "../index";
23
10
  import { safeInvoke } from "../util";
24
11
  import { ReportAdButton } from "./ReportAdButton";
12
+ import { AdZoneTypes } from "src/componentTypes/AdZone";
25
13
 
26
- /**
27
- * Props interface for {@link AdZone}.
28
- */
29
- interface Props {
30
- /**
31
- * The app ID.
32
- */
33
- appId: string;
34
- /**
35
- * The session ID.
36
- */
37
- sessionId: string;
38
- /**
39
- * The UDID.
40
- */
41
- udid: string;
42
- /**
43
- * The touch sensitivity of the Ad Zone in both the X and Y directions.
44
- * This is used to determine the click/press sensitivity when the
45
- * Ad Zone is being touched by the user as a regular touch or while
46
- * scrolling the view. If the amount of touch "drag" distance in either
47
- * X or Y direction is less than this value, we will treat the action as
48
- * a click/press on the Ad Zone.
49
- */
50
- xyDragDistanceAllowed: number;
51
- /**
52
- * The device OS used for API requests.
53
- */
54
- deviceOs: DeviceOS;
55
- /**
56
- * The API environment to use when making an API request.
57
- */
58
- apiEnv: ApiEnv;
59
- /**
60
- * The ad zone data.
61
- */
62
- adZoneData: Zone;
63
- /**
64
- * Callback that gets triggered when an "add to list" item/items are clicked.
65
- * @param items - The array of items to "add to list".
66
- */
67
- onAddToListTriggered?(items: DetailedListItem[]): void;
68
- /**
69
- * An ad zone that is not visible on screen for the initial render.
70
- */
71
- offScreenAdZone: boolean;
72
- /**
73
- * Track the ad zone visibility in parent component. (for off-screen ads)
74
- */
75
- isAdZoneVisible?: boolean;
76
- }
77
-
78
- /**
79
- * Interface for tracking "touch" coordinates.
80
- */
81
- interface TouchCoordinates {
82
- /**
83
- * The X coordinate for the touch.
84
- */
85
- x: number;
86
- /**
87
- * The Y coordinate for the touch.
88
- */
89
- y: number;
90
- }
91
-
92
- /**
93
- * Defines the style typing for the component.
94
- */
95
- interface StyleDef {
96
- /**
97
- * Styles for the main View element.
98
- */
99
- mainView: ViewStyle;
100
- /**
101
- * Styles for the WebView element.
102
- */
103
- webView: ViewStyle;
104
- /**
105
- * Styles for the ReportAdButton.
106
- */
107
- reportAd: ViewStyle;
108
- }
109
14
  /**
110
15
  * Timer used for cycling through ads in the zone
111
16
  * based on the ad "refresh time" for each ad.
@@ -117,20 +22,21 @@ let cycleAdTimer: ReturnType<typeof setTimeout> | undefined;
117
22
  * @param props - properties passed to AdZone.
118
23
  * @returns an AdZone JSX Element.
119
24
  */
120
- export const AdZone = (props: Props): React.ReactElement => {
25
+ export const AdZone = (props: AdZoneTypes.Props): React.ReactElement => {
121
26
  /**
122
27
  * Tracks the current ad index being shown.
123
28
  */
124
29
  const [adIndexShown, setAdIndexShown] = useState(
125
- Math.floor(Math.random() * props.adZoneData.ads.length)
30
+ Math.floor(Math.random() * props.adZoneData.ads.length),
126
31
  );
127
32
  /**
128
33
  * Tracks the coordinates when the user started touching the Ad View.
129
34
  */
130
- const [touchStartCoords, setTouchStartCoords] = useState<TouchCoordinates>({
131
- x: 0,
132
- y: 0,
133
- });
35
+ const [touchStartCoords, setTouchStartCoords] =
36
+ useState<AdZoneTypes.TouchCoordinates>({
37
+ x: 0,
38
+ y: 0,
39
+ });
134
40
 
135
41
  /**
136
42
  * Track ad visibility (for off-screen ads).
@@ -150,6 +56,7 @@ export const AdZone = (props: Props): React.ReactElement => {
150
56
  return () => {
151
57
  clearTimeout(cycleAdTimer);
152
58
  DeviceEventEmitter.removeAllListeners("acknowledge");
59
+ DeviceEventEmitter.removeAllListeners("visibility-event");
153
60
  };
154
61
  // eslint-disable-next-line react-hooks/exhaustive-deps
155
62
  }, []);
@@ -177,12 +84,19 @@ export const AdZone = (props: Props): React.ReactElement => {
177
84
  // eslint-disable-next-line react-hooks/exhaustive-deps
178
85
  }, [isAdZoneVisible]);
179
86
 
87
+ useEffect(() => {
88
+ if (props.adZoneData.ads.length > 0) {
89
+ cycleDisplayedAd();
90
+ }
91
+ // eslint-disable-next-line react-hooks/exhaustive-deps
92
+ }, [props.isContextualAd]);
93
+
180
94
  /**
181
95
  * Generates all component related styles.
182
96
  * @returns the styles needed for the component.
183
97
  */
184
- function generateStyles(): StyleDef {
185
- return StyleSheet.create({
98
+ function generateStyles(): AdZoneTypes.StyleDef {
99
+ return StyleSheet.create<AdZoneTypes.StyleDef>({
186
100
  mainView: {
187
101
  width: "100%",
188
102
  height: "100%",
@@ -232,7 +146,7 @@ export const AdZone = (props: Props): React.ReactElement => {
232
146
  ) {
233
147
  safeInvoke(
234
148
  props.onAddToListTriggered,
235
- currentlyDisplayedAd.payload.detailed_list_items
149
+ currentlyDisplayedAd.payload.detailed_list_items,
236
150
  );
237
151
  }
238
152
 
@@ -251,7 +165,7 @@ export const AdZone = (props: Props): React.ReactElement => {
251
165
  if (item.product_title === itemName) {
252
166
  triggerReportAdEvent(
253
167
  ad,
254
- ReportedEventType.INTERACTION
168
+ ReportedEventType.INTERACTION,
255
169
  );
256
170
  }
257
171
  });
@@ -286,7 +200,7 @@ export const AdZone = (props: Props): React.ReactElement => {
286
200
  ],
287
201
  },
288
202
  props.deviceOs,
289
- props.apiEnv
203
+ props.apiEnv,
290
204
  )
291
205
  .then(() => {
292
206
  // Do nothing with the response for now...
@@ -326,15 +240,15 @@ export const AdZone = (props: Props): React.ReactElement => {
326
240
  nextAdIndex = 0;
327
241
  }
328
242
 
329
- if (!lastAd.impression_tracked && !isAdZoneVisible) {
243
+ if (lastAd && !lastAd.impression_tracked && !isAdZoneVisible) {
330
244
  // Send invisible ad impression if ad was not visible before end of timer cycle.
331
245
  triggerReportAdEvent(
332
246
  lastAd,
333
- ReportedEventType.INVISIBLE_IMPRESSION
247
+ ReportedEventType.INVISIBLE_IMPRESSION,
334
248
  );
335
249
  }
336
250
 
337
- if (lastAd.impression_tracked) {
251
+ if (lastAd && lastAd.impression_tracked) {
338
252
  // Reset ad impression tracking status.
339
253
  lastAd.impression_tracked = false;
340
254
  }
@@ -348,7 +262,10 @@ export const AdZone = (props: Props): React.ReactElement => {
348
262
  function sendAdImpression(): void {
349
263
  const ad = props.adZoneData.ads[adIndexShown];
350
264
 
351
- if (ad.impression_tracked === undefined || !ad.impression_tracked) {
265
+ if (
266
+ ad &&
267
+ (ad.impression_tracked === undefined || !ad.impression_tracked)
268
+ ) {
352
269
  triggerReportAdEvent(ad, ReportedEventType.IMPRESSION);
353
270
  ad.impression_tracked = true;
354
271
  }
@@ -367,6 +284,10 @@ export const AdZone = (props: Props): React.ReactElement => {
367
284
  automaticallyAdjustContentInsets={false}
368
285
  style={styles.webView}
369
286
  onTouchStart={(e) => {
287
+ triggerReportAdEvent(
288
+ props.adZoneData.ads[adIndexShown],
289
+ ReportedEventType.INTERACTION,
290
+ );
370
291
  setTouchStartCoords({
371
292
  x: e.nativeEvent.pageX,
372
293
  y: e.nativeEvent.pageY,
@@ -374,21 +295,22 @@ export const AdZone = (props: Props): React.ReactElement => {
374
295
  }}
375
296
  onTouchEnd={(e) => {
376
297
  if (touchStartCoords) {
377
- const touchEndCoords: TouchCoordinates = {
378
- x: e.nativeEvent.pageX,
379
- y: e.nativeEvent.pageY,
380
- };
298
+ const touchEndCoords: AdZoneTypes.TouchCoordinates =
299
+ {
300
+ x: e.nativeEvent.pageX,
301
+ y: e.nativeEvent.pageY,
302
+ };
381
303
 
382
304
  if (
383
305
  Math.abs(
384
- touchStartCoords.x - touchEndCoords.x
306
+ touchStartCoords.x - touchEndCoords.x,
385
307
  ) < props.xyDragDistanceAllowed &&
386
308
  Math.abs(
387
- touchStartCoords.y - touchEndCoords.y
309
+ touchStartCoords.y - touchEndCoords.y,
388
310
  ) < props.xyDragDistanceAllowed
389
311
  ) {
390
312
  onAdZoneSelected(
391
- props.adZoneData.ads[adIndexShown]
313
+ props.adZoneData.ads[adIndexShown],
392
314
  );
393
315
  }
394
316