UNPKG

2.63 kBJavaScriptView Raw
1import React from 'react';
2import { requireNativeComponent, View } from 'react-native';
3
4const RNBanner = requireNativeComponent('RNAdMob', AdMobBanner);
5
6export default class AdMobBanner extends React.Component {
7 state = {
8 style: {},
9 };
10
11 _handleSizeChange = event => {
12 const { height, width } = event.nativeEvent;
13 this.setState({ style: { width, height } });
14 };
15
16 render() {
17 const {
18 adUnitID,
19 testDeviceID,
20 bannerSize,
21 didFailToReceiveAdWithError,
22 } = this.props;
23 return (
24 <View style={this.props.style}>
25 <RNBanner
26 style={this.state.style}
27 onSizeChange={this._handleSizeChange}
28 onAdViewDidReceiveAd={this.props.adViewDidReceiveAd}
29 onDidFailToReceiveAdWithError={event =>
30 didFailToReceiveAdWithError(event.nativeEvent.error)}
31 onAdViewWillPresentScreen={this.props.adViewWillPresentScreen}
32 onAdViewWillDismissScreen={this.props.adViewWillDismissScreen}
33 onAdViewDidDismissScreen={this.props.adViewDidDismissScreen}
34 onAdViewWillLeaveApplication={this.props.adViewWillLeaveApplication}
35 testDeviceID={testDeviceID}
36 adUnitID={adUnitID}
37 bannerSize={bannerSize}
38 />
39 </View>
40 );
41 }
42}
43
44AdMobBanner.propTypes = {
45 style: View.propTypes.style,
46
47 /**
48 * AdMob iOS library banner size constants
49 * (https://developers.google.com/admob/ios/banner)
50 * banner (320x50, Standard Banner for Phones and Tablets)
51 * largeBanner (320x100, Large Banner for Phones and Tablets)
52 * mediumRectangle (300x250, IAB Medium Rectangle for Phones and Tablets)
53 * fullBanner (468x60, IAB Full-Size Banner for Tablets)
54 * leaderboard (728x90, IAB Leaderboard for Tablets)
55 * smartBannerPortrait (Screen width x 32|50|90, Smart Banner for Phones and Tablets)
56 * smartBannerLandscape (Screen width x 32|50|90, Smart Banner for Phones and Tablets)
57 *
58 * banner is default
59 */
60 bannerSize: React.PropTypes.string,
61
62 /**
63 * AdMob ad unit ID
64 */
65 adUnitID: React.PropTypes.string,
66
67 /**
68 * Test device ID
69 */
70 testDeviceID: React.PropTypes.string,
71
72 /**
73 * AdMob iOS library events
74 */
75 adViewDidReceiveAd: React.PropTypes.func,
76 didFailToReceiveAdWithError: React.PropTypes.func,
77 adViewWillPresentScreen: React.PropTypes.func,
78 adViewWillDismissScreen: React.PropTypes.func,
79 adViewDidDismissScreen: React.PropTypes.func,
80 adViewWillLeaveApplication: React.PropTypes.func,
81 ...View.propTypes,
82};
83
84AdMobBanner.defaultProps = {
85 bannerSize: 'smartBannerPortrait',
86 didFailToReceiveAdWithError: () => {},
87};