forked from sbugert/react-native-admob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ios.js
78 lines (69 loc) · 2.07 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
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Platform,
TouchableHighlight,
} from 'react-native';
import { AdMobRewarded } from 'react-native-admob';
export default class Example extends Component {
componentDidMount() {
AdMobRewarded.setTestDeviceID('EMULATOR');
AdMobRewarded.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
AdMobRewarded.addEventListener('rewardedVideoDidRewardUser',
(type, amount) => console.log('rewardedVideoDidRewardUser', type, amount)
);
AdMobRewarded.addEventListener('rewardedVideoDidLoad',
() => console.log('rewardedVideoDidLoad')
);
AdMobRewarded.addEventListener('rewardedVideoDidFailToLoad',
(error) => console.log('rewardedVideoDidFailToLoad', error)
);
AdMobRewarded.addEventListener('rewardedVideoDidOpen',
() => console.log('rewardedVideoDidOpen')
);
AdMobRewarded.addEventListener('rewardedVideoDidClose',
() => {
console.log('rewardedVideoDidClose');
AdMobRewarded.requestAd((error) => error && console.log(error));
}
);
AdMobRewarded.addEventListener('rewardedVideoWillLeaveApplication',
() => console.log('rewardedVideoWillLeaveApplication')
);
AdMobRewarded.requestAd((error) => error && console.log(error));
}
componentWillUnmount() {
AdMobRewarded.removeAllListeners();
}
showRewarded() {
AdMobRewarded.showAd((error) => error && console.log(error));
}
render() {
return (
<View style={styles.container}>
<View style={{ flex: 1 }}>
<TouchableHighlight>
<Text onPress={this.showRewarded} style={styles.button}>
Show Rewarded Video and preload next
</Text>
</TouchableHighlight>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
marginTop: (Platform.OS === 'ios') ? 30 : 10,
flex: 1,
alignItems: 'center',
},
button: {
color: '#333333',
marginBottom: 15,
},
});
AppRegistry.registerComponent('Example', () => Example);