-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
PublisherBanner.js
114 lines (103 loc) · 3.7 KB
/
PublisherBanner.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
// @flow
import React from 'react';
import PropTypes from 'prop-types';
import { requireNativeViewManager } from 'expo-core';
import { View, ViewPropTypes } from 'react-native';
type AppEvent = { [string]: Object };
export type PropsType = ViewPropTypes & {
/**
* 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
*/
bannerSize:
| 'banner'
| 'largeBanner'
| 'mediumRectangle'
| 'fullBanner'
| 'leaderboard'
| 'smartBannerPortrait'
| 'smartBannerLandscape',
/**
* AdMob ad unit ID
*/
adUnitID: ?string,
/**
* Test device ID
*/
testDeviceID: ?string,
/**
* AdMob iOS library events
*/
onAdViewDidReceiveAd?: () => void,
onDidFailToReceiveAdWithError?: string => void,
onAdViewWillPresentScreen?: () => void,
onAdViewWillDismissScreen?: () => void,
onAdViewDidDismissScreen?: () => void,
onAdViewWillLeaveApplication?: () => void,
onAdMobDispatchAppEvent?: AppEvent => void,
};
type StateType = {
style: { width?: number, height?: number },
};
export default class PublisherBanner extends React.Component<PropsType, StateType> {
static propTypes = {
bannerSize: PropTypes.oneOf([
'banner',
'largeBanner',
'mediumRectangle',
'fullBanner',
'leaderboard',
'smartBannerPortrait',
'smartBannerLandscape',
]),
adUnitID: PropTypes.string,
testDeviceID: PropTypes.string,
onAdViewDidReceiveAd: PropTypes.func,
onDidFailToReceiveAdWithError: PropTypes.func,
onAdViewWillPresentScreen: PropTypes.func,
onAdViewWillDismissScreen: PropTypes.func,
onAdViewDidDismissScreen: PropTypes.func,
onAdViewWillLeaveApplication: PropTypes.func,
onAdmobDispatchAppEvent: PropTypes.func,
...ViewPropTypes,
};
static defaultProps = { bannerSize: 'smartBannerPortrait' };
state = { style: {} };
_handleSizeChange = ({ nativeEvent }: { nativeEvent: { width: number, height: number } }) => {
const { height, width } = nativeEvent;
this.setState({ style: { width, height } });
};
_handleDidFailToReceiveAdWithError = ({ nativeEvent }: { nativeEvent: { error: string } }) =>
this.props.onDidFailToReceiveAdWithError &&
this.props.onDidFailToReceiveAdWithError(nativeEvent.error);
render() {
return (
<View style={this.props.style}>
<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}
onAdmobDispatchAppEvent={this.props.onAdMobDispatchAppEvent}
/>
</View>
);
}
}
const ExpoBannerView = requireNativeViewManager('ExpoAdsPublisherBannerView', PublisherBanner);