react-native-applovin-max 9.0.0 → 9.2.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.
Files changed (147) hide show
  1. package/android/build.gradle +3 -3
  2. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdView.java +4 -10
  3. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewUiComponent.java +17 -8
  4. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXModuleImpl.java +36 -14
  5. package/android/src/newarch/com/applovin/reactnative/AppLovinMAXModule.java +6 -6
  6. package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXModule.java +6 -6
  7. package/ios/AppLovinMAX.mm +36 -13
  8. package/ios/AppLovinMAXAdView.h +1 -0
  9. package/ios/AppLovinMAXAdView.mm +3 -9
  10. package/ios/AppLovinMAXAdViewUIComponent.h +1 -2
  11. package/ios/AppLovinMAXAdViewUIComponent.mm +18 -10
  12. package/lib/commonjs/AdView.js +63 -79
  13. package/lib/commonjs/AdView.js.map +1 -1
  14. package/lib/commonjs/AppLovinMAX.js +43 -29
  15. package/lib/commonjs/AppLovinMAX.js.map +1 -1
  16. package/lib/commonjs/BannerAd.js +2 -3
  17. package/lib/commonjs/BannerAd.js.map +1 -1
  18. package/lib/commonjs/ErrorCode.js +24 -31
  19. package/lib/commonjs/ErrorCode.js.map +1 -1
  20. package/lib/commonjs/EventEmitter.js +22 -1
  21. package/lib/commonjs/EventEmitter.js.map +1 -1
  22. package/lib/commonjs/Utils.js +22 -4
  23. package/lib/commonjs/Utils.js.map +1 -1
  24. package/lib/commonjs/index.js +1 -2
  25. package/lib/commonjs/index.js.map +1 -1
  26. package/lib/commonjs/nativeAd/NativeAdView.js +34 -24
  27. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  28. package/lib/commonjs/nativeAd/NativeAdViewComponents.js +85 -43
  29. package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
  30. package/lib/commonjs/nativeAd/NativeAdViewProvider.js +30 -2
  31. package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
  32. package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js +27 -0
  33. package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -1
  34. package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js +23 -0
  35. package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -1
  36. package/lib/commonjs/specs/NativeAppLovinMAXModule.js +7 -0
  37. package/lib/commonjs/specs/NativeAppLovinMAXModule.js.map +1 -1
  38. package/lib/commonjs/types/AdInfo.js +13 -16
  39. package/lib/commonjs/types/AdInfo.js.map +1 -1
  40. package/lib/module/AdView.js +62 -77
  41. package/lib/module/AdView.js.map +1 -1
  42. package/lib/module/AppLovinMAX.js +44 -29
  43. package/lib/module/AppLovinMAX.js.map +1 -1
  44. package/lib/module/BannerAd.js +2 -3
  45. package/lib/module/BannerAd.js.map +1 -1
  46. package/lib/module/ErrorCode.js +24 -31
  47. package/lib/module/ErrorCode.js.map +1 -1
  48. package/lib/module/EventEmitter.js +22 -1
  49. package/lib/module/EventEmitter.js.map +1 -1
  50. package/lib/module/Utils.js +22 -4
  51. package/lib/module/Utils.js.map +1 -1
  52. package/lib/module/nativeAd/NativeAdView.js +34 -21
  53. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  54. package/lib/module/nativeAd/NativeAdViewComponents.js +87 -40
  55. package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
  56. package/lib/module/nativeAd/NativeAdViewProvider.js +30 -0
  57. package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
  58. package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js +28 -0
  59. package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -1
  60. package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js +24 -0
  61. package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -1
  62. package/lib/module/specs/NativeAppLovinMAXModule.js +9 -0
  63. package/lib/module/specs/NativeAppLovinMAXModule.js.map +1 -1
  64. package/lib/module/types/AdInfo.js +13 -16
  65. package/lib/module/types/AdInfo.js.map +1 -1
  66. package/lib/typescript/src/AdView.d.ts +27 -21
  67. package/lib/typescript/src/AdView.d.ts.map +1 -1
  68. package/lib/typescript/src/AppLovinMAX.d.ts +22 -21
  69. package/lib/typescript/src/AppLovinMAX.d.ts.map +1 -1
  70. package/lib/typescript/src/BannerAd.d.ts.map +1 -1
  71. package/lib/typescript/src/ErrorCode.d.ts +24 -31
  72. package/lib/typescript/src/ErrorCode.d.ts.map +1 -1
  73. package/lib/typescript/src/EventEmitter.d.ts +16 -0
  74. package/lib/typescript/src/EventEmitter.d.ts.map +1 -1
  75. package/lib/typescript/src/Utils.d.ts +15 -0
  76. package/lib/typescript/src/Utils.d.ts.map +1 -1
  77. package/lib/typescript/src/nativeAd/NativeAdView.d.ts +15 -7
  78. package/lib/typescript/src/nativeAd/NativeAdView.d.ts.map +1 -1
  79. package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts +65 -1
  80. package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  81. package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts +17 -0
  82. package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  83. package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts +45 -1
  84. package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts.map +1 -1
  85. package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts +57 -6
  86. package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts.map +1 -1
  87. package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts +13 -3
  88. package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts.map +1 -1
  89. package/lib/typescript/src/types/AdEvent.d.ts +10 -4
  90. package/lib/typescript/src/types/AdEvent.d.ts.map +1 -1
  91. package/lib/typescript/src/types/AdInfo.d.ts +78 -85
  92. package/lib/typescript/src/types/AdInfo.d.ts.map +1 -1
  93. package/lib/typescript/src/types/AdProps.d.ts +14 -15
  94. package/lib/typescript/src/types/AdProps.d.ts.map +1 -1
  95. package/lib/typescript/src/types/AdViewProps.d.ts +32 -29
  96. package/lib/typescript/src/types/AdViewProps.d.ts.map +1 -1
  97. package/lib/typescript/src/types/AppLovinMAX.d.ts +50 -53
  98. package/lib/typescript/src/types/AppLovinMAX.d.ts.map +1 -1
  99. package/lib/typescript/src/types/BannerAd.d.ts +24 -18
  100. package/lib/typescript/src/types/BannerAd.d.ts.map +1 -1
  101. package/lib/typescript/src/types/CMPError.d.ts +7 -4
  102. package/lib/typescript/src/types/CMPError.d.ts.map +1 -1
  103. package/lib/typescript/src/types/Configuration.d.ts +12 -14
  104. package/lib/typescript/src/types/Configuration.d.ts.map +1 -1
  105. package/lib/typescript/src/types/FullscreenAd.d.ts +39 -46
  106. package/lib/typescript/src/types/FullscreenAd.d.ts.map +1 -1
  107. package/lib/typescript/src/types/MRecAd.d.ts +7 -3
  108. package/lib/typescript/src/types/MRecAd.d.ts.map +1 -1
  109. package/lib/typescript/src/types/NativeAd.d.ts +12 -11
  110. package/lib/typescript/src/types/NativeAd.d.ts.map +1 -1
  111. package/lib/typescript/src/types/NativeAdViewProps.d.ts +4 -3
  112. package/lib/typescript/src/types/NativeAdViewProps.d.ts.map +1 -1
  113. package/lib/typescript/src/types/Privacy.d.ts +13 -6
  114. package/lib/typescript/src/types/Privacy.d.ts.map +1 -1
  115. package/lib/typescript/src/types/RewardedAd.d.ts +7 -5
  116. package/lib/typescript/src/types/RewardedAd.d.ts.map +1 -1
  117. package/lib/typescript/src/types/ViewAd.d.ts +46 -50
  118. package/lib/typescript/src/types/ViewAd.d.ts.map +1 -1
  119. package/package.json +1 -1
  120. package/react-native-applovin-max.podspec +2 -2
  121. package/src/AdView.tsx +64 -82
  122. package/src/AppLovinMAX.ts +39 -29
  123. package/src/BannerAd.ts +2 -3
  124. package/src/ErrorCode.ts +24 -31
  125. package/src/EventEmitter.ts +20 -2
  126. package/src/Utils.ts +20 -1
  127. package/src/nativeAd/NativeAdView.tsx +31 -21
  128. package/src/nativeAd/NativeAdViewComponents.tsx +97 -38
  129. package/src/nativeAd/NativeAdViewProvider.tsx +23 -0
  130. package/src/specs/AppLovinMAXAdViewNativeComponent.ts +62 -1
  131. package/src/specs/AppLovinMAXNativeAdViewNativeComponent.ts +70 -6
  132. package/src/specs/NativeAppLovinMAXModule.ts +77 -56
  133. package/src/types/AdEvent.ts +10 -4
  134. package/src/types/AdInfo.ts +78 -85
  135. package/src/types/AdProps.ts +14 -15
  136. package/src/types/AdViewProps.ts +33 -29
  137. package/src/types/AppLovinMAX.ts +50 -53
  138. package/src/types/BannerAd.ts +24 -18
  139. package/src/types/CMPError.ts +7 -4
  140. package/src/types/Configuration.ts +12 -14
  141. package/src/types/FullscreenAd.ts +39 -46
  142. package/src/types/MRecAd.ts +7 -3
  143. package/src/types/NativeAd.ts +12 -11
  144. package/src/types/NativeAdViewProps.ts +4 -3
  145. package/src/types/Privacy.ts +13 -6
  146. package/src/types/RewardedAd.ts +7 -5
  147. package/src/types/ViewAd.ts +46 -50
