From b43b2b48b1b41b27d3d3002c5840af1a55ee4ef0 Mon Sep 17 00:00:00 2001 From: ifsnow Date: Tue, 2 Feb 2021 09:07:56 +0900 Subject: [PATCH] fix(admob): improve defense logic to prevent multiple calls --- packages/admob/lib/ads/InterstitialAd.js | 4 ++-- packages/admob/lib/ads/MobileAd.js | 2 ++ packages/admob/lib/ads/RewardedAd.js | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/admob/lib/ads/InterstitialAd.js b/packages/admob/lib/ads/InterstitialAd.js index e5f8612d0b..7a84ab7d1f 100644 --- a/packages/admob/lib/ads/InterstitialAd.js +++ b/packages/admob/lib/ads/InterstitialAd.js @@ -45,11 +45,11 @@ export default class InterstitialAd extends MobileAd { load() { // Prevent multiple load calls - if (this._loaded) { + if (this._loaded || this._isLoadCalled) { return; } - this._loaded = true; + this._isLoadCalled = true; this._admob.native.interstitialLoad(this._requestId, this._adUnitId, this._requestOptions); } diff --git a/packages/admob/lib/ads/MobileAd.js b/packages/admob/lib/ads/MobileAd.js index a1f2ee5b52..4679444ad1 100644 --- a/packages/admob/lib/ads/MobileAd.js +++ b/packages/admob/lib/ads/MobileAd.js @@ -28,6 +28,7 @@ export default class MobileAd { this._requestOptions = requestOptions; this._loaded = false; + this._isLoadCalled = false; this._onAdEventHandler = null; this._nativeListener = admob.emitter.addListener( @@ -45,6 +46,7 @@ export default class MobileAd { if (type === AdEventType.CLOSED || type === RewardedAdEventType.CLOSED) { this._loaded = false; + this._isLoadCalled = false; } if (this._onAdEventHandler) { diff --git a/packages/admob/lib/ads/RewardedAd.js b/packages/admob/lib/ads/RewardedAd.js index 74100db777..8601ea8d72 100644 --- a/packages/admob/lib/ads/RewardedAd.js +++ b/packages/admob/lib/ads/RewardedAd.js @@ -45,11 +45,11 @@ export default class RewardedAd extends MobileAd { load() { // Prevent multiple load calls - if (this._loaded) { + if (this._loaded || this._isLoadCalled) { return; } - this._loaded = true; + this._isLoadCalled = true; this._admob.native.rewardedLoad(this._requestId, this._adUnitId, this._requestOptions); }