forked from sbugert/react-native-admob
-
Notifications
You must be signed in to change notification settings - Fork 1
/
RNAdMobNativeExpress.js
100 lines (89 loc) · 2.51 KB
/
RNAdMobNativeExpress.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
import React, { Component } from "react";
import {
Platform,
requireNativeComponent,
View,
ViewPropTypes,
} from "react-native";
import _isEqual from "lodash/isEqual";
import PropTypes from "prop-types";
const RNBanner = requireNativeComponent(
"RNAdMobNativeExpress",
AdMobNativeExpress
);
export default class AdMobNativeExpress extends Component {
constructor() {
super();
this.onSizeChange = this.onSizeChange.bind(this);
this.state = {
style: {},
};
}
onSizeChange(event) {
const { height, width } = event.nativeEvent;
this.setState({ style: { width, height } });
}
shouldComponentUpdate(nextProps, nextState) {
return !_isEqual(this.props, nextProps) || !_isEqual(this.state, nextState);
}
render() {
const {
adUnitID,
testDeviceID,
bannerWidth,
bannerHeight,
didFailToReceiveAdWithError,
} = this.props;
return (
<View style={this.props.style}>
<RNBanner
style={this.state.style}
onSizeChange={this.onSizeChange.bind(this)}
onAdViewDidReceiveAd={this.props.adViewDidReceiveAd}
onDidFailToReceiveAdWithError={event =>
didFailToReceiveAdWithError(event.nativeEvent.error)}
onAdViewWillPresentScreen={this.props.adViewWillPresentScreen}
onAdViewWillDismissScreen={this.props.adViewWillDismissScreen}
onAdViewDidDismissScreen={this.props.adViewDidDismissScreen}
onAdViewWillLeaveApplication={this.props.adViewWillLeaveApplication}
bannerWidth={parseInt(bannerWidth)}
bannerHeight={parseInt(bannerHeight)}
testDeviceID={testDeviceID}
adUnitID={adUnitID}
/>
</View>
);
}
}
AdMobNativeExpress.propTypes = {
style: ViewPropTypes.style,
/**
* Native Express size
* (https://firebase.google.com/docs/admob/android/native-express#choose_a_size)
*/
bannerWidth: PropTypes.number,
bannerHeight: PropTypes.number,
/**
* AdMob ad unit ID
*/
adUnitID: PropTypes.string,
/**
* Test device ID
*/
testDeviceID: PropTypes.string,
/**
* AdMob library events
*/
adViewDidReceiveAd: PropTypes.func,
didFailToReceiveAdWithError: PropTypes.func,
adViewWillPresentScreen: PropTypes.func,
adViewWillDismissScreen: PropTypes.func,
adViewDidDismissScreen: PropTypes.func,
adViewWillLeaveApplication: PropTypes.func,
...ViewPropTypes,
};
AdMobNativeExpress.defaultProps = {
bannerWidth: 400,
bannerHeight: 300,
didFailToReceiveAdWithError: () => {},
};