package/src/AdView.tsx CHANGED
@@ -13,7 +13,7 @@ import { makeExtraParametersArray, makeLocalExtraParametersArray } from './Utils
13
13
  const { ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOADED_EVENT, ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOAD_FAILED_EVENT } = AppLovinMAX.getConstants();
14
14
 
15
15
  /**
16
- * Defines a format of an ad.
16
+ * Defines the format of an ad.
17
17
  */
18
18
  export enum AdFormat {
19
19
  /**
@@ -28,7 +28,7 @@ export enum AdFormat {
28
28
  }
29
29
 
30
30
  /**
31
- * Defines a position of a banner or MREC ad.
31
+ * Defines the position for rendering a banner or MREC ad within its container.
32
32
  */
33
33
  export enum AdViewPosition {
34
34
  TOP_CENTER = 'top_center',
@@ -51,76 +51,53 @@ const ADVIEW_SIZE = {
51
51
  mrec: { width: 300, height: 250 },
52
52
  };
53
53
 
54
- // Returns 'auto' for unspecified width / height
54
+ // Extracts width and height from the style prop, defaulting to 'auto' when unspecified.
55
55
  const getOutlineViewSize = (style: StyleProp<ViewStyle>): [DimensionValue, DimensionValue] => {
56
56
  const viewStyle = StyleSheet.flatten(style) || {};
57
57
  return [viewStyle.width ?? 'auto', viewStyle.height ?? 'auto'];
58
58
  };
59
59
 
60
- const sizeBannerDimensions = async (sizeProps: SizeRecord, adaptiveBannerEnabled: boolean, screenWidth: number, bannerFormatSize: SizeRecord): Promise<SizeRecord> => {
61
- const width = sizeProps.width === 'auto' ? screenWidth : sizeProps.width;
62
-
63
- let height;
64
- if (sizeProps.height === 'auto') {
65
- if (adaptiveBannerEnabled) {
66
- try {
67
- height = await AppLovinMAX.getAdaptiveBannerHeightForWidth(screenWidth);
68
- } catch (error) {
69
- console.error('Error getting adaptive banner height:', error);
70
- height = bannerFormatSize.height;
71
- }
72
- } else {
73
- height = bannerFormatSize.height;
74
- }
75
- } else {
76
- height = sizeProps.height;
77
- }
78
-
79
- return { width, height };
80
- };
81
-
82
60
  const handleAdViewEvent = <T extends AdInfoEvent | AdLoadFailedEvent | AdDisplayFailedEvent>(event: NativeSyntheticEvent<T>, callback?: (adInfo: T) => void) => {
83
61
  if (!callback) return;
84
-
85
- let adInfo: any = { ...event.nativeEvent };
86
-
87
- if ('size' in event.nativeEvent) {
88
- adInfo.size = {
89
- width: event.nativeEvent.size?.width ?? 0,
90
- height: event.nativeEvent.size?.height ?? 0,
91
- };
92
- }
93
-
94
- callback(adInfo);
62
+ callback(event.nativeEvent);
95
63
  };
96
64
 
97
65
  /**
98
- * The {@link AdView} component renders banner or MREC ads with responsive sizing.
99
- * - **Banners**: 320x50 on phones, 728x90 on tablets.
100
- * - **MRECs**: 300x250 on all devices.
66
+ * Renders a banner or MREC ad using a native view, with adaptive or responsive sizing.
101
67
  *
102
- * Use {@link AppLovinMAX.isTablet()} to determine device type for layout adjustments.
103
- * For adaptive banners, use {@link BannerAd.getAdaptiveHeightForWidth()} for precise sizing.
68
+ * - **Banners**: 320×50 on phones, 728×90 on tablets.
69
+ * - **MRECs**: Fixed size of 300×250 on all devices.
70
+ *
71
+ * Internally uses {@link AppLovinMAX.isTablet()} to determine banner size on tablets.
72
+ * You can also use this method externally to assist with layout decisions.
73
+ *
74
+ * For adaptive banners, use {@link BannerAd.getAdaptiveHeightForWidth()} to determine the appropriate height.
104
75
  *
105
76
  * **Preloading**:
106
- * When preloading an {@link AdView} using {@link preloadNativeUIComponentAdView},
107
- * the returned {@link AdViewId} must be passed to identify the preloaded instance.
77
+ * If you preload an ad for AdView using {@link preloadNativeUIComponentAdView},
78
+ * pass the returned {@link AdViewId} to this component to display the preloaded instance.
79
+ *
80
+ * **Note:** The AppLovin SDK must be initialized before using this component.
108
81
  *
109
82
  * ### Example:
110
- * ```js
83
+ * ```tsx
111
84
  * <AdView
112
85
  * adUnitId={adUnitId}
113
86
  * adFormat={AdFormat.BANNER}
114
87
  * placement="my_placement"
115
88
  * customData="my_customData"
116
- * extraParameters={{"key1":"value1", "key2":"value2"}}
117
- * localExtraParameters={{"key1":123", "key2":object}}
89
+ * extraParameters={{ key1: "value1", key2: "value2" }}
90
+ * localExtraParameters={{ key1: "value1", key2: true }}
118
91
  * adaptiveBannerEnabled={false}
119
92
  * autoRefresh={false}
120
93
  * style={styles.banner}
121
94
  * onAdLoaded={(adInfo: AdInfo) => { ... }}
122
95
  * />
123
96
  * ```
97
+ *
98
+ * For complete implementation examples, see:
99
+ * - https://github.com/AppLovin/AppLovin-MAX-React-Native/blob/master/example/src/NativeBannerExample.tsx
100
+ * - https://github.com/AppLovin/AppLovin-MAX-React-Native/blob/master/example/src/NativeMRecExample.tsx
124
101
  */
125
102
  export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(function AdView(
126
103
  {
@@ -151,10 +128,13 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
151
128
  const [, forceUpdate] = useReducer((x) => x + 1, 0);
152
129
  const adViewRef = useRef<React.ElementRef<typeof AdViewComponent> | undefined>();
153
130
  const [isInitialized, setIsInitialized] = useState<boolean>(false);
154
- const sizeProps = useRef<SizeRecord>({});
155
131
  const dimensions = useRef<SizeRecord>({});
156
132
 
157
- useImperativeHandle(ref, () => ({ loadAd: () => Commands.loadAd(adViewRef.current!) }), []);
133
+ const loadAd = useCallback(() => {
134
+ adViewRef.current && Commands.loadAd(adViewRef.current);
135
+ }, []);
136
+
137
+ useImperativeHandle(ref, () => ({ loadAd }), [loadAd]);
158
138
 
159
139
  useEffect(() => {
160
140
  (async () => {
@@ -164,7 +144,7 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
164
144
  const initialized = await AppLovinMAX.isInitialized();
165
145
  setIsInitialized(initialized);
166
146
  if (!initialized) {
167
- console.warn('AdView is mounted before the initialization of the AppLovin MAX React Native module');
147
+ console.warn('AdView was mounted before the AppLovin MAX React Native module was initialized.');
168
148
  }
169
149
  })();
170
150
  }, [adFormat]);
@@ -172,45 +152,50 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
172
152
  useEffect(() => {
173
153
  const [width, height] = getOutlineViewSize(style);
174
154
 
175
- if (sizeProps.current.width === width && sizeProps.current.height === height) return;
176
-
177
- sizeProps.current = { width, height };
155
+ if (dimensions.current.width === width && dimensions.current.height === height) return;
178
156
 
179
157
  (async () => {
180
- if (adFormat === AdFormat.BANNER) {
181
- const adaptedSize = await sizeBannerDimensions(sizeProps.current, adaptiveBannerEnabled, screenWidth, adFormatSize.current);
182
-
183
- if (dimensions.current.width !== adaptedSize.width || dimensions.current.height !== adaptedSize.height) {
184
- dimensions.current = adaptedSize;
185
- forceUpdate();
158
+ const isBanner = adFormat === AdFormat.BANNER;
159
+ const isWidthAuto = width === 'auto';
160
+ const isHeightAuto = height === 'auto';
161
+
162
+ const resolvedWidth = isWidthAuto ? (isBanner ? screenWidth : adFormatSize.current.width) : width;
163
+
164
+ let resolvedHeight: DimensionValue | undefined = height;
165
+
166
+ if (isHeightAuto) {
167
+ if (isBanner && adaptiveBannerEnabled) {
168
+ try {
169
+ resolvedHeight = await AppLovinMAX.getAdaptiveBannerHeightForWidth(screenWidth);
170
+ } catch (error) {
171
+ console.error('Error getting adaptive banner height:', error);
172
+ resolvedHeight = adFormatSize.current.height;
173
+ }
174
+ } else {
175
+ resolvedHeight = adFormatSize.current.height;
186
176
  }
187
- } else {
188
- dimensions.current = {
189
- width: width === 'auto' ? adFormatSize.current.width : width,
190
- height: height === 'auto' ? adFormatSize.current.height : height,
191
- };
177
+ }
178
+
179
+ const newSize = { width: resolvedWidth, height: resolvedHeight };
180
+
181
+ if (dimensions.current.width !== newSize.width || dimensions.current.height !== newSize.height) {
182
+ dimensions.current = newSize;
192
183
  forceUpdate();
193
184
  }
194
185
  })();
195
186
  }, [adFormat, adaptiveBannerEnabled, isInitialized, screenWidth, style]);
196
187
 
197
188
  const onAdLoadedEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdLoaded), [onAdLoaded]);
198
-
199
189
  const onAdLoadFailedEvent = useCallback((event: NativeSyntheticEvent<AdLoadFailedEvent>) => handleAdViewEvent(event, onAdLoadFailed), [onAdLoadFailed]);
200
-
201
190
  const onAdDisplayFailedEvent = useCallback((event: NativeSyntheticEvent<AdDisplayFailedEvent>) => handleAdViewEvent(event, onAdDisplayFailed), [onAdDisplayFailed]);
202
-
203
191
  const onAdClickedEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdClicked), [onAdClicked]);
204
-
205
192
  const onAdExpandedEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdExpanded), [onAdExpanded]);
206
-
207
193
  const onAdCollapsedEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdCollapsed), [onAdCollapsed]);
