From 88695bb413efcf68c653c202740f1be809038fca Mon Sep 17 00:00:00 2001
From: kf <7kfpun@gmail.com>
Date: Sat, 8 Sep 2018 22:26:37 +0800
Subject: [PATCH] Add custom ad display
---
app/elements/ad-custom.js | 12 ++++++------
app/elements/admob.js | 32 +++++++++++++++++++++++++++++++-
2 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/app/elements/ad-custom.js b/app/elements/ad-custom.js
index 271734dd..307e38de 100644
--- a/app/elements/ad-custom.js
+++ b/app/elements/ad-custom.js
@@ -42,13 +42,13 @@ export default class AdCustom extends Component {
imageUrl: ad.imageUrl,
destinationUrl: ad.destinationUrl,
});
- }
- tracker.logEvent(`ad-custom-${this.props.client}-impression`, {
- client: this.props.client,
- url: ad.imageUrl,
- destinationUrl: ad.destinationUrl,
- });
+ tracker.logEvent(`ad-custom-${this.props.client}-impression`, {
+ client: this.props.client,
+ url: ad.imageUrl,
+ destinationUrl: ad.destinationUrl,
+ });
+ }
}
onOpenAd = (url) => {
diff --git a/app/elements/admob.js b/app/elements/admob.js
index 598c672a..9663e0d8 100644
--- a/app/elements/admob.js
+++ b/app/elements/admob.js
@@ -10,6 +10,7 @@ import firebase from 'react-native-firebase';
import AdCustom from './ad-custom';
import { config } from '../config';
+import { getAd } from '../utils/firebase-config';
const { AdRequest, Banner } = firebase.admob;
const request = new AdRequest();
@@ -52,18 +53,42 @@ export default class Admob extends Component {
state = {
isReceived: false,
isReceivedFailed: false,
+ isShowAdCustom: false,
};
componentDidMount() {
this.setIsReceivedFailedTimeout = setTimeout(() => {
- if (!this.state.isReceived) {
+ if (!this.state.isReceived && !this.state.isShowAdCustom) {
this.setState({ isReceivedFailed: true });
}
}, 30 * 1000);
+
+ this.checkShinbaAd();
+ this.checkShinbaAdInterval = setInterval(() => {
+ this.checkShinbaAd();
+ }, 60 * 1000);
}
componentWillUnmount() {
if (this.setIsReceivedFailedTimeout) clearTimeout(this.setIsReceivedFailedTimeout);
+ if (this.checkShinbaAdInterval) clearInterval(this.checkShinbaAdInterval);
+ }
+
+ async checkShinbaAd() {
+ const ad = await getAd('shinba');
+ const isShowAdCustom = ad.impressionRate > Math.random();
+ console.log('isShowAdCustom', isShowAdCustom);
+
+ if (isShowAdCustom && ad.impressionRate > 0) {
+ this.setState({
+ isShowAdCustom: true,
+ key: Math.random(),
+ });
+ } else {
+ this.setState({
+ isShowAdCustom: false,
+ });
+ }
}
render() {
@@ -71,6 +96,10 @@ export default class Admob extends Component {
return ;
}
+ if (this.state.isShowAdCustom) {
+ return ;
+ }
+
let height = 50;
if (this.props.bannerSize === 'LARGE_BANNER') {
height = 100;
@@ -89,6 +118,7 @@ export default class Admob extends Component {
}}
>