react-native-applovin-max 8.2.0 → 9.1.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 (196) hide show
  1. package/android/build.gradle +14 -3
  2. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdView.java +34 -27
  3. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewManagerImpl.java +110 -0
  4. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewUiComponent.java +15 -13
  5. package/android/src/main/java/com/applovin/reactnative/{AppLovinMAXModule.java → AppLovinMAXModuleImpl.java} +108 -168
  6. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdView.java +84 -56
  7. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManagerImpl.java +101 -0
  8. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXPackage.java +44 -11
  9. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXUtils.java +56 -0
  10. package/android/src/newarch/com/applovin/reactnative/AppLovinMAXAdViewManager.java +151 -0
  11. package/android/src/newarch/com/applovin/reactnative/AppLovinMAXModule.java +453 -0
  12. package/android/src/newarch/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +130 -0
  13. package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXAdViewManager.java +128 -0
  14. package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXModule.java +453 -0
  15. package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +93 -0
  16. package/ios/AppLovinMAX.h +8 -3
  17. package/ios/{AppLovinMAX.m → AppLovinMAX.mm} +67 -53
  18. package/ios/AppLovinMAXAdView.h +7 -2
  19. package/ios/AppLovinMAXAdView.mm +747 -0
  20. package/ios/{AppLovinMAXAdViewManager.m → AppLovinMAXAdViewManager.mm} +3 -2
  21. package/ios/{AppLovinMAXAdViewUIComponent.m → AppLovinMAXAdViewUIComponent.mm} +2 -1
  22. package/ios/AppLovinMAXNativeAdView.h +15 -4
  23. package/ios/AppLovinMAXNativeAdView.mm +745 -0
  24. package/ios/AppLovinMAXNativeAdViewManager.mm +116 -0
  25. package/lib/commonjs/AdView.js +102 -142
  26. package/lib/commonjs/AdView.js.map +1 -1
  27. package/lib/commonjs/AppLovinMAX.js +49 -34
  28. package/lib/commonjs/AppLovinMAX.js.map +1 -1
  29. package/lib/commonjs/AppOpenAd.js +8 -10
  30. package/lib/commonjs/AppOpenAd.js.map +1 -1
  31. package/lib/commonjs/BannerAd.js +19 -21
  32. package/lib/commonjs/BannerAd.js.map +1 -1
  33. package/lib/commonjs/ErrorCode.js +27 -36
  34. package/lib/commonjs/ErrorCode.js.map +1 -1
  35. package/lib/commonjs/EventEmitter.js +24 -5
  36. package/lib/commonjs/EventEmitter.js.map +1 -1
  37. package/lib/commonjs/InterstitialAd.js +8 -10
  38. package/lib/commonjs/InterstitialAd.js.map +1 -1
  39. package/lib/commonjs/MRecAd.js +14 -16
  40. package/lib/commonjs/MRecAd.js.map +1 -1
  41. package/lib/commonjs/Privacy.js +3 -5
  42. package/lib/commonjs/Privacy.js.map +1 -1
  43. package/lib/commonjs/RewardedAd.js +8 -10
  44. package/lib/commonjs/RewardedAd.js.map +1 -1
  45. package/lib/commonjs/Utils.js +43 -0
  46. package/lib/commonjs/Utils.js.map +1 -0
  47. package/lib/commonjs/nativeAd/NativeAdView.js +84 -50
  48. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  49. package/lib/commonjs/nativeAd/NativeAdViewComponents.js +129 -82
  50. package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
  51. package/lib/commonjs/nativeAd/NativeAdViewProvider.js +67 -8
  52. package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
  53. package/lib/commonjs/nativeAd/img/blank_icon.png +0 -0
  54. package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js +41 -0
  55. package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -0
  56. package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js +37 -0
  57. package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -0
  58. package/lib/commonjs/specs/NativeAppLovinMAXModule.js +16 -0
  59. package/lib/commonjs/specs/NativeAppLovinMAXModule.js.map +1 -0
  60. package/lib/commonjs/types/AdInfo.js +13 -16
  61. package/lib/commonjs/types/AdInfo.js.map +1 -1
  62. package/lib/module/AdView.js +98 -139
  63. package/lib/module/AdView.js.map +1 -1
  64. package/lib/module/AppLovinMAX.js +47 -32
  65. package/lib/module/AppLovinMAX.js.map +1 -1
  66. package/lib/module/AppOpenAd.js +1 -4
  67. package/lib/module/AppOpenAd.js.map +1 -1
  68. package/lib/module/BannerAd.js +1 -4
  69. package/lib/module/BannerAd.js.map +1 -1
  70. package/lib/module/ErrorCode.js +25 -35
  71. package/lib/module/ErrorCode.js.map +1 -1
  72. package/lib/module/EventEmitter.js +24 -5
  73. package/lib/module/EventEmitter.js.map +1 -1
  74. package/lib/module/InterstitialAd.js +2 -5
  75. package/lib/module/InterstitialAd.js.map +1 -1
  76. package/lib/module/MRecAd.js +1 -4
  77. package/lib/module/MRecAd.js.map +1 -1
  78. package/lib/module/Privacy.js +1 -4
  79. package/lib/module/Privacy.js.map +1 -1
  80. package/lib/module/RewardedAd.js +2 -5
  81. package/lib/module/RewardedAd.js.map +1 -1
  82. package/lib/module/Utils.js +35 -0
  83. package/lib/module/Utils.js.map +1 -0
  84. package/lib/module/nativeAd/NativeAdView.js +83 -47
  85. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  86. package/lib/module/nativeAd/NativeAdViewComponents.js +134 -83
  87. package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
  88. package/lib/module/nativeAd/NativeAdViewProvider.js +69 -9
  89. package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
  90. package/lib/module/nativeAd/img/blank_icon.png +0 -0
  91. package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js +35 -0
  92. package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -0
  93. package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js +31 -0
  94. package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -0
  95. package/lib/module/specs/NativeAppLovinMAXModule.js +12 -0
  96. package/lib/module/specs/NativeAppLovinMAXModule.js.map +1 -0
  97. package/lib/module/types/AdInfo.js +13 -16
  98. package/lib/module/types/AdInfo.js.map +1 -1
  99. package/lib/typescript/src/AdView.d.ts +38 -32
  100. package/lib/typescript/src/AdView.d.ts.map +1 -1
  101. package/lib/typescript/src/AppLovinMAX.d.ts +22 -21
  102. package/lib/typescript/src/AppLovinMAX.d.ts.map +1 -1
  103. package/lib/typescript/src/AppOpenAd.d.ts.map +1 -1
  104. package/lib/typescript/src/BannerAd.d.ts.map +1 -1
  105. package/lib/typescript/src/ErrorCode.d.ts +24 -31
  106. package/lib/typescript/src/ErrorCode.d.ts.map +1 -1
  107. package/lib/typescript/src/EventEmitter.d.ts +16 -0
  108. package/lib/typescript/src/EventEmitter.d.ts.map +1 -1
  109. package/lib/typescript/src/InterstitialAd.d.ts.map +1 -1
  110. package/lib/typescript/src/MRecAd.d.ts.map +1 -1
  111. package/lib/typescript/src/Privacy.d.ts.map +1 -1
  112. package/lib/typescript/src/RewardedAd.d.ts.map +1 -1
  113. package/lib/typescript/src/Utils.d.ts +31 -0
  114. package/lib/typescript/src/Utils.d.ts.map +1 -0
  115. package/lib/typescript/src/nativeAd/NativeAdView.d.ts +15 -7
  116. package/lib/typescript/src/nativeAd/NativeAdView.d.ts.map +1 -1
  117. package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts +65 -1
  118. package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  119. package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts +31 -5
  120. package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  121. package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts +130 -0
  122. package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts.map +1 -0
  123. package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts +131 -0
  124. package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts.map +1 -0
  125. package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts +142 -0
  126. package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts.map +1 -0
  127. package/lib/typescript/src/types/AdEvent.d.ts +10 -4
  128. package/lib/typescript/src/types/AdEvent.d.ts.map +1 -1
  129. package/lib/typescript/src/types/AdInfo.d.ts +79 -86
  130. package/lib/typescript/src/types/AdInfo.d.ts.map +1 -1
  131. package/lib/typescript/src/types/AdProps.d.ts +16 -17
  132. package/lib/typescript/src/types/AdProps.d.ts.map +1 -1
  133. package/lib/typescript/src/types/AdViewProps.d.ts +28 -29
  134. package/lib/typescript/src/types/AdViewProps.d.ts.map +1 -1
  135. package/lib/typescript/src/types/AppLovinMAX.d.ts +50 -53
  136. package/lib/typescript/src/types/AppLovinMAX.d.ts.map +1 -1
  137. package/lib/typescript/src/types/BannerAd.d.ts +22 -17
  138. package/lib/typescript/src/types/BannerAd.d.ts.map +1 -1
  139. package/lib/typescript/src/types/CMPError.d.ts +7 -4
  140. package/lib/typescript/src/types/CMPError.d.ts.map +1 -1
  141. package/lib/typescript/src/types/Configuration.d.ts +12 -14
  142. package/lib/typescript/src/types/Configuration.d.ts.map +1 -1
  143. package/lib/typescript/src/types/FullscreenAd.d.ts +39 -46
  144. package/lib/typescript/src/types/FullscreenAd.d.ts.map +1 -1
  145. package/lib/typescript/src/types/MRecAd.d.ts +7 -3
  146. package/lib/typescript/src/types/MRecAd.d.ts.map +1 -1
  147. package/lib/typescript/src/types/NativeAd.d.ts +15 -10
  148. package/lib/typescript/src/types/NativeAd.d.ts.map +1 -1
  149. package/lib/typescript/src/types/NativeAdViewProps.d.ts +4 -3
  150. package/lib/typescript/src/types/NativeAdViewProps.d.ts.map +1 -1
  151. package/lib/typescript/src/types/Privacy.d.ts +13 -6
  152. package/lib/typescript/src/types/Privacy.d.ts.map +1 -1
  153. package/lib/typescript/src/types/RewardedAd.d.ts +7 -5
  154. package/lib/typescript/src/types/RewardedAd.d.ts.map +1 -1
  155. package/lib/typescript/src/types/ViewAd.d.ts +46 -50
  156. package/lib/typescript/src/types/ViewAd.d.ts.map +1 -1
  157. package/package.json +9 -1
  158. package/react-native-applovin-max.podspec +3 -3
  159. package/src/AdView.tsx +100 -183
  160. package/src/AppLovinMAX.ts +42 -33
  161. package/src/AppOpenAd.ts +1 -3
  162. package/src/BannerAd.ts +1 -3
  163. package/src/ErrorCode.ts +25 -34
  164. package/src/EventEmitter.ts +22 -5
  165. package/src/InterstitialAd.ts +2 -4
  166. package/src/MRecAd.ts +1 -3
  167. package/src/Privacy.ts +1 -3
  168. package/src/RewardedAd.ts +2 -4
  169. package/src/Utils.ts +45 -0
  170. package/src/nativeAd/NativeAdView.tsx +83 -73
  171. package/src/nativeAd/NativeAdViewComponents.tsx +120 -89
  172. package/src/nativeAd/NativeAdViewProvider.tsx +60 -12
  173. package/src/nativeAd/img/blank_icon.png +0 -0
  174. package/src/specs/AppLovinMAXAdViewNativeComponent.ts +157 -0
  175. package/src/specs/AppLovinMAXNativeAdViewNativeComponent.ts +153 -0
  176. package/src/specs/NativeAppLovinMAXModule.ts +228 -0
  177. package/src/types/AdEvent.ts +10 -4
  178. package/src/types/AdInfo.ts +79 -86
  179. package/src/types/AdProps.ts +16 -17
  180. package/src/types/AdViewProps.ts +28 -29
  181. package/src/types/AppLovinMAX.ts +50 -53
  182. package/src/types/BannerAd.ts +22 -17
  183. package/src/types/CMPError.ts +7 -4
  184. package/src/types/Configuration.ts +12 -14
  185. package/src/types/FullscreenAd.ts +39 -46
  186. package/src/types/MRecAd.ts +7 -3
  187. package/src/types/NativeAd.ts +16 -10
  188. package/src/types/NativeAdViewProps.ts +4 -3
  189. package/src/types/Privacy.ts +13 -6
  190. package/src/types/RewardedAd.ts +7 -5
  191. package/src/types/ViewAd.ts +46 -50
  192. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewManager.java +0 -149
  193. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +0 -163
  194. package/ios/AppLovinMAXAdView.m +0 -325
  195. package/ios/AppLovinMAXNativeAdView.m +0 -432
  196. package/ios/AppLovinMAXNativeAdViewManager.m +0 -64