208
-
209
194
  const onAdRevenuePaidEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdRevenuePaid), [onAdRevenuePaid]);
210
195
 
211
196
  if (!isInitialized || Object.keys(dimensions.current).length === 0) {
212
197
  // Early return if not initialized or dimensions are not set
213
- return <View style={Object.assign({}, style, dimensions.current)} {...otherProps} />;
198
+ return <View style={style} {...otherProps} />;
214
199
  }
215
200
 
216
201
  return (
@@ -234,7 +219,7 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
234
219
  onAdExpandedEvent={onAdExpandedEvent}
235
220
  onAdCollapsedEvent={onAdCollapsedEvent}
236
221
  onAdRevenuePaidEvent={onAdRevenuePaidEvent}
237
- style={Object.assign({}, style, dimensions.current)}
222
+ style={[style, dimensions.current]}
238
223
  {...otherProps}
239
224
  />
240
225
  );
@@ -247,15 +232,15 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
247
232
  * - Unmounting {@link AdView} does not destroy the preloaded component—it will be reused on the next mount.
248
233
  * - You must manually destroy the preloaded component when it is no longer needed using {@link destroyNativeUIComponentAdView}.
249
234
  *
250
- * @param adUnitId - The Ad Unit ID for which the ads should be preloaded.
235
+ * @param adUnitId - The Ad Unit ID for which ads should be preloaded.
251
236
  * @param adFormat - The ad format to preload. Must be either {@link AdFormat.BANNER} or {@link AdFormat.MREC}.
