react-native-applovin-max 5.7.2 → 6.0.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 (50) hide show
  1. package/README.md +1 -1
  2. package/android/build.gradle +2 -2
  3. package/android/src/main/java/com/applovin/mediation/adapters/GoogleAdManagerMediationAdapter.java.saved +1616 -0
  4. package/android/src/main/java/com/applovin/mediation/adapters/{GoogleMediationAdapter.java.saved → GoogleMediationAdapter.java.old} +126 -49
  5. package/android/src/main/java/com/applovin/mediation/adapters/MintegralMediationAdapter.java.old +1481 -0
  6. package/ios/AppLovinMAX.m +1 -9
  7. package/ios/AppLovinMAX.xcodeproj/project.pbxproj +4 -4
  8. package/ios/AppLovinMAX.xcworkspace/xcuserdata/hiroshi.watanabe.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  9. package/ios/AppLovinMAXNativeAdView.m +8 -1
  10. package/ios/Podfile +1 -1
  11. package/package.json +2 -1
  12. package/react-native-applovin-max.podspec +1 -1
  13. package/src/AdView.tsx +251 -0
  14. package/src/AppLovinMAX.ts +24 -0
  15. package/src/AppOpenAd.ts +128 -0
  16. package/src/BannerAd.ts +175 -0
  17. package/src/EventEmitter.ts +27 -0
  18. package/src/InterstitialAd.ts +128 -0
  19. package/src/MRecAd.ts +147 -0
  20. package/src/Privacy.ts +6 -0
  21. package/src/RewardedAd.ts +144 -0
  22. package/src/TargetingData.ts +168 -0
  23. package/src/index.ts +21 -0
  24. package/src/nativeAd/NativeAdView.tsx +161 -0
  25. package/src/nativeAd/NativeAdViewComponents.tsx +185 -0
  26. package/src/nativeAd/NativeAdViewProvider.tsx +35 -0
  27. package/src/types/AdEvent.ts +26 -0
  28. package/src/types/AdInfo.ts +348 -0
  29. package/src/types/AdProps.ts +60 -0
  30. package/src/types/AdViewProps.ts +36 -0
  31. package/src/types/AppLovinMAX.ts +86 -0
  32. package/src/types/AppOpenAd.ts +3 -0
  33. package/src/types/BannerAd.ts +47 -0
  34. package/src/types/Configuration.ts +11 -0
  35. package/src/types/FullscreenAd.ts +135 -0
  36. package/src/types/InterstitialAd.ts +3 -0
  37. package/src/types/MRecAd.ts +13 -0
  38. package/src/types/NativeAd.ts +50 -0
  39. package/src/types/NativeAdViewProps.ts +17 -0
  40. package/src/types/Privacy.ts +73 -0
  41. package/src/types/RewardedAd.ts +18 -0
  42. package/src/types/ViewAd.ts +158 -0
  43. package/src/types/index.ts +4 -0
  44. package/src/AppLovinMAXAdView.js +0 -231
  45. package/src/AppLovinMAXEventListeners.js +0 -419
  46. package/src/NativeAdComponents.js +0 -208
  47. package/src/NativeAdView.js +0 -164
  48. package/src/NativeAdViewProvider.js +0 -19
  49. package/src/TargetingData.js +0 -104
  50. package/src/index.js +0 -291
package/ios/AppLovinMAX.m CHANGED
@@ -1777,15 +1777,7 @@ RCT_EXPORT_METHOD(setAppOpenAdLocalExtraParameter:(NSString *)adUnitIdentifier :
1777
1777
  // All positions have constant height
1778
1778
  NSMutableArray<NSLayoutConstraint *> *constraints = [NSMutableArray arrayWithObject: [adView.heightAnchor constraintEqualToConstant: adViewSize.height]];
1779
1779
 
1780
- UILayoutGuide *layoutGuide;
1781
- if ( @available(iOS 11.0, *) )
1782
- {
1783
- layoutGuide = superview.safeAreaLayoutGuide;
1784
- }
1785
- else
1786
- {
1787
- layoutGuide = superview.layoutMarginsGuide;
1788
- }
1780
+ UILayoutGuide *layoutGuide = superview.safeAreaLayoutGuide;
1789
1781
 
1790
1782
  // If top of bottom center, stretch width of screen
1791
1783
  if ( [adViewPosition isEqual: TOP_CENTER] || [adViewPosition isEqual: BOTTOM_CENTER] )
@@ -240,7 +240,7 @@
240
240
  GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
241
241
  GCC_WARN_UNUSED_FUNCTION = YES;
242
242
  GCC_WARN_UNUSED_VARIABLE = YES;
243
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
243
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
244
244
  MTL_ENABLE_DEBUG_INFO = YES;
245
245
  ONLY_ACTIVE_ARCH = YES;
246
246
  SDKROOT = iphoneos;
@@ -286,7 +286,7 @@
286
286
  GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
287
287
  GCC_WARN_UNUSED_FUNCTION = YES;
288
288
  GCC_WARN_UNUSED_VARIABLE = YES;
289
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
289
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
290
290
  MTL_ENABLE_DEBUG_INFO = NO;
291
291
  SDKROOT = iphoneos;
292
292
  VALIDATE_PRODUCT = YES;
@@ -307,7 +307,7 @@
307
307
  "$(SRCROOT)/../../../React/**",
308
308
  "$(SRCROOT)/../../react-native/React/**",
309
309
  );
