react-native-applovin-max 3.2.2 → 3.3.1

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.
@@ -1,63 +1,71 @@
1
- import { requireNativeComponent, UIManager, findNodeHandle } from "react-native";
1
+ import { NativeModules, requireNativeComponent, UIManager, findNodeHandle, View, Text, StyleSheet } from "react-native";
2
2
  import PropTypes from "prop-types";
3
3
  import React from "react";
4
- import AppLovinMAX from "./index.js";
5
-
6
- class AdView extends React.Component {
7
-
8
- static defaultProps = {
9
- adaptiveBannerEnabled: true
10
- }
11
-
12
- componentDidMount() {
13
- this.setAdUnitId(this.props.adUnitId);
14
- this.setAdFormat(this.props.adFormat);
15
- this.setPlacement(this.props.placement);
16
- this.setCustomData(this.props.customData);
17
- this.setAdaptiveBannerEnabled(this.props.adaptiveBannerEnabled);
18
- }
19
-
20
- componentDidUpdate(prevProps) {
21
- // Only call setters for actual changes.
22
- if (prevProps.adUnitId !== this.props.adUnitId) {
23
- this.setAdUnitId(this.props.adUnitId);
24
- }
25
-
26
- if (prevProps.adFormat !== this.props.adFormat) {
27
- this.setAdFormat(this.props.adFormat);
28
- }
29
4
 
30
- if (prevProps.placement !== this.props.placement) {
31
- this.setPlacement(this.props.placement);
32
- }
33
-
34
- if (prevProps.customData !== this.props.customData) {
35
- this.setCustomData(this.props.customData);
36
- }
5
+ const { AppLovinMAX } = NativeModules;
37
6
 
38
- if (prevProps.adaptiveBannerEnabled !== this.props.adaptiveBannerEnabled) {
39
- this.setAdaptiveBannerEnabled(this.props.adaptiveBannerEnabled);
40
- }
41
- }
42
-
43
- render() {
44
- let { style, ...otherProps } = this.props;
45
-
46
- return <AppLovinMAXAdView
47
- // This merges the pub-specified style with ours, but overwrites width/height.
48
- style = { Object.assign({}, style, this.sizeForAdFormat(otherProps.adFormat)) } {...otherProps }
49
- />;
50
- }
51
-
52
- // Helper Functions
7
+ export const AdFormat = {
8
+ BANNER: "banner",
9
+ MREC: "mrec",
10
+ };
53
11
 
54
- sizeForAdFormat(adFormat) {
55
- if (adFormat === AppLovinMAX.AdFormat.BANNER) {
12
+ export const AdViewPosition = {
13
+ TOP_CENTER: "top_center",
14
+ TOP_LEFT: "top_left",
15
+ TOP_RIGHT: "top_right",
16
+ CENTERED: "centered",
17
+ CENTER_LEFT: "center_left",
18
+ CENTER_RIGHT: "center_right",
19
+ BOTTOM_LEFT: "bottom_left",
20
+ BOTTOM_CENTER: "bottom_center",
21
+ BOTTOM_RIGHT: "bottom_right",
22
+ };
56
23
 
57
- var width = AppLovinMAX.isTablet() ? 728 : 320;
58
- var height;
24
+ /**
25
+ * Returns AdView when AppLovinMax has been initialized or returns a black empty View as
26
+ * a placeholder of AdView when AppLovinMax has not been initialized.
27
+ *
28
+ * The purpose of this AdView wrapper is for the application not to access AdView
29
+ * before the completion of the AppLovinMax initialization.
30
+ *
31
+ * Note: this does not re-render itself when the status of the AppLovinMax initialization
32
+ * has changed so that the black view may stay even after the completion of
33
+ * the AppLovinMax initialization.
34
+ */
35
+ const AdViewWrapper = (props) => {
36
+ const {style, ...rest} = props;
37
+ return (
38
+ AppLovinMAX.isInitialized() ?
39
+ <AdView {...style} {...rest}/>
40
+ :
41
+ <View style={[styles.container, style]} {...rest}>
42
+ {
43
+ console.warn('[AppLovinSdk] [AppLovinMAX] <AdView/> has been mounted before AppLovin initialization')
44
+ }
45
+ </View>
46
+ );
47
+ };
59
48
 
60
- if (this.props.adaptiveBannerEnabled) {
49
+ const styles = StyleSheet.create({
50
+ container: {
51
+ flexDirection: 'column',
52
+ justifyContent: 'flex-end',
53
+ alignItems: 'center',
54
+ backgroundColor: 'black',
55
+ borderColor: 'whitesmoke',
56
+ borderWidth: 1,
57
+ },
58
+ });
59
+
60
+ const AdView = (props) => {
61
+ const {style, ...otherProps} = props;
62
+
63
+ const sizeForAdFormat = () => {
64
+ if (props.adFormat === AdFormat.BANNER) {
65
+ let width = AppLovinMAX.isTablet() ? 728 : 320;
66
+ let height;
67
+
68
+ if (props.adaptiveBannerEnabled) {
61
69
  height = AppLovinMAX.getAdaptiveBannerHeightForWidth(-1);
62
70
  } else {
63
71
  height = AppLovinMAX.isTablet() ? 90 : 50;
@@ -67,70 +75,15 @@ class AdView extends React.Component {
67
75
  } else {
68
76
  return { width: 300, height: 250 }
69
77
  }
70
- }
71
-
72
- setAdUnitId(adUnitId) {
73
- UIManager.dispatchViewManagerCommand(
74
- findNodeHandle(this),
75
- Platform.OS === 'android' ? "setAdUnitId" : UIManager.getViewManagerConfig("AppLovinMAXAdView").Commands.setAdUnitId,
76
- [adUnitId]
77
- );
78
- }
79
-
80
- setAdFormat(adFormatStr) {
81
- UIManager.dispatchViewManagerCommand(
82
- findNodeHandle(this),
83
- Platform.OS === 'android' ? "setAdFormat" : UIManager.getViewManagerConfig("AppLovinMAXAdView").Commands.setAdFormat,
84
- [adFormatStr]
85
- );
86
- }
87
-
88
- setPlacement(placement) {
89
- var adUnitId = this.props.adUnitId;
90
- var adFormat = this.props.adFormat;
91
-
92
- // If the ad unit id or ad format are unset, we can't set the placement.
93
- if (adUnitId == null || adFormat == null) return;
94
-
95
- UIManager.dispatchViewManagerCommand(
96
- findNodeHandle(this),
97
- Platform.OS === 'android' ? "setPlacement" : UIManager.getViewManagerConfig("AppLovinMAXAdView").Commands.setPlacement,
98
- [placement]
99
- );
100
- }
101
-
102
- setCustomData(customData) {
103
- var adUnitId = this.props.adUnitId;
104
- var adFormat = this.props.adFormat;
105
-
106
- // If the ad unit id or ad format are unset, we can't set the customData.
107
- if (adUnitId == null || adFormat == null) return;
108
-
109
- UIManager.dispatchViewManagerCommand(
110
- findNodeHandle(this),
111
- Platform.OS === 'android' ? "setCustomData" : UIManager.getViewManagerConfig("AppLovinMAXAdView").Commands.setCustomData,
112
- [customData]
113
- );
114
- }
115
-
116
- setAdaptiveBannerEnabled(enabled) {
117
- var adUnitId = this.props.adUnitId;
118
- var adFormat = this.props.adFormat;
119
-
120
- // If the ad unit id or ad format are unset, we can't set the value
121
- if (adUnitId == null || adFormat == null) return;
122
-
123
- if (adFormat === AppLovinMAX.AdFormat.BANNER) {
124
- if (enabled === true || enabled === false) {
125
- UIManager.dispatchViewManagerCommand(
126
- findNodeHandle(this),
127
- Platform.OS === 'android' ? "setAdaptiveBannerEnabled" : UIManager.getViewManagerConfig("AppLovinMAXAdView").Commands.setAdaptiveBannerEnabled,
128
- [enabled ? "true" : "false"]
129
- );
130
- }
131
- }
132
- }
133
- }
78
+ };
79
+
80
+ return (
81
+ <AppLovinMAXAdView
82
+ style={[sizeForAdFormat(), style]}
83
+ {...otherProps }
84
+ />
85
+ );
86
+ };
134
87
 
135
88
  AdView.propTypes = {
136
89
  /**
@@ -157,9 +110,21 @@ AdView.propTypes = {
157
110
  * A boolean value representing whether or not to enable adaptive banners. Note that adaptive banners are enabled by default as of v2.3.0.
158
111
  */
159
112
  adaptiveBannerEnabled: PropTypes.bool,
113
+
114
+ /**
115
+ * A boolean value representing whether or not to enable auto-refresh. Note that auto-refresh is enabled by default.
116
+ */
117
+ autoRefresh: PropTypes.bool,
160
118
  };
161
119
 
120
+ // Defiens default values for the props.
121
+ AdView.defaultProps = {
122
+ adaptiveBannerEnabled: true,
123
+ autoRefresh: true,
124
+ };
125
+
126
+
162
127
  // requireNativeComponent automatically resolves 'AppLovinMAXAdView' to 'AppLovinMAXAdViewManager'
163
- var AppLovinMAXAdView = requireNativeComponent("AppLovinMAXAdView", AdView);
128
+ const AppLovinMAXAdView = requireNativeComponent("AppLovinMAXAdView", AdView);
164
129
 
165
- export default AdView;
130
+ export default AdViewWrapper;
@@ -1,4 +1,6 @@
1
- import AppLovinMAX from "./index.js";
1
+ import { NativeModules } from "react-native";
2
+
3
+ const { AppLovinMAX } = NativeModules;
2
4
 
3
5
  const AdContentRating = {
4
6
  None: 0,
package/src/index.js CHANGED
@@ -1,11 +1,10 @@
1
1
  import { NativeModules, NativeEventEmitter } from "react-native";
2
- import AdView from "./AppLovinMAXAdView";
2
+ import AdView, { AdFormat, AdViewPosition } from "./AppLovinMAXAdView";
3
3
  import { TargetingData as targetingData, AdContentRating, UserGender } from "./TargetingData";
4
- import { UserSegment as userSegment } from "./UserSegment";
5
4
 
6
5
  const { AppLovinMAX } = NativeModules;
7
6
 
8
- const VERSION = "3.2.2";
7
+ const VERSION = "3.3.1";
9
8
 
10
9
  /**
11
10
  * This enum represents whether or not the consent dialog should be shown for this user.
@@ -28,25 +27,6 @@ const ConsentDialogState = {
28
27
  DOES_NOT_APPLY: 2,
29
28
  };
30
29
 
31
- const AdFormat = {
32
- BANNER: "banner",
33
- MREC: "mrec",
34
- };
35
-
36
- const AdViewPosition = {
37
- TOP_CENTER: "top_center",
38
- TOP_LEFT: "top_left",
39
- TOP_RIGHT: "top_right",
40
- CENTERED: "centered",
41
- CENTER_LEFT: "center_left",
42
- CENTER_RIGHT: "center_right",
43
- BOTTOM_LEFT: "bottom_left",
44
- BOTTOM_CENTER: "bottom_center",
45
- BOTTOM_RIGHT: "bottom_right",
46
- };
47
-
48
- // const AdView = AppLovinMAXAdView;
49
-
50
30
  const emitter = new NativeEventEmitter(AppLovinMAX);
51
31
  const subscriptions = {};
52
32
 
@@ -104,7 +84,6 @@ const showRewardedAd = (adUnitId, ...args) => {
104
84
  export default {
105
85
  ...AppLovinMAX,
106
86
  AdView,
107
- userSegment,
108
87
  targetingData,
109
88
  AdContentRating,
110
89
  UserGender,
@@ -1,12 +0,0 @@
1
- import AppLovinMAX from "./index.js";
2
-
3
- let UserSegment = {
4
-
5
- set name(value) {
6
- AppLovinMAX.setUserSegment(value);
7
- },
8
- };
9
-
10
- export {
11
- UserSegment,
12
- };