252
237
  * @param options - Optional properties to configure the native UI component (e.g., placement, custom data).
253
- * @returns A promise resolving to an {@link AdViewId}, which uniquely identifies the preloaded component.
238
+ * @returns A promise that resolves to an {@link AdViewId}, uniquely identifying the preloaded component instance.
254
239
  * @throws An error if the preload request fails.
255
240
  */
256
241
  export const preloadNativeUIComponentAdView = async (adUnitId: string, adFormat: AdFormat, options: NativeUIComponentAdViewOptions = {}): Promise<AdViewId> => {
257
- const { placement = null, customData = null, extraParameters = {}, localExtraParameters = {} } = options;
258
- return AppLovinMAX.preloadNativeUIComponentAdView(adUnitId, adFormat, placement, customData, extraParameters, localExtraParameters);
242
+ const { isAdaptive = true, placement = null, customData = null, extraParameters = {}, localExtraParameters = {} } = options;
243
+ return AppLovinMAX.preloadNativeUIComponentAdView(adUnitId, adFormat, isAdaptive, placement, customData, extraParameters, localExtraParameters);
259
244
  };
260
245
 
261
246
  /**
@@ -275,8 +260,7 @@ export const destroyNativeUIComponentAdView = async (adViewId: AdViewId): Promis
275
260
  };
276
261
 
277
262
  /**
278
- * Adds the specified event listener to receive {@link AdInfo} when a native UI component loads a
279
- * new ad.
263
+ * Adds the specified event listener to receive {@link AdInfo} when a native UI component loads a new ad.
280
264
  *
281
265
  * @param listener Listener to be notified.
282
266
  */