package/src/AdView.tsx CHANGED
@@ -1,76 +1,47 @@
1
1
  import * as React from 'react';
2
2
  import { useEffect, useState, useRef, useCallback, useImperativeHandle, useReducer, forwardRef } from 'react';
3
- import { NativeModules, requireNativeComponent, StyleSheet, UIManager, findNodeHandle, useWindowDimensions, View } from 'react-native';
4
- import type { ViewProps, ViewStyle, StyleProp, NativeMethods, DimensionValue } from 'react-native';
5
- import type { AdDisplayFailedInfo, AdInfo, AdLoadFailedInfo } from './types/AdInfo';
6
- import type { AdNativeEvent } from './types/AdEvent';
7
- import type { AdViewProps, AdViewHandler, NativeUIComponentAdViewOptions, AdViewId } from './types/AdViewProps';
3
+ import { StyleSheet, useWindowDimensions, View } from 'react-native';
4
+ import type { NativeSyntheticEvent, ViewProps, ViewStyle, StyleProp, DimensionValue } from 'react-native';
5
+ import AppLovinMAX from './specs/NativeAppLovinMAXModule';
6
+ import AdViewComponent, { Commands } from './specs/AppLovinMAXAdViewNativeComponent';
7
+ import type { AdInfoEvent, AdLoadFailedEvent, AdDisplayFailedEvent } from './specs/AppLovinMAXAdViewNativeComponent';
8
8
  import { addEventListener, removeEventListener } from './EventEmitter';
