1 | import { requireNativeViewManager } from '@unimodules/core';
|
2 | import * as React from 'react';
|
3 | import { View } from 'react-native';
|
4 | let _hasWarnedAboutTestDeviceID = false;
|
5 | export 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 | const additionalRequestParams = {
|
18 | ...this.props.additionalRequestParams,
|
19 | };
|
20 | if (!this.props.servePersonalizedAds) {
|
21 | additionalRequestParams.npa = '1';
|
22 | }
|
23 | if (this.props.testDeviceID && !_hasWarnedAboutTestDeviceID) {
|
24 | console.warn('The `testDeviceID` prop of AdMobBanner is deprecated. Test device IDs are now set globally. Use AdMob.setTestDeviceIDAsync instead.');
|
25 | _hasWarnedAboutTestDeviceID = true;
|
26 | }
|
27 | return (React.createElement(View, { style: this.props.style },
|
28 | React.createElement(ExpoBannerView, { style: this.state.style, adUnitID: this.props.adUnitID, bannerSize: this.props.bannerSize, onSizeChange: this._handleSizeChange, additionalRequestParams: additionalRequestParams, onAdViewDidReceiveAd: this.props.onAdViewDidReceiveAd, onDidFailToReceiveAdWithError: this._handleDidFailToReceiveAdWithError, onAdViewWillPresentScreen: this.props.onAdViewWillPresentScreen, onAdViewWillDismissScreen: this.props.onAdViewWillDismissScreen, onAdViewDidDismissScreen: this.props.onAdViewDidDismissScreen, onAdViewWillLeaveApplication: this.props.onAdViewWillLeaveApplication })));
|
29 | }
|
30 | }
|
31 | AdMobBanner.defaultProps = { bannerSize: 'smartBannerPortrait' };
|
32 | const ExpoBannerView = requireNativeViewManager('ExpoAdsAdMobBannerView');
|
33 |
|
\ | No newline at end of file |