react-native-applovin-max 5.7.1 → 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 (56) 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.old +1788 -0
  5. package/android/src/main/java/com/applovin/mediation/adapters/MintegralMediationAdapter.java.old +1481 -0
  6. package/android/src/main/java/com/applovin/mediation/adapters/MintegralMediationAdapter.java.saved +1448 -0
  7. package/ios/AppLovinMAX.m +1 -9
  8. package/ios/AppLovinMAX.xcodeproj/project.pbxproj +4 -4
  9. package/ios/AppLovinMAX.xcworkspace/xcuserdata/hiroshi.watanabe.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  10. package/ios/AppLovinMAXNativeAdView.m +8 -1
  11. package/ios/Podfile +1 -1
  12. package/package.json +2 -1
  13. package/react-native-applovin-max.podspec +1 -1
  14. package/src/AdView.tsx +251 -0
  15. package/src/AppLovinMAX.ts +24 -0
  16. package/src/AppOpenAd.ts +128 -0
  17. package/src/BannerAd.ts +175 -0
  18. package/src/EventEmitter.ts +27 -0
  19. package/src/InterstitialAd.ts +128 -0
  20. package/src/MRecAd.ts +147 -0
  21. package/src/Privacy.ts +6 -0
  22. package/src/RewardedAd.ts +144 -0
  23. package/src/TargetingData.ts +168 -0
  24. package/src/index.ts +21 -0
  25. package/src/nativeAd/NativeAdView.tsx +161 -0
  26. package/src/nativeAd/NativeAdViewComponents.tsx +185 -0
  27. package/src/nativeAd/NativeAdViewProvider.tsx +35 -0
  28. package/src/types/AdEvent.ts +26 -0
  29. package/src/types/AdInfo.ts +348 -0
  30. package/src/types/AdProps.ts +60 -0
  31. package/src/types/AdViewProps.ts +36 -0
  32. package/src/types/AppLovinMAX.ts +86 -0
  33. package/src/types/AppOpenAd.ts +3 -0
  34. package/src/types/BannerAd.ts +47 -0
  35. package/src/types/Configuration.ts +11 -0
  36. package/src/types/FullscreenAd.ts +135 -0
  37. package/src/types/InterstitialAd.ts +3 -0
  38. package/src/types/MRecAd.ts +13 -0
  39. package/src/types/NativeAd.ts +50 -0
  40. package/src/types/NativeAdViewProps.ts +17 -0
  41. package/src/types/Privacy.ts +73 -0
  42. package/src/types/RewardedAd.ts +18 -0
  43. package/src/types/ViewAd.ts +158 -0
  44. package/src/types/index.ts +4 -0
  45. package/ios/AppLovinMAX.xcworkspace/xcuserdata/thomasso.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  46. package/ios/AppLovinMAX.xcworkspace/xcuserdata/thomasso.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +0 -24
  47. package/src/.idea/modules.xml +0 -8
  48. package/src/.idea/src.iml +0 -8
  49. package/src/.idea/vcs.xml +0 -6
  50. package/src/AppLovinMAXAdView.js +0 -231
  51. package/src/AppLovinMAXEventListeners.js +0 -419
  52. package/src/NativeAdComponents.js +0 -208
  53. package/src/NativeAdView.js +0 -164
  54. package/src/NativeAdViewProvider.js +0 -19
  55. package/src/TargetingData.js +0 -104
  56. package/src/index.js +0 -291
