UNPKG

expo-ads-admob

Version:

Provides support for the Google AdMob SDK (https://www.google.com/admob/) for mobile advertising. This module is largely based of the react-native-admob (https://github.com/sbugert/react-native-admob) module, as the documentation and questions surrounding

74 lines 2.5 kB
import { EventEmitter, UnavailabilityError } from 'expo-modules-core'; import AdMobNativeModule from './ExpoAdsAdMobInterstitialManager'; const moduleName = 'AdMobInterstitial'; const eventNames = [ 'interstitialDidLoad', 'interstitialDidFailToLoad', 'interstitialDidOpen', 'interstitialDidClose', ]; const eventEmitter = new EventEmitter(AdMobNativeModule); const eventHandlers = {}; for (const eventName of eventNames) { eventHandlers[eventName] = new Map(); } export default { async setAdUnitID(id) { if (!AdMobNativeModule.setAdUnitID) { throw new UnavailabilityError(moduleName, 'setAdUnitID'); } await AdMobNativeModule.setAdUnitID(id); }, async requestAdAsync(options = {}) { if (!AdMobNativeModule.requestAd) { throw new UnavailabilityError(moduleName, 'requestAdAsync'); } const params = { ...options.additionalRequestParams, }; if (!options.servePersonalizedAds) { params.npa = '1'; } await AdMobNativeModule.requestAd(params); }, async showAdAsync() { if (!AdMobNativeModule.showAd) { throw new UnavailabilityError(moduleName, 'showAdAsync'); } await AdMobNativeModule.showAd(); }, async dismissAdAsync() { if (!AdMobNativeModule.dismissAd) { throw new UnavailabilityError(moduleName, 'dismissAdAsync'); } await AdMobNativeModule.dismissAd(); }, async getIsReadyAsync() { if (!AdMobNativeModule.getIsReady) { throw new UnavailabilityError(moduleName, 'getIsReadyAsync'); } return await AdMobNativeModule.getIsReady(); }, addEventListener(type, handler) { if (eventNames.includes(type)) { eventHandlers[type].set(handler, eventEmitter.addListener(type, handler)); } else { console.log(`Event with type ${type} does not exist.`); } }, removeEventListener(type, handler) { const eventSubscription = eventHandlers[type].get(handler); if (!eventHandlers[type].has(handler) || !eventSubscription) { return; } eventSubscription.remove(); eventHandlers[type].delete(handler); }, removeAllListeners() { for (const eventName of eventNames) { eventEmitter.removeAllListeners(eventName); } }, }; //# sourceMappingURL=AdMobInterstitial.js.map