react-native-google-mobile-ads 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +32 -0
- package/README.md +65 -0
- package/RNGoogleMobileAds.podspec +42 -0
- package/__tests__/consent.test.ts +25 -0
- package/__tests__/googleMobileAds.test.ts +63 -0
- package/__tests__/interstitial.test.ts +53 -0
- package/__tests__/requestOptions.test.tsx +4 -0
- package/__tests__/rewarded.test.tsx +4 -0
- package/__tests__/showOptions.test.tsx +4 -0
- package/android/.editorconfig +10 -0
- package/android/app-json.gradle +69 -0
- package/android/build.gradle +98 -0
- package/android/lint.xml +5 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +17 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeAppModule.java +169 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.java +161 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java +209 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java +256 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsConsentModule.java +226 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsEvent.java +72 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.java +159 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +143 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.java +48 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.java +177 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/RCTConvert.java +111 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeApp.java +34 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeEvent.java +41 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeEventEmitter.java +150 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeInitProvider.java +77 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeJSON.java +107 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeMeta.java +92 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeModule.java +96 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativePreferences.java +86 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/SharedUtils.java +427 -0
- package/android/src/main/java/io/invertase/googlemobileads/common/TaskExecutorService.java +124 -0
- package/android/src/main/java/io/invertase/googlemobileads/interfaces/ContextProvider.java +30 -0
- package/android/src/main/java/io/invertase/googlemobileads/interfaces/NativeError.java +28 -0
- package/android/src/main/java/io/invertase/googlemobileads/interfaces/NativeEvent.java +26 -0
- package/babel.config.js +18 -0
- package/docs/displaying-ads.mdx +319 -0
- package/docs/european-user-consent.mdx +258 -0
- package/docs/img/logo_admob_192px.svg +19 -0
- package/docs/index.mdx +168 -0
- package/docs.json +9 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.h +29 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m +98 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.h +23 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.m +153 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h +60 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +201 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.h +26 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.m +179 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.h +32 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.m +57 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.h +25 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m +124 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.h +24 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.m +104 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.h +25 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.m +173 -0
- package/ios/RNGoogleMobileAds/common/RNAppModule.h +24 -0
- package/ios/RNGoogleMobileAds/common/RNAppModule.m +158 -0
- package/ios/RNGoogleMobileAds/common/RNJSON.h +34 -0
- package/ios/RNGoogleMobileAds/common/RNJSON.m +93 -0
- package/ios/RNGoogleMobileAds/common/RNMeta.h +30 -0
- package/ios/RNGoogleMobileAds/common/RNMeta.m +61 -0
- package/ios/RNGoogleMobileAds/common/RNPreferences.h +44 -0
- package/ios/RNGoogleMobileAds/common/RNPreferences.m +94 -0
- package/ios/RNGoogleMobileAds/common/RNRCTEventEmitter.h +73 -0
- package/ios/RNGoogleMobileAds/common/RNRCTEventEmitter.m +150 -0
- package/ios/RNGoogleMobileAds/common/RNSharedUtils.h +48 -0
- package/ios/RNGoogleMobileAds/common/RNSharedUtils.m +56 -0
- package/ios/RNGoogleMobileAds.xcodeproj/project.pbxproj +377 -0
- package/ios/RNGoogleMobileAds.xcodeproj/xcshareddata/IDETemplateMacros.plist +24 -0
- package/ios_config.sh +140 -0
- package/jest.config.js +6 -0
- package/jest.setup.ts +29 -0
- package/lib/commonjs/AdEventType.js +34 -0
- package/lib/commonjs/AdEventType.js.map +1 -0
- package/lib/commonjs/AdsConsent.js +160 -0
- package/lib/commonjs/AdsConsent.js.map +1 -0
- package/lib/commonjs/AdsConsentDebugGeography.js +38 -0
- package/lib/commonjs/AdsConsentDebugGeography.js.map +1 -0
- package/lib/commonjs/AdsConsentStatus.js +36 -0
- package/lib/commonjs/AdsConsentStatus.js.map +1 -0
- package/lib/commonjs/BannerAdSize.js +38 -0
- package/lib/commonjs/BannerAdSize.js.map +1 -0
- package/lib/commonjs/MaxAdContentRating.js +33 -0
- package/lib/commonjs/MaxAdContentRating.js.map +1 -0
- package/lib/commonjs/MobileAds.js +67 -0
- package/lib/commonjs/MobileAds.js.map +1 -0
- package/lib/commonjs/RewardedAdEventType.js +31 -0
- package/lib/commonjs/RewardedAdEventType.js.map +1 -0
- package/lib/commonjs/TestIds.js +47 -0
- package/lib/commonjs/TestIds.js.map +1 -0
- package/lib/commonjs/ads/AppOpenAd.js +96 -0
- package/lib/commonjs/ads/AppOpenAd.js.map +1 -0
- package/lib/commonjs/ads/BannerAd.js +128 -0
- package/lib/commonjs/ads/BannerAd.js.map +1 -0
- package/lib/commonjs/ads/InterstitialAd.js +163 -0
- package/lib/commonjs/ads/InterstitialAd.js.map +1 -0
- package/lib/commonjs/ads/MobileAd.js +90 -0
- package/lib/commonjs/ads/MobileAd.js.map +1 -0
- package/lib/commonjs/ads/RewardedAd.js +169 -0
- package/lib/commonjs/ads/RewardedAd.js.map +1 -0
- package/lib/commonjs/common/Base64.js +121 -0
- package/lib/commonjs/common/Base64.js.map +1 -0
- package/lib/commonjs/common/MutatableParams.js +46 -0
- package/lib/commonjs/common/MutatableParams.js.map +1 -0
- package/lib/commonjs/common/ReferenceBase.js +59 -0
- package/lib/commonjs/common/ReferenceBase.js.map +1 -0
- package/lib/commonjs/common/deeps.js +101 -0
- package/lib/commonjs/common/deeps.js.map +1 -0
- package/lib/commonjs/common/id.js +82 -0
- package/lib/commonjs/common/id.js.map +1 -0
- package/lib/commonjs/common/index.js +212 -0
- package/lib/commonjs/common/index.js.map +1 -0
- package/lib/commonjs/common/path.js +144 -0
- package/lib/commonjs/common/path.js.map +1 -0
- package/lib/commonjs/common/promise.js +70 -0
- package/lib/commonjs/common/promise.js.map +1 -0
- package/lib/commonjs/common/serialize.js +52 -0
- package/lib/commonjs/common/serialize.js.map +1 -0
- package/lib/commonjs/common/validate.js +239 -0
- package/lib/commonjs/common/validate.js.map +1 -0
- package/lib/commonjs/declarations.d.js +2 -0
- package/lib/commonjs/declarations.d.js.map +1 -0
- package/lib/commonjs/index.js +143 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/internal/GoogleMobileAdsNativeEventEmitter.js +76 -0
- package/lib/commonjs/internal/GoogleMobileAdsNativeEventEmitter.js.map +1 -0
- package/lib/commonjs/internal/Module.js +60 -0
- package/lib/commonjs/internal/Module.js.map +1 -0
- package/lib/commonjs/internal/NativeError.js +70 -0
- package/lib/commonjs/internal/NativeError.js.map +1 -0
- package/lib/commonjs/internal/SharedEventEmitter.js +31 -0
- package/lib/commonjs/internal/SharedEventEmitter.js.map +1 -0
- package/lib/commonjs/internal/constants.js +30 -0
- package/lib/commonjs/internal/constants.js.map +1 -0
- package/lib/commonjs/internal/index.js +49 -0
- package/lib/commonjs/internal/index.js.map +1 -0
- package/lib/commonjs/internal/registry/nativeModule.js +231 -0
- package/lib/commonjs/internal/registry/nativeModule.js.map +1 -0
- package/lib/commonjs/types/AdEventListener.js +6 -0
- package/lib/commonjs/types/AdEventListener.js.map +1 -0
- package/lib/commonjs/types/AdShowOptions.js +2 -0
- package/lib/commonjs/types/AdShowOptions.js.map +1 -0
- package/lib/commonjs/types/AdapterStatus.js +18 -0
- package/lib/commonjs/types/AdapterStatus.js.map +1 -0
- package/lib/commonjs/types/AdsConsent.interface.js +6 -0
- package/lib/commonjs/types/AdsConsent.interface.js.map +1 -0
- package/lib/commonjs/types/BannerAdProps.js +6 -0
- package/lib/commonjs/types/BannerAdProps.js.map +1 -0
- package/lib/commonjs/types/GoogleMobileAdsNativeModule.js +6 -0
- package/lib/commonjs/types/GoogleMobileAdsNativeModule.js.map +1 -0
- package/lib/commonjs/types/MobileAd.interface.js +6 -0
- package/lib/commonjs/types/MobileAd.interface.js.map +1 -0
- package/lib/commonjs/types/MobileAdsModule.interface.js +6 -0
- package/lib/commonjs/types/MobileAdsModule.interface.js.map +1 -0
- package/lib/commonjs/types/Module.interface.js +2 -0
- package/lib/commonjs/types/Module.interface.js.map +1 -0
- package/lib/commonjs/types/RequestConfiguration.js +6 -0
- package/lib/commonjs/types/RequestConfiguration.js.map +1 -0
- package/lib/commonjs/types/RequestOptions.js +2 -0
- package/lib/commonjs/types/RequestOptions.js.map +1 -0
- package/lib/commonjs/types/RewardedAdReward.js +2 -0
- package/lib/commonjs/types/RewardedAdReward.js.map +1 -0
- package/lib/commonjs/validateAdRequestConfiguration.js +69 -0
- package/lib/commonjs/validateAdRequestConfiguration.js.map +1 -0
- package/lib/commonjs/validateAdRequestOptions.js +158 -0
- package/lib/commonjs/validateAdRequestOptions.js.map +1 -0
- package/lib/commonjs/validateAdShowOptions.js +47 -0
- package/lib/commonjs/validateAdShowOptions.js.map +1 -0
- package/lib/commonjs/version.js +10 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/AdEventType.js +26 -0
- package/lib/module/AdEventType.js.map +1 -0
- package/lib/module/AdsConsent.js +148 -0
- package/lib/module/AdsConsent.js.map +1 -0
- package/lib/module/AdsConsentDebugGeography.js +30 -0
- package/lib/module/AdsConsentDebugGeography.js.map +1 -0
- package/lib/module/AdsConsentStatus.js +28 -0
- package/lib/module/AdsConsentStatus.js.map +1 -0
- package/lib/module/BannerAdSize.js +30 -0
- package/lib/module/BannerAdSize.js.map +1 -0
- package/lib/module/MaxAdContentRating.js +25 -0
- package/lib/module/MaxAdContentRating.js.map +1 -0
- package/lib/module/MobileAds.js +53 -0
- package/lib/module/MobileAds.js.map +1 -0
- package/lib/module/RewardedAdEventType.js +23 -0
- package/lib/module/RewardedAdEventType.js.map +1 -0
- package/lib/module/TestIds.js +38 -0
- package/lib/module/TestIds.js.map +1 -0
- package/lib/module/ads/AppOpenAd.js +81 -0
- package/lib/module/ads/AppOpenAd.js.map +1 -0
- package/lib/module/ads/BannerAd.js +108 -0
- package/lib/module/ads/BannerAd.js.map +1 -0
- package/lib/module/ads/InterstitialAd.js +149 -0
- package/lib/module/ads/InterstitialAd.js.map +1 -0
- package/lib/module/ads/MobileAd.js +94 -0
- package/lib/module/ads/MobileAd.js.map +1 -0
- package/lib/module/ads/RewardedAd.js +155 -0
- package/lib/module/ads/RewardedAd.js.map +1 -0
- package/lib/module/common/Base64.js +106 -0
- package/lib/module/common/Base64.js.map +1 -0
- package/lib/module/common/MutatableParams.js +52 -0
- package/lib/module/common/MutatableParams.js.map +1 -0
- package/lib/module/common/ReferenceBase.js +50 -0
- package/lib/module/common/ReferenceBase.js.map +1 -0
- package/lib/module/common/deeps.js +91 -0
- package/lib/module/common/deeps.js.map +1 -0
- package/lib/module/common/id.js +74 -0
- package/lib/module/common/id.js.map +1 -0
- package/lib/module/common/index.js +109 -0
- package/lib/module/common/index.js.map +1 -0
- package/lib/module/common/path.js +120 -0
- package/lib/module/common/path.js.map +1 -0
- package/lib/module/common/promise.js +60 -0
- package/lib/module/common/promise.js.map +1 -0
- package/lib/module/common/serialize.js +41 -0
- package/lib/module/common/serialize.js.map +1 -0
- package/lib/module/common/validate.js +197 -0
- package/lib/module/common/validate.js.map +1 -0
- package/lib/module/declarations.d.js +2 -0
- package/lib/module/declarations.d.js.map +1 -0
- package/lib/module/index.js +33 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/internal/GoogleMobileAdsNativeEventEmitter.js +83 -0
- package/lib/module/internal/GoogleMobileAdsNativeEventEmitter.js.map +1 -0
- package/lib/module/internal/Module.js +64 -0
- package/lib/module/internal/Module.js.map +1 -0
- package/lib/module/internal/NativeError.js +61 -0
- package/lib/module/internal/NativeError.js.map +1 -0
- package/lib/module/internal/SharedEventEmitter.js +20 -0
- package/lib/module/internal/SharedEventEmitter.js.map +1 -0
- package/lib/module/internal/constants.js +20 -0
- package/lib/module/internal/constants.js.map +1 -0
- package/lib/module/internal/index.js +21 -0
- package/lib/module/internal/index.js.map +1 -0
- package/lib/module/internal/registry/nativeModule.js +215 -0
- package/lib/module/internal/registry/nativeModule.js.map +1 -0
- package/lib/module/types/AdEventListener.js +2 -0
- package/lib/module/types/AdEventListener.js.map +1 -0
- package/lib/module/types/AdShowOptions.js +2 -0
- package/lib/module/types/AdShowOptions.js.map +1 -0
- package/lib/module/types/AdapterStatus.js +10 -0
- package/lib/module/types/AdapterStatus.js.map +1 -0
- package/lib/module/types/AdsConsent.interface.js +2 -0
- package/lib/module/types/AdsConsent.interface.js.map +1 -0
- package/lib/module/types/BannerAdProps.js +2 -0
- package/lib/module/types/BannerAdProps.js.map +1 -0
- package/lib/module/types/GoogleMobileAdsNativeModule.js +2 -0
- package/lib/module/types/GoogleMobileAdsNativeModule.js.map +1 -0
- package/lib/module/types/MobileAd.interface.js +2 -0
- package/lib/module/types/MobileAd.interface.js.map +1 -0
- package/lib/module/types/MobileAdsModule.interface.js +2 -0
- package/lib/module/types/MobileAdsModule.interface.js.map +1 -0
- package/lib/module/types/Module.interface.js +2 -0
- package/lib/module/types/Module.interface.js.map +1 -0
- package/lib/module/types/RequestConfiguration.js +2 -0
- package/lib/module/types/RequestConfiguration.js.map +1 -0
- package/lib/module/types/RequestOptions.js +2 -0
- package/lib/module/types/RequestOptions.js.map +1 -0
- package/lib/module/types/RewardedAdReward.js +2 -0
- package/lib/module/types/RewardedAdReward.js.map +1 -0
- package/lib/module/validateAdRequestConfiguration.js +60 -0
- package/lib/module/validateAdRequestConfiguration.js.map +1 -0
- package/lib/module/validateAdRequestOptions.js +150 -0
- package/lib/module/validateAdRequestOptions.js.map +1 -0
- package/lib/module/validateAdShowOptions.js +39 -0
- package/lib/module/validateAdShowOptions.js.map +1 -0
- package/lib/module/version.js +3 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/AdEventType.d.ts +47 -0
- package/lib/typescript/AdsConsent.d.ts +2 -0
- package/lib/typescript/AdsConsentDebugGeography.d.ts +19 -0
- package/lib/typescript/AdsConsentStatus.d.ts +17 -0
- package/lib/typescript/BannerAdSize.d.ts +34 -0
- package/lib/typescript/MaxAdContentRating.d.ts +18 -0
- package/lib/typescript/MobileAds.d.ts +11 -0
- package/lib/typescript/RewardedAdEventType.d.ts +46 -0
- package/lib/typescript/TestIds.d.ts +6 -0
- package/lib/typescript/ads/AppOpenAd.d.ts +11 -0
- package/lib/typescript/ads/BannerAd.d.ts +3 -0
- package/lib/typescript/ads/InterstitialAd.d.ts +78 -0
- package/lib/typescript/ads/MobileAd.d.ts +32 -0
- package/lib/typescript/ads/RewardedAd.d.ts +84 -0
- package/lib/typescript/common/Base64.d.ts +14 -0
- package/lib/typescript/common/MutatableParams.d.ts +9 -0
- package/lib/typescript/common/ReferenceBase.d.ts +11 -0
- package/lib/typescript/common/deeps.d.ts +18 -0
- package/lib/typescript/common/id.d.ts +11 -0
- package/lib/typescript/common/index.d.ts +28 -0
- package/lib/typescript/common/path.d.ts +43 -0
- package/lib/typescript/common/promise.d.ts +13 -0
- package/lib/typescript/common/serialize.d.ts +5 -0
- package/lib/typescript/common/validate.d.ts +90 -0
- package/lib/typescript/index.d.ts +14 -0
- package/lib/typescript/internal/GoogleMobileAdsNativeEventEmitter.d.ts +12 -0
- package/lib/typescript/internal/Module.d.ts +13 -0
- package/lib/typescript/internal/NativeError.d.ts +26 -0
- package/lib/typescript/internal/SharedEventEmitter.d.ts +2 -0
- package/lib/typescript/internal/constants.d.ts +3 -0
- package/lib/typescript/internal/index.d.ts +4 -0
- package/lib/typescript/internal/registry/nativeModule.d.ts +15 -0
- package/lib/typescript/types/AdEventListener.d.ts +11 -0
- package/lib/typescript/types/AdShowOptions.d.ts +12 -0
- package/lib/typescript/types/AdapterStatus.d.ts +18 -0
- package/lib/typescript/types/AdsConsent.interface.d.ts +286 -0
- package/lib/typescript/types/BannerAdProps.d.ts +66 -0
- package/lib/typescript/types/GoogleMobileAdsNativeModule.d.ts +14 -0
- package/lib/typescript/types/MobileAd.interface.d.ts +64 -0
- package/lib/typescript/types/MobileAdsModule.interface.d.ts +38 -0
- package/lib/typescript/types/Module.interface.d.ts +14 -0
- package/lib/typescript/types/RequestConfiguration.d.ts +36 -0
- package/lib/typescript/types/RequestOptions.d.ts +106 -0
- package/lib/typescript/types/RewardedAdReward.d.ts +13 -0
- package/lib/typescript/validateAdRequestConfiguration.d.ts +2 -0
- package/lib/typescript/validateAdRequestOptions.d.ts +2 -0
- package/lib/typescript/validateAdShowOptions.d.ts +2 -0
- package/lib/typescript/version.d.ts +1 -0
- package/package.json +143 -0
- package/react-native.config.js +19 -0
- package/src/AdEventType.ts +68 -0
- package/src/AdsConsent.ts +191 -0
- package/src/AdsConsentDebugGeography.ts +38 -0
- package/src/AdsConsentStatus.ts +36 -0
- package/src/BannerAdSize.ts +59 -0
- package/src/MaxAdContentRating.ts +38 -0
- package/src/MobileAds.ts +84 -0
- package/src/RewardedAdEventType.ts +64 -0
- package/src/TestIds.ts +39 -0
- package/src/ads/AppOpenAd.ts +85 -0
- package/src/ads/BannerAd.tsx +126 -0
- package/src/ads/InterstitialAd.ts +156 -0
- package/src/ads/MobileAd.ts +101 -0
- package/src/ads/RewardedAd.ts +161 -0
- package/src/common/Base64.ts +114 -0
- package/src/common/MutatableParams.ts +50 -0
- package/src/common/ReferenceBase.ts +45 -0
- package/src/common/deeps.ts +88 -0
- package/src/common/id.ts +74 -0
- package/src/common/index.ts +103 -0
- package/src/common/path.ts +114 -0
- package/src/common/promise.ts +66 -0
- package/src/common/serialize.ts +43 -0
- package/src/common/validate.ts +205 -0
- package/src/declarations.d.ts +3 -0
- package/src/index.ts +35 -0
- package/src/internal/GoogleMobileAdsNativeEventEmitter.ts +81 -0
- package/src/internal/Module.ts +58 -0
- package/src/internal/NativeError.ts +56 -0
- package/src/internal/SharedEventEmitter.ts +22 -0
- package/src/internal/constants.ts +43 -0
- package/src/internal/index.ts +21 -0
- package/src/internal/registry/nativeModule.ts +226 -0
- package/src/types/AdEventListener.ts +16 -0
- package/src/types/AdShowOptions.ts +12 -0
- package/src/types/AdapterStatus.ts +20 -0
- package/src/types/AdsConsent.interface.ts +306 -0
- package/src/types/BannerAdProps.ts +73 -0
- package/src/types/GoogleMobileAdsNativeModule.ts +15 -0
- package/src/types/MobileAd.interface.ts +69 -0
- package/src/types/MobileAdsModule.interface.ts +43 -0
- package/src/types/Module.interface.ts +16 -0
- package/src/types/RequestConfiguration.ts +40 -0
- package/src/types/RequestOptions.ts +113 -0
- package/src/types/RewardedAdReward.ts +14 -0
- package/src/validateAdRequestConfiguration.ts +71 -0
- package/src/validateAdRequestOptions.ts +168 -0
- package/src/validateAdShowOptions.ts +41 -0
- package/src/version.ts +2 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export enum RewardedAdEventType {
|
|
19
|
+
/**
|
|
20
|
+
* An event fired when a rewarded ad has loaded.
|
|
21
|
+
*
|
|
22
|
+
* This type differs from `AdEventType.LOADED` as when a rewarded ad is loaded,
|
|
23
|
+
* an additional data payload is provided to the event handler containing the ad reward
|
|
24
|
+
* (assuming the user earns the reward).
|
|
25
|
+
*
|
|
26
|
+
* The reward contains a `type` and `amount`.
|
|
27
|
+
*
|
|
28
|
+
* #### Example
|
|
29
|
+
*
|
|
30
|
+
* ```js
|
|
31
|
+
* import { RewardedAdEventType } from 'react-native-google-mobile-ads';
|
|
32
|
+
*
|
|
33
|
+
* rewardedAd.onAdEvent((type, error, data) => {
|
|
34
|
+
* if (type === RewardedAdEventType.LOADED) {
|
|
35
|
+
* console.log(`Rewarded Ad loaded with ${data.amount} ${data.type} as reward`);
|
|
36
|
+
* // E.g. "Rewarded Ad loaded with 50 coins as reward"
|
|
37
|
+
* rewardedAd.show();
|
|
38
|
+
* }
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
LOADED = 'rewarded_loaded',
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* An event fired when the user earned the reward for the video. If the user does not earn a reward,
|
|
46
|
+
* the `AdEventType.CLOSED` event will be fired with no rewarded event.
|
|
47
|
+
*
|
|
48
|
+
* The reward contains a `type` and `amount`.
|
|
49
|
+
*
|
|
50
|
+
* #### Example
|
|
51
|
+
*
|
|
52
|
+
* ```js
|
|
53
|
+
* import { RewardedAdEventType } from 'react-native-google-mobile-ads';
|
|
54
|
+
*
|
|
55
|
+
* rewardedAd.onAdEvent((type, error, data) => {
|
|
56
|
+
* if (type === RewardedAdEventType.EARNED_REWARD) {
|
|
57
|
+
* console.log(`User earned ${data.amount} ${data.type}`);
|
|
58
|
+
* // E.g. "User earned 50 coins"
|
|
59
|
+
* }
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
EARNED_REWARD = 'rewarded_earned_reward',
|
|
64
|
+
}
|
package/src/TestIds.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { Platform } from 'react-native';
|
|
19
|
+
|
|
20
|
+
export const TestIds = {
|
|
21
|
+
APP_OPEN: '',
|
|
22
|
+
BANNER: '',
|
|
23
|
+
INTERSTITIAL: '',
|
|
24
|
+
REWARDED: '',
|
|
25
|
+
...Platform.select({
|
|
26
|
+
android: {
|
|
27
|
+
APP_OPEN: 'ca-app-pub-3940256099942544/3419835294',
|
|
28
|
+
BANNER: 'ca-app-pub-3940256099942544/6300978111',
|
|
29
|
+
INTERSTITIAL: 'ca-app-pub-3940256099942544/1033173712',
|
|
30
|
+
REWARDED: 'ca-app-pub-3940256099942544/5224354917',
|
|
31
|
+
},
|
|
32
|
+
ios: {
|
|
33
|
+
APP_OPEN: 'ca-app-pub-3940256099942544/5662855259',
|
|
34
|
+
BANNER: 'ca-app-pub-3940256099942544/2934735716',
|
|
35
|
+
INTERSTITIAL: 'ca-app-pub-3940256099942544/4411468910',
|
|
36
|
+
REWARDED: 'ca-app-pub-3940256099942544/1712485313',
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { isFunction, isString } from '../common';
|
|
19
|
+
import { MobileAds } from '../MobileAds';
|
|
20
|
+
import { validateAdRequestOptions } from '../validateAdRequestOptions';
|
|
21
|
+
import { validateAdShowOptions } from '../validateAdShowOptions';
|
|
22
|
+
import { MobileAd } from './MobileAd';
|
|
23
|
+
import { AdEventListener } from '../types/AdEventListener';
|
|
24
|
+
import { AdShowOptions } from '../types/AdShowOptions';
|
|
25
|
+
import { RequestOptions } from '../types/RequestOptions';
|
|
26
|
+
import { MobileAdInterface } from '../types/MobileAd.interface';
|
|
27
|
+
|
|
28
|
+
let _appOpenRequest = 0;
|
|
29
|
+
|
|
30
|
+
export class AppOpenAd extends MobileAd implements MobileAdInterface {
|
|
31
|
+
static createForAdRequest(adUnitId: string, requestOptions?: RequestOptions): AppOpenAd {
|
|
32
|
+
if (!isString(adUnitId)) {
|
|
33
|
+
throw new Error("AppOpenAd.createForAdRequest(*) 'adUnitId' expected an string value.");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let options = {};
|
|
37
|
+
try {
|
|
38
|
+
options = validateAdRequestOptions(requestOptions);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
if (e instanceof Error) {
|
|
41
|
+
throw new Error(`AppOpenAd.createForAdRequest(_, *) ${e.message}.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const requestId = _appOpenRequest++;
|
|
46
|
+
return new AppOpenAd('app_open', MobileAds(), requestId, adUnitId, options);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
load() {
|
|
50
|
+
// Prevent multiple load calls
|
|
51
|
+
if (this._loaded || this._isLoadCalled) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
this._isLoadCalled = true;
|
|
56
|
+
this._googleMobileAds.native.appOpenLoad(this._requestId, this._adUnitId, this._requestOptions);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onAdEvent(handler: AdEventListener) {
|
|
60
|
+
if (!isFunction(handler)) {
|
|
61
|
+
throw new Error("AppOpenAd.onAdEvent(*) 'handler' expected a function.");
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return this._setAdEventHandler(handler);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
show(showOptions?: AdShowOptions) {
|
|
68
|
+
if (!this._loaded) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
'AppOpenAd.show() The requested AppOpenAd has not loaded and could not be shown.',
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let options;
|
|
75
|
+
try {
|
|
76
|
+
options = validateAdShowOptions(showOptions);
|
|
77
|
+
} catch (e) {
|
|
78
|
+
if (e instanceof Error) {
|
|
79
|
+
throw new Error(`AppOpenAd.show(*) ${e.message}.`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return this._googleMobileAds.native.appOpenShow(this._requestId, options);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import React, { useState, useEffect } from 'react';
|
|
19
|
+
import { HostComponent, requireNativeComponent } from 'react-native';
|
|
20
|
+
import { isFunction } from '../common';
|
|
21
|
+
import { NativeError } from '../internal/NativeError';
|
|
22
|
+
import { BannerAdSize } from '../BannerAdSize';
|
|
23
|
+
import { validateAdRequestOptions } from '../validateAdRequestOptions';
|
|
24
|
+
import { BannerAdProps } from '../types/BannerAdProps';
|
|
25
|
+
import { RequestOptions } from '../types/RequestOptions';
|
|
26
|
+
|
|
27
|
+
type NativeEvent =
|
|
28
|
+
| {
|
|
29
|
+
type: 'onAdLoaded' | 'onSizeChange';
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
}
|
|
33
|
+
| { type: 'onAdOpened' | 'onAdClosed' }
|
|
34
|
+
| {
|
|
35
|
+
type: 'onAdFailedToLoad';
|
|
36
|
+
code: string;
|
|
37
|
+
message: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const initialState = [0, 0];
|
|
41
|
+
const sizeRegex = /([0-9]+)x([0-9]+)/;
|
|
42
|
+
|
|
43
|
+
export function BannerAd({ unitId, size, requestOptions, ...props }: BannerAdProps) {
|
|
44
|
+
const [dimensions, setDimensions] = useState(initialState);
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (!unitId) {
|
|
48
|
+
throw new Error("BannerAd: 'unitId' expected a valid string unit ID.");
|
|
49
|
+
}
|
|
50
|
+
}, [unitId]);
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!(size in BannerAdSize) && !sizeRegex.test(size)) {
|
|
54
|
+
throw new Error("BannerAd: 'size' expected a valid BannerAdSize or custom size string.");
|
|
55
|
+
}
|
|
56
|
+
}, [size]);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!(size in BannerAdSize) && !sizeRegex.test(size)) {
|
|
60
|
+
throw new Error("BannerAd: 'size' expected a valid BannerAdSize or custom size string.");
|
|
61
|
+
}
|
|
62
|
+
}, [size]);
|
|
63
|
+
|
|
64
|
+
const parsedRequestOptions = JSON.stringify(requestOptions);
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (requestOptions) {
|
|
68
|
+
try {
|
|
69
|
+
validateAdRequestOptions(requestOptions);
|
|
70
|
+
} catch (e) {
|
|
71
|
+
if (e instanceof Error) {
|
|
72
|
+
throw new Error(`BannerAd: ${e.message}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, [parsedRequestOptions]);
|
|
77
|
+
|
|
78
|
+
function onNativeEvent({ nativeEvent }: { nativeEvent: NativeEvent }) {
|
|
79
|
+
const { type } = nativeEvent;
|
|
80
|
+
|
|
81
|
+
if (type !== 'onSizeChange' && isFunction(props[type])) {
|
|
82
|
+
let eventHandler;
|
|
83
|
+
if (type === 'onAdFailedToLoad') {
|
|
84
|
+
const eventPayload = NativeError.fromEvent(nativeEvent, 'googleMobileAds');
|
|
85
|
+
if ((eventHandler = props[type])) eventHandler(eventPayload);
|
|
86
|
+
} else if ((eventHandler = props[type])) eventHandler();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if ((type === 'onAdLoaded' || type === 'onSizeChange') && size !== 'FLUID') {
|
|
90
|
+
const { width, height } = nativeEvent;
|
|
91
|
+
if (width && height) setDimensions([width, height]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let style;
|
|
96
|
+
if (size === 'FLUID') {
|
|
97
|
+
// @ts-ignore: Property 'style' does not exist on type error
|
|
98
|
+
style = props.style;
|
|
99
|
+
} else {
|
|
100
|
+
style = {
|
|
101
|
+
width: dimensions[0],
|
|
102
|
+
height: dimensions[1],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<GoogleMobileAdsBannerView
|
|
108
|
+
size={size}
|
|
109
|
+
style={style}
|
|
110
|
+
unitId={unitId}
|
|
111
|
+
request={validateAdRequestOptions(requestOptions)}
|
|
112
|
+
onNativeEvent={onNativeEvent}
|
|
113
|
+
/>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const GoogleMobileAdsBannerView: HostComponent<{
|
|
118
|
+
size: BannerAdProps['size'];
|
|
119
|
+
style: {
|
|
120
|
+
width: number;
|
|
121
|
+
height: number;
|
|
122
|
+
};
|
|
123
|
+
unitId: string;
|
|
124
|
+
request: RequestOptions;
|
|
125
|
+
onNativeEvent: (event: { nativeEvent: NativeEvent }) => void;
|
|
126
|
+
}> = requireNativeComponent('RNGoogleMobileAdsBannerView');
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { isFunction, isString } from '../common';
|
|
19
|
+
import { MobileAds } from '../MobileAds';
|
|
20
|
+
import { validateAdRequestOptions } from '../validateAdRequestOptions';
|
|
21
|
+
import { validateAdShowOptions } from '../validateAdShowOptions';
|
|
22
|
+
import { MobileAd } from './MobileAd';
|
|
23
|
+
import { AdEventListener } from '../types/AdEventListener';
|
|
24
|
+
import { AdShowOptions } from '../types/AdShowOptions';
|
|
25
|
+
import { RequestOptions } from '../types/RequestOptions';
|
|
26
|
+
import { MobileAdInterface } from '../types/MobileAd.interface';
|
|
27
|
+
|
|
28
|
+
let _interstitialRequest = 0;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A class for interacting and showing Interstitial Ads.
|
|
32
|
+
*
|
|
33
|
+
* An Interstitial advert can be pre-loaded and shown at a suitable point in your apps flow, such as at the end of a level
|
|
34
|
+
* in a game. An Interstitial is a full screen advert, laid on-top of your entire application which the user can interact with.
|
|
35
|
+
* Interactions are passed back via events which should be handled accordingly inside of your app.
|
|
36
|
+
*
|
|
37
|
+
* #### Example
|
|
38
|
+
*
|
|
39
|
+
* First create a new Interstitial instance, passing in your Ad Unit ID from the Google Mobile Ads configuration console, and any additional
|
|
40
|
+
* request options. The example below will present a test advert, and only request a non-personalized ad.
|
|
41
|
+
*
|
|
42
|
+
* ```js
|
|
43
|
+
* import { InterstitialAd, TestIds } from 'react-native-google-mobile-ads';
|
|
44
|
+
*
|
|
45
|
+
* const interstitial = InterstitialAd.createForAdRequest(TestIds.INTERSTITIAL, {
|
|
46
|
+
* requestNonPersonalizedAdsOnly: true,
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* Each advert needs to be loaded from Google Mobile Ads before being shown. It is recommended this is performed before the user
|
|
51
|
+
* reaches the checkpoint to show the advert, so it's ready to go. Before loading the advert, we need to setup
|
|
52
|
+
* event listeners to listen for updates from Google Mobile Ads, such as advert loaded or failed to load.
|
|
53
|
+
*
|
|
54
|
+
* Event types match the `AdEventType` interface. Once the advert has loaded, we can trigger it to show:
|
|
55
|
+
*
|
|
56
|
+
* ```js
|
|
57
|
+
* import { AdEventType } from 'react-native-google-mobile-ads';
|
|
58
|
+
*
|
|
59
|
+
* interstitial.onAdEvent((type) => {
|
|
60
|
+
* if (type === AdEventType.LOADED) {
|
|
61
|
+
* interstitial.show();
|
|
62
|
+
* }
|
|
63
|
+
* });
|
|
64
|
+
*
|
|
65
|
+
* interstitial.load();
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* The advert will be presented to the user, and several more events can be triggered such as the user clicking the
|
|
69
|
+
* advert or closing it.
|
|
70
|
+
*/
|
|
71
|
+
export class InterstitialAd extends MobileAd implements MobileAdInterface {
|
|
72
|
+
/**
|
|
73
|
+
* Creates a new InterstitialAd instance.
|
|
74
|
+
*
|
|
75
|
+
* #### Example
|
|
76
|
+
*
|
|
77
|
+
* ```js
|
|
78
|
+
* import { InterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads';
|
|
79
|
+
*
|
|
80
|
+
* const interstitialAd = await InterstitialAd.createForAdRequest(TestIds.INTERSTITIAL, {
|
|
81
|
+
* requestAgent: 'CoolAds',
|
|
82
|
+
* });
|
|
83
|
+
*
|
|
84
|
+
* interstitialAd.onAdEvent((type, error) => {
|
|
85
|
+
* console.log('New event: ', type, error);
|
|
86
|
+
*
|
|
87
|
+
* if (type === AdEventType.LOADED) {
|
|
88
|
+
* interstitialAd.show();
|
|
89
|
+
* }
|
|
90
|
+
* });
|
|
91
|
+
*
|
|
92
|
+
* interstitialAd.load();
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @param adUnitId The Ad Unit ID for the Interstitial. You can find this on your Google Mobile Ads dashboard.
|
|
96
|
+
* @param requestOptions Optional RequestOptions used to load the ad.
|
|
97
|
+
*/
|
|
98
|
+
static createForAdRequest(adUnitId: string, requestOptions?: RequestOptions): InterstitialAd {
|
|
99
|
+
if (!isString(adUnitId)) {
|
|
100
|
+
throw new Error("InterstitialAd.createForAdRequest(*) 'adUnitId' expected an string value.");
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
let options = {};
|
|
104
|
+
try {
|
|
105
|
+
options = validateAdRequestOptions(requestOptions);
|
|
106
|
+
} catch (e) {
|
|
107
|
+
if (e instanceof Error) {
|
|
108
|
+
throw new Error(`InterstitialAd.createForAdRequest(_, *) ${e.message}.`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const requestId = _interstitialRequest++;
|
|
113
|
+
return new InterstitialAd('interstitial', MobileAds(), requestId, adUnitId, options);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
load() {
|
|
117
|
+
// Prevent multiple load calls
|
|
118
|
+
if (this._loaded || this._isLoadCalled) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this._isLoadCalled = true;
|
|
123
|
+
this._googleMobileAds.native.interstitialLoad(
|
|
124
|
+
this._requestId,
|
|
125
|
+
this._adUnitId,
|
|
126
|
+
this._requestOptions,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
onAdEvent(handler: AdEventListener) {
|
|
131
|
+
if (!isFunction(handler)) {
|
|
132
|
+
throw new Error("InterstitialAd.onAdEvent(*) 'handler' expected a function.");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return this._setAdEventHandler(handler);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
show(showOptions?: AdShowOptions) {
|
|
139
|
+
if (!this._loaded) {
|
|
140
|
+
throw new Error(
|
|
141
|
+
'InterstitialAd.show() The requested InterstitialAd has not loaded and could not be shown.',
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
let options;
|
|
146
|
+
try {
|
|
147
|
+
options = validateAdShowOptions(showOptions);
|
|
148
|
+
} catch (e) {
|
|
149
|
+
if (e instanceof Error) {
|
|
150
|
+
throw new Error(`InterstitialAd.show(*) ${e.message}.`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return this._googleMobileAds.native.interstitialShow(this._requestId, options);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { EmitterSubscription } from 'react-native';
|
|
19
|
+
import { NativeError } from '../internal/NativeError';
|
|
20
|
+
import { RewardedAdEventType } from '../RewardedAdEventType';
|
|
21
|
+
import { AdEventType } from '../AdEventType';
|
|
22
|
+
import { AdEventListener } from '../types/AdEventListener';
|
|
23
|
+
import { RequestOptions } from '../types/RequestOptions';
|
|
24
|
+
import { MobileAdsModuleInterface } from '../types/MobileAdsModule.interface';
|
|
25
|
+
import { RewardedAdReward } from '../types/RewardedAdReward';
|
|
26
|
+
|
|
27
|
+
export class MobileAd {
|
|
28
|
+
_type: 'app_open' | 'interstitial' | 'rewarded';
|
|
29
|
+
_googleMobileAds: MobileAdsModuleInterface;
|
|
30
|
+
_requestId: number;
|
|
31
|
+
_adUnitId: string;
|
|
32
|
+
_requestOptions: RequestOptions;
|
|
33
|
+
_loaded: boolean;
|
|
34
|
+
_isLoadCalled: boolean;
|
|
35
|
+
_onAdEventHandler: AdEventListener | null;
|
|
36
|
+
_nativeListener: EmitterSubscription;
|
|
37
|
+
|
|
38
|
+
constructor(
|
|
39
|
+
type: 'app_open' | 'interstitial' | 'rewarded',
|
|
40
|
+
googleMobileAds: MobileAdsModuleInterface,
|
|
41
|
+
requestId: number,
|
|
42
|
+
adUnitId: string,
|
|
43
|
+
requestOptions: RequestOptions,
|
|
44
|
+
) {
|
|
45
|
+
this._type = type;
|
|
46
|
+
this._googleMobileAds = googleMobileAds;
|
|
47
|
+
this._requestId = requestId;
|
|
48
|
+
this._adUnitId = adUnitId;
|
|
49
|
+
this._requestOptions = requestOptions;
|
|
50
|
+
|
|
51
|
+
this._loaded = false;
|
|
52
|
+
this._isLoadCalled = false;
|
|
53
|
+
this._onAdEventHandler = null;
|
|
54
|
+
|
|
55
|
+
this._nativeListener = googleMobileAds.emitter.addListener(
|
|
56
|
+
`google_mobile_ads_${type}_event:${adUnitId}:${requestId}`,
|
|
57
|
+
this._handleAdEvent.bind(this),
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
_handleAdEvent(event: {
|
|
62
|
+
body: {
|
|
63
|
+
type: AdEventType | RewardedAdEventType;
|
|
64
|
+
error?: { code: string; message: string };
|
|
65
|
+
data?: RewardedAdReward;
|
|
66
|
+
};
|
|
67
|
+
}) {
|
|
68
|
+
const { type, error, data } = event.body;
|
|
69
|
+
|
|
70
|
+
if (type === AdEventType.LOADED || type === RewardedAdEventType.LOADED) {
|
|
71
|
+
this._loaded = true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (type === AdEventType.CLOSED) {
|
|
75
|
+
this._loaded = false;
|
|
76
|
+
this._isLoadCalled = false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (this._onAdEventHandler) {
|
|
80
|
+
let nativeError;
|
|
81
|
+
if (error) {
|
|
82
|
+
nativeError = NativeError.fromEvent(error, 'googleMobileAds');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this._onAdEventHandler(type, nativeError, data);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
_setAdEventHandler(handler: AdEventListener) {
|
|
90
|
+
this._onAdEventHandler = handler;
|
|
91
|
+
return () => (this._onAdEventHandler = null);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get adUnitId() {
|
|
95
|
+
return this._adUnitId;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get loaded() {
|
|
99
|
+
return this._loaded;
|
|
100
|
+
}
|
|
101
|
+
}
|