@@ -0,0 +1,161 @@
1
+ import React, { forwardRef, useContext, useImperativeHandle, useRef, useState, useEffect, useCallback } from "react";
2
+ import { NativeModules, requireNativeComponent, UIManager, findNodeHandle } from "react-native";
3
+ import type { ViewProps } from "react-native";
4
+ import { NativeAdViewContext, NativeAdViewProvider } from "./NativeAdViewProvider";
5
+ import type { AdInfo, AdLoadFailedInfo, AdRevenueInfo } from "../types/AdInfo";
6
+ import type { AdNativeEvent } from "../types/AdEvent";
7
+ import type { NativeAd } from "../types/NativeAd";
8
+ import type { NativeAdViewHandler, NativeAdViewProps } from "../types/NativeAdViewProps";
9
+ import type { NativeAdViewType, NativeAdViewContextType } from "./NativeAdViewProvider";
10
+
11
+ const { AppLovinMAX } = NativeModules;
12
+
13
+ type NativeAdViewNativeEvents = {
14
+ onAdLoadedEvent(event: { nativeEvent: { nativeAd: NativeAd; adInfo: AdInfo; } }): void
15
+ onAdLoadFailedEvent(event: AdNativeEvent<AdLoadFailedInfo>): void
16
+ onAdClickedEvent(event: AdNativeEvent<AdInfo>): void
17
+ onAdRevenuePaidEvent(event: AdNativeEvent<AdRevenueInfo>): void
18
+ };
19
+
20
+ const NativeAdViewComponent = requireNativeComponent<NativeAdViewProps & ViewProps & NativeAdViewNativeEvents>('AppLovinMAXNativeAdView');
21
+
22
+ /**
23
+ * The {@link NativeAdView} component for building a native ad. This loads a native ad and renders it with
24
+ * the asset views:
25
+ *
26
+ * - {@link IconView}
27
+ * - {@link TitleView}
28
+ * - {@link AdvertiserView}
29
+ * - {@link StarRatingView}
30
+ * - {@link BodyView}
31
+ * - {@link MediaView}
32
+ * - {@link CallToActionView}
33
+ *
34
+ * Each asset view will be filled with the data of a native ad when loaded, but you need to provide
35
+ * the layout and style of the asset views. A new native ad can be re-loaded via the ref handler.
36
+ *
37
+ * ### Example:
38
+ * ```js
39
+ * <NativeAdView
40
+ * ref={nativeAdViewHandler}
41
+ * adUnitId={adUnitId}
42
+ * style={styles.nativead}
43
+ * onAdLoaded={(adInfo: AdInfo) => { ... }}
44
+ * >
45
+ * <View style={ ... }>
46
+ * <IconView style={styles.icon} />
47
+ * <TitleView style={styles.title} />
48
+ * <AdvertiserView style={styles.advertiser} />
49
+ * <StarRatingView style={styles.starRatingView} />
50
+ * <OptionsView style={styles.optionsView} />
51
+ * <BodyView style={styles.body} />
52
+ * <MediaView style={styles.mediaView} />
53
+ * <CallToActionView style={styles.callToAction} />
54
+ * </View>
55
+ * </NativeAdView>
56
+ * ```
57
+ */
58
+ export const NativeAdView = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>((props, ref) => {
59
+ const [isInitialized, setIsInitialized] = useState<boolean>(false);
60
+
61
+ useEffect(() => {
62
+ // check that AppLovinMAX has been initialized
63
+ AppLovinMAX.isInitialized().then((result: boolean) => {
64
+ setIsInitialized(result);
65
+ if (!result) {
66
+ console.warn("ERROR: NativeAdView is mounted before the initialization of the AppLovin MAX React Native module");
67
+ }
68
+ });
69
+ }, []);
70
+
71
+ // Not ready to render NativeAdView
72
+ if (!isInitialized) {
73
+ return null;
74
+ }
75
+
76
+ return (
77
+ <NativeAdViewProvider>
78
+ <NativeAdViewImpl {...props} ref={ref} />
79
+ </NativeAdViewProvider>
80
+ );
81
+ });
82
+
83
+ const NativeAdViewImpl = forwardRef<NativeAdViewHandler, NativeAdViewProps & ViewProps>(({
84
+ adUnitId,
85
+ placement,
86
+ customData,
87
+ extraParameters,
88
+ localExtraParameters,
89
+ onAdLoaded,
90
+ onAdLoadFailed,
91
+ onAdClicked,
92
+ onAdRevenuePaid,
93
+ children,
94
+ style,
95
+ ...otherProps
96
+ }, ref) => {
97
+
98
+ // context from NativeAdViewProvider
99
+ const { setNativeAd, setNativeAdView } = useContext(NativeAdViewContext) as NativeAdViewContextType;
100
+
101
+ // keep the nativeAdView ref
102
+ const nativeAdViewRef = useRef<NativeAdViewType | null>(null);
103
+
104
+ // invoke the native ad loader
105
+ const loadAd = () => {
106
+ if (nativeAdViewRef) {
107
+ UIManager.dispatchViewManagerCommand(
108
+ findNodeHandle(nativeAdViewRef.current),
109
+ UIManager.getViewManagerConfig("AppLovinMAXNativeAdView").Commands.loadAd,
110
+ undefined
111
+ );
112
+ }
113
+ };
114
+
115
+ // expose a list of functions via the provided ref
116
+ useImperativeHandle(ref, () => ({ loadAd }), []);
117
+
118
+ // save the DOM element via the ref callback
119
+ const saveElement = useCallback((element: NativeAdViewType | null) => {
120
+ if (element) {
121
+ nativeAdViewRef.current = element;
122
+ setNativeAdView(element);
123
+ }
124
+ }, []);
125
+
126
+ const onAdLoadedEvent = (event: { nativeEvent: { nativeAd: NativeAd; adInfo: AdInfo; } }) => {
127
+ setNativeAd(event.nativeEvent.nativeAd);
128
+ if (onAdLoaded) onAdLoaded(event.nativeEvent.adInfo);
129
+ };
130
+
131
+ const onAdLoadFailedEvent = (event: AdNativeEvent<AdLoadFailedInfo>) => {
132
+ if (onAdLoadFailed) onAdLoadFailed(event.nativeEvent);
133
+ };
134
+
135
+ const onAdClickedEvent = (event: AdNativeEvent<AdInfo>) => {
136
+ if (onAdClicked) onAdClicked(event.nativeEvent);
137
+ };
138
+
139
+ const onAdRevenuePaidEvent = (event: AdNativeEvent<AdRevenueInfo>) => {
140
+ if (onAdRevenuePaid) onAdRevenuePaid(event.nativeEvent);
141
+ };
142
+
143
+ return (
144
+ <NativeAdViewComponent
145
+ ref={saveElement}
146
+ adUnitId={adUnitId}
147
+ placement={placement}
148
+ customData={customData}
149
+ extraParameters={extraParameters}
150
+ localExtraParameters={localExtraParameters}
151
+ onAdLoadedEvent={onAdLoadedEvent}
152
+ onAdLoadFailedEvent={onAdLoadFailedEvent}
153
+ onAdClickedEvent={onAdClickedEvent}
154
+ onAdRevenuePaidEvent={onAdRevenuePaidEvent}
155
+ style={style}
156
+ {...otherProps}
157
+ >
158
+ {children}
159
+ </NativeAdViewComponent>
160
+ );
161
+ });
@@ -0,0 +1,185 @@
1
+ import React, { useContext, useRef, useEffect } from "react";
2
+ import { findNodeHandle, Text, Image, View, TouchableOpacity, StyleSheet } from "react-native";
3
+ import type { ViewProps, ImageProps, TextStyle, StyleProp } from "react-native";
4
+ import { NativeAdViewContext } from "./NativeAdViewProvider";
5
+
6
+ export const TitleView = (props: ViewProps) => {
7
+ const titleRef = useRef(null);
8
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
9
+
10
+ useEffect(() => {
11
+ if (!nativeAd.title || !titleRef.current) return;
12
+
13
+ nativeAdView?.setNativeProps({
14
+ titleView: findNodeHandle(titleRef.current),
15
+ });
16
+ }, [nativeAd]);
17
+
18
+ return (
19
+ <Text {...props} ref={titleRef}>
20
+ {nativeAd.title || null}
21
+ </Text>
22
+ );
23
+ };
24
+
25
+ export const AdvertiserView = (props: ViewProps) => {
26
+ const advertiserRef = useRef(null);
27
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
28
+
29
+ useEffect(() => {
30
+ if (!nativeAd.advertiser || !advertiserRef.current) return;
31
+
32
+ nativeAdView?.setNativeProps({
33
+ advertiserView: findNodeHandle(advertiserRef.current),
34
+ });
35
+ }, [nativeAd]);
36
+
37
+ return (
38
+ <Text {...props} ref={advertiserRef}>
39
+ {nativeAd.advertiser || null}
40
+ </Text>
41
+ );
42
+ };
43
+
44
+ export const BodyView = (props: ViewProps) => {
45
+ const bodyRef = useRef(null);
46
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
47
+
48
+ useEffect(() => {
49
+ if (!nativeAd.body || !bodyRef.current) return;
50
+
51
+ nativeAdView?.setNativeProps({
52
+ bodyView: findNodeHandle(bodyRef.current),
53
+ });
54
+ }, [nativeAd]);
55
+
56
+ return (
57
+ <Text {...props} ref={bodyRef}>
58
+ {nativeAd.body || null}
59
+ </Text>
60
+ );
61
+ };
62
+
63
+ export const CallToActionView = (props: ViewProps) => {
64
+ const callToActionRef = useRef(null);
65
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
66
+
67
+ useEffect(() => {
68
+ if (!nativeAd.callToAction || !callToActionRef.current) return;
69
+
70
+ nativeAdView?.setNativeProps({
71
+ callToActionView: findNodeHandle(callToActionRef.current),
72
+ });
73
+ }, [nativeAd]);
74
+
75
+ return (
76
+ <TouchableOpacity {...props}>
77
+ <Text {...props} ref={callToActionRef}>
78
+ {nativeAd.callToAction || null}
79
+ </Text>
80
+ </TouchableOpacity>
81
+ );
82
+ };
83
+
84
+ export const IconView = (props: Omit<ImageProps, | 'source'>) => {
85
+ const imageRef = useRef(null);
86
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
87
+
88
+ useEffect(() => {
89
+ if (!nativeAd.image || !imageRef.current) return;
90
+
91
+ nativeAdView?.setNativeProps({
92
+ iconView: findNodeHandle(imageRef.current),
93
+ });
94
+ }, [nativeAd]);
95
+
96
+ return (
97
+ nativeAd.url ? <Image {...props} source={{ uri: nativeAd.url }} /> :
98
+ nativeAd.image ? <Image {...props} ref={imageRef} source={0} /> :
99
+ <View {...props} />
100
+ );
101
+ };
102
+
103
+ export const OptionsView = (props: ViewProps) => {
104
+ const viewRef = useRef(null);
105
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
106
+
107
+ useEffect(() => {
108
+ if (!nativeAd.isOptionsViewAvailable || !viewRef.current) return;
109
+ nativeAdView?.setNativeProps({
110
+ optionsView: findNodeHandle(viewRef.current),
111
+ });
112
+ }, [nativeAd]);
113
+
114
+ return (
115
+ <View {...props} ref={viewRef} />
116
+ );
117
+ };
118
+
119
+ export const MediaView = (props: ViewProps) => {
120
+ const viewRef = useRef(null);
121
+ const { nativeAd, nativeAdView } = useContext(NativeAdViewContext);
122
+
123
+ useEffect(() => {
124
+ if (!nativeAd.isMediaViewAvailable || !viewRef.current) return;
125
+
126
+ nativeAdView?.setNativeProps({
127
+ mediaView: findNodeHandle(viewRef.current),
128
+ });
129
+ }, [nativeAd]);
130
+
131
+ return (
132
+ <View {...props} ref={viewRef} />
133
+ );
134
+ };
135
+
136
+ export const StarRatingView = (props: ViewProps) => {
137
+ const { style, ...restProps } = props;
138
+
139
+ const maxStarCount = 5;
140
+ const starColor = StyleSheet.flatten(style as StyleProp<TextStyle> || {}).color ?? "#ffe234";
141
+ const starSize = StyleSheet.flatten(style as StyleProp<TextStyle> || {}).fontSize ?? 10;
142
+
143
+ const { nativeAd } = useContext(NativeAdViewContext);
144
+
145
+ const FilledStar = () => {
146
+ return (
147
+ // black star in unicode
148
+ <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2605)}</Text>
149
+ );
150
+ };
151
+
152
+ const EmptyStar = () => {
153
+ return (
154
+ // white star in unicode
155
+ <Text style={{ fontSize: starSize, color: starColor }}>{String.fromCodePoint(0x2606)}</Text>
156
+ );
157
+ };
158
+
159
+ return (
160
+ <View {...restProps} style={[style, { flexDirection: 'row', alignItems: 'center' }]}>
161
+ {(() => {
162
+ let stars = [];
163
+ for (let index = 0; index < maxStarCount; index++) {
164
+ if (nativeAd.starRating) {
165
+ const width = (nativeAd.starRating - index) * starSize;
166
+ stars.push(
167
+ <View key={index}>
168
+ <EmptyStar />
169
+ {
170
+ (nativeAd.starRating > index) &&
171
+ <View style={{ width: width, overflow: 'hidden', position: 'absolute' }}>
172
+ <FilledStar />
173
+ </View>
174
+ }
175
+ </View>
176
+ );
177
+ } else {
178
+ stars.push(<Text key={index} style={{ fontSize: starSize }}> </Text>);
179
+ }
180
+ }
181
+ return stars;
182
+ })()}
183
+ </View>
184
+ );
185
+ };
@@ -0,0 +1,35 @@
1
+ import React, { useState, createContext } from "react";
2
+ import type { NativeMethods } from "react-native";
3
+ import type { NativeAd } from "../types/NativeAd";
4
+ import type { NativeAdViewProps } from "../types/NativeAdViewProps";
5
+
6
+ export type NativeAdViewType = React.Component<NativeAdViewProps> & NativeMethods;
7
+
8
+ export type NativeAdViewContextType = {
9
+ nativeAd: NativeAd;
10
+ nativeAdView: NativeAdViewType | null;
11
+ setNativeAd: React.Dispatch<React.SetStateAction<NativeAd>>;
12
+ setNativeAdView: React.Dispatch<React.SetStateAction<NativeAdViewType>>;
13
+ };
14
+
15
+ export const NativeAdViewContext = createContext<NativeAdViewContextType>({
16
+ nativeAd: { isOptionsViewAvailable: false, isMediaViewAvailable: false },
17
+ nativeAdView: null,
18
+ setNativeAd: () => { },
19
+ setNativeAdView: () => { }
20
+ });
21
+
22
+ export const NativeAdViewProvider: React.FC<{ children: React.ReactNode }> = (props) => {
23
+ const [nativeAd, setNativeAd] = useState({ isOptionsViewAvailable: false, isMediaViewAvailable: false });
24
+ const [nativeAdView, setNativeAdView] = useState(Object);
25
+
26
+ const providerValue = {
27
+ nativeAd, nativeAdView, setNativeAd, setNativeAdView,
28
+ };
29
+
30
+ return (
31
+ <NativeAdViewContext.Provider value={providerValue}>
32
+ {props.children}
33
+ </NativeAdViewContext.Provider>
34
+ );
35
+ };
@@ -0,0 +1,26 @@
1
+ import type {
2
+ AdInfo,
3
+ AdLoadFailedInfo,
4
+ AdDisplayFailedInfo,
5
+ AdRevenueInfo,
6
+ AdRewardInfo
7
+ } from "./AdInfo";
8
+
9
+ export type AdEventObject =
10
+ AdInfo |
11
+ AdLoadFailedInfo |
12
+ AdDisplayFailedInfo |
13
+ AdRevenueInfo |
14
+ AdRewardInfo;
15
+
16
+ /**
17
+ * Defines a generic event listener for the pragrammatic methods to receive an event from the native
18
+ * module.
19
+ */
20
+ export type AdEventListener<T extends AdEventObject> = (event: T) => void;
21
+
22
+ /**
23
+ * Defines a generic event object for the UI components i.e. AdView and NativeAdView to receive an
24
+ * event from the native module.
25
+ */
26
+ export type AdNativeEvent<T extends AdEventObject> = { nativeEvent: T };