react-native-applovin-max 3.3.1 → 4.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 +3 -3
- package/android/gradle/wrapper/gradle-wrapper.properties +1 -1
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXModule.java +20 -3
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdView.java +365 -0
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXNativeAdViewManager.java +148 -0
- package/android/src/main/java/com/applovin/reactnative/AppLovinMAXPackage.java +2 -1
- package/ios/AppLovinMAX.h +5 -0
- package/ios/AppLovinMAX.m +31 -3
- package/ios/AppLovinMAX.xcodeproj/project.pbxproj +14 -2
- package/ios/AppLovinMAX.xcworkspace/xcuserdata/thomasso.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/AppLovinMAXAdView.h +7 -0
- package/ios/AppLovinMAXAdView.m +7 -0
- package/ios/AppLovinMAXNativeAdView.h +27 -0
- package/ios/AppLovinMAXNativeAdView.m +308 -0
- package/ios/AppLovinMAXNativeAdViewManager.h +19 -0
- package/ios/AppLovinMAXNativeAdViewManager.m +60 -0
- package/ios/Podfile +1 -1
- package/ios/Podfile.lock +4 -4
- package/package.json +1 -1
- package/react-native-applovin-max.podspec +2 -2
- package/src/AppLovinMAXAdView.js +1 -1
- package/src/NativeAdComponents.js +156 -0
- package/src/NativeAdView.js +118 -0
- package/src/NativeAdViewProvider.js +19 -0
- package/src/index.js +3 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import React, {useContext, useRef, useEffect} from "react";
|
|
2
|
+
import {findNodeHandle, UIManager, Text, Image, View, TouchableOpacity} from "react-native";
|
|
3
|
+
import {NativeAdViewContext} from "./NativeAdViewProvider";
|
|
4
|
+
|
|
5
|
+
export const TitleView = (props) => {
|
|
6
|
+
const titleRef = useRef();
|
|
7
|
+
const {nativeAd, nativeAdView} = useContext(NativeAdViewContext);
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (Object.keys(nativeAd).length === 0 || !nativeAdView) return;
|
|
11
|
+
|
|
12
|
+
nativeAdView.setNativeProps({
|
|
13
|
+
titleView: findNodeHandle(titleRef.current),
|
|
14
|
+
});
|
|
15
|
+
}, [nativeAd, nativeAdView]);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
nativeAdView ?
|
|
19
|
+
<Text {...props} ref={titleRef}>
|
|
20
|
+
{nativeAd.title || null}
|
|
21
|
+
</Text>
|
|
22
|
+
:
|
|
23
|
+
null
|
|
24
|
+
);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const AdvertiserView = (props) => {
|
|
28
|
+
const advertiserRef = useRef();
|
|
29
|
+
const {nativeAd, nativeAdView} = useContext(NativeAdViewContext);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (Object.keys(nativeAd).length === 0 || !nativeAdView) return;
|
|
33
|
+
|
|
34
|
+
nativeAdView.setNativeProps({
|
|
35
|
+
advertiserView: findNodeHandle(advertiserRef.current),
|
|
36
|
+
});
|
|
37
|
+
}, [nativeAd, nativeAdView]);
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
nativeAdView ?
|
|
41
|
+
<Text {...props} ref={advertiserRef}>
|
|
42
|
+
{nativeAd.advertiser || null}
|
|
43
|
+
</Text>
|
|
44
|
+
:
|
|
45
|
+
null
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const BodyView = (props) => {
|
|
50
|
+
const bodyRef = useRef();
|
|
51
|
+
const {nativeAd, nativeAdView} = useContext(NativeAdViewContext);
|
|
52
|
+
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (Object.keys(nativeAd).length === 0 || !nativeAdView) return;
|
|
55
|
+
|
|
56
|
+
nativeAdView.setNativeProps({
|
|
57
|
+
bodyView: findNodeHandle(bodyRef.current),
|
|
58
|
+
});
|
|
59
|
+
}, [nativeAd, nativeAdView]);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
nativeAdView ?
|
|
63
|
+
<Text {...props} ref={bodyRef}>
|
|
64
|
+
{nativeAd.body || null}
|
|
65
|
+
</Text>
|
|
66
|
+
:
|
|
67
|
+
null
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const CallToActionView = (props) => {
|
|
72
|
+
const callToActionRef = useRef();
|
|
73
|
+
const {nativeAd, nativeAdView} = useContext(NativeAdViewContext);
|
|
74
|
+
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (Object.keys(nativeAd).length === 0 || !nativeAdView) return;
|
|
77
|
+
|
|
78
|
+
nativeAdView.setNativeProps({
|
|
79
|
+
callToActionView: findNodeHandle(callToActionRef.current),
|
|
80
|
+
});
|
|
81
|
+
}, [nativeAd, nativeAdView]);
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
nativeAdView ?
|
|
85
|
+
<TouchableOpacity {...props}>
|
|
86
|
+
<Text {...props} ref={callToActionRef}>
|
|
87
|
+
{nativeAd.callToAction || null}
|
|
88
|
+
</Text>
|
|
89
|
+
</TouchableOpacity>
|
|
90
|
+
:
|
|
91
|
+
null
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const IconView = (props) => {
|
|
96
|
+
const imageRef = useRef();
|
|
97
|
+
|
|
98
|
+
const {nativeAd, nativeAdView} = useContext(NativeAdViewContext);
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
if (Object.keys(nativeAd).length === 0 || !nativeAdView) return;
|
|
102
|
+
|
|
103
|
+
nativeAdView.setNativeProps({
|
|
104
|
+
iconView: findNodeHandle(imageRef.current),
|
|
105
|
+
});
|
|
106
|
+
}, [nativeAd, nativeAdView]);
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
nativeAdView ?
|
|
110
|
+
<Image {...props} ref={imageRef} source={{uri: nativeAd.url || null}}/>
|
|
111
|
+
:
|
|
112
|
+
null
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const OptionsView = (props) => {
|
|
117
|
+
const viewRef = useRef();
|
|
118
|
+
|
|
119
|
+
const {nativeAd, nativeAdView} = useContext(NativeAdViewContext);
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (Object.keys(nativeAd).length === 0 || !nativeAdView) return;
|
|
123
|
+
|
|
124
|
+
nativeAdView.setNativeProps({
|
|
125
|
+
optionsView: findNodeHandle(viewRef.current),
|
|
126
|
+
});
|
|
127
|
+
}, [nativeAd, nativeAdView]);
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
nativeAdView ?
|
|
131
|
+
<View {...props} ref={viewRef}/>
|
|
132
|
+
:
|
|
133
|
+
null
|
|
134
|
+
);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export const MediaView = (props) => {
|
|
138
|
+
const viewRef = useRef();
|
|
139
|
+
|
|
140
|
+
const {nativeAd, nativeAdView} = useContext(NativeAdViewContext);
|
|
141
|
+
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
if (Object.keys(nativeAd).length === 0 || !nativeAdView) return;
|
|
144
|
+
|
|
145
|
+
nativeAdView.setNativeProps({
|
|
146
|
+
mediaView: findNodeHandle(viewRef.current),
|
|
147
|
+
});
|
|
148
|
+
}, [nativeAd, nativeAdView]);
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
nativeAdView ?
|
|
152
|
+
<View {...props} ref={viewRef}/>
|
|
153
|
+
:
|
|
154
|
+
null
|
|
155
|
+
);
|
|
156
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React, { forwardRef, useContext, useImperativeHandle, useRef, useCallback } from "react";
|
|
2
|
+
import PropTypes from "prop-types";
|
|
3
|
+
import { NativeModules, requireNativeComponent, UIManager, findNodeHandle, View, StyleSheet } from "react-native";
|
|
4
|
+
import { NativeAdViewContext, NativeAdViewProvider } from "./NativeAdViewProvider";
|
|
5
|
+
import { TitleView, AdvertiserView, BodyView, CallToActionView, IconView, OptionsView, MediaView } from "./NativeAdComponents";
|
|
6
|
+
|
|
7
|
+
const { AppLovinMAX } = NativeModules;
|
|
8
|
+
|
|
9
|
+
// Returns NativeAdView if AppLovinMAX has been initialized, or returns an empty black view if
|
|
10
|
+
// AppLovinMAX has not been initialized
|
|
11
|
+
const NativeAdViewWrapper = forwardRef((props, ref) => {
|
|
12
|
+
const {style, ...rest} = props;
|
|
13
|
+
return (
|
|
14
|
+
AppLovinMAX.isInitialized() ?
|
|
15
|
+
<NativeAdViewProvider>
|
|
16
|
+
<NativeAdView {...props} ref={ref}/>
|
|
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>
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
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
|
+
const AppLovinMAXNativeAdView = requireNativeComponent('AppLovinMAXNativeAdView', NativeAdView);
|
|
39
|
+
|
|
40
|
+
// NativeAdView renders itself multiple times:
|
|
41
|
+
// 1. initial render
|
|
42
|
+
// 2. update of the nativeAdView context by saveElement, which locates and renders the all child
|
|
43
|
+
// components including the user's components without nativeAd
|
|
44
|
+
// 3. update of the nativeAd context by onNativeAdLoaded, which renders the ad components with nativeAd
|
|
45
|
+
const NativeAdView = forwardRef((props, ref) => {
|
|
46
|
+
|
|
47
|
+
// context from NativeAdViewProvider
|
|
48
|
+
const {nativeAd, nativeAdView, setNativeAd, setNativeAdView} = useContext(NativeAdViewContext);
|
|
49
|
+
|
|
50
|
+
// keep the nativeAdView ref
|
|
51
|
+
const nativeAdViewRef = useRef();
|
|
52
|
+
|
|
53
|
+
// invoke the native ad loader
|
|
54
|
+
const loadAd = () => {
|
|
55
|
+
if (nativeAdViewRef) {
|
|
56
|
+
UIManager.dispatchViewManagerCommand(
|
|
57
|
+
findNodeHandle(nativeAdViewRef.current),
|
|
58
|
+
UIManager.getViewManagerConfig("AppLovinMAXNativeAdView").Commands.loadAd,
|
|
59
|
+
undefined
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// expose a list of functions via the provided ref
|
|
65
|
+
useImperativeHandle(ref, () => ({ loadAd }), []);
|
|
66
|
+
|
|
67
|
+
// save the DOM element via the ref callback
|
|
68
|
+
const saveElement = useCallback((element) => {
|
|
69
|
+
if (element) {
|
|
70
|
+
nativeAdViewRef.current = element;
|
|
71
|
+
setNativeAdView(element);
|
|
72
|
+
}
|
|
73
|
+
}, [nativeAdViewRef]);
|
|
74
|
+
|
|
75
|
+
// callback from the native module to set a loaded ad
|
|
76
|
+
const onAdLoaded = useCallback((event) => {
|
|
77
|
+
setNativeAd(event.nativeEvent);
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<AppLovinMAXNativeAdView {...props} ref={saveElement} onAdLoaded={onAdLoaded}>
|
|
82
|
+
{props.children}
|
|
83
|
+
</AppLovinMAXNativeAdView>
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
NativeAdView.propTypes = {
|
|
88
|
+
/**
|
|
89
|
+
* A string value representing the ad unit id to load ads for.
|
|
90
|
+
*/
|
|
91
|
+
adUnitId: PropTypes.string.isRequired,
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A string value representing the placement name that you assign when you integrate each ad format, for granular reporting in ad events.
|
|
95
|
+
*/
|
|
96
|
+
placement: PropTypes.string,
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A string value representing the customData name that you assign when you integrate each ad format, for granular reporting in ad events.
|
|
100
|
+
*/
|
|
101
|
+
customData: PropTypes.string,
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* A dictionary value representing the extra parameters to set a list of key-value string pairs.
|
|
105
|
+
*/
|
|
106
|
+
extraParameters: PropTypes.object,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Add the child ad components
|
|
110
|
+
NativeAdViewWrapper.TitleView = TitleView;
|
|
111
|
+
NativeAdViewWrapper.AdvertiserView = AdvertiserView;
|
|
112
|
+
NativeAdViewWrapper.BodyView = BodyView;
|
|
113
|
+
NativeAdViewWrapper.CallToActionView = CallToActionView;
|
|
114
|
+
NativeAdViewWrapper.IconView = IconView;
|
|
115
|
+
NativeAdViewWrapper.OptionsView = OptionsView;
|
|
116
|
+
NativeAdViewWrapper.MediaView = MediaView;
|
|
117
|
+
|
|
118
|
+
export default NativeAdViewWrapper;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { useState, createContext } from "react";
|
|
2
|
+
|
|
3
|
+
export const NativeAdViewContext = createContext();
|
|
4
|
+
|
|
5
|
+
export const NativeAdViewProvider = props => {
|
|
6
|
+
|
|
7
|
+
const [nativeAd, setNativeAd] = useState({});
|
|
8
|
+
const [nativeAdView, setNativeAdView] = useState();
|
|
9
|
+
|
|
10
|
+
const providerValue = {
|
|
11
|
+
nativeAd, nativeAdView, setNativeAd, setNativeAdView,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<NativeAdViewContext.Provider value={providerValue}>
|
|
16
|
+
{props.children}
|
|
17
|
+
</NativeAdViewContext.Provider>
|
|
18
|
+
);
|
|
19
|
+
};
|
package/src/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { NativeModules, NativeEventEmitter } from "react-native";
|
|
2
2
|
import AdView, { AdFormat, AdViewPosition } from "./AppLovinMAXAdView";
|
|
3
3
|
import { TargetingData as targetingData, AdContentRating, UserGender } from "./TargetingData";
|
|
4
|
+
import NativeAdView from "./NativeAdView";
|
|
4
5
|
|
|
5
6
|
const { AppLovinMAX } = NativeModules;
|
|
6
7
|
|
|
7
|
-
const VERSION = "
|
|
8
|
+
const VERSION = "4.0.0";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* This enum represents whether or not the consent dialog should be shown for this user.
|
|
@@ -90,6 +91,7 @@ export default {
|
|
|
90
91
|
ConsentDialogState,
|
|
91
92
|
AdViewPosition,
|
|
92
93
|
AdFormat,
|
|
94
|
+
NativeAdView,
|
|
93
95
|
addEventListener,
|
|
94
96
|
removeEventListener,
|
|
95
97
|
// Use callback to avoid need for attaching listeners at top level on each re-render
|