9
+ import type { AdInfo, AdLoadFailedInfo } from './types/AdInfo';
10
+ import type { AdViewProps, AdViewHandler, NativeUIComponentAdViewOptions, AdViewId } from './types/AdViewProps';
11
+ import { makeExtraParametersArray, makeLocalExtraParametersArray } from './Utils';
9
12
 
10
- const { AppLovinMAX } = NativeModules;
11
-
12
- const {
13
- BANNER_AD_FORMAT_LABEL,
14
- MREC_AD_FORMAT_LABEL,
15
-
16
- TOP_CENTER_POSITION,
17
- TOP_LEFT_POSITION,
18
- TOP_RIGHT_POSITION,
19
- CENTERED_POSITION,
20
- CENTER_LEFT_POSITION,
21
- CENTER_RIGHT_POSITION,
22
- BOTTOM_LEFT_POSITION,
23
- BOTTOM_CENTER_POSITION,
24
- BOTTOM_RIGHT_POSITION,
25
-
26
- ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOADED_EVENT,
27
- ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOAD_FAILED_EVENT,
28
- } = AppLovinMAX.getConstants();
13
+ const { ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOADED_EVENT, ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOAD_FAILED_EVENT } = AppLovinMAX.getConstants();
29
14
 
30
15
  /**
31
- * Defines a format of an ad.
16
+ * Defines the format of an ad.
32
17
  */