@@ -285,15 +269,14 @@ export const addNativeUIComponentAdViewAdLoadedEventListener = (listener: (adInf
285
269
  };
286
270
 
287
271
  /**
288
- * Removes the event listener to receive {@link AdInfo} when a native UI component loads a new ad.
272
+ * Removes the event listener registered to receive {@link AdInfo} when a native UI component loads a new ad.
289
273
  */
290
274
  export const removeNativeUIComponentAdViewAdLoadedEventListener = (): void => {
291
275
  removeEventListener(ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOADED_EVENT);
292
276
  };
293
277
 
294
278
  /**
295
- * Adds the specified event listener to receive {@link AdLoadFailedInfo} when a native UI component
296
- * could not load a new ad.
279
+ * Adds the specified event listener to receive {@link AdLoadFailedInfo} when a native UI component could not load a new ad.
297
280
  *
298
281
  * @param listener Listener to be notified.
299
282
  */
@@ -302,8 +285,7 @@ export const addNativeUIComponentAdViewAdLoadFailedEventListener = (listener: (e
302
285
  };
303
286
 
304
287
  /**
305
- * Removes the event listener to receive {@link AdLoadFailedInfo} when a native UI component could
306
- * not load a new ad.
288
+ * Removes the event listener registered to receive {@link AdLoadFailedInfo} when a native UI component could not load a new ad.
307
289
  */
308
290
  export const removeNativeUIComponentAdViewAdLoadFailedEventListener = (): void => {
309
291
  removeEventListener(ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOAD_FAILED_EVENT);
@@ -2,93 +2,100 @@ import type { AppLovinMAXType } from './types/AppLovinMAX';
2
2
  import type { Configuration } from './types/Configuration';
3
3
  import NativeAppLovinMAX from './specs/NativeAppLovinMAXModule';
4
4
 
5
- const VERSION = '9.0.0';
5
+ const VERSION = '9.2.0';
6
6
 
7
7
  /**
8
- * This enum represents the user's geography used to determine the type of consent flow shown to the
9
- * user.
8
+ * Represents the user's geography, used to determine which type of consent flow to display.
10
9
  */
11
10
  export enum ConsentFlowUserGeography {
12
11
  /**
13
- * User's geography is unknown.
12
+ * The user's geography could not be determined.
14
13
  */
15
14
  UNKNOWN = 'U',
16
15
 
17
16
  /**
18
- * The user is in GDPR region.
17
+ * The user is located in a GDPR region.
19
18
  */
20
19
  GDPR = 'G',
21
20
 
22
21
  /**
23
- * The user is in a non-GDPR region.
22
+ * The user is not in a GDPR region.
24
23
  */
25
24
  OTHER = 'O',
26
25
  }
27
26
 
28
27
  /**
29
- * AppLovin SDK-defined app tracking transparency status values (extended to include "unavailable"
30
- * state on iOS before iOS14).
28
+ * App tracking transparency status values as defined by the AppLovin SDK.
29
+ *
30
+ * These values are based on Apple's AppTrackingTransparency framework (iOS 14+).
31
31
  */
32
32
  export enum AppTrackingStatus {
33
33
  /**
34
- * Device is on iOS before iOS14, AppTrackingTransparency.framework is not available.
34
+ * Device is running an iOS version prior to iOS 14.
35
+ * AppTrackingTransparency is not available.
35
36
  */
36
37
  UNAVAILABLE = 'U',
37
38
 
38
39
  /**
39
- * The user has not yet received an authorization request to authorize access to app-related
40
- * data that can be used for tracking the user or the device.
40
+ * The user has not yet responded to the tracking authorization prompt.
41
41
  */
42
42
  NOT_DETERMINED = 'N',
43
43
 
44
44
  /**
45
- * Authorization to access app-related data that can be used for tracking the user or the device
46
- * is restricted.
45
+ * Tracking is restricted (e.g. due to parental controls).
47
46
  */
48
47
  RESTRICTED = 'R',
49
48
 
50
49
  /**
51
- * The user denies authorization to access app-related data that can be used for tracking the
52
- * user or the device.
50
+ * The user denied authorization for tracking.
53
51
  */
54
52
  DENIED = 'D',
55
53
 
56
54
  /**
57
- * The user authorizes access to app-related data that can be used for tracking the user or the
58
- * device.
55
+ * The user authorized tracking access.
59
56
  */
60
57
  AUTHORIZED = 'A',
61
58
  }
62
59
 
63
60
  /**
64
- * Represents errors for CMP flow.
61
+ * Error codes returned from the Consent Management Platform (CMP) flow.
65
62
  */
66
63
  export enum CMPErrorCode {
67
64
  /**
68
- * Indicates that an unspecified error has occurred.
65
+ * An unspecified error occurred.
69
66
  */
70
67
  UNSPECIFIED = -1,
71
68
 
72
69
  /**
73
- * Indicates that the CMP has not been integrated correctly.
70
+ * The CMP was not integrated correctly.
74
71
  */
75
72
  INTEGRATION_ERROR = 1,
76
73
 
77
74
  /**
78
- * Indicates that the CMP form is unavailable.
75
+ * The CMP form is unavailable.
79
76
  */
80
77
  FORM_UNAVAILABLE = 2,
81
78
 
82
79
  /**
83
- * Indicates that the CMP form is not required.
80
+ * The CMP form is not required for this user.
84
81
  */
85
82
  FORM_NOT_REQUIRED = 3,
86
83
  }
87
84
 
88
- const initialize = (sdkKey: string): Promise<Configuration> => {
89
- return NativeAppLovinMAX.initialize(VERSION, sdkKey);
90
- };
85
+ /**
86
+ * Initializes the AppLovin MAX SDK with the provided SDK key.
87
+ *
88
+ * @param sdkKey - Your AppLovin SDK key.
89
+ * @returns A promise that resolves with the SDK configuration.
90
+ */
91
+ const initialize = (sdkKey: string): Promise<Configuration> => NativeAppLovinMAX.initialize(VERSION, sdkKey);
91
92
 
93
+ /**
94
+ * Retrieves the user segments.
95
+ *
96
+ * @returns A promise resolving to a Map of segment IDs to arrays of group IDs,
97
+ * or `null` if no segments are available.
98
+ */
92
99
  const getSegments = async (): Promise<Map<number, number[]> | null> => {
93
100
  const segments = await NativeAppLovinMAX.getSegments();
94
101
 
@@ -98,10 +105,8 @@ const getSegments = async (): Promise<Map<number, number[]> | null> => {
98
105
 
99
106
  const map = new Map<number, number[]>();
100
107
 
101
- for (const key in segments) {
102
- // Convert the key from a string to a number. In JavaScript, an object cannot have an
103
- // integer as a key, but the Map object can have keys of any data type.
104
- const value = segments[key];
108
+ for (const [key, value] of Object.entries(segments)) {
109
+ // In JavaScript, object keys are always strings, so we convert them to numbers for the Map.
105
110
  if (value) {
106
111
  map.set(Number(key), value);
107
112
  }
@@ -110,10 +115,15 @@ const getSegments = async (): Promise<Map<number, number[]> | null> => {
110
115
  return map;
111
116
  };
112
117
 
118
+ // All native methods except those overridden here
113
119
  type NativeAppLovinMAXType = Omit<AppLovinMAXType, 'initialize' | 'getSegments'>;
114
120
 
115
121
  const nativeMethods: NativeAppLovinMAXType = NativeAppLovinMAX;
116
122
 
123
+ /**
124
+ * Main AppLovin MAX module interface exposed to JavaScript.
125
+ * Wraps the native module and overrides `initialize()` and `getSegments()` for custom handling.
126
+ */
117
127
  export const AppLovinMAX: AppLovinMAXType = Object.create(nativeMethods, {
118
128
  initialize: {
119
129
  value: initialize,
package/src/BannerAd.ts CHANGED
@@ -14,9 +14,8 @@ const {
14
14
  ON_BANNER_AD_REVENUE_PAID,
15
15
  } = AppLovinMAX.getConstants();
16
16
 
17
- const createAd = (adUnitId: string, position: AdViewPosition, xOffset: number = 0, yOffset: number = 0): void => {
18
- AppLovinMAX.createBannerWithOffsets(adUnitId, position, xOffset, yOffset);
19
- AppLovinMAX.setBannerExtraParameter(adUnitId, 'adaptive_banner', 'true');
17
+ const createAd = (adUnitId: string, position: AdViewPosition, xOffset: number = 0, yOffset: number = 0, isAdaptive: boolean = true): void => {
18
+ AppLovinMAX.createBannerWithOffsets(adUnitId, position, xOffset, yOffset, isAdaptive);
20
19
  };
21
20
 
22
21
  const destroyAd = (adUnitId: string): void => {
package/src/ErrorCode.ts CHANGED
@@ -16,85 +16,78 @@ const {
16
16
  } = AppLovinMAX.getConstants();
17
17
 
18
18
  /**
19
- * This enum contains various error codes that the SDK can return when a MAX ad fails to load or
20
- * display.
19
+ * Error codes returned by the AppLovin MAX SDK when an ad fails to load or display.
21
20
  */
22
21
  export enum ErrorCode {
23
22
  /**
24
- * This error code represents an error that could not be categorized into one of the other defined
25
- * errors. See the message field in the error object for more details.
23
+ * An unspecified error occurred.
24
+ * See the `message` field for more details.
26
25
  */
27
26
  UNSPECIFIED = MAX_ERROR_CODE_UNSPECIFIED,
28
27
 
29
28
  /**
30
- * This error code indicates that MAX returned no eligible ads from any mediated networks for this
31
- * app/device.
29
+ * No eligible ads were returned from any mediated networks.
32
30
  */
33
31
  NO_FILL = MAX_ERROR_CODE_NO_FILL,
34
32
 
35
33
  /**
36
- * This error code indicates that MAX returned eligible ads from mediated networks, but all ads
37
- * failed to load. See the adLoadFailureInfo field in the error object for more details.
34
+ * Eligible ads were returned but all failed to load.
35
+ * See `adLoadFailureInfo` for more details.
38
36
  */
39
37
  AD_LOAD_FAILED = MAX_ERROR_CODE_AD_LOAD_FAILED,
40
38
 
41
39
  /**
42
- * This error code represents an error that was encountered when showing an ad.
40
+ * An error occurred while attempting to display the ad.
43
41
  */
44
42
  AD_DISPLAY_FAILED = MAX_ERROR_CODE_AD_DISPLAY_FAILED,
45
43
 
46
44
  /**
47
- * This error code indicates that the ad request failed due to a generic network error. See the
48
- * message field in the error object for more details.
45
+ * The ad request failed due to a general network issue.
46
+ * See the `message` field for details.
49
47
  */
50
48
  NETWORK_ERROR = MAX_ERROR_CODE_NETWORK_ERROR,
51
49
 
52
50
  /**
53
- * This error code indicates that the ad request timed out due to a slow internet connection.
51
+ * The ad request timed out, likely due to a slow internet connection.
54
52
  */
55
53
  NETWORK_TIMEOUT = MAX_ERROR_CODE_NETWORK_TIMEOUT,
56
54
 
57
55
  /**
58
- * This error code indicates that the ad request failed because the device is not connected to the
59
- * internet.
56
+ * The ad request failed because the device was offline.
60
57
  */
61
58
  NO_NETWORK = MAX_ERROR_CODE_NO_NETWORK,
62
59
 
63
60
  /**
64
- * This error code indicates that you attempted to show a fullscreen ad while another fullscreen ad
65
- * is still showing.
61
+ * A fullscreen ad was requested while another one was already showing.
66
62
  */
67
63
  FULLSCREEN_AD_ALREADY_SHOWING = MAX_ERROR_CODE_FULLSCREEN_AD_ALREADY_SHOWING,
68
64
 
69
65
  /**
70
- * This error code indicates you are attempting to show a fullscreen ad before the one has been
71
- * loaded.
66
+ * A fullscreen ad was requested before it had finished loading.
72
67
  */
73
68
  FULLSCREEN_AD_NOT_READY = MAX_ERROR_CODE_FULLSCREEN_AD_NOT_READY,
74
69
 
75
70
  /**
76
- * This error code indicates you attempted to present a fullscreen ad from an invalid view
77
- * controller.
78
- * **iOS ONLY**.
71
+ * The ad was presented from an invalid view controller.
72
+ * **iOS only**.
79
73
  */
80
74
  FULLSCREEN_AD_INVALID_VIEW_CONTROLLER = MAX_ERROR_CODE_FULLSCREEN_AD_INVALID_VIEW_CONTROLLER,
81
75
 
82
76
  /**
83
- * This error code indicates that the SDK failed to display an ad because the user has the
84
- * "Don't Keep Activities" developer setting enabled.
85
- * **Android ONLY**.
77
+ * The SDK was unable to display the ad because the
78
+ * "Don't Keep Activities" developer setting is enabled.
79
+ * **Android only**.
86
80
  */
87
81
  DONT_KEEP_ACTIVITIES_ENABLED = MAX_ERROR_CODE_DONT_KEEP_ACTIVITIES_ENABLED,
88
82
 
89
83
  /**
90
- * This error code indicates that the SDK failed to load an ad because the publisher provided an
91
- * invalid ad unit identifier.
84
+ * The ad failed to load due to an invalid ad unit identifier.
92
85
  *
93
- * Possible reasons for an invalid ad unit identifier:
94
- * 1. Ad unit identifier is malformed or does not exist.
95
- * 2. Ad unit is disabled.
96
- * 3. Ad unit is not associated with the current app's package name.
97
- * 4. Ad unit was created within the last 30-60 minutes.
86
+ * Possible causes:
87
+ * 1. The ad unit ID is malformed or does not exist.
88
+ * 2. The ad unit is disabled.
89
+ * 3. The ad unit is not linked to the current apps package name.
90
+ * 4. The ad unit was recently created (less than ~3060 minutes ago).
98
91
  */
99
92
  INVALID_AD_UNIT_ID = MAX_ERROR_CODE_INVALID_AD_UNIT_ID,
100
93
  }
@@ -1,15 +1,28 @@
1
+ /**
2
+ * Manages AppLovin MAX ad event listeners using a shared NativeEventEmitter.
3
+ * Ensures only one active subscription per event type at any given time.
4
+ */
5
+
1
6
  import { NativeEventEmitter } from 'react-native';
2
7
  import type { EventSubscription } from 'react-native';
3
8
  import type { AdEventObject, AdEventListener } from './types/AdEvent';
4
9
  import AppLovinMAX from './specs/NativeAppLovinMAXModule';
5
10
 
6
- // Note that this is a singleton in ES6 module
11
+ // Singleton event emitter for AppLovin MAX native events.
7
12
  const emitter = new NativeEventEmitter(AppLovinMAX);
8
13
 
14
+ // Tracks active subscriptions by event type.
9
15
  const subscriptions: Record<string, EventSubscription> = {};
10
16
 
17
+ /**
18
+ * Subscribes to a specific ad event.
19
+ * If a listener already exists for the event, it will be replaced.
20
+ *
21
+ * @param event - The event name to listen for.
22
+ * @param handler - The callback to handle the event.
23
+ */
11
24
  export const addEventListener = <T extends AdEventObject>(event: string, handler: AdEventListener<T>): void => {
12
- const subscription: EventSubscription = emitter.addListener(event, handler);
25
+ const subscription = emitter.addListener(event, handler);
13
26
  const currentSubscription = subscriptions[event];
14
27
  if (currentSubscription) {
15
28
  currentSubscription.remove();
@@ -17,6 +30,11 @@ export const addEventListener = <T extends AdEventObject>(event: string, handler
17
30
  subscriptions[event] = subscription;
18
31
  };
19
32
 
33
+ /**
34
+ * Unsubscribes from a specific ad event, if a listener exists.
35
+ *
36
+ * @param event - The event name to unsubscribe from.
37
+ */
20
38
  export const removeEventListener = (event: string): void => {
21
39
  const currentSubscription = subscriptions[event];
22
40
  if (currentSubscription) {
package/src/Utils.ts CHANGED
@@ -1,6 +1,17 @@
1
1
  import type { LocalExtraParameterValue } from './types/AdProps';
2
2
 
3
- export const makeExtraParametersArray = (input?: Record<string, string | null>) => (input ? Object.entries(input).map(([key, value]) => ({ key, value })) : []);
3
+ /**
4
+ * Converts a record of string-based extra parameters into an array of `{ key, value }` objects.
5
+ * Used for sending extra parameters to the native SDK.
6
+ *
7
+ * @param input - An optional map of key-value string pairs (or null values).
8
+ * @returns An array of `{ key, value }` objects. Returns an empty array if input is undefined.
9
+ */
10
+ export const makeExtraParametersArray = (input?: Record<string, string | null>): { key: string; value: string | null }[] => {
11
+ if (!input) return [];
12
+
13
+ return Object.entries(input).map(([key, value]) => ({ key, value }));
14
+ };
4
15
 
5
16
  type LocalExtraParameterType = 'str' | 'bool';
6
17
 
@@ -9,6 +20,14 @@ type LocalExtraParameterValueMap = {
9
20
  bool: boolean | null;
10
21
  };
11
22
 
23
+ /**
24
+ * Converts a map of local extra parameters into a filtered array of `{ key, value }` pairs.
25
+ * Only values matching the specified type (`'str'` or `'bool'`) are included.
26
+ *
27
+ * @param input - A record of local extra parameters (string, boolean, or null).
28
+ * @param type - The expected type of each value: `'str'` for strings, `'bool'` for booleans.
29
+ * @returns A filtered array of `{ key, value }` objects, cast to the specified type.
30
+ */
12
31
  export const makeLocalExtraParametersArray = <T extends LocalExtraParameterType>(
13
32
  input: Record<string, LocalExtraParameterValue> | undefined,
14
33
  type: T