import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Platform,
TouchableHighlight,
Button,
ScrollView,
} from 'react-native';
import {
AdMobBanner,
AdMobRewarded,
AdMobInterstitial,
PublisherBanner,
} from 'react-native-admob';
const BannerExample = ({ style, title, children, ...props }) => (
{title}
{children}
);
const bannerWidths = [200, 250, 320];
export default class Example extends Component {
constructor() {
super();
this.state = {
fluidSizeIndex: 0,
};
}
componentDidMount() {
AdMobRewarded.setTestDevices([AdMobRewarded.simulatorId]);
AdMobRewarded.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
AdMobRewarded.addEventListener('rewardedVideoDidRewardUser',
(reward) => console.log('rewardedVideoDidRewardUser', reward)
);
AdMobRewarded.addEventListener('rewardedVideoDidLoad',
() => console.log('rewardedVideoDidLoad')
);
AdMobRewarded.addEventListener('rewardedVideoDidFailToLoad',
(error) => console.log('rewardedVideoDidFailToLoad', error)
);
AdMobRewarded.addEventListener('rewardedVideoDidOpen',
() => console.log('rewardedVideoDidOpen')
);
AdMobRewarded.addEventListener('rewardedVideoDidStartPlaying',
() => console.log('rewardedVideoDidStartPlaying')
);
AdMobRewarded.addEventListener('rewardedVideoDidClose',
() => {
console.log('rewardedVideoDidClose');
AdMobRewarded.requestAd().catch(error => console.log(error));
}
);
AdMobRewarded.addEventListener('rewardedVideoWillLeaveApplication',
() => console.log('rewardedVideoWillLeaveApplication')
);
AdMobRewarded.requestAd().catch(error => console.log(error));
AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/4411468910');
AdMobInterstitial.addEventListener('interstitialDidLoad',
() => console.log('interstitialDidLoad')
);
AdMobInterstitial.addEventListener('interstitialDidFailToLoad',
(error) => console.log('interstitialDidFailToLoad', error)
);
AdMobInterstitial.addEventListener('interstitialDidOpen',
() => console.log('interstitialDidOpen')
);
AdMobInterstitial.addEventListener('interstitialDidClose',
() => {
console.log('interstitialDidClose');
AdMobInterstitial.requestAd().catch(error => console.log(error));
}
);
AdMobInterstitial.addEventListener('interstitialWillLeaveApplication',
() => console.log('interstitialWillLeaveApplication')
);
AdMobInterstitial.requestAd().catch(error => console.log(error));
}
componentWillUnmount() {
AdMobRewarded.removeAllListeners();
AdMobInterstitial.removeAllListeners();
}
showRewarded() {
AdMobRewarded.showAd().catch(error => console.log(error));
}
showInterstitial() {
AdMobInterstitial.showAd().catch(error => console.log(error));
}
render() {
return (
(this._basicExample = el)}
/>
(this._adSizesExample = el)}
/>
{
if (event.name === 'color') {
this.setState({
appEventsExampleStyle: { backgroundColor: event.info },
});
}
}}
ref={el => (this._appEventsExample = el)}
/>
(this._appFluidAdSizeExample = el)}
style={{ flex: 1 }}
/>
);
}
}
const styles = StyleSheet.create({
container: {
marginTop: (Platform.OS === 'ios') ? 30 : 10,
},
example: {
paddingVertical: 10,
},
title: {
margin: 10,
fontSize: 20,
},
});
AppRegistry.registerComponent('Example', () => Example);