33
18
  export enum AdFormat {
34
19
  /**
35
20
  * Banner ad.
36
21
  */
37
- BANNER = BANNER_AD_FORMAT_LABEL,
22
+ BANNER = 'BANNER',
38
23
 
39
24
  /**
40
25
  * MREC ad.
41
26
  */
42
- MREC = MREC_AD_FORMAT_LABEL,
27
+ MREC = 'MREC',
43
28
  }
44
29
 
45
30
  /**
46
- * Defines a position of a banner or MREC ad.
31
+ * Defines the position for rendering a banner or MREC ad within its container.
47
32
  */
48
33
  export enum AdViewPosition {
49
- TOP_CENTER = TOP_CENTER_POSITION,
50
- TOP_LEFT = TOP_LEFT_POSITION,
51
- TOP_RIGHT = TOP_RIGHT_POSITION,
52
- CENTERED = CENTERED_POSITION,
53
- CENTER_LEFT = CENTER_LEFT_POSITION,
54
- CENTER_RIGHT = CENTER_RIGHT_POSITION,
55
- BOTTOM_LEFT = BOTTOM_LEFT_POSITION,
56
- BOTTOM_CENTER = BOTTOM_CENTER_POSITION,
57
- BOTTOM_RIGHT = BOTTOM_RIGHT_POSITION,
34
+ TOP_CENTER = 'top_center',
35
+ TOP_LEFT = 'top_left',
36
+ TOP_RIGHT = 'top_right',
37
+ CENTERED = 'centered',
38
+ CENTER_LEFT = 'center_left',
39
+ CENTER_RIGHT = 'center_right',
40
+ BOTTOM_LEFT = 'bottom_left',
41
+ BOTTOM_CENTER = 'bottom_center',
42
+ BOTTOM_RIGHT = 'bottom_right',
58
43
  }
59
44
 
60
- type AdViewNativeEvents = {
61
- onAdLoadedEvent(event: AdNativeEvent<AdInfo>): void;
62
- onAdLoadFailedEvent(event: AdNativeEvent<AdLoadFailedInfo>): void;
63
- onAdDisplayFailedEvent(event: AdNativeEvent<AdDisplayFailedInfo>): void;
64
- onAdClickedEvent(event: AdNativeEvent<AdInfo>): void;
65
- onAdExpandedEvent(event: AdNativeEvent<AdInfo>): void;
66
- onAdCollapsedEvent(event: AdNativeEvent<AdInfo>): void;
67
- onAdRevenuePaidEvent(event: AdNativeEvent<AdInfo>): void;
68
- };
69
-
70
- const AdViewComponent = requireNativeComponent<AdViewProps & ViewProps & AdViewNativeEvents>('AppLovinMAXAdView');
71
-
72
- type AdViewType = React.Component<AdViewProps> & NativeMethods;
73
-
74
45
  type SizeKey = 'width' | 'height';
75
46
  type SizeRecord = Partial<Record<SizeKey, DimensionValue>>;
76
47
 
@@ -80,61 +51,53 @@ const ADVIEW_SIZE = {
80
51
  mrec: { width: 300, height: 250 },
81
52
  };
82
53
 
83
- // Returns 'auto' for unspecified width / height
54
+ // Extracts width and height from the style prop, defaulting to 'auto' when unspecified.
84
55
  const getOutlineViewSize = (style: StyleProp<ViewStyle>): [DimensionValue, DimensionValue] => {
85
56
  const viewStyle = StyleSheet.flatten(style) || {};
86
57
  return [viewStyle.width ?? 'auto', viewStyle.height ?? 'auto'];
87
58
  };
88
59
 
