-
Notifications
You must be signed in to change notification settings - Fork 529
/
RNPublisherBanner.js
124 lines (106 loc) · 3.51 KB
/
RNPublisherBanner.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import React, { Component } from 'react';
import {
NativeModules,
requireNativeComponent,
View,
NativeEventEmitter,
Platform,
UIManager,
findNodeHandle,
} from 'react-native';
class PublisherBanner extends Component {
constructor() {
super();
this.handleSizeChange = this.handleSizeChange.bind(this);
this.handleAdmobDispatchAppEvent = this.handleAdmobDispatchAppEvent.bind(this);
this.handleDidFailToReceiveAdWithError = this.handleDidFailToReceiveAdWithError.bind(this);
this.state = {
style: {},
};
}
componentDidMount() {
this.loadBanner();
}
loadBanner() {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this._bannerView),
UIManager.RNDFPBannerView.Commands.loadBanner,
null,
);
}
handleSizeChange(event) {
const { height, width } = event.nativeEvent;
this.setState({ style: { width, height } });
if (this.props.onSizeChange) {
this.props.onSizeChange({ width, height });
}
}
handleAdmobDispatchAppEvent(event) {
if (this.props.onAdmobDispatchAppEvent) {
const { name, info } = event.nativeEvent;
this.props.onAdmobDispatchAppEvent({ name, info });
}
}
handleDidFailToReceiveAdWithError(event) {
if (this.props.onDidFailToReceiveAdWithError) {
this.props.onDidFailToReceiveAdWithError(event.nativeEvent.error);
}
}
render() {
return (
<RNDFPBannerView
{...this.props}
style={[this.props.style, this.state.style]}
onSizeChange={this.handleSizeChange}
onDidFailToReceiveAdWithError={this.handleDidFailToReceiveAdWithError}
onAdmobDispatchAppEvent={this.handleAdmobDispatchAppEvent}
ref={el => (this._bannerView = el)}
/>
);
}
}
PublisherBanner.simulatorId = Platform.OS === 'android' ? 'EMULATOR' : NativeModules.RNDFPBannerViewManager.simulatorId;
PublisherBanner.propTypes = {
...View.propTypes,
/**
* AdMob iOS library banner size constants
* (https://developers.google.com/admob/ios/banner)
* banner (320x50, Standard Banner for Phones and Tablets)
* largeBanner (320x100, Large Banner for Phones and Tablets)
* mediumRectangle (300x250, IAB Medium Rectangle for Phones and Tablets)
* fullBanner (468x60, IAB Full-Size Banner for Tablets)
* leaderboard (728x90, IAB Leaderboard for Tablets)
* smartBannerPortrait (Screen width x 32|50|90, Smart Banner for Phones and Tablets)
* smartBannerLandscape (Screen width x 32|50|90, Smart Banner for Phones and Tablets)
*
* banner is default
*/
adSize: React.PropTypes.string,
/**
* Optional array specifying all valid sizes that are appropriate for this slot.
*/
validAdSizes: React.PropTypes.arrayOf(React.PropTypes.string),
/**
* AdMob ad unit ID
*/
adUnitID: React.PropTypes.string,
/**
* Array of test devices. Use PublisherBanner.simulatorId for the simulator
*/
testDevices: React.PropTypes.arrayOf(React.PropTypes.string),
/**
* AdMob iOS library events
*/
onSizeChange: React.PropTypes.func,
onAdViewDidReceiveAd: React.PropTypes.func,
onDidFailToReceiveAdWithError: React.PropTypes.func,
onAdViewWillPresentScreen: React.PropTypes.func,
onAdViewWillDismissScreen: React.PropTypes.func,
onAdViewDidDismissScreen: React.PropTypes.func,
onAdViewWillLeaveApplication: React.PropTypes.func,
onAdmobDispatchAppEvent: React.PropTypes.func,
};
PublisherBanner.defaultProps = {
};
const RNDFPBannerView = requireNativeComponent('RNDFPBannerView', PublisherBanner);
export default PublisherBanner;