forked from sbugert/react-native-admob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNAdMobNative.js
104 lines (89 loc) · 2.53 KB
/
RNAdMobNative.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
import { arrayOf, func, string, number } from 'prop-types';
import React, { Component } from 'react';
import {
findNodeHandle,
requireNativeComponent,
UIManager,
ViewPropTypes,
} from 'react-native';
import { createErrorFromErrorData } from './utils';
class RNAdMobNative extends Component {
constructor() {
super();
this.handleAdFailedToLoad = this.handleAdFailedToLoad.bind(this);
this.state = {
style: {},
};
}
componentDidMount() {
const { adUnitID, navBarHeight } = this.props;
console.debug("NativeAd dd",adUnitID )
if (adUnitID) {
return this.loadNativeAd(adUnitID , navBarHeight);
}
console.warn('Attempted to load native ad without ad unit id');
}
loadNativeAd(adUnitId, navBarHeight) {
UIManager.dispatchViewManagerCommand(
findNodeHandle(this._nativeView),
UIManager.getViewManagerConfig('RNGADNativeView').Commands.loadNativeAd,
[adUnitId, navBarHeight]
);
}
handleAdFailedToLoad(event) {
if (this.props.onAdFailedToLoad) {
this.props.onAdFailedToLoad(
createErrorFromErrorData(event.nativeEvent.error)
);
}
}
setRef = (el) => (this._nativeView = el);
render() {
return (
<RNGADNativeView
{...this.props}
style={[this.props.style, this.state.style]}
onAdFailedToLoad={this.handleAdFailedToLoad}
ref={this.setRef}
/>
);
}
}
RNAdMobNative.simulatorId = 'SIMULATOR';
RNAdMobNative.propTypes = {
...ViewPropTypes,
/**
* Google AdMob templates are being used to display native ads
* (https://developers.google.com/admob/ios/native/templates)
* Two sizes are available; medium and small
*
* small is default
*/
adSize: string,
navBarHeight: string,
/**
* AdMob ad unit ID
*/
adUnitID: string,
/**
* Array of test devices. Use AdMobBanner.simulatorId for the simulator
*/
testDevices: arrayOf(string),
/**
* GADUnifiedNativeAdDelegate lifecycle methods
* https://developers.google.com/ad-manager/mobile-ads-sdk/ios/api/reference/Protocols/GADUnifiedNativeAdDelegate
*/
onAdOpened: func,
onAdClosed: func,
onAdLeftApplication: func,
didRecordImpression: func,
didRecordClick: func,
/**
* GADUnifiedNativeAdLoaderDelegate
* https://developers.google.com/ad-manager/mobile-ads-sdk/ios/api/reference/Protocols/GADUnifiedNativeAdLoaderDelegate
*/
onAdLoaded: func,
onAdFailedToLoad: func,
};
const RNGADNativeView = requireNativeComponent('RNGADNativeView', RNAdMobNative);
export default RNAdMobNative;