89
- const sizeBannerDimensions = async (sizeProps: SizeRecord, adaptiveBannerEnabled: boolean, screenWidth: number, bannerFormatSize: SizeRecord): Promise<SizeRecord> => {
90
- const width = sizeProps.width === 'auto' ? screenWidth : sizeProps.width;
91
-
92
- let height;
93
- if (sizeProps.height === 'auto') {
94
- if (adaptiveBannerEnabled) {
95
- try {
96
- height = await AppLovinMAX.getAdaptiveBannerHeightForWidth(screenWidth);
97
- } catch (error) {
98
- console.error('Error getting adaptive banner height:', error);
99
- height = bannerFormatSize.height;
100
- }
101
- } else {
102
- height = bannerFormatSize.height;
103
- }
104
- } else {
105
- height = sizeProps.height;
106
- }
107
-
108
- return { width, height };
60
+ const handleAdViewEvent = <T extends AdInfoEvent | AdLoadFailedEvent | AdDisplayFailedEvent>(event: NativeSyntheticEvent<T>, callback?: (adInfo: T) => void) => {
61
+ if (!callback) return;
62
+ callback(event.nativeEvent);
109
63
  };
110
64
 
111
65
  /**
112
- * The {@link AdView} component renders banner or MREC ads with responsive sizing.
113
- * - **Banners**: 320x50 on phones, 728x90 on tablets.
114
- * - **MRECs**: 300x250 on all devices.
66
+ * Renders a banner or MREC ad using a native view, with adaptive or responsive sizing.
67
+ *
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.
115
73
  *
116
- * Use {@link AppLovinMAX.isTablet()} to determine device type for layout adjustments.
117
- * For adaptive banners, use {@link BannerAd.getAdaptiveHeightForWidth()} for precise sizing.
74
+ * For adaptive banners, use {@link BannerAd.getAdaptiveHeightForWidth()} to determine the appropriate height.
118
75
  *
119
76
  * **Preloading**:
120
- * When preloading an {@link AdView} using {@link preloadNativeUIComponentAdView},
121
- * 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.
122
81
  *
123
82
  * ### Example:
124
- * ```js
83
+ * ```tsx
125
84
  * <AdView
126
85
  * adUnitId={adUnitId}
127
86
  * adFormat={AdFormat.BANNER}
128
87
  * placement="my_placement"
129
88
  * customData="my_customData"
130
- * extraParameters={{"key1":"value1", "key2":"value2"}}
131
- * localExtraParameters={{"key1":123", "key2":object}}
89
+ * extraParameters={{ key1: "value1", key2: "value2" }}
90
+ * localExtraParameters={{ key1: "value1", key2: true }}
132
91
  * adaptiveBannerEnabled={false}
133
92
  * autoRefresh={false}
134
93
  * style={styles.banner}
135
94
  * onAdLoaded={(adInfo: AdInfo) => { ... }}
136
95
  * />
137
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
138
101
  */
139
102
  export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(function AdView(
140
103
  {
@@ -163,43 +126,25 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
163
126
  const { width: screenWidth } = useWindowDimensions();
164
127
  const adFormatSize = useRef<SizeRecord>({});
165
128
  const [, forceUpdate] = useReducer((x) => x + 1, 0);
166
- const adViewRef = useRef<AdViewType | null>(null);
129
+ const adViewRef = useRef<React.ElementRef<typeof AdViewComponent> | undefined>();
167
130
  const [isInitialized, setIsInitialized] = useState<boolean>(false);
168
- const sizeProps = useRef<SizeRecord>({});
169
131
  const dimensions = useRef<SizeRecord>({});
170
132
 
171
133
  const loadAd = useCallback(() => {
172
- if (adViewRef.current) {
173
- UIManager.dispatchViewManagerCommand(
174
- findNodeHandle(adViewRef.current),
175
- // @ts-ignore: Issue in RN ts defs
176
- UIManager.getViewManagerConfig('AppLovinMAXAdView').Commands.loadAd,
177
- undefined
178
- );
179
- }
134
+ adViewRef.current && Commands.loadAd(adViewRef.current);
180
135
  }, []);
181
136
 
182
137
  useImperativeHandle(ref, () => ({ loadAd }), [loadAd]);
183
138
 
184
- const saveElement = useCallback((element: AdViewType | null) => {
185
- adViewRef.current = element;
186
- }, []);
187
-
188
139
  useEffect(() => {
189
140
  (async () => {
190
- if (adFormat === AdFormat.BANNER) {
191
- const isTablet = await AppLovinMAX.isTablet();
192
- adFormatSize.current = isTablet
193
- ? { width: ADVIEW_SIZE.leader.width, height: ADVIEW_SIZE.leader.height }
194
- : { width: ADVIEW_SIZE.banner.width, height: ADVIEW_SIZE.banner.height };
195
- } else {
196
- adFormatSize.current = { width: ADVIEW_SIZE.mrec.width, height: ADVIEW_SIZE.mrec.height };
197
- }
141
+ const isTablet = adFormat === AdFormat.BANNER ? await AppLovinMAX.isTablet() : false;
142
+ adFormatSize.current = adFormat === AdFormat.BANNER ? (isTablet ? ADVIEW_SIZE.leader : ADVIEW_SIZE.banner) : ADVIEW_SIZE.mrec;
198
143
 
199
144
  const initialized = await AppLovinMAX.isInitialized();
200
145
  setIsInitialized(initialized);
201
146
  if (!initialized) {
202
- 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.');
203
148
  }
204
149
  })();
205
150
  }, [adFormat]);
@@ -207,85 +152,55 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
207
152
  useEffect(() => {
208
153
  const [width, height] = getOutlineViewSize(style);
209
154
 
210
- if (sizeProps.current.width === width && sizeProps.current.height === height) return;
211
-
212
- sizeProps.current = { width, height };
155
+ if (dimensions.current.width === width && dimensions.current.height === height) return;
213
156
 
214
157
  (async () => {
215
- if (adFormat === AdFormat.BANNER) {
216
- const adaptedSize = await sizeBannerDimensions(sizeProps.current, adaptiveBannerEnabled, screenWidth, adFormatSize.current);
217
-
218
- if (dimensions.current.width !== adaptedSize.width || dimensions.current.height !== adaptedSize.height) {
219
- dimensions.current = adaptedSize;
220
- 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;
221
176
  }
222
- } else {
223
- dimensions.current = {
224
- width: width === 'auto' ? adFormatSize.current.width : width,
225
- height: height === 'auto' ? adFormatSize.current.height : height,
226
- };
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;
227
183
  forceUpdate();
228
184
  }
229
185
  })();
230
186
  }, [adFormat, adaptiveBannerEnabled, isInitialized, screenWidth, style]);
231
187
 
232
- const onAdLoadedEvent = useCallback(
233
- (event: AdNativeEvent<AdInfo>) => {
234
- onAdLoaded?.(event.nativeEvent);
235
- },
236
- [onAdLoaded]
237
- );
238
-
239
- const onAdLoadFailedEvent = useCallback(
240
- (event: AdNativeEvent<AdLoadFailedInfo>) => {
241
- onAdLoadFailed?.(event.nativeEvent);
242
- },
243
- [onAdLoadFailed]
244
- );
245
-
246
- const onAdDisplayFailedEvent = useCallback(
247
- (event: AdNativeEvent<AdDisplayFailedInfo>) => {
248
- onAdDisplayFailed?.(event.nativeEvent);
249
- },
250
- [onAdDisplayFailed]
251
- );
252
-
253
- const onAdClickedEvent = useCallback(
254
- (event: AdNativeEvent<AdInfo>) => {
255
- onAdClicked?.(event.nativeEvent);
256
- },
257
- [onAdClicked]
258
- );
259
-
260
- const onAdExpandedEvent = useCallback(
261
- (event: AdNativeEvent<AdInfo>) => {
262
- onAdExpanded?.(event.nativeEvent);
263
- },
264
- [onAdExpanded]
265
- );
266
-
267
- const onAdCollapsedEvent = useCallback(
268
- (event: AdNativeEvent<AdInfo>) => {
269
- onAdCollapsed?.(event.nativeEvent);
270
- },
271
- [onAdCollapsed]
272
- );
273
-
274
- const onAdRevenuePaidEvent = useCallback(
275
- (event: AdNativeEvent<AdInfo>) => {
276
- onAdRevenuePaid?.(event.nativeEvent);
277
- },
278
- [onAdRevenuePaid]
279
- );
188
+ const onAdLoadedEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdLoaded), [onAdLoaded]);
189
+ const onAdLoadFailedEvent = useCallback((event: NativeSyntheticEvent<AdLoadFailedEvent>) => handleAdViewEvent(event, onAdLoadFailed), [onAdLoadFailed]);
190
+ const onAdDisplayFailedEvent = useCallback((event: NativeSyntheticEvent<AdDisplayFailedEvent>) => handleAdViewEvent(event, onAdDisplayFailed), [onAdDisplayFailed]);
191
+ const onAdClickedEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdClicked), [onAdClicked]);
192
+ const onAdExpandedEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdExpanded), [onAdExpanded]);
193
+ const onAdCollapsedEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdCollapsed), [onAdCollapsed]);
194
+ const onAdRevenuePaidEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleAdViewEvent(event, onAdRevenuePaid), [onAdRevenuePaid]);
280
195
 