310
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
310
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
311
311
  LIBRARY_SEARCH_PATHS = "$(inherited)";
312
312
  OTHER_LDFLAGS = "-ObjC";
313
313
  PRODUCT_NAME = AppLovinMAX;
@@ -331,7 +331,7 @@
331
331
  "$(SRCROOT)/../../../React/**",
332
332
  "$(SRCROOT)/../../react-native/React/**",
333
333
  );
334
- IPHONEOS_DEPLOYMENT_TARGET = 10.0;
334
+ IPHONEOS_DEPLOYMENT_TARGET = 11.0;
335
335
  LIBRARY_SEARCH_PATHS = "$(inherited)";
336
336
  OTHER_LDFLAGS = "-ObjC";
337
337
  PRODUCT_NAME = AppLovinMAX;
@@ -221,7 +221,14 @@
221
221
  if ( !icon.URL && icon.image )
222
222
  {
223
223
  RCTImageView *iconImageView = (RCTImageView *) view;
224
- iconImageView.defaultImage = icon.image;
224
+ if ( [iconImageView respondsToSelector: @selector(setImage:)] )
225
+ {
226
+ [iconImageView performSelector: @selector(setImage:) withObject: icon.image];
227
+ }
228
+ else
229
+ {
230
+ [[AppLovinMAX shared] log: @"Unable to set native ad IconView image"];
231
+ }
225
232
  }
226
233
  }
227
234
  }
package/ios/Podfile CHANGED
@@ -1,5 +1,5 @@
1
1
  # Uncomment the next line to define a global platform for your project
2
- platform :ios, '10.0'
2
+ platform :ios, '11.0'
3
3
  require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
4
4
 
5
5
  target 'AppLovinMAX' do
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-applovin-max",
3
3
  "author": "AppLovin Corporation",
4
- "version": "5.7.2",
4
+ "version": "6.0.0",
5
5
  "description": "AppLovin MAX React Native Plugin for Android and iOS",
6
6
  "homepage": "https://github.com/AppLovin/AppLovin-MAX-React-Native",
7
7
  "license": "MIT",
@@ -24,6 +24,7 @@
24
24
  ],
25
25
  "repository": "https://github.com/AppLovin/AppLovin-MAX-React-Native",
26
26
  "devDependencies": {
27
+ "@types/react-native": "^0.63.1",
27
28
  "react": "^16.13.1",
28
29
  "react-native": "^0.63.1"
29
30
  },
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
11
11
  s.authors = package["author"]
12
12
 
13
13
  s.platforms = { :ios => "10.0" }
14
- s.source = { :git => "https://github.com/AppLovin/AppLovin-MAX-React-Native.git", :tag => "release_5_7_2" }
14
+ s.source = { :git => "https://github.com/AppLovin/AppLovin-MAX-React-Native.git", :tag => "release_6_0_0" }
15
15
 
16
16
  s.source_files = "ios/AppLovinMAX*.{h,m}"
17
17
 
