-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathApp.js
81 lines (75 loc) · 2.21 KB
/
App.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
import {
AdMobBanner,
AdMobInterstitial,
AdMobRewarded,
PublisherBanner,
} from 'expo'
import React, { Component } from 'react'
import { SafeAreaView, ScrollView } from 'react-native'
import { Button, Text } from 'react-native-elements'
console.disableYellowBox = true
AdMobInterstitial.setAdUnitID(INTERSTITIAL_ID)
AdMobInterstitial.setTestDeviceID('EMULATOR')
AdMobRewarded.setAdUnitID(REWARDED_ID)
AdMobRewarded.setTestDeviceID('EMULATOR')
class App extends Component {
state = {
disableInterstitialBtn: false,
disableRewardedBtn: false,
}
_openInterstitial = async () => {
try {
this.setState({ disableInterstitialBtn: true })
await AdMobInterstitial.requestAdAsync()
await AdMobInterstitial.showAdAsync()
} catch (error) {
console.error(error)
} finally {
this.setState({ disableInterstitialBtn: false })
}
}
_openRewarded = async () => {
try {
this.setState({ disableRewardedBtn: true })
await AdMobRewarded.requestAdAsync()
await AdMobRewarded.showAdAsync()
} catch (error) {
console.error(error)
} finally {
this.setState({ disableRewardedBtn: false })
}
}
render() {
const { disableInterstitialBtn, disableRewardedBtn } = this.state
return (
<ScrollView>
<SafeAreaView style={{ margin: 20 }}>
<Text h2>GOOGLE ADMOB DEMO</Text>
<Text>
Set Ad Unit Id, Interstitial Id & Rewarded Id only on the top level
component once.
</Text>
<Text h4>Banner Ad</Text>
<AdMobBanner bannerSize="mediumRectangle" adUnitID={BANNER_ID} />
<Text h4>Publisher Banner</Text>
<PublisherBanner bannerSize="banner" adUnitID={BANNER_ID} />
<Text h4>Interstitial Ad</Text>
<Button
title="Open"
type="outline"
disabled={disableInterstitialBtn}
onPress={this._openInterstitial}
/>
<Text h4>Rewarded Ad</Text>
<Button
title="Open"
type="outline"
disabled={disableRewardedBtn}
onPress={this._openRewarded}
/>
</SafeAreaView>
</ScrollView>
)
}
}
export default App