react-native-applovin-max 7.1.1 → 8.0.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 (88) hide show
  1. package/android/build.gradle +3 -3
  2. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXModule.java +17 -24
  3. package/ios/AppLovinMAX.m +17 -11
  4. package/lib/commonjs/AdView.js +86 -98
  5. package/lib/commonjs/AdView.js.map +1 -1
  6. package/lib/commonjs/AppLovinMAX.js +1 -1
  7. package/lib/commonjs/AppOpenAd.js +7 -7
  8. package/lib/commonjs/AppOpenAd.js.map +1 -1
  9. package/lib/commonjs/BannerAd.js +8 -8
  10. package/lib/commonjs/BannerAd.js.map +1 -1
  11. package/lib/commonjs/ErrorCode.js +49 -0
  12. package/lib/commonjs/ErrorCode.js.map +1 -0
  13. package/lib/commonjs/EventEmitter.js.map +1 -1
  14. package/lib/commonjs/InterstitialAd.js +7 -7
  15. package/lib/commonjs/InterstitialAd.js.map +1 -1
  16. package/lib/commonjs/MRecAd.js +6 -6
  17. package/lib/commonjs/MRecAd.js.map +1 -1
  18. package/lib/commonjs/RewardedAd.js +8 -8
  19. package/lib/commonjs/RewardedAd.js.map +1 -1
  20. package/lib/commonjs/index.js +8 -0
  21. package/lib/commonjs/index.js.map +1 -1
  22. package/lib/commonjs/nativeAd/NativeAdView.js +26 -29
  23. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  24. package/lib/commonjs/nativeAd/NativeAdViewComponents.js +69 -102
  25. package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
  26. package/lib/commonjs/nativeAd/NativeAdViewProvider.js +13 -13
  27. package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
  28. package/lib/commonjs/types/AdInfo.js.map +1 -1
  29. package/lib/module/AdView.js +87 -99
  30. package/lib/module/AdView.js.map +1 -1
  31. package/lib/module/AppLovinMAX.js +1 -1
  32. package/lib/module/AppOpenAd.js +7 -7
  33. package/lib/module/AppOpenAd.js.map +1 -1
  34. package/lib/module/BannerAd.js +8 -8
  35. package/lib/module/BannerAd.js.map +1 -1
  36. package/lib/module/ErrorCode.js +43 -0
  37. package/lib/module/ErrorCode.js.map +1 -0
  38. package/lib/module/EventEmitter.js.map +1 -1
  39. package/lib/module/InterstitialAd.js +7 -7
  40. package/lib/module/InterstitialAd.js.map +1 -1
  41. package/lib/module/MRecAd.js +6 -6
  42. package/lib/module/MRecAd.js.map +1 -1
  43. package/lib/module/RewardedAd.js +8 -8
  44. package/lib/module/RewardedAd.js.map +1 -1
  45. package/lib/module/index.js +1 -0
  46. package/lib/module/index.js.map +1 -1
  47. package/lib/module/nativeAd/NativeAdView.js +27 -30
  48. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  49. package/lib/module/nativeAd/NativeAdViewComponents.js +71 -104
  50. package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
  51. package/lib/module/nativeAd/NativeAdViewProvider.js +13 -13
  52. package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
  53. package/lib/module/types/AdInfo.js.map +1 -1
  54. package/lib/typescript/src/AdView.d.ts +2 -2
  55. package/lib/typescript/src/AdView.d.ts.map +1 -1
  56. package/lib/typescript/src/ErrorCode.d.ts +83 -0
  57. package/lib/typescript/src/ErrorCode.d.ts.map +1 -0
  58. package/lib/typescript/src/EventEmitter.d.ts.map +1 -1
  59. package/lib/typescript/src/index.d.ts +1 -0
  60. package/lib/typescript/src/index.d.ts.map +1 -1
  61. package/lib/typescript/src/nativeAd/NativeAdView.d.ts.map +1 -1
  62. package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  63. package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts +3 -2
  64. package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  65. package/lib/typescript/src/types/AdInfo.d.ts +6 -5
  66. package/lib/typescript/src/types/AdInfo.d.ts.map +1 -1
  67. package/lib/typescript/src/types/NativeAd.d.ts +3 -3
  68. package/lib/typescript/src/types/NativeAd.d.ts.map +1 -1
  69. package/lib/typescript/src/types/Privacy.d.ts +0 -12
  70. package/lib/typescript/src/types/Privacy.d.ts.map +1 -1
  71. package/package.json +1 -1
  72. package/react-native-applovin-max.podspec +2 -2
  73. package/src/AdView.tsx +103 -92
  74. package/src/AppLovinMAX.ts +1 -1
  75. package/src/AppOpenAd.ts +21 -21
  76. package/src/BannerAd.ts +20 -20
  77. package/src/ErrorCode.ts +116 -0
  78. package/src/EventEmitter.ts +2 -2
  79. package/src/InterstitialAd.ts +21 -21
  80. package/src/MRecAd.ts +18 -18
  81. package/src/RewardedAd.ts +24 -24
  82. package/src/index.ts +1 -0
  83. package/src/nativeAd/NativeAdView.tsx +41 -29
  84. package/src/nativeAd/NativeAdViewComponents.tsx +72 -98
  85. package/src/nativeAd/NativeAdViewProvider.tsx +21 -15
  86. package/src/types/AdInfo.ts +7 -5
  87. package/src/types/NativeAd.ts +3 -3
  88. package/src/types/Privacy.ts +0 -16
