diff --git a/lib/modules/admob/EventTypes.js b/lib/modules/admob/EventTypes.js index 1afdd1f0..510f62e3 100644 --- a/lib/modules/admob/EventTypes.js +++ b/lib/modules/admob/EventTypes.js @@ -1,3 +1,6 @@ +/** + * @flow + */ export default { onAdLoaded: 'onAdLoaded', onAdOpened: 'onAdOpened', diff --git a/lib/modules/admob/Interstitial.js b/lib/modules/admob/Interstitial.js index 74fcd5d2..a2f4c821 100644 --- a/lib/modules/admob/Interstitial.js +++ b/lib/modules/admob/Interstitial.js @@ -1,18 +1,20 @@ -import { NativeModules, Platform } from 'react-native'; +import { Platform } from 'react-native'; import { statics } from './'; import AdRequest from './AdRequest'; import { SharedEventEmitter } from '../../utils/events'; +import { getNativeModule } from '../../utils/native'; import { nativeToJSError } from '../../utils'; - -const FirebaseAdMob = NativeModules.RNFirebaseAdMob; +import type AdMob from './'; let subscriptions = []; export default class Interstitial { - constructor(admob: Object, adUnit: string) { + _admob: AdMob; + + constructor(admob: AdMob, adUnit: string) { // Interstitials on iOS require a new instance each time if (Platform.OS === 'ios') { - FirebaseAdMob.clearInterstitial(adUnit); + getNativeModule(admob).clearInterstitial(adUnit); } for (let i = 0, len = subscriptions.length; i < len; i++) { @@ -20,7 +22,7 @@ export default class Interstitial { } subscriptions = []; - this.admob = admob; + this._admob = admob; this.adUnit = adUnit; this.loaded = false; SharedEventEmitter.removeAllListeners(`interstitial_${adUnit}`); @@ -67,7 +69,10 @@ export default class Interstitial { adRequest = new AdRequest().addTestDevice().build(); } - return FirebaseAdMob.interstitialLoadAd(this.adUnit, adRequest); + return getNativeModule(this._admob).interstitialLoadAd( + this.adUnit, + adRequest + ); } /** @@ -84,7 +89,7 @@ export default class Interstitial { */ show() { if (this.loaded) { - FirebaseAdMob.interstitialShowAd(this.adUnit); + getNativeModule(this._admob).interstitialShowAd(this.adUnit); } } diff --git a/lib/modules/admob/RewardedVideo.js b/lib/modules/admob/RewardedVideo.js index 601e5a78..f5f6e0db 100644 --- a/lib/modules/admob/RewardedVideo.js +++ b/lib/modules/admob/RewardedVideo.js @@ -1,21 +1,22 @@ -import { NativeModules } from 'react-native'; import { statics } from './'; import AdRequest from './AdRequest'; import { SharedEventEmitter } from '../../utils/events'; +import { getNativeModule } from '../../utils/native'; import { nativeToJSError } from '../../utils'; - -const FirebaseAdMob = NativeModules.RNFirebaseAdMob; +import type AdMob from './'; let subscriptions = []; export default class RewardedVideo { - constructor(admob: Object, adUnit: string) { + _admob: AdMob; + + constructor(admob: AdMob, adUnit: string) { for (let i = 0, len = subscriptions.length; i < len; i++) { subscriptions[i].remove(); } subscriptions = []; - this.admob = admob; + this._admob = admob; this.adUnit = adUnit; this.loaded = false; SharedEventEmitter.removeAllListeners(`rewarded_video_${adUnit}`); @@ -62,7 +63,10 @@ export default class RewardedVideo { adRequest = new AdRequest().addTestDevice().build(); } - return FirebaseAdMob.rewardedVideoLoadAd(this.adUnit, adRequest); + return getNativeModule(this._admob).rewardedVideoLoadAd( + this.adUnit, + adRequest + ); } /** @@ -79,7 +83,7 @@ export default class RewardedVideo { */ show() { if (this.loaded) { - FirebaseAdMob.rewardedVideoShowAd(this.adUnit); + getNativeModule(this._admob).rewardedVideoShowAd(this.adUnit); } } diff --git a/lib/modules/admob/index.js b/lib/modules/admob/index.js index 3a43d503..691a35bb 100644 --- a/lib/modules/admob/index.js +++ b/lib/modules/admob/index.js @@ -61,7 +61,7 @@ export default class AdMob extends ModuleBase { const { adUnit } = event; const jsEventType = `interstitial_${adUnit}`; - if (!SharedEventEmitter.hasListeners(jsEventType)) { + if (SharedEventEmitter.listeners(jsEventType).length === 0) { // TODO } @@ -72,7 +72,7 @@ export default class AdMob extends ModuleBase { const { adUnit } = event; const jsEventType = `rewarded_video_${adUnit}`; - if (!SharedEventEmitter.hasListeners(jsEventType)) { + if (SharedEventEmitter.listeners(jsEventType).length === 0) { // TODO }