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/ErrorCode.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { NativeModules } from 'react-native';
2
-
3
- const { AppLovinMAX } = NativeModules;
1
+ import AppLovinMAX from './specs/NativeAppLovinMAXModule';
4
2
 
5
3
  const {
6
4
  MAX_ERROR_CODE_UNSPECIFIED,
@@ -18,85 +16,78 @@ const {
18
16
  } = AppLovinMAX.getConstants();
19
17
 
20
18
  /**
21
- * This enum contains various error codes that the SDK can return when a MAX ad fails to load or
22
- * display.
19
+ * Error codes returned by the AppLovin MAX SDK when an ad fails to load or display.
23
20
  */
24
21
  export enum ErrorCode {
25
22
  /**
26
- * This error code represents an error that could not be categorized into one of the other defined
27
- * 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.
28
25
  */
29
26
  UNSPECIFIED = MAX_ERROR_CODE_UNSPECIFIED,
30
27
 
31
28
  /**
32
- * This error code indicates that MAX returned no eligible ads from any mediated networks for this
33
- * app/device.
29
+ * No eligible ads were returned from any mediated networks.
34
30
  */
35
31
  NO_FILL = MAX_ERROR_CODE_NO_FILL,
36
32
 
37
33
  /**
38
- * This error code indicates that MAX returned eligible ads from mediated networks, but all ads
39
- * 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.
40
36
  */
41
37
  AD_LOAD_FAILED = MAX_ERROR_CODE_AD_LOAD_FAILED,
42
38
 
43
39
  /**
44
- * This error code represents an error that was encountered when showing an ad.
40
+ * An error occurred while attempting to display the ad.
45
41
  */
46
42
  AD_DISPLAY_FAILED = MAX_ERROR_CODE_AD_DISPLAY_FAILED,
47
43
 
48
44
  /**
49
- * This error code indicates that the ad request failed due to a generic network error. See the
50
- * 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.
51
47
  */
52
48
  NETWORK_ERROR = MAX_ERROR_CODE_NETWORK_ERROR,
53
49
 
54
50
  /**
55
- * 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.
56
52
  */
57
53
  NETWORK_TIMEOUT = MAX_ERROR_CODE_NETWORK_TIMEOUT,
58
54
 
59
55
  /**
60
- * This error code indicates that the ad request failed because the device is not connected to the
61
- * internet.
56
+ * The ad request failed because the device was offline.
62
57
  */
63
58
  NO_NETWORK = MAX_ERROR_CODE_NO_NETWORK,
64
59
 
65
60
  /**
66
- * This error code indicates that you attempted to show a fullscreen ad while another fullscreen ad
67
- * is still showing.
61
+ * A fullscreen ad was requested while another one was already showing.
68
62
  */
69
63
  FULLSCREEN_AD_ALREADY_SHOWING = MAX_ERROR_CODE_FULLSCREEN_AD_ALREADY_SHOWING,
70
64
 
71
65
  /**
72
- * This error code indicates you are attempting to show a fullscreen ad before the one has been
73
- * loaded.
66
+ * A fullscreen ad was requested before it had finished loading.
74
67
  */
75
68
  FULLSCREEN_AD_NOT_READY = MAX_ERROR_CODE_FULLSCREEN_AD_NOT_READY,
76
69
 
77
70
  /**
78
- * This error code indicates you attempted to present a fullscreen ad from an invalid view
79
- * controller.
80
- * **iOS ONLY**.
71
+ * The ad was presented from an invalid view controller.
72
+ * **iOS only**.
81
73
  */
82
74
  FULLSCREEN_AD_INVALID_VIEW_CONTROLLER = MAX_ERROR_CODE_FULLSCREEN_AD_INVALID_VIEW_CONTROLLER,
83
75
 
84
76
  /**
85
- * This error code indicates that the SDK failed to display an ad because the user has the
86
- * "Don't Keep Activities" developer setting enabled.
87
- * **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**.
88
80
  */
89
81
  DONT_KEEP_ACTIVITIES_ENABLED = MAX_ERROR_CODE_DONT_KEEP_ACTIVITIES_ENABLED,
90
82
 
91
83
  /**
92
- * This error code indicates that the SDK failed to load an ad because the publisher provided an
93
- * invalid ad unit identifier.
84
+ * The ad failed to load due to an invalid ad unit identifier.
94
85
  *
95
- * Possible reasons for an invalid ad unit identifier:
96
- * 1. Ad unit identifier is malformed or does not exist.
97
- * 2. Ad unit is disabled.
98
- * 3. Ad unit is not associated with the current app's package name.
99
- * 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).
100
91
  */
101
92
  INVALID_AD_UNIT_ID = MAX_ERROR_CODE_INVALID_AD_UNIT_ID,
102
93
  }
@@ -1,16 +1,28 @@
1
- import { NativeModules, NativeEventEmitter } from 'react-native';
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
+
6
+ import { NativeEventEmitter } from 'react-native';
2
7
  import type { EventSubscription } from 'react-native';
3
8
  import type { AdEventObject, AdEventListener } from './types/AdEvent';
9
+ import AppLovinMAX from './specs/NativeAppLovinMAXModule';
4
10
 
5
- const { AppLovinMAX } = NativeModules;
6
-
7
- // Note that this is a singleton in ES6 module
11
+ // Singleton event emitter for AppLovin MAX native events.
8
12
  const emitter = new NativeEventEmitter(AppLovinMAX);
9
13
 
14
+ // Tracks active subscriptions by event type.
10
15
  const subscriptions: Record<string, EventSubscription> = {};
11
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
+ */
12
24
  export const addEventListener = <T extends AdEventObject>(event: string, handler: AdEventListener<T>): void => {
13
- const subscription: EventSubscription = emitter.addListener(event, handler);
25
+ const subscription = emitter.addListener(event, handler);
14
26
  const currentSubscription = subscriptions[event];
15
27
  if (currentSubscription) {
16
28
  currentSubscription.remove();
@@ -18,6 +30,11 @@ export const addEventListener = <T extends AdEventObject>(event: string, handler
18
30
  subscriptions[event] = subscription;
19
31
  };
20
32
 
33
+ /**
34
+ * Unsubscribes from a specific ad event, if a listener exists.
35
+ *
36
+ * @param event - The event name to unsubscribe from.
37
+ */
21
38
  export const removeEventListener = (event: string): void => {
22
39
  const currentSubscription = subscriptions[event];
23
40
  if (currentSubscription) {
@@ -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 { InterstitialAdType } from './types/InterstitialAd';
6
-
7
- const { AppLovinMAX } = NativeModules;
5
+ import AppLovinMAX from './specs/NativeAppLovinMAXModule';
8
6
 
9
7
  const {
10
8
  ON_INTERSTITIAL_LOADED_EVENT,
@@ -25,7 +23,7 @@ const loadAd = (adUnitId: string): void => {
25
23
  };
26
24
 
27
25
  const showAd = (adUnitId: string, placement?: string | null, customData?: string | null): void => {
28
- AppLovinMAX.showInterstitial(adUnitId, placement ?? null, customData ?? null);
26
+ AppLovinMAX.showInterstitial(adUnitId, placement ?? undefined, customData ?? undefined);
29
27
  };
30
28
 
31
29
  const setExtraParameter = (adUnitId: string, key: string, value: string | null): void => {
package/src/MRecAd.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 { MRecAdType } from './types/MRecAd';
6
5
  import type { AdViewPosition } from './AdView';
7
-
8
- const { AppLovinMAX } = NativeModules;
6
+ import AppLovinMAX from './specs/NativeAppLovinMAXModule';
9
7
 
10
8
  const { ON_MREC_AD_LOADED_EVENT, ON_MREC_AD_LOAD_FAILED_EVENT, ON_MREC_AD_CLICKED_EVENT, ON_MREC_AD_COLLAPSED_EVENT, ON_MREC_AD_EXPANDED_EVENT, ON_MREC_AD_REVENUE_PAID } =
11
9
  AppLovinMAX.getConstants();
package/src/Privacy.ts CHANGED
@@ -1,6 +1,4 @@
1
- import { NativeModules } from 'react-native';
2
1
  import type { PrivacyType } from './types/Privacy';
3
-
4
- const { AppLovinMAX } = NativeModules;
2
+ import AppLovinMAX from './specs/NativeAppLovinMAXModule';
5
3
 
6
4
  export const Privacy: PrivacyType = AppLovinMAX;
package/src/RewardedAd.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, AdRewardInfo } from './types/AdInfo';
4
3
  import type { LocalExtraParameterValue } from './types/AdProps';
5
4
  import type { RewardedAdType } from './types/RewardedAd';
6
-
7
- const { AppLovinMAX } = NativeModules;
5
+ import AppLovinMAX from './specs/NativeAppLovinMAXModule';
8
6
 
9
7
  const {
10
8
  ON_REWARDED_AD_LOADED_EVENT,
@@ -26,7 +24,7 @@ const loadAd = (adUnitId: string): void => {
26
24
  };
27
25
 
28
26
  const showAd = (adUnitId: string, placement?: string | null, customData?: string | null): void => {
29
- AppLovinMAX.showRewardedAd(adUnitId, placement ?? null, customData ?? null);
27
+ AppLovinMAX.showRewardedAd(adUnitId, placement ?? undefined, customData ?? undefined);
30
28
  };
31
29
 
32
30
  const setExtraParameter = (adUnitId: string, key: string, value: string | null): void => {
package/src/Utils.ts ADDED
@@ -0,0 +1,45 @@
1
+ import type { LocalExtraParameterValue } from './types/AdProps';
2
+
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
+ };
15
+
16
+ type LocalExtraParameterType = 'str' | 'bool';
17
+
18
+ type LocalExtraParameterValueMap = {
19
+ str: string | null;
20
+ bool: boolean | null;
21
+ };
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
+ */
31
+ export const makeLocalExtraParametersArray = <T extends LocalExtraParameterType>(
32
+ input: Record<string, LocalExtraParameterValue> | undefined,
33
+ type: T
34
+ ): { key: string; value: LocalExtraParameterValueMap[T] }[] => {
35
+ if (!input) return [];
36
+
37
+ return Object.entries(input)
38
+ .filter(([_, value]) => {
39
+ if (value === null) return true;
40
+ if (type === 'str') return typeof value === 'string';
41
+ if (type === 'bool') return typeof value === 'boolean';
42
+ return false;
43
+ })
44
+ .map(([key, value]) => ({ key, value: value as LocalExtraParameterValueMap[T] }));
45
+ };
@@ -1,28 +1,22 @@
1
+ /**
2
+ * Provides the NativeAdView component, which manages loading and rendering of native ads using the
3
+ * AppLovin MAX SDK in React Native.
4
+ */
5
+
1
6
  import * as React from 'react';
2
7
  import { forwardRef, useContext, useImperativeHandle, useRef, useState, useEffect, useCallback } from 'react';
3
- import { NativeModules, requireNativeComponent, UIManager, findNodeHandle, View } from 'react-native';
4
- import type { ViewProps } from 'react-native';
8
+ import { findNodeHandle, View } from 'react-native';
9
+ import type { NativeSyntheticEvent, ViewProps } from 'react-native';
10
+ import AppLovinMAX from '../specs/NativeAppLovinMAXModule';
11
+ import NativeAdViewComponent, { Commands } from '../specs/AppLovinMAXNativeAdViewNativeComponent';
12
+ import type { AdInfoEvent, AdLoadFailedEvent } from '../specs/AppLovinMAXNativeAdViewNativeComponent';
5
13
  import { NativeAdViewContext, NativeAdViewProvider } from './NativeAdViewProvider';
6
- import type { AdInfo, AdLoadFailedInfo } from '../types/AdInfo';
7
- import type { AdNativeEvent } from '../types/AdEvent';
8
- import type { NativeAd } from '../types/NativeAd';
14
+ import type { NativeAdViewContextType } from './NativeAdViewProvider';
9
15
  import type { NativeAdViewHandler, NativeAdViewProps } from '../types/NativeAdViewProps';
10
- import type { NativeAdViewType, NativeAdViewContextType } from './NativeAdViewProvider';
11
-
12
- const { AppLovinMAX } = NativeModules;
13
-
14
- type NativeAdViewNativeEvents = {
15
- onAdLoadedEvent(event: { nativeEvent: { nativeAd: NativeAd; adInfo: AdInfo } }): void;
16
- onAdLoadFailedEvent(event: AdNativeEvent<AdLoadFailedInfo>): void;
17
- onAdClickedEvent(event: AdNativeEvent<AdInfo>): void;
18
- onAdRevenuePaidEvent(event: AdNativeEvent<AdInfo>): void;
19
- };
20
-
21
- const NativeAdViewComponent = requireNativeComponent<NativeAdViewProps & ViewProps & NativeAdViewNativeEvents>('AppLovinMAXNativeAdView');
16
+ import { makeExtraParametersArray, makeLocalExtraParametersArray } from '../Utils';
22
17
 
23
18
  /**
24
- * The {@link NativeAdView} component that you use building a native ad. This loads a native ad and
25
- * renders it with the asset views:
19
+ * The {@link NativeAdView} component renders a native ad and binds it to asset views:
26
20
  *
27
21
  * - {@link IconView}
28
22
  * - {@link TitleView}
@@ -32,19 +26,21 @@ const NativeAdViewComponent = requireNativeComponent<NativeAdViewProps & ViewPro
32
26
  * - {@link MediaView}
33
27
  * - {@link CallToActionView}
34
28
  *
35
- * {@link NativeAdView} fills each asset view with the data of a native ad as soon as it loads the native
36
- * ad, but you need to provide the layout and style of the asset views.
37
- * {@link NativeAdView} can reload a new native ad by using the ref handler.
29
+ * Each asset view must be manually laid out and styled.
30
+ * The component automatically populates content once an ad is loaded.
31
+ * You can reload the ad using the component’s ref via `loadAd()`.
32
+ *
33
+ * **Note:** The AppLovin SDK must be initialized before using this component.
38
34
  *
39
35
  * ### Example:
40
- * ```js
36
+ * ```tsx
41
37
  * <NativeAdView
42
38
  * ref={nativeAdViewHandler}
43
39
  * adUnitId={adUnitId}
44
40
  * style={styles.nativead}
45
41
  * onAdLoaded={(adInfo: AdInfo) => { ... }}
46
42
  * >
47
- * <View style={ ... }>
43
+ * <View style={...}>
48
44
  * <IconView style={styles.icon} />
49
45
  * <TitleView style={styles.title} />
50
46
  * <AdvertiserView style={styles.advertiser} />
@@ -56,20 +52,21 @@ const NativeAdViewComponent = requireNativeComponent<NativeAdViewProps & ViewPro
56
52
  * </View>
57
53
  * </NativeAdView>
58
54
  * ```
55
+ *
56
+ * For a complete implementation example, see:
57
+ * https://github.com/AppLovin/AppLovin-MAX-React-Native/blob/master/example/src/NativeAdViewExample.tsx
59
58
  */
60
59
  export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(function NativeAdView(props, ref) {
61
60
  const [isInitialized, setIsInitialized] = useState<boolean>(false);
62
61
 
63
62
  useEffect(() => {
64
- const checkInitialization = async () => {
63
+ (async () => {
65
64
  const result = await AppLovinMAX.isInitialized();
66
65
  setIsInitialized(result);
67
66
  if (!result) {
68
67
  console.warn('NativeAdView is mounted before the initialization of the AppLovin MAX React Native module.');
69
68
  }
70
- };
71
-
72
- checkInitialization();
69
+ })();
73
70
  }, []);
74
71
 
75
72
  // Avoid rendering the NativeAdView if the SDK is not initialized
@@ -84,76 +81,89 @@ export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps &
84
81
  );
85
82
  });
86
83
 
84
+ /**
85
+ * Extracts native ad info from a synthetic event and invokes the provided callback, if any.
86
+ * Ensures optional native ad fields have fallback defaults.
87
+ */
88
+ const handleNativeAdViewEvent = <T extends AdInfoEvent | AdLoadFailedEvent>(event: NativeSyntheticEvent<T>, callback?: (adInfo: T) => void) => {
89
+ if (!callback) return;
90
+ callback(event.nativeEvent);
91
+ };
92
+
87
93
  const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(function NativeAdViewImpl(
88
94
  { adUnitId, placement, customData, extraParameters, localExtraParameters, onAdLoaded, onAdLoadFailed, onAdClicked, onAdRevenuePaid, children, style, ...otherProps },
89
95
  ref
90
96
  ) {
91
97
  // Context provides functions to manage native ad and native ad view state
92
- const { setNativeAd, setNativeAdView } = useContext(NativeAdViewContext) as NativeAdViewContextType;
98
+ const { titleRef, advertiserRef, bodyRef, callToActionRef, imageRef, optionViewRef, mediaViewRef, setNativeAd } = useContext(NativeAdViewContext) as NativeAdViewContextType;
93
99
 
94
- const nativeAdViewRef = useRef<NativeAdViewType | null>(null);
100
+ const nativeAdViewRef = useRef<React.ElementRef<typeof NativeAdViewComponent> | undefined>();
95
101
 
96
- // Load a new ad
102
+ // Triggers a native ad load via the native command
97
103
  const loadAd = useCallback(() => {
98
- const nativeAdView = nativeAdViewRef.current;
99
- if (nativeAdView) {
100
- const viewManagerConfig = UIManager.getViewManagerConfig('AppLovinMAXNativeAdView');
101
- if (viewManagerConfig?.Commands && typeof viewManagerConfig.Commands.loadAd === 'number') {
102
- UIManager.dispatchViewManagerCommand(findNodeHandle(nativeAdView), viewManagerConfig.Commands.loadAd, []);
103
- }
104
- }
104
+ nativeAdViewRef.current && Commands.loadAd(nativeAdViewRef.current);
105
105
  }, []);
106
106
 
107
107
  useImperativeHandle(ref, () => ({ loadAd }), [loadAd]);
108
108
 
109
- // Save the DOM element reference
110
- const saveElement = useCallback(
111
- (element: NativeAdViewType | null) => {
112
- if (element) {
113
- nativeAdViewRef.current = element;
114
- setNativeAdView(element);
115
- }
116
- },
117
- [setNativeAdView]
118
- );
109
+ /**
110
+ * Updates the native asset view binding for a given view type (e.g., TitleView, MediaView).
111
+ */
112
+ const updateAssetView = useCallback((assetViewRef: React.RefObject<View>, type: string) => {
113
+ if (!nativeAdViewRef.current || !assetViewRef.current) return;
114
+
115
+ const node = findNodeHandle(assetViewRef.current);
116
+ if (node) {
117
+ Commands.updateAssetView(nativeAdViewRef.current, node, type);
118
+ }
119
+ }, []);
119
120
 
121
+ /**
122
+ * Handles native ad load event:
123
+ * - Updates context with the new native ad data
124
+ * - Notifies native module of updated asset view mappings
125
+ * - Triggers native rendering after all asset views are registered
126
+ */
120
127
  const onAdLoadedEvent = useCallback(
121
- (event: { nativeEvent: { nativeAd: NativeAd; adInfo: AdInfo } }) => {
122
- setNativeAd(event.nativeEvent.nativeAd);
123
- onAdLoaded?.(event.nativeEvent.adInfo);
124
- },
125
- [onAdLoaded, setNativeAd]
126
- );
128
+ (event: NativeSyntheticEvent<AdInfoEvent>) => {
129
+ const nativeAdImpl = event.nativeEvent.nativeAdImpl;
130
+
131
+ if (nativeAdImpl) {
132
+ setNativeAd({ ...nativeAdImpl });
133
+
134
+ if (nativeAdImpl.title) updateAssetView(titleRef, 'TitleView');
135
+ if (nativeAdImpl.advertiser) updateAssetView(advertiserRef, 'AdvertiserView');
136
+ if (nativeAdImpl.body) updateAssetView(bodyRef, 'BodyView');
137
+ if (nativeAdImpl.callToAction) updateAssetView(callToActionRef, 'CallToActionView');
138
+ if (nativeAdImpl.url || nativeAdImpl.image || nativeAdImpl.imageSource) updateAssetView(imageRef, 'IconView');
139
+ if (nativeAdImpl.isOptionsViewAvailable) updateAssetView(optionViewRef, 'OptionsView');
140
+ if (nativeAdImpl.isMediaViewAvailable) updateAssetView(mediaViewRef, 'MediaView');
141
+ }
127
142
 
128
- const onAdLoadFailedEvent = useCallback(
129
- (event: AdNativeEvent<AdLoadFailedInfo>) => {
130
- onAdLoadFailed?.(event.nativeEvent);
131
- },
132
- [onAdLoadFailed]
133
- );
143
+ if (nativeAdViewRef.current) {
144
+ Commands.renderNativeAd(nativeAdViewRef.current);
145
+ }
134
146
 
135
- const onAdClickedEvent = useCallback(
136
- (event: AdNativeEvent<AdInfo>) => {
137
- onAdClicked?.(event.nativeEvent);
147
+ handleNativeAdViewEvent(event, onAdLoaded);
138
148
  },
139
- [onAdClicked]
149
+ [setNativeAd, onAdLoaded, updateAssetView, titleRef, advertiserRef, bodyRef, callToActionRef, imageRef, optionViewRef, mediaViewRef]
140
150
  );
141
151
 
142
- const onAdRevenuePaidEvent = useCallback(
143
- (event: AdNativeEvent<AdInfo>) => {
144
- onAdRevenuePaid?.(event.nativeEvent);
145
- },
146
- [onAdRevenuePaid]
147
- );
152
+ const onAdLoadFailedEvent = useCallback((event: NativeSyntheticEvent<AdLoadFailedEvent>) => handleNativeAdViewEvent(event, onAdLoadFailed), [onAdLoadFailed]);
153
+
154
+ const onAdClickedEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleNativeAdViewEvent(event, onAdClicked), [onAdClicked]);
155
+
156
+ const onAdRevenuePaidEvent = useCallback((event: NativeSyntheticEvent<AdInfoEvent>) => handleNativeAdViewEvent(event, onAdRevenuePaid), [onAdRevenuePaid]);
148
157
 
149
158
  return (
150
159
  <NativeAdViewComponent
151
- ref={saveElement}
160
+ ref={(element) => (nativeAdViewRef.current = element ?? undefined)}
152
161
  adUnitId={adUnitId}
153
162
  placement={placement}
154
163
  customData={customData}
155
- extraParameters={extraParameters}
156
- localExtraParameters={localExtraParameters}
164
+ extraParameters={makeExtraParametersArray(extraParameters)}
165
+ strLocalExtraParameters={makeLocalExtraParametersArray(localExtraParameters, 'str')}
166
+ boolLocalExtraParameters={makeLocalExtraParametersArray(localExtraParameters, 'bool')}
157
167
  onAdLoadedEvent={onAdLoadedEvent}
158
168
  onAdLoadFailedEvent={onAdLoadFailedEvent}
159
169
  onAdClickedEvent={onAdClickedEvent}