@@ -1,21 +1,31 @@
1
1
  import * as React from 'react';
2
- import { useContext, useRef, useEffect } from 'react';
3
- import type { ReactNode } from 'react';
4
- import { findNodeHandle, Text, Image, View, TouchableOpacity, StyleSheet } from 'react-native';
2
+ import { useContext, useRef, useEffect, useCallback, useMemo } from 'react';
3
+ import { findNodeHandle, Text, Image, View, TouchableOpacity, StyleSheet, Platform } from 'react-native';
5
4
  import type { ViewProps, ImageProps, TextStyle, StyleProp, TextProps } from 'react-native';
6
5
  import { NativeAdViewContext } from './NativeAdViewProvider';
6
+ import type { NativeAd } from '../types/NativeAd';
7
7
 
8
- export const TitleView = (props: TextProps) => {
9
- const titleRef = useRef(null);
8
+ // Custom hook to handle setting native ad view properties and return nativeAd
9
+ const useNativeAdViewProps = (nativeAdProp: keyof NativeAd, ref: React.RefObject<any>, nativePropKey: string) => {
10
10
  const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
11
11
 
12
- useEffect(() => {
13
- if (!nativeAd.title || !titleRef.current) return;
14
-
12
+ const setNativeProps = useCallback(() => {
13
+ if (!nativeAd[nativeAdProp] || !ref.current) return;
15
14
  nativeAdView?.setNativeProps({
16
- titleView: findNodeHandle(titleRef.current),
15
+ [nativePropKey]: findNodeHandle(ref.current),
17
16
  });
18
- }, [nativeAd, nativeAdView]);
17
+ }, [nativeAd, nativeAdProp, nativeAdView, ref, nativePropKey]);
18
+
19
+ useEffect(() => {
20
+ setNativeProps();
21
+ }, [setNativeProps]);
22
+
23
+ return nativeAd;
24
+ };
25
+
26
+ export const TitleView = (props: TextProps) => {
27
+ const titleRef = useRef<Text | null>(null);
28
+ const nativeAd = useNativeAdViewProps('title', titleRef, 'titleView');
19
29
 
20
30
  return (
21
31
  <Text {...props} ref={titleRef}>
@@ -25,16 +35,8 @@ export const TitleView = (props: TextProps) => {
25
35
  };
26
36
 
27
37
  export const AdvertiserView = (props: TextProps) => {
28
- const advertiserRef = useRef(null);
29
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
30
-
31
- useEffect(() => {
32
- if (!nativeAd.advertiser || !advertiserRef.current) return;
33
-
34
- nativeAdView?.setNativeProps({
35
- advertiserView: findNodeHandle(advertiserRef.current),
36
- });
37
- }, [nativeAd, nativeAdView]);
38
+ const advertiserRef = useRef<Text | null>(null);
39
+ const nativeAd = useNativeAdViewProps('advertiser', advertiserRef, 'advertiserView');
38
40
 
39
41
  return (
40
42
  <Text {...props} ref={advertiserRef}>
@@ -44,16 +46,8 @@ export const AdvertiserView = (props: TextProps) => {
44
46
  };
45
47
 
46
48
  export const BodyView = (props: TextProps) => {
47
- const bodyRef = useRef(null);
48
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
49
-
50
- useEffect(() => {
51
- if (!nativeAd.body || !bodyRef.current) return;
52
-
53
- nativeAdView?.setNativeProps({
54
- bodyView: findNodeHandle(bodyRef.current),
55
- });
56
- }, [nativeAd, nativeAdView]);
49
+ const bodyRef = useRef<Text | null>(null);
50
+ const nativeAd = useNativeAdViewProps('body', bodyRef, 'bodyView');
57
51
 
58
52
  return (
59
53
  <Text {...props} ref={bodyRef}>
@@ -63,37 +57,30 @@ export const BodyView = (props: TextProps) => {
63
57
  };
64
58
 
65
59
  export const CallToActionView = (props: TextProps) => {
66
- const callToActionRef = useRef(null);
67
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
68
-
69
- useEffect(() => {
70
- if (!nativeAd.callToAction || !callToActionRef.current) return;
60
+ const callToActionRef = useRef<Text | null>(null);
61
+ const nativeAd = useNativeAdViewProps('callToAction', callToActionRef, 'callToActionView');
71
62
 
72
- nativeAdView?.setNativeProps({
73
- callToActionView: findNodeHandle(callToActionRef.current),
74
- });
75
- }, [nativeAd, nativeAdView]);
76
-
77
- return (
78
- <TouchableOpacity>
63
+ // TouchableOpacity disables clicking on certain Android devices.
64
+ if (Platform.OS === 'android') {
65
+ return (
79
66
  <Text {...props} ref={callToActionRef}>
80
67
  {nativeAd.callToAction || null}
81
68
  </Text>
82
- </TouchableOpacity>
83
- );
69
+ );
70
+ } else {
71
+ return (
72
+ <TouchableOpacity>
73
+ <Text {...props} ref={callToActionRef}>
74
+ {nativeAd.callToAction || null}
75
+ </Text>
76
+ </TouchableOpacity>
77
+ );
78
+ }
84
79
  };
85
80
 
86
81
  export const IconView = (props: Omit<ImageProps, 'source'>) => {
87
- const imageRef = useRef(null);
88
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
89
-
90
- useEffect(() => {
91
- if (!(nativeAd.image || nativeAd.url) || !imageRef.current) return;
92
-
93
- nativeAdView?.setNativeProps({
94
- iconView: findNodeHandle(imageRef.current),
95
- });
96
- }, [nativeAd, nativeAdView]);
82
+ const imageRef = useRef<Image | null>(null);
83
+ const nativeAd = useNativeAdViewProps('image', imageRef, 'iconView');
97
84
 
98
85
  return nativeAd.url ? (
99
86
  <Image {...props} ref={imageRef} source={{ uri: nativeAd.url }} />
@@ -105,30 +92,15 @@ export const IconView = (props: Omit<ImageProps, 'source'>) => {
105
92
  };
106
93
 
107
94
  export const OptionsView = (props: ViewProps) => {
108
- const viewRef = useRef(null);
109
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
110
-
111
- useEffect(() => {
112
- if (!nativeAd.isOptionsViewAvailable || !viewRef.current) return;
113
- nativeAdView?.setNativeProps({
114
- optionsView: findNodeHandle(viewRef.current),
115
- });
116
- }, [nativeAd, nativeAdView]);
95
+ const viewRef = useRef<View | null>(null);
96
+ useNativeAdViewProps('isOptionsViewAvailable', viewRef, 'optionsView');
117
97
 
118
98
  return <View {...props} ref={viewRef} />;
119
99
  };
120
100
 
121
101
  export const MediaView = (props: ViewProps) => {
122
- const viewRef = useRef(null);
123
- const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
124
-
125
- useEffect(() => {
126
- if (!nativeAd.isMediaViewAvailable || !viewRef.current) return;
127
-
128
- nativeAdView?.setNativeProps({
129
- mediaView: findNodeHandle(viewRef.current),
130
- });
131
- }, [nativeAd, nativeAdView]);
102
+ const viewRef = useRef<View | null>(null);
103
+ useNativeAdViewProps('isMediaViewAvailable', viewRef, 'mediaView');
132
104
 
133
105
  return <View {...props} ref={viewRef} />;
134
106
  };
@@ -142,33 +114,35 @@ export const StarRatingView = (props: ViewProps) => {
142
114
 
143
115
  const { nativeAd } = useContext(NativeAdViewContext);
144
116
 
117
+ // Memoize the star rendering process
118
+ const stars = useMemo(() => {
119
+ if (!nativeAd.starRating) {
120
+ return Array.from({ length: maxStarCount }).map((_, index) => (
121
+ <Text key={index} style={{ fontSize: starSize }}>
122
+ {' '}
123
+ </Text>
124
+ ));
125
+ }
126
+
127
+ return Array.from({ length: maxStarCount }).map((_, index) => {
128
+ const starRating = nativeAd.starRating!;
129
+ const width = (starRating - index) * starSize;
130
+ return (
131
+ <View key={index}>
132
+ <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2606)}</Text>
133
+ {starRating > index && (
134
+ <View style={[{ width: width }, styles.starRating]}>
135
+ <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2605)}</Text>
136
+ </View>
137
+ )}
138
+ </View>
139
+ );
140
+ });
141
+ }, [nativeAd.starRating, starColor, starSize]);
142
+
145
143
  return (
146
144
  <View {...restProps} style={[style, styles.starRatingContainer]}>
147
- {(() => {
148
- const stars: ReactNode[] = [];
149
- for (let index = 0; index < maxStarCount; index++) {
150
- if (nativeAd.starRating) {
151
- const width = (nativeAd.starRating - index) * starSize;
152
- stars.push(
153
- <View key={index}>
154
- <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2606)}</Text>
155
- {nativeAd.starRating > index && (
156
- <View style={[{ width: width }, styles.starRating]}>
157
- <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2605)}</Text>
158
- </View>
159
- )}
160
- </View>
161
- );
162
- } else {
163
- stars.push(
164
- <Text key={index} style={{ fontSize: starSize }}>
165
- {' '}
166
- </Text>
167
- );
168
- }
169
- }
170
- return stars;
171
- })()}
145
+ {stars}
172
146
  </View>
173
147
  );
174
148
  };
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { useState, createContext } from 'react';
3
+ import type { ReactNode } from 'react';
3
4
  import type { NativeMethods } from 'react-native';
4
5
  import type { NativeAd } from '../types/NativeAd';
5
6
  import type { NativeAdViewProps } from '../types/NativeAdViewProps';
@@ -10,29 +11,34 @@ export type NativeAdViewContextType = {
10
11
  nativeAd: NativeAd;
11
12
  nativeAdView: NativeAdViewType | null;
12
13
  setNativeAd: React.Dispatch<React.SetStateAction<NativeAd>>;
13
- setNativeAdView: React.Dispatch<React.SetStateAction<NativeAdViewType>>;
14
+ setNativeAdView: React.Dispatch<React.SetStateAction<NativeAdViewType | null>>;
15
+ };
16
+
17
+ const defaultNativeAd: NativeAd = {
18
+ isOptionsViewAvailable: false,
19
+ isMediaViewAvailable: false,
14
20
  };
15
21
 
16
22
  export const NativeAdViewContext = createContext<NativeAdViewContextType>({
17
- nativeAd: { isOptionsViewAvailable: false, isMediaViewAvailable: false },
23
+ nativeAd: defaultNativeAd,
18
24
  nativeAdView: null,
19
25
  setNativeAd: () => {},
20
26
  setNativeAdView: () => {},
21
27
  });
22
28
 
23
- export const NativeAdViewProvider: React.FC<{ children: React.ReactNode }> = (props) => {
24
- const [nativeAd, setNativeAd] = useState({
25
- isOptionsViewAvailable: false,
26
- isMediaViewAvailable: false,
27
- });
28
- const [nativeAdView, setNativeAdView] = useState(Object);
29
+ export const NativeAdViewProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
30
+ const [nativeAd, setNativeAd] = useState<NativeAd>(defaultNativeAd);
31
+ const [nativeAdView, setNativeAdView] = useState<NativeAdViewType | null>(null);
29
32
 
30
- const providerValue = {
31
- nativeAd,
32
- nativeAdView,
33
- setNativeAd,
34
- setNativeAdView,
35
- };
33
+ const providerValue = React.useMemo(
34
+ () => ({
35
+ nativeAd,
36
+ nativeAdView,
37
+ setNativeAd,
38
+ setNativeAdView,
39
+ }),
40
+ [nativeAd, nativeAdView]
41
+ );
36
42
 
37
- return <NativeAdViewContext.Provider value={providerValue}>{props.children}</NativeAdViewContext.Provider>;
43
+ return <NativeAdViewContext.Provider value={providerValue}>{children}</NativeAdViewContext.Provider>;
38
44
  };
@@ -1,3 +1,5 @@
1
+ import type { ErrorCode } from '../ErrorCode';
2
+
1
3
  /**
2
4
  * Represents an ad that has been served by AppLovin MAX.
3
5
  */
@@ -30,7 +32,7 @@ export type AdInfo = {
30
32
 
31
33
  /**
32
34
  * The ad’s revenue amount. In the case where no revenue amount exists, or it is not available
33
- * yet, return 0.
35
+ * yet, returns 0.
34
36
  */
35
37
  revenue: number;
36
38
 
@@ -70,7 +72,7 @@ export type AdLoadFailedInfo = {
70
72
  /**
71
73
  * The error code for the error.
72
74
  */
73
- code: string | null;
75
+ code: ErrorCode;
74
76
 
75
77
  /**
76
78
  * The error message for the error.
@@ -105,7 +107,7 @@ export type AdDisplayFailedInfo = AdInfo & {
105
107
  /**
106
108
  * The error code for the error.
107
109
  */
108
- code: string | null;
110
+ code: ErrorCode;
109
111
 
110
112
  /**
111
113
  * The error message for the error.
@@ -237,7 +239,7 @@ export type AdWaterfallInfo = {
237
239
  networkResponses: AdNetworkResponseInfo[];
238
240
 
239
241
  /**
240
- * The total latency in seconds for this waterfall to finish processing.
242
+ * The total latency in milliseconds for this waterfall to finish processing.
241
243
  */
242
244
  latencyMillis: number;
243
245
  };
@@ -271,7 +273,7 @@ export type AdErrorInfo = {
271
273
  /**
272
274
  * The error code for the error.
273
275
  */
274
- code: number;
276
+ code: ErrorCode;
275
277
 
276
278
  /**
277
279
  * The error message for the error.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Represents a native ad for rendering `NativeAdView`. Internal use only.
2
+ * Represents a native ad for rendering in {@link NativeAdView}. This type is intended for internal use only.
3
3
  */
4
4
  export type NativeAd = {
5
5
  /**
@@ -30,12 +30,12 @@ export type NativeAd = {
30
30
  /**
31
31
  * The URL string of the icon.
32
32
  */
33
- url?: string | null;
33
+ url?: string;
34
34
 
35
35
  /**
36
36
  * The star rating of the native ad.
37
37
  */
38
- starRating?: number | null;
38
+ starRating?: number;
39
39
 
40
40
  /**
41
41
  * Whether or not the Options view is available.
@@ -1,8 +1,4 @@
1
1
  export type PrivacyType = {
2
- /**********************************************************************************/
3
- /* Privacy */
4
- /**********************************************************************************/
5
-
6
2
  /**
7
3
  * Sets whether or not the user provided consent for information-sharing with AppLovin.
8
4
  *
@@ -15,18 +11,6 @@ export type PrivacyType = {
15
11
  */
16
12
  hasUserConsent(): Promise<boolean>;
17
13
 
18
- /**
19
- * Marks the user as age-restricted (i.e. under 16).
20
- *
21
- * @param isAgeRestrictedUser true if the user is age restricted (i.e. under 16).
22
- */
23
- setIsAgeRestrictedUser(isAgeRestrictedUser: boolean): void;
24
-
25
- /**
26
- * Checks if the user is age-restricted.
27
- */
28
- isAgeRestrictedUser(): Promise<boolean>;
29
-
30
14
  /**
31
15
  * Sets whether or not the user opted out of the sale of their personal information.
32
16
  *