-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.ios.js
100 lines (92 loc) · 2.44 KB
/
index.ios.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
/************************
* Sample React Native App
* Created By Melih Mucuk
* https://github.com/melihmucuk/react-native-admob-sample
************************/
'use strict';
var BannerAdUnitId = 'Your Banner Ad Unit ID';
var InterstitialAdUnitId = 'Your Interstitial Ad Unit ID';
var React = require('react-native');
var AdMob = require('NativeModules').AdMobManager;
var {
AppRegistry,
StyleSheet,
Text,
View,
Component,
TouchableHighlight
} = React;
class AdMobSample extends Component{
constructor(props){
super(props);
AdMob.loadInterstitial(InterstitialAdUnitId);
}
render(){
return(
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native
{'\n'}
Admob Sample!
</Text>
<Text style={styles.instructions}>
To get started, edit BannerAdUnitId & InterstitialAdUnitId in index.ios.js
</Text>
<Text style={styles.instructions}>
Press Cmd+R to reload,{'\n'}
Cmd+D or shake for dev menu
</Text>
<TouchableHighlight style={styles.button} onPress={this.showInterstitial.bind(this)}>
<Text style={styles.buttonText}>
Show Interstitial Ad
</Text>
</TouchableHighlight>
<TouchableHighlight style={styles.button} onPress={this.showBanner.bind(this)}>
<Text style={styles.buttonText}>
Show Banner Ad
</Text>
</TouchableHighlight>
</View>
);
}
showInterstitial(){
AdMob.showInterstitial();
}
showBanner(){
AdMob.showBannerOnBottomOfTheView(BannerAdUnitId);
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
button: {
height: 50,
backgroundColor: '#48bbec',
borderRadius: 10,
alignSelf: 'stretch',
marginTop: 10,
justifyContent: 'center',
marginLeft: 10,
marginRight: 10
},
buttonText: {
fontSize: 22,
color: '#FFF',
alignSelf: 'center'
},
});
AppRegistry.registerComponent('AdMobSample', () => AdMobSample);