UNPKG

2.17 kBJavaScriptView Raw
1import { requireNativeViewManager } from '@unimodules/core';
2import PropTypes from 'prop-types';
3import * as React from 'react';
4import { View, ViewPropTypes } from 'react-native';
5export default class AdMobBanner extends React.Component {
6 constructor() {
7 super(...arguments);
8 this.state = { style: {} };
9 this._handleSizeChange = ({ nativeEvent }) => {
10 const { height, width } = nativeEvent;
11 this.setState({ style: { width, height } });
12 };
13 this._handleDidFailToReceiveAdWithError = ({ nativeEvent }) => this.props.onDidFailToReceiveAdWithError &&
14 this.props.onDidFailToReceiveAdWithError(nativeEvent.error);
15 }
16 render() {
17 return (<View style={this.props.style}>
18 <ExpoBannerView style={this.state.style} adUnitID={this.props.adUnitID} bannerSize={this.props.bannerSize} testDeviceID={this.props.testDeviceID} onSizeChange={this._handleSizeChange} onAdViewDidReceiveAd={this.props.onAdViewDidReceiveAd} onDidFailToReceiveAdWithError={this._handleDidFailToReceiveAdWithError} onAdViewWillPresentScreen={this.props.onAdViewWillPresentScreen} onAdViewWillDismissScreen={this.props.onAdViewWillDismissScreen} onAdViewDidDismissScreen={this.props.onAdViewDidDismissScreen} onAdViewWillLeaveApplication={this.props.onAdViewWillLeaveApplication}/>
19 </View>);
20 }
21}
22AdMobBanner.propTypes = {
23 bannerSize: PropTypes.oneOf([
24 'banner',
25 'largeBanner',
26 'mediumRectangle',
27 'fullBanner',
28 'leaderboard',
29 'smartBannerPortrait',
30 'smartBannerLandscape',
31 ]),
32 adUnitID: PropTypes.string,
33 testDeviceID: PropTypes.string,
34 onAdViewDidReceiveAd: PropTypes.func,
35 onDidFailToReceiveAdWithError: PropTypes.func,
36 onAdViewWillPresentScreen: PropTypes.func,
37 onAdViewWillDismissScreen: PropTypes.func,
38 onAdViewDidDismissScreen: PropTypes.func,
39 onAdViewWillLeaveApplication: PropTypes.func,
40 ...ViewPropTypes,
41};
42AdMobBanner.defaultProps = { bannerSize: 'smartBannerPortrait' };
43const ExpoBannerView = requireNativeViewManager('ExpoAdsAdMobBannerView');
44//# sourceMappingURL=AdMobBanner.js.map
\No newline at end of file