react-native-applovin-max 4.1.7 → 5.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.
- package/android/build.gradle +2 -12
- package/android/gradle.properties +0 -1
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdView.java +85 -23
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXAdViewManager.java +39 -11
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXModule.java +712 -209
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdView.java +107 -39
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +17 -7
- package/ios/AppLovinMAX.h +22 -2
- package/ios/AppLovinMAX.m +586 -144
- package/ios/AppLovinMAXAdView.m +43 -12
- package/ios/AppLovinMAXAdViewManager.m +10 -0
- package/ios/AppLovinMAXNativeAdView.m +86 -41
- package/ios/AppLovinMAXNativeAdViewManager.m +7 -3
- package/package.json +1 -1
- package/react-native-applovin-max.podspec +1 -1
- package/src/AppLovinMAXAdView.js +163 -62
- package/src/AppLovinMAXEventListeners.js +419 -0
- package/src/NativeAdComponents.js +39 -46
- package/src/NativeAdView.js +79 -34
- package/src/TargetingData.js +35 -3
- package/src/index.js +116 -328
package/src/NativeAdView.js
CHANGED
|
@@ -1,40 +1,19 @@
|
|
|
1
|
-
import React, { forwardRef, useContext, useImperativeHandle, useRef,
|
|
1
|
+
import React, { forwardRef, useContext, useImperativeHandle, useRef, useState, useEffect } from "react";
|
|
2
2
|
import PropTypes from "prop-types";
|
|
3
|
-
import { NativeModules, requireNativeComponent, UIManager, findNodeHandle
|
|
3
|
+
import { NativeModules, requireNativeComponent, UIManager, findNodeHandle } from "react-native";
|
|
4
4
|
import { NativeAdViewContext, NativeAdViewProvider } from "./NativeAdViewProvider";
|
|
5
5
|
import { TitleView, AdvertiserView, BodyView, CallToActionView, IconView, OptionsView, MediaView } from "./NativeAdComponents";
|
|
6
6
|
|
|
7
7
|
const { AppLovinMAX } = NativeModules;
|
|
8
8
|
|
|
9
|
-
// Returns NativeAdView if AppLovinMAX has been initialized, or returns an empty black view if
|
|
10
|
-
// AppLovinMAX has not been initialized
|
|
11
9
|
const NativeAdViewWrapper = forwardRef((props, ref) => {
|
|
12
|
-
const {style, ...rest} = props;
|
|
13
10
|
return (
|
|
14
|
-
|
|
15
|
-
<
|
|
16
|
-
|
|
17
|
-
</NativeAdViewProvider>
|
|
18
|
-
:
|
|
19
|
-
<View style={[styles.container, style]} {...rest}>
|
|
20
|
-
{
|
|
21
|
-
console.warn('[AppLovinSdk] [AppLovinMAX] <NativeAdView/> has been mounted before AppLovin initialization')
|
|
22
|
-
}
|
|
23
|
-
</View>
|
|
11
|
+
<NativeAdViewProvider>
|
|
12
|
+
<NativeAdView {...props} ref={ref}/>
|
|
13
|
+
</NativeAdViewProvider>
|
|
24
14
|
);
|
|
25
15
|
});
|
|
26
16
|
|
|
27
|
-
const styles = StyleSheet.create({
|
|
28
|
-
container: {
|
|
29
|
-
flexDirection: 'column',
|
|
30
|
-
justifyContent: 'flex-end',
|
|
31
|
-
alignItems: 'center',
|
|
32
|
-
backgroundColor: 'black',
|
|
33
|
-
borderColor: 'whitesmoke',
|
|
34
|
-
borderWidth: 1,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
17
|
const AppLovinMAXNativeAdView = requireNativeComponent('AppLovinMAXNativeAdView', NativeAdView);
|
|
39
18
|
|
|
40
19
|
// NativeAdView renders itself multiple times:
|
|
@@ -44,6 +23,8 @@ const AppLovinMAXNativeAdView = requireNativeComponent('AppLovinMAXNativeAdView'
|
|
|
44
23
|
// 3. update of the nativeAd context by onNativeAdLoaded, which renders the ad components with nativeAd
|
|
45
24
|
const NativeAdView = forwardRef((props, ref) => {
|
|
46
25
|
|
|
26
|
+
const {extraParameters, localExtraParameters, ...otherProps} = props;
|
|
27
|
+
|
|
47
28
|
// context from NativeAdViewProvider
|
|
48
29
|
const {nativeAd, nativeAdView, setNativeAd, setNativeAdView} = useContext(NativeAdViewContext);
|
|
49
30
|
|
|
@@ -65,20 +46,59 @@ const NativeAdView = forwardRef((props, ref) => {
|
|
|
65
46
|
useImperativeHandle(ref, () => ({ loadAd }), []);
|
|
66
47
|
|
|
67
48
|
// save the DOM element via the ref callback
|
|
68
|
-
const saveElement =
|
|
49
|
+
const saveElement = (element) => {
|
|
69
50
|
if (element) {
|
|
70
51
|
nativeAdViewRef.current = element;
|
|
71
52
|
setNativeAdView(element);
|
|
72
53
|
}
|
|
73
|
-
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const onAdLoadedEvent = (event) => {
|
|
57
|
+
setNativeAd(event.nativeEvent.nativeAd);
|
|
58
|
+
if (props.onAdLoaded) props.onAdLoaded(event.nativeEvent.adInfo);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const onAdLoadFailedEvent = (event) => {
|
|
62
|
+
if (props.onAdLoadFailed) props.onAdLoadFailed(event.nativeEvent);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const onAdClickedEvent = (event) => {
|
|
66
|
+
if (props.onAdClicked) props.onAdClicked(event.nativeEvent);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const onAdRevenuePaidEvent = (event) => {
|
|
70
|
+
if (props.onAdRevenuePaid) props.onAdRevenuePaid(event.nativeEvent);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const sanitizeExtraParameters = (name, params) => {
|
|
74
|
+
if (!params) return params;
|
|
75
|
+
|
|
76
|
+
for (const key in params) {
|
|
77
|
+
const value = params[key];
|
|
78
|
+
|
|
79
|
+
// `null` and `undefined` are valid values (e.g. for clearing previously-set values)
|
|
80
|
+
if (value == null || value == undefined) continue;
|
|
81
|
+
|
|
82
|
+
if (typeof value !== 'string') {
|
|
83
|
+
console.warn("AppLovinMAXNativeAdView only support string values: " + value + ", deleting value for key: " + key);
|
|
84
|
+
delete params[key];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
74
87
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
setNativeAd(event.nativeEvent);
|
|
78
|
-
}, []);
|
|
88
|
+
return params;
|
|
89
|
+
};
|
|
79
90
|
|
|
80
91
|
return (
|
|
81
|
-
<AppLovinMAXNativeAdView
|
|
92
|
+
<AppLovinMAXNativeAdView
|
|
93
|
+
ref={saveElement}
|
|
94
|
+
extraParameters={sanitizeExtraParameters('extraParameters', extraParameters)}
|
|
95
|
+
localExtraParameters={sanitizeExtraParameters('localExtraParameters', localExtraParameters)}
|
|
96
|
+
onAdLoadedEvent={onAdLoadedEvent}
|
|
97
|
+
onAdLoadFailedEvent={onAdLoadFailedEvent}
|
|
98
|
+
onAdClickedEvent={onAdClickedEvent}
|
|
99
|
+
onAdRevenuePaidEvent={onAdRevenuePaidEvent}
|
|
100
|
+
{...otherProps}
|
|
101
|
+
>
|
|
82
102
|
{props.children}
|
|
83
103
|
</AppLovinMAXNativeAdView>
|
|
84
104
|
);
|
|
@@ -101,9 +121,34 @@ NativeAdView.propTypes = {
|
|
|
101
121
|
customData: PropTypes.string,
|
|
102
122
|
|
|
103
123
|
/**
|
|
104
|
-
* A dictionary
|
|
124
|
+
* A dictionary of extra parameters consisting of key-value string pairs.
|
|
105
125
|
*/
|
|
106
126
|
extraParameters: PropTypes.object,
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* A dictionary of local extra parameters consisting of key-value string pairs.
|
|
130
|
+
*/
|
|
131
|
+
localExtraParameters: PropTypes.object,
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A callback fuction to be fired when a new ad has been loaded.
|
|
135
|
+
*/
|
|
136
|
+
onAdLoaded: PropTypes.func,
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A callback fuction to be fired when an ad could not be retrieved.
|
|
140
|
+
*/
|
|
141
|
+
onAdLoadFailed: PropTypes.func,
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A callback fuction to be fired when ad is clicked.
|
|
145
|
+
*/
|
|
146
|
+
onAdClicked: PropTypes.func,
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* A callback fuction to be fired when the revenue event is detected.
|
|
150
|
+
*/
|
|
151
|
+
onAdRevenuePaid: PropTypes.func,
|
|
107
152
|
};
|
|
108
153
|
|
|
109
154
|
// Add the child ad components
|
package/src/TargetingData.js
CHANGED
|
@@ -19,11 +19,17 @@ const UserGender = {
|
|
|
19
19
|
const TargetingData = {
|
|
20
20
|
|
|
21
21
|
set yearOfBirth(value) {
|
|
22
|
-
AppLovinMAX.setTargetingDataYearOfBirth(value);
|
|
22
|
+
AppLovinMAX.setTargetingDataYearOfBirth(value ? value : 0);
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
get yearOfBirth() {
|
|
26
|
+
return AppLovinMAX.getTargetingDataYearOfBirth();
|
|
23
27
|
},
|
|
24
28
|
|
|
25
29
|
set gender(value) {
|
|
26
|
-
if ( value
|
|
30
|
+
if ( !value ) {
|
|
31
|
+
AppLovinMAX.setTargetingDataGender(UserGender.Unknown);
|
|
32
|
+
} else if ( value === UserGender.Unknown ||
|
|
27
33
|
value === UserGender.Female ||
|
|
28
34
|
value === UserGender.Male ||
|
|
29
35
|
value === UserGender.Other ) {
|
|
@@ -31,8 +37,14 @@ const TargetingData = {
|
|
|
31
37
|
}
|
|
32
38
|
},
|
|
33
39
|
|
|
40
|
+
get gender() {
|
|
41
|
+
return AppLovinMAX.getTargetingDataGender();
|
|
42
|
+
},
|
|
43
|
+
|
|
34
44
|
set maximumAdContentRating(value) {
|
|
35
|
-
if ( value
|
|
45
|
+
if ( !value ) {
|
|
46
|
+
AppLovinMAX.setTargetingDataMaximumAdContentRating(AdContentRating.None);
|
|
47
|
+
} else if ( value === AdContentRating.None ||
|
|
36
48
|
value === AdContentRating.AllAudiences ||
|
|
37
49
|
value === AdContentRating.EveryoneOverTwelve ||
|
|
38
50
|
value === AdContentRating.MatureAudiences ) {
|
|
@@ -40,22 +52,42 @@ const TargetingData = {
|
|
|
40
52
|
}
|
|
41
53
|
},
|
|
42
54
|
|
|
55
|
+
get maximumAdContentRating() {
|
|
56
|
+
return AppLovinMAX.getTargetingDataMaximumAdContentRating();
|
|
57
|
+
},
|
|
58
|
+
|
|
43
59
|
set email(value) {
|
|
44
60
|
AppLovinMAX.setTargetingDataEmail(value);
|
|
45
61
|
},
|
|
46
62
|
|
|
63
|
+
get email() {
|
|
64
|
+
return AppLovinMAX.getTargetingDataEmail();
|
|
65
|
+
},
|
|
66
|
+
|
|
47
67
|
set phoneNumber(value) {
|
|
48
68
|
AppLovinMAX.setTargetingDataPhoneNumber(value);
|
|
49
69
|
},
|
|
50
70
|
|
|
71
|
+
get phoneNumber() {
|
|
72
|
+
return AppLovinMAX.getTargetingDataPhoneNumber();
|
|
73
|
+
},
|
|
74
|
+
|
|
51
75
|
set keywords(value) {
|
|
52
76
|
AppLovinMAX.setTargetingDataKeywords(value);
|
|
53
77
|
},
|
|
54
78
|
|
|
79
|
+
get keywords() {
|
|
80
|
+
return AppLovinMAX.getTargetingDataKeywords();
|
|
81
|
+
},
|
|
82
|
+
|
|
55
83
|
set interests(value) {
|
|
56
84
|
AppLovinMAX.setTargetingDataInterests(value);
|
|
57
85
|
},
|
|
58
86
|
|
|
87
|
+
get interests() {
|
|
88
|
+
return AppLovinMAX.getTargetingDataInterests();
|
|
89
|
+
},
|
|
90
|
+
|
|
59
91
|
clearAll() {
|
|
60
92
|
AppLovinMAX.clearAllTargetingData();
|
|
61
93
|
}
|