281
196
  if (!isInitialized || Object.keys(dimensions.current).length === 0) {
282
197
  // Early return if not initialized or dimensions are not set
283
- return <View style={Object.assign({}, style, dimensions.current)} {...otherProps} />;
198
+ return <View style={style} {...otherProps} />;
284
199
  }
285
200
 
286
201
  return (
287
202
  <AdViewComponent
288
- ref={saveElement}
203
+ ref={(element) => (adViewRef.current = element ?? undefined)}
289
204
  adUnitId={adUnitId}
290
205
  adFormat={adFormat}
291
206
  adViewId={adViewId || 0}
@@ -294,8 +209,9 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
294
209
  adaptiveBannerEnabled={adaptiveBannerEnabled}
295
210
  autoRefresh={autoRefresh}
296
211
  loadOnMount={loadOnMount}
297
- extraParameters={extraParameters}
298
- localExtraParameters={localExtraParameters}
212
+ extraParameters={makeExtraParametersArray(extraParameters)}
213
+ strLocalExtraParameters={makeLocalExtraParametersArray(localExtraParameters, 'str')}
214
+ boolLocalExtraParameters={makeLocalExtraParametersArray(localExtraParameters, 'bool')}
299
215
  onAdLoadedEvent={onAdLoadedEvent}
300
216
  onAdLoadFailedEvent={onAdLoadFailedEvent}
301
217
  onAdDisplayFailedEvent={onAdDisplayFailedEvent}
@@ -303,7 +219,7 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
303
219
  onAdExpandedEvent={onAdExpandedEvent}
304
220
  onAdCollapsedEvent={onAdCollapsedEvent}
305
221
  onAdRevenuePaidEvent={onAdRevenuePaidEvent}
306
- style={Object.assign({}, style, dimensions.current)}
222
+ style={[style, dimensions.current]}
307
223
  {...otherProps}
308
224
  />
309
225
  );
