forked from ammarahm-ed/react-native-admob-native-ads
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NativeAdView.js
executable file
·101 lines (85 loc) · 2.11 KB
/
NativeAdView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { arrayOf, func, object, string } from "prop-types";
import React, { Component } from "react";
import {
findNodeHandle,
requireNativeComponent,
UIManager,
ViewPropTypes,
Platform
} from "react-native";
class NativeAdView extends Component {
constructor() {
super();
this.handleAdFailedToLoad = this.handleAdFailedToLoad.bind(this);
this.state = {
style: {
}
};
}
componentDidMount() {
const { adUnitID } = this.props;
if (adUnitID) {
return this.loadNativeAd(adUnitID);
}
console.warn("Attempted to load native ad without ad unit id");
}
loadNativeAd(adUnitId) {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this._nativeView),
UIManager.getViewManagerConfig("RNGADNativeView").Commands.loadNativeAd,
[adUnitId]
);
}
getHeight() {
if (this.props.adSize === "small") {
return 120
} else if (this.props.adSize === "medium") {
return 160;
} else {
return 410
}
}
handleAdFailedToLoad(event) {
if (this.props.onAdFailedToLoad) {
this.props.onAdFailedToLoad(event.nativeEvent.error);
}
}
setRef = el => (this._nativeView = el);
render() {
return (
<UnifiedNativeAdView
{...this.props}
style={[this.props.style, this.state.style, {
// height: Platform.OS === "android"? this.getHeight() : null
}]}
onAdFailedToLoad={this.handleAdFailedToLoad}
ref={this.setRef}
/>
);
}
}
NativeAdView.simulatorId = "SIMULATOR";
NativeAdView.propTypes = {
...ViewPropTypes,
adSize: string,
adUnitID: string,
buttonStyle: object,
backgroundStyle: object,
headlineTextColor: string,
descriptionTextColor: string,
advertiserTextColor: string,
ratingBarColor: string,
testDevices: arrayOf(string),
onAdOpened: func,
onAdClosed: func,
onAdLeftApplication: func,
onAdImpression: func,
onAdClick: func,
onAdLoaded: func,
onAdFailedToLoad: func
};
const UnifiedNativeAdView = requireNativeComponent(
"RNGADNativeView",
NativeAdView
);
export default NativeAdView;