package/src/AdView.tsx ADDED
@@ -0,0 +1,251 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { NativeModules, requireNativeComponent, StyleSheet } from "react-native";
3
+ import type { ViewProps, ViewStyle, StyleProp } from "react-native";
4
+ import type { AdDisplayFailedInfo, AdInfo, AdLoadFailedInfo, AdRevenueInfo } from "./types/AdInfo";
5
+ import type { AdNativeEvent } from "./types/AdEvent";
6
+ import type { AdViewProps } from "./types/AdViewProps";
7
+
8
+ const { AppLovinMAX } = NativeModules;
9
+
10
+ const {
11
+ BANNER_AD_FORMAT_LABEL,
12
+ MREC_AD_FORMAT_LABEL,
13
+
14
+ TOP_CENTER_POSITION,
15
+ TOP_LEFT_POSITION,
16
+ TOP_RIGHT_POSITION,
17
+ CENTERED_POSITION,
18
+ CENTER_LEFT_POSITION,
19
+ CENTER_RIGHT_POSITION,
20
+ BOTTOM_LEFT_POSITION,
21
+ BOTTOM_CENTER_POSITION,
22
+ BOTTOM_RIGHT_POSITION,
23
+ } = AppLovinMAX.getConstants();
24
+
25
+ /**
26
+ * Defines a format of an ad.
27
+ */
28
+ export enum AdFormat {
29
+
30
+ /**
31
+ * Banner ad.
32
+ */
33
+ BANNER = BANNER_AD_FORMAT_LABEL,
34
+
35
+ /**
36
+ * MREC ad.
37
+ */
38
+ MREC = MREC_AD_FORMAT_LABEL,
39
+ }
40
+
41
+ /**
42
+ * Defines a position of a banner and MREC ad.
43
+ */
44
+ export enum AdViewPosition {
45
+ TOP_CENTER = TOP_CENTER_POSITION,
46
+ TOP_LEFT = TOP_LEFT_POSITION,
47
+ TOP_RIGHT = TOP_RIGHT_POSITION,
48
+ CENTERED = CENTERED_POSITION,
49
+ CENTER_LEFT = CENTER_LEFT_POSITION,
50
+ CENTER_RIGHT = CENTER_RIGHT_POSITION,
51
+ BOTTOM_LEFT = BOTTOM_LEFT_POSITION,
52
+ BOTTOM_CENTER = BOTTOM_CENTER_POSITION,
53
+ BOTTOM_RIGHT = BOTTOM_RIGHT_POSITION,
54
+ }
55
+
56
+ type AdViewNativeEvents = {
57
+ onAdLoadedEvent(event: AdNativeEvent<AdInfo>): void
58
+ onAdLoadFailedEvent(event: AdNativeEvent<AdLoadFailedInfo>): void
59
+ onAdDisplayFailedEvent(event: AdNativeEvent<AdDisplayFailedInfo>): void
60
+ onAdClickedEvent(event: AdNativeEvent<AdInfo>): void
61
+ onAdExpandedEvent(event: AdNativeEvent<AdInfo>): void
62
+ onAdCollapsedEvent(event: AdNativeEvent<AdInfo>): void
63
+ onAdRevenuePaidEvent(event: AdNativeEvent<AdRevenueInfo>): void
64
+ }
65
+
66
+ const AdViewComponent = requireNativeComponent<AdViewProps & ViewProps & AdViewNativeEvents>("AppLovinMAXAdView");
67
+
68
+ const ADVIEW_SIZE = {
69
+ banner: { width: 320, height: 50 },
70
+ leader: { width: 728, height: 90 },
71
+ mrec: { width: 300, height: 250 },
72
+ };
73
+
74
+ const getOutlineViewSize = (style: StyleProp<ViewStyle>) => {
75
+ const viewStyle = StyleSheet.flatten(style || {});
76
+ return [viewStyle?.width, viewStyle?.height];
77
+ };
78
+
79
+ const sizeAdViewDimensions = (adFormat: AdFormat, adaptiveBannerEnabled?: boolean, width?: number | string, height?: number | string): Promise<{}> => {
80
+ const sizeForBannerFormat = async () => {
81
+ const isTablet = await AppLovinMAX.isTablet();
82
+
83
+ const minWidth = isTablet ? ADVIEW_SIZE.leader.width : ADVIEW_SIZE.banner.width;
84
+
85
+ let minHeight;
86
+ if (adaptiveBannerEnabled) {
87
+ if (typeof width === "number" && width > minWidth) {
88
+ minHeight = await AppLovinMAX.getAdaptiveBannerHeightForWidth(width);
89
+ } else {
90
+ minHeight = await AppLovinMAX.getAdaptiveBannerHeightForWidth(minWidth);
91
+ }
92
+ } else {
93
+ minHeight = isTablet ? ADVIEW_SIZE.leader.height : ADVIEW_SIZE.banner.height;
94
+ }
95
+
96
+ return Promise.resolve({
97
+ ...width === "auto" ? {
98
+ width: minWidth,
99
+ } : {
100
+ minWidth: minWidth,
101
+ },
102
+ ...height === "auto" ? {
103
+ height: minHeight,
104
+ } : {
105
+ minHeight: minHeight,
106
+ }
107
+ });
108
+ }
109
+
110
+ if (adFormat === AdFormat.BANNER) {
111
+ return sizeForBannerFormat();
112
+ } else {
113
+ return Promise.resolve({
114
+ ...width === "auto" ? {
115
+ width: ADVIEW_SIZE.mrec.width,
116
+ } : {
117
+ minWidth: ADVIEW_SIZE.mrec.width,
118
+ },
119
+ ...height === "auto" ? {
120
+ height: ADVIEW_SIZE.mrec.height,
121
+ } : {
122
+ minHeight: ADVIEW_SIZE.mrec.height,
123
+ }
124
+ });
125
+ }
126
+ }
127
+
128
+ /**
129
+ * The {@link AdView} component for building a banner or a MREC. Banners are sized to 320x50 on phones
130
+ * and 728x90 on tablets. MRECs are sized to 300x250 on phones and tablets. You may use the
131
+ * utility method `AppLovinMAX.isTablet()` to help with view sizing adjustments. For adaptive
132
+ * banners, call `BannerAd.getAdaptiveHeightForWidth(width)` to get the banner height, and then adjust
133
+ * your content accordingly.
134
+ *
135
+ * ### Example:
136
+ * ```js
137
+ * <AdView
138
+ * adUnitId={adUnitId}
139
+ * adFormat={AdFormat.BANNER}
140
+ * placement="my_placement"
141
+ * customData="my_customData"
142
+ * extraParameters={{"key1":"value1", "key2":"value2"}}
143
+ * localExtraParameters={{"key1":123", "key2":object}}
144
+ * adaptiveBannerEnabled={false}
145
+ * autoRefresh={false}
146
+ * style={styles.banner}
147
+ * onAdLoaded={(adInfo: AdInfo) => { ... }}
148
+ * />
149
+ * ```
150
+ */
151
+ export const AdView = ({
152
+ adUnitId,
153
+ adFormat,
154
+ placement,
155
+ customData,
156
+ adaptiveBannerEnabled = true,
157
+ autoRefresh = true,
158
+ extraParameters,
159
+ localExtraParameters,
160
+ onAdLoaded,
161
+ onAdLoadFailed,
162
+ onAdDisplayFailed,
163
+ onAdClicked,
164
+ onAdExpanded,
165
+ onAdCollapsed,
166
+ onAdRevenuePaid,
167
+ style,
168
+ ...otherProps
169
+ }: AdViewProps & ViewProps) => {
170
+ const [isInitialized, setIsInitialized] = useState<boolean>(false);
171
+ const [dimensions, setDimensions] = useState({});
172
+
173
+ useEffect(() => {
174
+ AppLovinMAX.isInitialized().then((result: boolean) => {
175
+ setIsInitialized(result);
176
+ if (!result) {
177
+ console.warn("ERROR: AdView is mounted before the initialization of the AppLovin MAX React Native module");
178
+ }
179
+ });
180
+ }, []);
181
+
182
+ useEffect(() => {
183
+ if (!isInitialized) return;
184
+ const [width, height] = getOutlineViewSize(style);
185
+ sizeAdViewDimensions(adFormat, adaptiveBannerEnabled, width, height).then((value: {}) => {
186
+ setDimensions(value);
187
+ });
188
+ }, [isInitialized]);
189
+
190
+ const onAdLoadedEvent = (event: AdNativeEvent<AdInfo>) => {
191
+ if (onAdLoaded) onAdLoaded(event.nativeEvent);
192
+ };
193
+
194
+ const onAdLoadFailedEvent = (event: AdNativeEvent<AdLoadFailedInfo>) => {
195
+ if (onAdLoadFailed) onAdLoadFailed(event.nativeEvent);
196
+ };
197
+
198
+ const onAdDisplayFailedEvent = (event: AdNativeEvent<AdDisplayFailedInfo>) => {
199
+ if (onAdDisplayFailed) onAdDisplayFailed(event.nativeEvent);
200
+ };
201
+
202
+ const onAdClickedEvent = (event: AdNativeEvent<AdInfo>) => {
203
+ if (onAdClicked) onAdClicked(event.nativeEvent);
204
+ };
205
+
206
+ const onAdExpandedEvent = (event: AdNativeEvent<AdInfo>) => {
207
+ if (onAdExpanded) onAdExpanded(event.nativeEvent);
208
+ };
209
+
210
+ const onAdCollapsedEvent = (event: AdNativeEvent<AdInfo>) => {
211
+ if (onAdCollapsed) onAdCollapsed(event.nativeEvent);
212
+ };
213
+
214
+ const onAdRevenuePaidEvent = (event: AdNativeEvent<AdRevenueInfo>) => {
215
+ if (onAdRevenuePaid) onAdRevenuePaid(event.nativeEvent);
216
+ };
217
+
218
+ // Not initialized
219
+ if (!isInitialized) {
220
+ return null;
221
+ } else {
222
+ const isDimensionsSet = (Object.keys(dimensions).length > 0);
223
+
224
+ // Not sized yet
225
+ if (!isDimensionsSet) {
226
+ return null;
227
+ }
228
+ }
229
+
230
+ return (
231
+ <AdViewComponent
232
+ adUnitId={adUnitId}
233
+ adFormat={adFormat}
234
+ placement={placement}
235
+ customData={customData}
236
+ adaptiveBannerEnabled={adaptiveBannerEnabled}
237
+ autoRefresh={autoRefresh}
238
+ extraParameters={extraParameters}
239
+ localExtraParameters={localExtraParameters}
240
+ onAdLoadedEvent={onAdLoadedEvent}
241
+ onAdLoadFailedEvent={onAdLoadFailedEvent}
242
+ onAdDisplayFailedEvent={onAdDisplayFailedEvent}
243
+ onAdClickedEvent={onAdClickedEvent}
244
+ onAdExpandedEvent={onAdExpandedEvent}
245
+ onAdCollapsedEvent={onAdCollapsedEvent}
246
+ onAdRevenuePaidEvent={onAdRevenuePaidEvent}
247
+ style={{ ...(style as ViewProps), ...dimensions }}
248
+ {...otherProps}
249
+ />
250
+ );
251
+ };
@@ -0,0 +1,24 @@
1
+ import { NativeModules } from "react-native";
2
+ import type { AppLovinMAXType } from "./types/AppLovinMAX";
3
+ import type { Configuration } from "./types/Configuration";
4
+
5
+ const NativeAppLovinMAX = NativeModules.AppLovinMAX;
6
+
7
+ const VERSION = "6.0.0";
8
+
9
+ const initialize = async (
10
+ sdkKey: string
11
+ ): Promise<Configuration> => {
12
+ return NativeAppLovinMAX.initialize(VERSION, sdkKey);
13
+ }
14
+
15
+ type NativeAppLovinMAXType = Omit<AppLovinMAXType, | 'initialize'>;
16
+
17
+ const nativeMethods: NativeAppLovinMAXType = NativeAppLovinMAX;
18
+
19
+ export const AppLovinMAX: AppLovinMAXType = {
20
+ ...nativeMethods,
21
+ initialize,
22
+ }
23
+
24
+ export default AppLovinMAX;
@@ -0,0 +1,128 @@
1
+ import { NativeModules } from "react-native";
2
+ import { addEventListener, removeEventListener } from "./EventEmitter"
3
+ import type { AdDisplayFailedInfo, AdInfo, AdLoadFailedInfo, AdRevenueInfo } from "./types/AdInfo";
4
+ import type { AppOpenAdType } from "./types/AppOpenAd";
5
+
6
+ const { AppLovinMAX } = NativeModules;
7
+
8
+ const {
9
+ ON_APPOPEN_AD_LOADED_EVENT,
10
+ ON_APPOPEN_AD_LOAD_FAILED_EVENT,
11
+ ON_APPOPEN_AD_CLICKED_EVENT,
12
+ ON_APPOPEN_AD_DISPLAYED_EVENT,
13
+ ON_APPOPEN_AD_FAILED_TO_DISPLAY_EVENT,
14
+ ON_APPOPEN_AD_HIDDEN_EVENT,
15
+ ON_APPOPEN_AD_REVENUE_PAID,
16
+ } = AppLovinMAX.getConstants();
17
+
18
+ const isAdReady = (adUnitId: string): Promise<boolean> => {
19
+ return AppLovinMAX.isAppOpenAdReady(adUnitId);
20
+ }
21
+
22
+ const loadAd = (adUnitId: string): void => {
23
+ AppLovinMAX.loadAppOpenAd(adUnitId);
24
+ }
25
+
26
+ const showAd = (
27
+ adUnitId: string,
28
+ placement?: string | null,
29
+ customData?: string | null
30
+ ): void => {
31
+ AppLovinMAX.showAppOpenAd(adUnitId, placement ?? undefined, customData ?? undefined);
32
+ }
33
+
34
+ const setExtraParameter = (adUnitId: string, key: string, value: any): void => {
35
+ AppLovinMAX.setAppOpenAdExtraParameter(adUnitId, key, value);
36
+ }
37
+
38
+ const setLocalExtraParameter = (adUnitId: string, key: string, value: any): void => {
39
+ AppLovinMAX.setAppOpenAdLocalExtraParameter(adUnitId, { [key]: value });
40
+ }
41
+
42
+ const addAdLoadedEventListener = (listener: (adInfo: AdInfo) => void) => {
43
+ addEventListener(ON_APPOPEN_AD_LOADED_EVENT, (adInfo: AdInfo) => listener(adInfo));
44
+ }
45
+
46
+ const removeAdLoadedEventListener = () => {
47
+ removeEventListener(ON_APPOPEN_AD_LOADED_EVENT);
48
+ }
49
+
50
+ const addAdLoadFailedEventListener = (listener: (errorInfo: AdLoadFailedInfo) => void) => {
51
+ addEventListener(ON_APPOPEN_AD_LOAD_FAILED_EVENT, (errorInfo: AdLoadFailedInfo) => listener(errorInfo));
52
+ }
53
+
54
+ const removeAdLoadFailedEventListener = () => {
55
+ removeEventListener(ON_APPOPEN_AD_LOAD_FAILED_EVENT);
56
+ }
57
+
58
+ const addAdClickedEventListener = (listener: (adInfo: AdInfo) => void) => {
59
+ addEventListener(ON_APPOPEN_AD_CLICKED_EVENT, (adInfo: AdInfo) => listener(adInfo));
60
+ }
61
+
62
+ const removeAdClickedEventListener = () => {
63
+ removeEventListener(ON_APPOPEN_AD_CLICKED_EVENT);
64
+ }
65
+
66
+ const addAdDisplayedEventListener = (listener: (adInfo: AdInfo) => void) => {
67
+ addEventListener(ON_APPOPEN_AD_DISPLAYED_EVENT, (adInfo: AdInfo) => listener(adInfo));
68
+ }
69
+
70
+ const removeAdDisplayedEventListener = () => {
71
+ removeEventListener(ON_APPOPEN_AD_DISPLAYED_EVENT);
72
+ }
73
+
74
+ const addAdFailedToDisplayEventListener = (listener: (errorInfo: AdDisplayFailedInfo) => void) => {
75
+ addEventListener(ON_APPOPEN_AD_FAILED_TO_DISPLAY_EVENT, (errorInfo: AdDisplayFailedInfo) => listener(errorInfo));
76
+ }
77
+
78
+ const removeAdFailedToDisplayEventListener = () => {
79
+ removeEventListener(ON_APPOPEN_AD_FAILED_TO_DISPLAY_EVENT);
80
+ }
81
+
82
+ const addAdHiddenEventListener = (listener: (adInfo: AdInfo) => void) => {
83
+ addEventListener(ON_APPOPEN_AD_HIDDEN_EVENT, (adInfo: AdInfo) => listener(adInfo));
84
+ }
85
+
86
+ const removeAdHiddenEventListener = () => {
87
+ removeEventListener(ON_APPOPEN_AD_HIDDEN_EVENT);
88
+ }
89
+
90
+ const addAdRevenuePaidListener = (listener: (adInfo: AdRevenueInfo) => void) => {
91
+ addEventListener(ON_APPOPEN_AD_REVENUE_PAID, (adInfo: AdRevenueInfo) => listener(adInfo));
92
+ }
93
+
94
+ const removeAdRevenuePaidListener = () => {
95
+ removeEventListener(ON_APPOPEN_AD_REVENUE_PAID);
96
+ }
97
+
98
+ export const AppOpenAd: AppOpenAdType = {
99
+ isAdReady,
100
+ loadAd,
101
+ showAd,
102
+
103
+ setExtraParameter,
104
+ setLocalExtraParameter,
105
+
106
+ addAdLoadedEventListener,
107
+ removeAdLoadedEventListener,
108
+
109
+ addAdLoadFailedEventListener,
110
+ removeAdLoadFailedEventListener,
111
+
112
+ addAdClickedEventListener,
113
+ removeAdClickedEventListener,
114
+
115
+ addAdDisplayedEventListener,
116
+ removeAdDisplayedEventListener,
117
+
118
+ addAdFailedToDisplayEventListener,
119
+ removeAdFailedToDisplayEventListener,
120
+
121
+ addAdHiddenEventListener,
122
+ removeAdHiddenEventListener,
123
+
124
+ addAdRevenuePaidListener,
125
+ removeAdRevenuePaidListener,
126
+ }
127
+
128
+ export default AppOpenAd;
@@ -0,0 +1,175 @@
1
+ import { NativeModules } from "react-native";
2
+ import { addEventListener, removeEventListener } from "./EventEmitter"
3
+ import type { AdInfo, AdLoadFailedInfo, AdRevenueInfo } from "./types/AdInfo";
4
+ import type { BannerAdType } from "./types/BannerAd";
5
+ import type { AdViewPosition } from "./AdView";
6
+
7
+ const { AppLovinMAX } = NativeModules;
8
+
9
+ const {
10
+ ON_BANNER_AD_LOADED_EVENT,
11
+ ON_BANNER_AD_LOAD_FAILED_EVENT,
12
+ ON_BANNER_AD_CLICKED_EVENT,
13
+ ON_BANNER_AD_COLLAPSED_EVENT,
14
+ ON_BANNER_AD_EXPANDED_EVENT,
15
+ ON_BANNER_AD_REVENUE_PAID,
16
+ } = AppLovinMAX.getConstants();
17
+
18
+ const createAd = (adUnitId: string, position: AdViewPosition, xOffset?: number, yOffset?: number): void => {
19
+ AppLovinMAX.createBannerWithOffsets(adUnitId, position, xOffset ?? 0, yOffset ?? 0);
20
+ }
21
+
22
+ const destroyAd = (adUnitId: string): void => {
23
+ AppLovinMAX.destroyBanner(adUnitId);
24
+ }
25
+
26
+ const showAd = (adUnitId: string): void => {
27
+ AppLovinMAX.showBanner(adUnitId);
28
+ }
29
+
30
+ const hideAd = (adUnitId: string): void => {
31
+ AppLovinMAX.hideBanner(adUnitId);
32
+ }
33
+
34
+ const setPlacement = (adUnitId: string, placement: string | null): void => {
35
+ AppLovinMAX.setBannerPlacement(adUnitId, placement);
36
+ }
37
+
38
+ const setCustomData = (adUnitId: string, customData: string | null): void => {
39
+ AppLovinMAX.setBannerCustomData(adUnitId, customData);
40
+ }
41
+
42
+ const updatePosition = (adUnitId: string, bannerPosition: AdViewPosition): void => {
43
+ AppLovinMAX.updateBannerPosition(adUnitId, bannerPosition);
44
+ }
45
+
46
+ const setExtraParameter = (adUnitId: string, key: string, value: any): void => {
47
+ AppLovinMAX.setBannerExtraParameter(adUnitId, key, value);
48
+ }
49
+
50
+ const setLocalExtraParameter = (adUnitId: string, key: string, value: any): void => {
51
+ AppLovinMAX.setBannerLocalExtraParameter(adUnitId, { [key]: value });
52
+ }
53
+
54
+ const startAutoRefresh = (adUnitId: string): void => {
55
+ AppLovinMAX.startBannerAutoRefresh(adUnitId);
56
+ }
57
+
58
+ const stopAutoRefresh = (adUnitId: string): void => {
59
+ AppLovinMAX.stopBannerAutoRefresh(adUnitId);
60
+ }
61
+
62
+ const addAdLoadedEventListener = (listener: (adInfo: AdInfo) => void) => {
63
+ addEventListener(ON_BANNER_AD_LOADED_EVENT, (adInfo: AdInfo) => listener(adInfo));
64
+ }
65
+
66
+ const removeAdLoadedEventListener = () => {
67
+ removeEventListener(ON_BANNER_AD_LOADED_EVENT);
68
+ }
69
+
70
+ const addAdLoadFailedEventListener = (listener: (errorInfo: AdLoadFailedInfo) => void) => {
71
+ addEventListener(ON_BANNER_AD_LOAD_FAILED_EVENT, (errorInfo: AdLoadFailedInfo) => listener(errorInfo));
72
+ }
73
+
74
+ const removeAdLoadFailedEventListener = () => {
75
+ removeEventListener(ON_BANNER_AD_LOAD_FAILED_EVENT);
76
+ }
77
+
78
+ const addAdClickedEventListener = (listener: (adInfo: AdInfo) => void) => {
79
+ addEventListener(ON_BANNER_AD_CLICKED_EVENT, (adInfo: AdInfo) => listener(adInfo));
80
+ }
81
+
82
+ const removeAdClickedEventListener = () => {
83
+ removeEventListener(ON_BANNER_AD_CLICKED_EVENT);
84
+ }
85
+
86
+ const addAdCollapsedEventListener = (listener: (adInfo: AdInfo) => void) => {
87
+ addEventListener(ON_BANNER_AD_COLLAPSED_EVENT, (adInfo: AdInfo) => listener(adInfo));
88
+ }
89
+
90
+ const removeAdCollapsedEventListener = () => {
91
+ removeEventListener(ON_BANNER_AD_COLLAPSED_EVENT);
92
+ }
93
+
94
+ const addAdExpandedEventListener = (listener: (adInfo: AdInfo) => void) => {
95
+ addEventListener(ON_BANNER_AD_EXPANDED_EVENT, (adInfo: AdInfo) => listener(adInfo));
96
+ }
97
+
98
+ const removeAdExpandedEventListener = () => {
99
+ removeEventListener(ON_BANNER_AD_EXPANDED_EVENT);
100
+ }
101
+
102
+ const addAdRevenuePaidListener = (listener: (adInfo: AdRevenueInfo) => void) => {
103
+ addEventListener(ON_BANNER_AD_REVENUE_PAID, (adInfo: AdRevenueInfo) => listener(adInfo));
104
+ }
105
+
106
+ const removeAdRevenuePaidListener = () => {
107
+ removeEventListener(ON_BANNER_AD_REVENUE_PAID);
108
+ }
109
+
110
+ // Banner specific APIs
111
+
112
+ const setBackgroundColor = (adUnitId: string, hexColorCode: string): void => {
113
+ AppLovinMAX.setBannerBackgroundColor(adUnitId, hexColorCode);
114
+ }
115
+
116
+ const setWidth = (adUnitId: string, width: number): void => {
117
+ AppLovinMAX.setBannerWidth(adUnitId, width);
118
+ }
119
+
120
+ const updateOffsets = (adUnitId: string, xOffset: number, yOffset: number): void => {
121
+ AppLovinMAX.updateBannerOffsets(adUnitId, xOffset, yOffset);
122
+ }
123
+
124
+ const getAdaptiveHeightForWidth = (width: number): Promise<number> => {
125
+ return AppLovinMAX.getAdaptiveBannerHeightForWidth(width);
126
+ }
127
+
128
+ export const BannerAd: BannerAdType = {
129
+ createAd,
130
+ destroyAd,
131
+
132
+ showAd,
133
+ hideAd,
134
+
135
+ setPlacement,
136
+ setCustomData,
137
+
138
+ updatePosition,
139
+
140
+ setExtraParameter,
141
+ setLocalExtraParameter,
142
+
143
+ startAutoRefresh,
144
+ stopAutoRefresh,
145
+
146
+ addAdLoadedEventListener,
147
+ removeAdLoadedEventListener,
148
+
149
+ addAdLoadFailedEventListener,
150
+ removeAdLoadFailedEventListener,
151
+
152
+ addAdClickedEventListener,
153
+ removeAdClickedEventListener,
154
+
155
+ addAdCollapsedEventListener,
156
+ removeAdCollapsedEventListener,
157
+
158
+ addAdExpandedEventListener,
159
+ removeAdExpandedEventListener,
160
+
161
+ addAdRevenuePaidListener,
162
+ removeAdRevenuePaidListener,
163
+
164
+ // Banner specific APIs
165
+
166
+ setBackgroundColor,
167
+
168
+ setWidth,
169
+
170
+ updateOffsets,
171
+
172
+ getAdaptiveHeightForWidth,
173
+ }
174
+
175
+ export default BannerAd;