@@ -316,14 +232,15 @@ export const AdView = forwardRef<AdViewHandler, AdViewProps & ViewProps>(functio
316
232
  * - Unmounting {@link AdView} does not destroy the preloaded component—it will be reused on the next mount.
317
233
  * - You must manually destroy the preloaded component when it is no longer needed using {@link destroyNativeUIComponentAdView}.
318
234
  *
319
- * @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.
320
236
  * @param adFormat - The ad format to preload. Must be either {@link AdFormat.BANNER} or {@link AdFormat.MREC}.
321
237
  * @param options - Optional properties to configure the native UI component (e.g., placement, custom data).
322
- * @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.
323
239
  * @throws An error if the preload request fails.
324
240
  */
325
- export const preloadNativeUIComponentAdView = async (adUnitId: string, adFormat: AdFormat, options?: NativeUIComponentAdViewOptions): Promise<AdViewId> => {
326
- return AppLovinMAX.preloadNativeUIComponentAdView(adUnitId, adFormat, options?.placement, options?.customData, options?.extraParameters, options?.localExtraParameters);
241
+ export const preloadNativeUIComponentAdView = async (adUnitId: string, adFormat: AdFormat, options: NativeUIComponentAdViewOptions = {}): Promise<AdViewId> => {
242
+ const { placement = null, customData = null, extraParameters = {}, localExtraParameters = {} } = options;
243
+ return AppLovinMAX.preloadNativeUIComponentAdView(adUnitId, adFormat, placement, customData, extraParameters, localExtraParameters);
327
244
  };
328
245
 
329
246
  /**
@@ -336,12 +253,14 @@ export const preloadNativeUIComponentAdView = async (adUnitId: string, adFormat:
336
253
  * @throws An error if the destruction process fails.
337
254
  */
338
255
  export const destroyNativeUIComponentAdView = async (adViewId: AdViewId): Promise<void> => {
256
+ if (adViewId === undefined) {
257
+ return Promise.reject(new Error('adViewId is not provided'));
258
+ }
339
259
  return AppLovinMAX.destroyNativeUIComponentAdView(adViewId);
340
260
  };
341
261
 
342
262
  /**
343
- * Adds the specified event listener to receive {@link AdInfo} when a native UI component loads a
344
- * new ad.
263
+ * Adds the specified event listener to receive {@link AdInfo} when a native UI component loads a new ad.
345
264
  *
346
265
  * @param listener Listener to be notified.
347
266
  */
@@ -350,15 +269,14 @@ export const addNativeUIComponentAdViewAdLoadedEventListener = (listener: (adInf
350
269
  };
351
270
 
352
271
  /**
353
- * 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.
354
273
  */
355
274
  export const removeNativeUIComponentAdViewAdLoadedEventListener = (): void => {
356
275
  removeEventListener(ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOADED_EVENT);
357
276
  };
358
277
 
359
278
  /**
360
- * Adds the specified event listener to receive {@link AdLoadFailedInfo} when a native UI component
361
- * 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.
362
280
  *
363
281
  * @param listener Listener to be notified.
364
282
  */
@@ -367,8 +285,7 @@ export const addNativeUIComponentAdViewAdLoadFailedEventListener = (listener: (e
367
285
  };
368
286
 
369
287
  /**
370
- * Removes the event listener to receive {@link AdLoadFailedInfo} when a native UI component could
371
- * 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.
372
289
  */
373
290
  export const removeNativeUIComponentAdViewAdLoadFailedEventListener = (): void => {
374
291
  removeEventListener(ON_NATIVE_UI_COMPONENT_ADVIEW_AD_LOAD_FAILED_EVENT);
@@ -1,96 +1,101 @@
1
- import { NativeModules } from 'react-native';
2
1
  import type { AppLovinMAXType } from './types/AppLovinMAX';
3
2
  import type { Configuration } from './types/Configuration';
3
+ import NativeAppLovinMAX from './specs/NativeAppLovinMAXModule';
4
4
 
5
- const NativeAppLovinMAX = NativeModules.AppLovinMAX;
6
-
7
- const VERSION = '8.2.0';
5
+ const VERSION = '9.1.0';
8
6
 
9
7
  /**
10
- * This enum represents the user's geography used to determine the type of consent flow shown to the
11
- * user.
8
+ * Represents the user's geography, used to determine which type of consent flow to display.
12
9
  */
13
10
  export enum ConsentFlowUserGeography {
14
11
  /**
15
- * User's geography is unknown.
12
+ * The user's geography could not be determined.
16
13
  */
17
14
  UNKNOWN = 'U',
18
15
 
19
16
  /**
20
- * The user is in GDPR region.
17
+ * The user is located in a GDPR region.
21
18
  */
22
19
  GDPR = 'G',
23
20
 
24
21
  /**
25
- * The user is in a non-GDPR region.
22
+ * The user is not in a GDPR region.
26
23
  */
27
24
  OTHER = 'O',
28
25
  }
29
26
 
30
27
  /**
31
- * AppLovin SDK-defined app tracking transparency status values (extended to include "unavailable"
32
- * 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+).
33
31
  */
34
32
  export enum AppTrackingStatus {
35
33
  /**
36
- * 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.
37
36
  */
38
37
  UNAVAILABLE = 'U',
39
38
 
40
39
  /**
41
- * The user has not yet received an authorization request to authorize access to app-related
42
- * data that can be used for tracking the user or the device.
40
+ * The user has not yet responded to the tracking authorization prompt.
43
41
  */
44
42
  NOT_DETERMINED = 'N',
45
43
 
46
44
  /**
47
- * Authorization to access app-related data that can be used for tracking the user or the device
48
- * is restricted.
45
+ * Tracking is restricted (e.g. due to parental controls).
49
46
  */
50
47
  RESTRICTED = 'R',
51
48
 
52
49
  /**
53
- * The user denies authorization to access app-related data that can be used for tracking the
54
- * user or the device.
50
+ * The user denied authorization for tracking.
55
51
  */
56
52
  DENIED = 'D',
57
53
 
58
54
  /**
59
- * The user authorizes access to app-related data that can be used for tracking the user or the
60
- * device.
55
+ * The user authorized tracking access.
61
56
  */
62
57
  AUTHORIZED = 'A',
63
58
  }
64
59
 
65
60
  /**
66
- * Represents errors for CMP flow.
61
+ * Error codes returned from the Consent Management Platform (CMP) flow.
67
62
  */
68
63
  export enum CMPErrorCode {
69
64
  /**
70
- * Indicates that an unspecified error has occurred.
65
+ * An unspecified error occurred.
71
66
  */
72
67
  UNSPECIFIED = -1,
73
68
 
74
69
  /**
75
- * Indicates that the CMP has not been integrated correctly.
70
+ * The CMP was not integrated correctly.
76
71
  */
77
72
  INTEGRATION_ERROR = 1,
78
73
 
79
74
  /**
80
- * Indicates that the CMP form is unavailable.
75
+ * The CMP form is unavailable.
81
76
  */
82
77
  FORM_UNAVAILABLE = 2,
83
78
 
84
79
  /**
85
- * Indicates that the CMP form is not required.
80
+ * The CMP form is not required for this user.
86
81
  */
87
82
  FORM_NOT_REQUIRED = 3,
88
83
  }
89
84
 
90
- const initialize = (sdkKey: string): Promise<Configuration> => {
91
- return NativeAppLovinMAX.initialize(VERSION, sdkKey);
92
- };
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);
93
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
+ */
94
99
  const getSegments = async (): Promise<Map<number, number[]> | null> => {
95
100
  const segments = await NativeAppLovinMAX.getSegments();
96
101
 
@@ -100,21 +105,25 @@ const getSegments = async (): Promise<Map<number, number[]> | null> => {
100
105
 
101
106
  const map = new Map<number, number[]>();
102
107
 
103
- for (const key in segments) {
104
- if (segments.hasOwnProperty(key)) {
105
- // Convert the key from a string to a number. In JavaScript, an object cannot have an
106
- // integer as a key, but the Map object can have keys of any data type.
107
- map.set(Number(key), 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.
110
+ if (value) {
111
+ map.set(Number(key), value);
108
112
  }
109
113
  }
110
114
 
111
115
  return map;
112
116
  };
113
117
 
118
+ // All native methods except those overridden here
114
119
  type NativeAppLovinMAXType = Omit<AppLovinMAXType, 'initialize' | 'getSegments'>;
115
120
 
116
121
  const nativeMethods: NativeAppLovinMAXType = NativeAppLovinMAX;
117
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
+ */
118
127
  export const AppLovinMAX: AppLovinMAXType = Object.create(nativeMethods, {
119
128
  initialize: {
120
129
  value: initialize,
package/src/AppOpenAd.ts CHANGED
@@ -1,10 +1,8 @@
1
- import { NativeModules } from 'react-native';
2
1
  import { addEventListener, removeEventListener } from './EventEmitter';
3
2
  import type { AdDisplayFailedInfo, AdInfo, AdLoadFailedInfo } from './types/AdInfo';
4
3
  import type { LocalExtraParameterValue } from './types/AdProps';
5
4
  import type { AppOpenAdType } from './types/AppOpenAd';
6
-
7
- const { AppLovinMAX } = NativeModules;
5
+ import AppLovinMAX from './specs/NativeAppLovinMAXModule';
8
6
 
9
7
  const {
10
8
  ON_APPOPEN_AD_LOADED_EVENT,
package/src/BannerAd.ts CHANGED
@@ -1,11 +1,9 @@
1
- import { NativeModules } from 'react-native';
2
1
  import { addEventListener, removeEventListener } from './EventEmitter';
3
2
  import type { AdInfo, AdLoadFailedInfo } from './types/AdInfo';
4
3
  import type { LocalExtraParameterValue } from './types/AdProps';
5
4
  import type { BannerAdType } from './types/BannerAd';
6
5
  import type { AdViewPosition } from './AdView';
7
-
8
- const { AppLovinMAX } = NativeModules;
6
+ import AppLovinMAX from './specs/NativeAppLovinMAXModule';
9
7
 
10
8
  const {
11
9
  ON_BANNER_AD_LOADED_EVENT,