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.
- package/android/build.gradle +14 -3
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdView.java +34 -27
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewManagerImpl.java +110 -0
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewUiComponent.java +15 -13
- package/android/src/main/java/com/applovin/reactnative/{AppLovinMAXModule.java → AppLovinMAXModuleImpl.java} +108 -168
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdView.java +84 -56
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManagerImpl.java +101 -0
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXPackage.java +44 -11
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXUtils.java +56 -0
- package/android/src/newarch/com/applovin/reactnative/AppLovinMAXAdViewManager.java +151 -0
- package/android/src/newarch/com/applovin/reactnative/AppLovinMAXModule.java +453 -0
- package/android/src/newarch/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +130 -0
- package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXAdViewManager.java +128 -0
- package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXModule.java +453 -0
- package/android/src/oldarch/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +93 -0
- package/ios/AppLovinMAX.h +8 -3
- package/ios/{AppLovinMAX.m → AppLovinMAX.mm} +67 -53
- package/ios/AppLovinMAXAdView.h +7 -2
- package/ios/AppLovinMAXAdView.mm +747 -0
- package/ios/{AppLovinMAXAdViewManager.m → AppLovinMAXAdViewManager.mm} +3 -2
- package/ios/{AppLovinMAXAdViewUIComponent.m → AppLovinMAXAdViewUIComponent.mm} +2 -1
- package/ios/AppLovinMAXNativeAdView.h +15 -4
- package/ios/AppLovinMAXNativeAdView.mm +745 -0
- package/ios/AppLovinMAXNativeAdViewManager.mm +116 -0
- package/lib/commonjs/AdView.js +102 -142
- package/lib/commonjs/AdView.js.map +1 -1
- package/lib/commonjs/AppLovinMAX.js +49 -34
- package/lib/commonjs/AppLovinMAX.js.map +1 -1
- package/lib/commonjs/AppOpenAd.js +8 -10
- package/lib/commonjs/AppOpenAd.js.map +1 -1
- package/lib/commonjs/BannerAd.js +19 -21
- package/lib/commonjs/BannerAd.js.map +1 -1
- package/lib/commonjs/ErrorCode.js +27 -36
- package/lib/commonjs/ErrorCode.js.map +1 -1
- package/lib/commonjs/EventEmitter.js +24 -5
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/InterstitialAd.js +8 -10
- package/lib/commonjs/InterstitialAd.js.map +1 -1
- package/lib/commonjs/MRecAd.js +14 -16
- package/lib/commonjs/MRecAd.js.map +1 -1
- package/lib/commonjs/Privacy.js +3 -5
- package/lib/commonjs/Privacy.js.map +1 -1
- package/lib/commonjs/RewardedAd.js +8 -10
- package/lib/commonjs/RewardedAd.js.map +1 -1
- package/lib/commonjs/Utils.js +43 -0
- package/lib/commonjs/Utils.js.map +1 -0
- package/lib/commonjs/nativeAd/NativeAdView.js +84 -50
- package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdViewComponents.js +129 -82
- package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdViewProvider.js +67 -8
- package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
- package/lib/commonjs/nativeAd/img/blank_icon.png +0 -0
- package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js +41 -0
- package/lib/commonjs/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js +37 -0
- package/lib/commonjs/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/NativeAppLovinMAXModule.js +16 -0
- package/lib/commonjs/specs/NativeAppLovinMAXModule.js.map +1 -0
- package/lib/commonjs/types/AdInfo.js +13 -16
- package/lib/commonjs/types/AdInfo.js.map +1 -1
- package/lib/module/AdView.js +98 -139
- package/lib/module/AdView.js.map +1 -1
- package/lib/module/AppLovinMAX.js +47 -32
- package/lib/module/AppLovinMAX.js.map +1 -1
- package/lib/module/AppOpenAd.js +1 -4
- package/lib/module/AppOpenAd.js.map +1 -1
- package/lib/module/BannerAd.js +1 -4
- package/lib/module/BannerAd.js.map +1 -1
- package/lib/module/ErrorCode.js +25 -35
- package/lib/module/ErrorCode.js.map +1 -1
- package/lib/module/EventEmitter.js +24 -5
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/InterstitialAd.js +2 -5
- package/lib/module/InterstitialAd.js.map +1 -1
- package/lib/module/MRecAd.js +1 -4
- package/lib/module/MRecAd.js.map +1 -1
- package/lib/module/Privacy.js +1 -4
- package/lib/module/Privacy.js.map +1 -1
- package/lib/module/RewardedAd.js +2 -5
- package/lib/module/RewardedAd.js.map +1 -1
- package/lib/module/Utils.js +35 -0
- package/lib/module/Utils.js.map +1 -0
- package/lib/module/nativeAd/NativeAdView.js +83 -47
- package/lib/module/nativeAd/NativeAdView.js.map +1 -1
- package/lib/module/nativeAd/NativeAdViewComponents.js +134 -83
- package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
- package/lib/module/nativeAd/NativeAdViewProvider.js +69 -9
- package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
- package/lib/module/nativeAd/img/blank_icon.png +0 -0
- package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js +35 -0
- package/lib/module/specs/AppLovinMAXAdViewNativeComponent.js.map +1 -0
- package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js +31 -0
- package/lib/module/specs/AppLovinMAXNativeAdViewNativeComponent.js.map +1 -0
- package/lib/module/specs/NativeAppLovinMAXModule.js +12 -0
- package/lib/module/specs/NativeAppLovinMAXModule.js.map +1 -0
- package/lib/module/types/AdInfo.js +13 -16
- package/lib/module/types/AdInfo.js.map +1 -1
- package/lib/typescript/src/AdView.d.ts +38 -32
- package/lib/typescript/src/AdView.d.ts.map +1 -1
- package/lib/typescript/src/AppLovinMAX.d.ts +22 -21
- package/lib/typescript/src/AppLovinMAX.d.ts.map +1 -1
- package/lib/typescript/src/AppOpenAd.d.ts.map +1 -1
- package/lib/typescript/src/BannerAd.d.ts.map +1 -1
- package/lib/typescript/src/ErrorCode.d.ts +24 -31
- package/lib/typescript/src/ErrorCode.d.ts.map +1 -1
- package/lib/typescript/src/EventEmitter.d.ts +16 -0
- package/lib/typescript/src/EventEmitter.d.ts.map +1 -1
- package/lib/typescript/src/InterstitialAd.d.ts.map +1 -1
- package/lib/typescript/src/MRecAd.d.ts.map +1 -1
- package/lib/typescript/src/Privacy.d.ts.map +1 -1
- package/lib/typescript/src/RewardedAd.d.ts.map +1 -1
- package/lib/typescript/src/Utils.d.ts +31 -0
- package/lib/typescript/src/Utils.d.ts.map +1 -0
- package/lib/typescript/src/nativeAd/NativeAdView.d.ts +15 -7
- package/lib/typescript/src/nativeAd/NativeAdView.d.ts.map +1 -1
- package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts +65 -1
- package/lib/typescript/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
- package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts +31 -5
- package/lib/typescript/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
- package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts +130 -0
- package/lib/typescript/src/specs/AppLovinMAXAdViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts +131 -0
- package/lib/typescript/src/specs/AppLovinMAXNativeAdViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts +142 -0
- package/lib/typescript/src/specs/NativeAppLovinMAXModule.d.ts.map +1 -0
- package/lib/typescript/src/types/AdEvent.d.ts +10 -4
- package/lib/typescript/src/types/AdEvent.d.ts.map +1 -1
- package/lib/typescript/src/types/AdInfo.d.ts +79 -86
- package/lib/typescript/src/types/AdInfo.d.ts.map +1 -1
- package/lib/typescript/src/types/AdProps.d.ts +16 -17
- package/lib/typescript/src/types/AdProps.d.ts.map +1 -1
- package/lib/typescript/src/types/AdViewProps.d.ts +28 -29
- package/lib/typescript/src/types/AdViewProps.d.ts.map +1 -1
- package/lib/typescript/src/types/AppLovinMAX.d.ts +50 -53
- package/lib/typescript/src/types/AppLovinMAX.d.ts.map +1 -1
- package/lib/typescript/src/types/BannerAd.d.ts +22 -17
- package/lib/typescript/src/types/BannerAd.d.ts.map +1 -1
- package/lib/typescript/src/types/CMPError.d.ts +7 -4
- package/lib/typescript/src/types/CMPError.d.ts.map +1 -1
- package/lib/typescript/src/types/Configuration.d.ts +12 -14
- package/lib/typescript/src/types/Configuration.d.ts.map +1 -1
- package/lib/typescript/src/types/FullscreenAd.d.ts +39 -46
- package/lib/typescript/src/types/FullscreenAd.d.ts.map +1 -1
- package/lib/typescript/src/types/MRecAd.d.ts +7 -3
- package/lib/typescript/src/types/MRecAd.d.ts.map +1 -1
- package/lib/typescript/src/types/NativeAd.d.ts +15 -10
- package/lib/typescript/src/types/NativeAd.d.ts.map +1 -1
- package/lib/typescript/src/types/NativeAdViewProps.d.ts +4 -3
- package/lib/typescript/src/types/NativeAdViewProps.d.ts.map +1 -1
- package/lib/typescript/src/types/Privacy.d.ts +13 -6
- package/lib/typescript/src/types/Privacy.d.ts.map +1 -1
- package/lib/typescript/src/types/RewardedAd.d.ts +7 -5
- package/lib/typescript/src/types/RewardedAd.d.ts.map +1 -1
- package/lib/typescript/src/types/ViewAd.d.ts +46 -50
- package/lib/typescript/src/types/ViewAd.d.ts.map +1 -1
- package/package.json +9 -1
- package/react-native-applovin-max.podspec +3 -3
- package/src/AdView.tsx +100 -183
- package/src/AppLovinMAX.ts +42 -33
- package/src/AppOpenAd.ts +1 -3
- package/src/BannerAd.ts +1 -3
- package/src/ErrorCode.ts +25 -34
- package/src/EventEmitter.ts +22 -5
- package/src/InterstitialAd.ts +2 -4
- package/src/MRecAd.ts +1 -3
- package/src/Privacy.ts +1 -3
- package/src/RewardedAd.ts +2 -4
- package/src/Utils.ts +45 -0
- package/src/nativeAd/NativeAdView.tsx +83 -73
- package/src/nativeAd/NativeAdViewComponents.tsx +120 -89
- package/src/nativeAd/NativeAdViewProvider.tsx +60 -12
- package/src/nativeAd/img/blank_icon.png +0 -0
- package/src/specs/AppLovinMAXAdViewNativeComponent.ts +157 -0
- package/src/specs/AppLovinMAXNativeAdViewNativeComponent.ts +153 -0
- package/src/specs/NativeAppLovinMAXModule.ts +228 -0
- package/src/types/AdEvent.ts +10 -4
- package/src/types/AdInfo.ts +79 -86
- package/src/types/AdProps.ts +16 -17
- package/src/types/AdViewProps.ts +28 -29
- package/src/types/AppLovinMAX.ts +50 -53
- package/src/types/BannerAd.ts +22 -17
- package/src/types/CMPError.ts +7 -4
- package/src/types/Configuration.ts +12 -14
- package/src/types/FullscreenAd.ts +39 -46
- package/src/types/MRecAd.ts +7 -3
- package/src/types/NativeAd.ts +16 -10
- package/src/types/NativeAdViewProps.ts +4 -3
- package/src/types/Privacy.ts +13 -6
- package/src/types/RewardedAd.ts +7 -5
- package/src/types/ViewAd.ts +46 -50
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewManager.java +0 -149
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +0 -163
- package/ios/AppLovinMAXAdView.m +0 -325
- package/ios/AppLovinMAXNativeAdView.m +0 -432
- package/ios/AppLovinMAXNativeAdViewManager.m +0 -64
package/src/ErrorCode.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import
|
|
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
|
-
*
|
|
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
|
-
*
|
|
27
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
39
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
50
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
79
|
-
*
|
|
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
|
-
*
|
|
86
|
-
* "Don't Keep Activities" developer setting enabled.
|
|
87
|
-
* **Android
|
|
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
|
-
*
|
|
93
|
-
* invalid ad unit identifier.
|
|
84
|
+
* The ad failed to load due to an invalid ad unit identifier.
|
|
94
85
|
*
|
|
95
|
-
* Possible
|
|
96
|
-
* 1.
|
|
97
|
-
* 2.
|
|
98
|
-
* 3.
|
|
99
|
-
* 4.
|
|
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 app’s package name.
|
|
90
|
+
* 4. The ad unit was recently created (less than ~30–60 minutes ago).
|
|
100
91
|
*/
|
|
101
92
|
INVALID_AD_UNIT_ID = MAX_ERROR_CODE_INVALID_AD_UNIT_ID,
|
|
102
93
|
}
|
package/src/EventEmitter.ts
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
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
|
|
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) {
|
package/src/InterstitialAd.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 { 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 ??
|
|
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
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 ??
|
|
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 {
|
|
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 {
|
|
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
|
|
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
|
|
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
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
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
|
-
* ```
|
|
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
|
-
|
|
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 {
|
|
98
|
+
const { titleRef, advertiserRef, bodyRef, callToActionRef, imageRef, optionViewRef, mediaViewRef, setNativeAd } = useContext(NativeAdViewContext) as NativeAdViewContextType;
|
|
93
99
|
|
|
94
|
-
const nativeAdViewRef = useRef<
|
|
100
|
+
const nativeAdViewRef = useRef<React.ElementRef<typeof NativeAdViewComponent> | undefined>();
|
|
95
101
|
|
|
96
|
-
//
|
|
102
|
+
// Triggers a native ad load via the native command
|
|
97
103
|
const loadAd = useCallback(() => {
|
|
98
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
},
|
|
132
|
-
[onAdLoadFailed]
|
|
133
|
-
);
|
|
143
|
+
if (nativeAdViewRef.current) {
|
|
144
|
+
Commands.renderNativeAd(nativeAdViewRef.current);
|
|
145
|
+
}
|
|
134
146
|
|
|
135
|
-
|
|
136
|
-
(event: AdNativeEvent<AdInfo>) => {
|
|
137
|
-
onAdClicked?.(event.nativeEvent);
|
|
147
|
+
handleNativeAdViewEvent(event, onAdLoaded);
|
|
138
148
|
},
|
|
139
|
-
[
|
|
149
|
+
[setNativeAd, onAdLoaded, updateAssetView, titleRef, advertiserRef, bodyRef, callToActionRef, imageRef, optionViewRef, mediaViewRef]
|
|
140
150
|
);
|
|
141
151
|
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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={
|
|
160
|
+
ref={(element) => (nativeAdViewRef.current = element ?? undefined)}
|
|
152
161
|
adUnitId={adUnitId}
|
|
153
162
|
placement={placement}
|
|
154
163
|
customData={customData}
|
|
155
|
-
extraParameters={extraParameters}
|
|
156
|
-
|
|
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}
|