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,161 @@
|
|
|
1
|
+
package io.invertase.googlemobileads;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsCommon.getCodeAndMessageFromAdError;
|
|
21
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsCommon.sendAdEvent;
|
|
22
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_APP_OPEN;
|
|
23
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_CLICKED;
|
|
24
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_CLOSED;
|
|
25
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_ERROR;
|
|
26
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_LOADED;
|
|
27
|
+
import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_OPENED;
|
|
28
|
+
|
|
29
|
+
import android.app.Activity;
|
|
30
|
+
import androidx.annotation.NonNull;
|
|
31
|
+
import com.facebook.react.bridge.Arguments;
|
|
32
|
+
import com.facebook.react.bridge.Promise;
|
|
33
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
34
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
35
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
36
|
+
import com.facebook.react.bridge.WritableMap;
|
|
37
|
+
import com.google.android.gms.ads.AdRequest;
|
|
38
|
+
import com.google.android.gms.ads.FullScreenContentCallback;
|
|
39
|
+
import com.google.android.gms.ads.LoadAdError;
|
|
40
|
+
import com.google.android.gms.ads.appopen.AppOpenAd;
|
|
41
|
+
import io.invertase.googlemobileads.common.ReactNativeModule;
|
|
42
|
+
import javax.annotation.Nullable;
|
|
43
|
+
|
|
44
|
+
public class ReactNativeGoogleMobileAdsAppOpenModule extends ReactNativeModule {
|
|
45
|
+
private static final String SERVICE = "RNGoogleMobileAdsAppOpenModule";
|
|
46
|
+
private AppOpenAd appOpenAd = null;
|
|
47
|
+
|
|
48
|
+
public ReactNativeGoogleMobileAdsAppOpenModule(ReactApplicationContext reactContext) {
|
|
49
|
+
super(reactContext, SERVICE);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private void sendAppOpenEvent(
|
|
53
|
+
String type, int requestId, String adUnitId, @Nullable WritableMap error) {
|
|
54
|
+
sendAdEvent(GOOGLE_MOBILE_ADS_EVENT_APP_OPEN, requestId, type, adUnitId, error);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@ReactMethod
|
|
58
|
+
public void appOpenLoad(int requestId, String adUnitId, ReadableMap adRequestOptions) {
|
|
59
|
+
Activity currentActivity = getCurrentActivity();
|
|
60
|
+
if (currentActivity == null) {
|
|
61
|
+
WritableMap error = Arguments.createMap();
|
|
62
|
+
error.putString("code", "null-activity");
|
|
63
|
+
error.putString(
|
|
64
|
+
"message", "App Open ad attempted to load but the current Activity was null.");
|
|
65
|
+
sendAppOpenEvent(GOOGLE_MOBILE_ADS_EVENT_ERROR, requestId, adUnitId, error);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
currentActivity.runOnUiThread(
|
|
69
|
+
() -> {
|
|
70
|
+
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
|
|
71
|
+
AdRequest adRequest = adRequestBuilder.build();
|
|
72
|
+
|
|
73
|
+
AppOpenAd.AppOpenAdLoadCallback appOpenAdLoadCallback =
|
|
74
|
+
new AppOpenAd.AppOpenAdLoadCallback() {
|
|
75
|
+
|
|
76
|
+
@Override
|
|
77
|
+
public void onAdLoaded(@NonNull AppOpenAd appOpenAd) {
|
|
78
|
+
|
|
79
|
+
appOpenAd.setFullScreenContentCallback(
|
|
80
|
+
new FullScreenContentCallback() {
|
|
81
|
+
@Override
|
|
82
|
+
public void onAdDismissedFullScreenContent() {
|
|
83
|
+
sendAppOpenEvent(
|
|
84
|
+
GOOGLE_MOBILE_ADS_EVENT_CLOSED, requestId, adUnitId, null);
|
|
85
|
+
ReactNativeGoogleMobileAdsAppOpenModule.this.appOpenAd = null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Override
|
|
89
|
+
public void onAdClicked() {
|
|
90
|
+
sendAppOpenEvent(
|
|
91
|
+
GOOGLE_MOBILE_ADS_EVENT_CLICKED, requestId, adUnitId, null);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
@Override
|
|
95
|
+
public void onAdShowedFullScreenContent() {
|
|
96
|
+
sendAppOpenEvent(
|
|
97
|
+
GOOGLE_MOBILE_ADS_EVENT_OPENED, requestId, adUnitId, null);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
ReactNativeGoogleMobileAdsAppOpenModule.this.appOpenAd = appOpenAd;
|
|
102
|
+
sendAppOpenEvent(GOOGLE_MOBILE_ADS_EVENT_LOADED, requestId, adUnitId, null);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Override
|
|
106
|
+
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
|
|
107
|
+
WritableMap error = Arguments.createMap();
|
|
108
|
+
String[] codeAndMessage = getCodeAndMessageFromAdError(loadAdError);
|
|
109
|
+
error.putString("code", codeAndMessage[0]);
|
|
110
|
+
error.putString("message", codeAndMessage[1]);
|
|
111
|
+
sendAppOpenEvent(GOOGLE_MOBILE_ADS_EVENT_ERROR, requestId, adUnitId, error);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
AppOpenAd.load(
|
|
116
|
+
currentActivity,
|
|
117
|
+
adUnitId,
|
|
118
|
+
adRequest,
|
|
119
|
+
AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT,
|
|
120
|
+
appOpenAdLoadCallback);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@ReactMethod
|
|
125
|
+
public void appOpenShow(int requestId, ReadableMap showOptions, Promise promise) {
|
|
126
|
+
if (getCurrentActivity() == null) {
|
|
127
|
+
rejectPromiseWithCodeAndMessage(
|
|
128
|
+
promise,
|
|
129
|
+
"null-activity",
|
|
130
|
+
"App Open ad attempted to show but the current Activity was null.");
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
getCurrentActivity()
|
|
134
|
+
.runOnUiThread(
|
|
135
|
+
() -> {
|
|
136
|
+
if (appOpenAd == null) {
|
|
137
|
+
rejectPromiseWithCodeAndMessage(
|
|
138
|
+
promise,
|
|
139
|
+
"null-appOpenAd",
|
|
140
|
+
"App Open ad attempted to show but its object was null.");
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (showOptions.hasKey("immersiveModeEnabled")) {
|
|
145
|
+
appOpenAd.setImmersiveMode(showOptions.getBoolean("immersiveModeEnabled"));
|
|
146
|
+
} else {
|
|
147
|
+
appOpenAd.setImmersiveMode(false);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
String a = String.valueOf(requestId);
|
|
151
|
+
|
|
152
|
+
if (appOpenAd != null) {
|
|
153
|
+
appOpenAd.show(getCurrentActivity());
|
|
154
|
+
promise.resolve(null);
|
|
155
|
+
} else {
|
|
156
|
+
rejectPromiseWithCodeAndMessage(
|
|
157
|
+
promise, "not-ready", "App Open ad attempted to show but was not ready.");
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
package io.invertase.googlemobileads;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.view.ViewGroup;
|
|
21
|
+
import androidx.annotation.NonNull;
|
|
22
|
+
import com.facebook.react.bridge.Arguments;
|
|
23
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
24
|
+
import com.facebook.react.bridge.WritableMap;
|
|
25
|
+
import com.facebook.react.common.MapBuilder;
|
|
26
|
+
import com.facebook.react.uimanager.PixelUtil;
|
|
27
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
28
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
29
|
+
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
30
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
31
|
+
import com.facebook.react.views.view.ReactViewGroup;
|
|
32
|
+
import com.google.android.gms.ads.AdListener;
|
|
33
|
+
import com.google.android.gms.ads.AdRequest;
|
|
34
|
+
import com.google.android.gms.ads.AdSize;
|
|
35
|
+
import com.google.android.gms.ads.AdView;
|
|
36
|
+
import com.google.android.gms.ads.LoadAdError;
|
|
37
|
+
import java.util.Map;
|
|
38
|
+
import javax.annotation.Nonnull;
|
|
39
|
+
|
|
40
|
+
public class ReactNativeGoogleMobileAdsBannerAdViewManager
|
|
41
|
+
extends SimpleViewManager<ReactViewGroup> {
|
|
42
|
+
private static final String REACT_CLASS = "RNGoogleMobileAdsBannerView";
|
|
43
|
+
private String EVENT_AD_LOADED = "onAdLoaded";
|
|
44
|
+
private String EVENT_AD_FAILED_TO_LOAD = "onAdFailedToLoad";
|
|
45
|
+
private String EVENT_AD_OPENED = "onAdOpened";
|
|
46
|
+
private String EVENT_AD_CLOSED = "onAdClosed";
|
|
47
|
+
|
|
48
|
+
private Boolean requested = false;
|
|
49
|
+
private AdRequest request;
|
|
50
|
+
private AdSize size;
|
|
51
|
+
private String unitId;
|
|
52
|
+
|
|
53
|
+
@Nonnull
|
|
54
|
+
@Override
|
|
55
|
+
public String getName() {
|
|
56
|
+
return REACT_CLASS;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Nonnull
|
|
60
|
+
@Override
|
|
61
|
+
public ReactViewGroup createViewInstance(@Nonnull ThemedReactContext themedReactContext) {
|
|
62
|
+
ReactViewGroup viewGroup = new ReactViewGroup(themedReactContext);
|
|
63
|
+
AdView adView = new AdView(themedReactContext);
|
|
64
|
+
viewGroup.addView(adView);
|
|
65
|
+
setAdListener(viewGroup);
|
|
66
|
+
return viewGroup;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private AdView getAdView(ReactViewGroup viewGroup) {
|
|
70
|
+
return (AdView) viewGroup.getChildAt(0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private void resetAdView(ReactViewGroup reactViewGroup) {
|
|
74
|
+
AdView oldAdView = getAdView(reactViewGroup);
|
|
75
|
+
AdView newAdView = new AdView(reactViewGroup.getContext());
|
|
76
|
+
reactViewGroup.removeViewAt(0);
|
|
77
|
+
if (oldAdView != null) oldAdView.destroy();
|
|
78
|
+
reactViewGroup.addView(newAdView);
|
|
79
|
+
setAdListener(reactViewGroup);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Override
|
|
83
|
+
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
|
|
84
|
+
MapBuilder.Builder<String, Object> builder = MapBuilder.builder();
|
|
85
|
+
builder.put("onNativeEvent", MapBuilder.of("registrationName", "onNativeEvent"));
|
|
86
|
+
return builder.build();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@ReactProp(name = "unitId")
|
|
90
|
+
public void setUnitId(ReactViewGroup reactViewGroup, String value) {
|
|
91
|
+
unitId = value;
|
|
92
|
+
requestAd(reactViewGroup);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@ReactProp(name = "request")
|
|
96
|
+
public void setRequest(ReactViewGroup reactViewGroup, ReadableMap value) {
|
|
97
|
+
request = ReactNativeGoogleMobileAdsCommon.buildAdRequest(value);
|
|
98
|
+
requestAd(reactViewGroup);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@ReactProp(name = "size")
|
|
102
|
+
public void setSize(ReactViewGroup reactViewGroup, String value) {
|
|
103
|
+
size = ReactNativeGoogleMobileAdsCommon.getAdSize(value, reactViewGroup);
|
|
104
|
+
|
|
105
|
+
WritableMap payload = Arguments.createMap();
|
|
106
|
+
|
|
107
|
+
int width = size.getWidth();
|
|
108
|
+
int height = size.getHeight();
|
|
109
|
+
|
|
110
|
+
payload.putDouble("width", width);
|
|
111
|
+
payload.putDouble("height", height);
|
|
112
|
+
|
|
113
|
+
if (size != AdSize.FLUID) {
|
|
114
|
+
sendEvent(reactViewGroup, "onSizeChange", payload);
|
|
115
|
+
}
|
|
116
|
+
requestAd(reactViewGroup);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private void setAdListener(ReactViewGroup reactViewGroup) {
|
|
120
|
+
final AdView adView = getAdView(reactViewGroup);
|
|
121
|
+
|
|
122
|
+
adView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
|
123
|
+
adView.setAdListener(
|
|
124
|
+
new AdListener() {
|
|
125
|
+
@Override
|
|
126
|
+
public void onAdLoaded() {
|
|
127
|
+
int top;
|
|
128
|
+
int left;
|
|
129
|
+
int width;
|
|
130
|
+
int height;
|
|
131
|
+
|
|
132
|
+
if (size == AdSize.FLUID) {
|
|
133
|
+
top = 0;
|
|
134
|
+
left = 0;
|
|
135
|
+
width = reactViewGroup.getWidth();
|
|
136
|
+
height = reactViewGroup.getHeight();
|
|
137
|
+
} else {
|
|
138
|
+
top = adView.getTop();
|
|
139
|
+
left = adView.getLeft();
|
|
140
|
+
width = adView.getAdSize().getWidthInPixels(reactViewGroup.getContext());
|
|
141
|
+
height = adView.getAdSize().getHeightInPixels(reactViewGroup.getContext());
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// TODO size=FLUID not loading ad, height of child FrameLayout incorrect?
|
|
145
|
+
adView.measure(width, height);
|
|
146
|
+
adView.layout(left, top, left + width, top + height);
|
|
147
|
+
|
|
148
|
+
WritableMap payload = Arguments.createMap();
|
|
149
|
+
|
|
150
|
+
if (size != AdSize.FLUID) {
|
|
151
|
+
payload.putInt("width", (int) PixelUtil.toDIPFromPixel(width) + 1);
|
|
152
|
+
payload.putInt("height", (int) PixelUtil.toDIPFromPixel(height) + 1);
|
|
153
|
+
} else {
|
|
154
|
+
payload.putInt("width", (int) PixelUtil.toDIPFromPixel(width));
|
|
155
|
+
payload.putInt("height", (int) PixelUtil.toDIPFromPixel(height));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
sendEvent(reactViewGroup, EVENT_AD_LOADED, payload);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@Override
|
|
162
|
+
public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
|
|
163
|
+
int errorCode = loadAdError.getCode();
|
|
164
|
+
WritableMap payload = ReactNativeGoogleMobileAdsCommon.errorCodeToMap(errorCode);
|
|
165
|
+
sendEvent(reactViewGroup, EVENT_AD_FAILED_TO_LOAD, payload);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@Override
|
|
169
|
+
public void onAdOpened() {
|
|
170
|
+
sendEvent(reactViewGroup, EVENT_AD_OPENED, null);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@Override
|
|
174
|
+
public void onAdClosed() {
|
|
175
|
+
sendEvent(reactViewGroup, EVENT_AD_CLOSED, null);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private void requestAd(ReactViewGroup reactViewGroup) {
|
|
181
|
+
if (size == null || unitId == null || request == null) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (requested) {
|
|
186
|
+
resetAdView(reactViewGroup);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
AdView adView = getAdView(reactViewGroup);
|
|
190
|
+
adView.setAdUnitId(unitId);
|
|
191
|
+
adView.setAdSize(size);
|
|
192
|
+
adView.loadAd(request);
|
|
193
|
+
|
|
194
|
+
requested = true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private void sendEvent(ReactViewGroup reactViewGroup, String type, WritableMap payload) {
|
|
198
|
+
WritableMap event = Arguments.createMap();
|
|
199
|
+
event.putString("type", type);
|
|
200
|
+
|
|
201
|
+
if (payload != null) {
|
|
202
|
+
event.merge(payload);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
((ThemedReactContext) reactViewGroup.getContext())
|
|
206
|
+
.getJSModule(RCTEventEmitter.class)
|
|
207
|
+
.receiveEvent(reactViewGroup.getId(), "onNativeEvent", event);
|
|
208
|
+
}
|
|
209
|
+
}
|
package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
package io.invertase.googlemobileads;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.location.Location;
|
|
21
|
+
import android.os.Bundle;
|
|
22
|
+
import android.util.DisplayMetrics;
|
|
23
|
+
import android.view.Display;
|
|
24
|
+
import com.facebook.react.bridge.Arguments;
|
|
25
|
+
import com.facebook.react.bridge.ReactContext;
|
|
26
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
27
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
28
|
+
import com.facebook.react.bridge.WritableMap;
|
|
29
|
+
import com.facebook.react.views.view.ReactViewGroup;
|
|
30
|
+
import com.google.ads.mediation.admob.AdMobAdapter;
|
|
31
|
+
import com.google.android.gms.ads.AdError;
|
|
32
|
+
import com.google.android.gms.ads.AdRequest;
|
|
33
|
+
import com.google.android.gms.ads.AdSize;
|
|
34
|
+
import io.invertase.googlemobileads.common.ReactNativeEventEmitter;
|
|
35
|
+
import java.util.ArrayList;
|
|
36
|
+
import java.util.Map;
|
|
37
|
+
import java.util.Objects;
|
|
38
|
+
import java.util.regex.Matcher;
|
|
39
|
+
import java.util.regex.Pattern;
|
|
40
|
+
import javax.annotation.Nullable;
|
|
41
|
+
|
|
42
|
+
public class ReactNativeGoogleMobileAdsCommon {
|
|
43
|
+
|
|
44
|
+
static AdSize getAdSizeForAdaptiveBanner(ReactViewGroup reactViewGroup) {
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
Display display =
|
|
48
|
+
Objects.requireNonNull(((ReactContext) reactViewGroup.getContext()).getCurrentActivity())
|
|
49
|
+
.getWindowManager()
|
|
50
|
+
.getDefaultDisplay();
|
|
51
|
+
|
|
52
|
+
DisplayMetrics outMetrics = new DisplayMetrics();
|
|
53
|
+
display.getMetrics(outMetrics);
|
|
54
|
+
int adWidth = (int) (outMetrics.widthPixels / outMetrics.density);
|
|
55
|
+
|
|
56
|
+
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
|
|
57
|
+
reactViewGroup.getContext(), adWidth);
|
|
58
|
+
} catch (Exception e) {
|
|
59
|
+
return AdSize.BANNER;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
static AdSize getAdSize(String preDefinedAdSize, ReactViewGroup reactViewGroup) {
|
|
64
|
+
if ("ADAPTIVE_BANNER".equals(preDefinedAdSize)) {
|
|
65
|
+
return ReactNativeGoogleMobileAdsCommon.getAdSizeForAdaptiveBanner(reactViewGroup);
|
|
66
|
+
} else {
|
|
67
|
+
return ReactNativeGoogleMobileAdsCommon.stringToAdSize(preDefinedAdSize);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static AdSize stringToAdSize(String value) {
|
|
72
|
+
Pattern pattern = Pattern.compile("([0-9]+)x([0-9]+)");
|
|
73
|
+
Matcher matcher = pattern.matcher(value);
|
|
74
|
+
|
|
75
|
+
// If size is "valXval"
|
|
76
|
+
if (matcher.find()) {
|
|
77
|
+
int width = Integer.parseInt(matcher.group(1));
|
|
78
|
+
int height = Integer.parseInt(matcher.group(2));
|
|
79
|
+
return new AdSize(width, height);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
switch (value.toUpperCase()) {
|
|
83
|
+
case "FLUID":
|
|
84
|
+
return AdSize.FLUID;
|
|
85
|
+
case "WIDE_SKYSCRAPER":
|
|
86
|
+
return AdSize.WIDE_SKYSCRAPER;
|
|
87
|
+
case "LARGE_BANNER":
|
|
88
|
+
return AdSize.LARGE_BANNER;
|
|
89
|
+
case "MEDIUM_RECTANGLE":
|
|
90
|
+
return AdSize.MEDIUM_RECTANGLE;
|
|
91
|
+
case "FULL_BANNER":
|
|
92
|
+
return AdSize.FULL_BANNER;
|
|
93
|
+
case "LEADERBOARD":
|
|
94
|
+
return AdSize.LEADERBOARD;
|
|
95
|
+
default:
|
|
96
|
+
case "BANNER":
|
|
97
|
+
return AdSize.BANNER;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Convert common Google Mobile Ads errors into a standard format */
|
|
102
|
+
static WritableMap errorCodeToMap(int errorCode) {
|
|
103
|
+
WritableMap map = Arguments.createMap();
|
|
104
|
+
|
|
105
|
+
switch (errorCode) {
|
|
106
|
+
case AdRequest.ERROR_CODE_INTERNAL_ERROR:
|
|
107
|
+
map.putString("code", "error-code-internal-error");
|
|
108
|
+
map.putString(
|
|
109
|
+
"message",
|
|
110
|
+
"Something happened internally; for instance, an invalid response was received from the"
|
|
111
|
+
+ " ad server.");
|
|
112
|
+
break;
|
|
113
|
+
case AdRequest.ERROR_CODE_INVALID_REQUEST:
|
|
114
|
+
map.putString("code", "error-code-invalid-request");
|
|
115
|
+
map.putString(
|
|
116
|
+
"message", "The ad request was invalid; for instance, the ad unit ID was incorrect.");
|
|
117
|
+
break;
|
|
118
|
+
case AdRequest.ERROR_CODE_NETWORK_ERROR:
|
|
119
|
+
map.putString("code", "error-code-network-error");
|
|
120
|
+
map.putString("message", "The ad request was unsuccessful due to network connectivity.");
|
|
121
|
+
break;
|
|
122
|
+
case AdRequest.ERROR_CODE_NO_FILL:
|
|
123
|
+
map.putString("code", "error-code-no-fill");
|
|
124
|
+
map.putString(
|
|
125
|
+
"message",
|
|
126
|
+
"The ad request was successful, but no ad was returned due to lack of ad inventory.");
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return map;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public static AdRequest buildAdRequest(ReadableMap adRequestOptions) {
|
|
134
|
+
AdRequest.Builder builder = new AdRequest.Builder();
|
|
135
|
+
Bundle extras = new Bundle();
|
|
136
|
+
|
|
137
|
+
if (adRequestOptions.hasKey("requestNonPersonalizedAdsOnly")
|
|
138
|
+
&& adRequestOptions.getBoolean("requestNonPersonalizedAdsOnly")) {
|
|
139
|
+
extras.putString("npa", "1");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (adRequestOptions.hasKey("networkExtras")) {
|
|
143
|
+
Map<String, Object> networkExtras = adRequestOptions.getMap("networkExtras").toHashMap();
|
|
144
|
+
|
|
145
|
+
for (Map.Entry<String, Object> entry : networkExtras.entrySet()) {
|
|
146
|
+
String key = entry.getKey();
|
|
147
|
+
String value = (String) entry.getValue();
|
|
148
|
+
extras.putString(key, value);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
builder.addNetworkExtrasBundle(AdMobAdapter.class, extras);
|
|
153
|
+
|
|
154
|
+
if (adRequestOptions.hasKey("keywords")) {
|
|
155
|
+
ArrayList<Object> keywords =
|
|
156
|
+
Objects.requireNonNull(adRequestOptions.getArray("keywords")).toArrayList();
|
|
157
|
+
|
|
158
|
+
for (Object keyword : keywords) {
|
|
159
|
+
builder.addKeyword((String) keyword);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (adRequestOptions.hasKey("contentUrl")) {
|
|
164
|
+
builder.setContentUrl(Objects.requireNonNull(adRequestOptions.getString("contentUrl")));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (adRequestOptions.hasKey("location")) {
|
|
168
|
+
ReadableArray locationArray = adRequestOptions.getArray("location");
|
|
169
|
+
Location location = new Location("");
|
|
170
|
+
location.setLatitude(Objects.requireNonNull(locationArray).getDouble(0));
|
|
171
|
+
location.setLongitude(Objects.requireNonNull(locationArray).getDouble(1));
|
|
172
|
+
|
|
173
|
+
builder.setLocation(location);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (adRequestOptions.hasKey("requestAgent")) {
|
|
177
|
+
builder.setRequestAgent(Objects.requireNonNull(adRequestOptions.getString("requestAgent")));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return builder.build();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public static void sendAdEvent(
|
|
184
|
+
String event, int requestId, String type, String adUnitId, @Nullable WritableMap error) {
|
|
185
|
+
ReactNativeEventEmitter emitter = ReactNativeEventEmitter.getSharedInstance();
|
|
186
|
+
|
|
187
|
+
WritableMap eventBody = Arguments.createMap();
|
|
188
|
+
eventBody.putString("type", type);
|
|
189
|
+
|
|
190
|
+
if (error != null) {
|
|
191
|
+
eventBody.putMap("error", error);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
emitter.sendEvent(new ReactNativeGoogleMobileAdsEvent(event, requestId, adUnitId, eventBody));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
public static void sendAdEvent(
|
|
198
|
+
String event,
|
|
199
|
+
int requestId,
|
|
200
|
+
String type,
|
|
201
|
+
String adUnitId,
|
|
202
|
+
@Nullable WritableMap error,
|
|
203
|
+
@Nullable WritableMap data) {
|
|
204
|
+
ReactNativeEventEmitter emitter = ReactNativeEventEmitter.getSharedInstance();
|
|
205
|
+
|
|
206
|
+
WritableMap eventBody = Arguments.createMap();
|
|
207
|
+
eventBody.putString("type", type);
|
|
208
|
+
|
|
209
|
+
if (error != null) {
|
|
210
|
+
eventBody.putMap("error", error);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (data != null) {
|
|
214
|
+
eventBody.putMap("data", data);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
emitter.sendEvent(new ReactNativeGoogleMobileAdsEvent(event, requestId, adUnitId, eventBody));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public static String[] getCodeAndMessageFromAdError(AdError adError) {
|
|
221
|
+
String code = "unknown";
|
|
222
|
+
String message = adError.getMessage();
|
|
223
|
+
|
|
224
|
+
switch (adError.getCode()) {
|
|
225
|
+
case AdRequest.ERROR_CODE_APP_ID_MISSING:
|
|
226
|
+
code = "app-id-missing";
|
|
227
|
+
break;
|
|
228
|
+
case AdRequest.ERROR_CODE_INTERNAL_ERROR:
|
|
229
|
+
code = "internal-error";
|
|
230
|
+
break;
|
|
231
|
+
case AdRequest.ERROR_CODE_INVALID_AD_STRING:
|
|
232
|
+
code = "invalid-ad-string";
|
|
233
|
+
break;
|
|
234
|
+
case AdRequest.ERROR_CODE_INVALID_REQUEST:
|
|
235
|
+
code = "invalid-request";
|
|
236
|
+
break;
|
|
237
|
+
case AdRequest.ERROR_CODE_MEDIATION_NO_FILL:
|
|
238
|
+
code = "mediation-no-fill";
|
|
239
|
+
break;
|
|
240
|
+
case AdRequest.ERROR_CODE_NETWORK_ERROR:
|
|
241
|
+
code = "network-error";
|
|
242
|
+
break;
|
|
243
|
+
case AdRequest.ERROR_CODE_NO_FILL:
|
|
244
|
+
code = "no-fill";
|
|
245
|
+
break;
|
|
246
|
+
case AdRequest.ERROR_CODE_REQUEST_ID_MISMATCH:
|
|
247
|
+
code = "request-id-mismatch";
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
String[] codeAndMessage = new String[2];
|
|
252
|
+
codeAndMessage[0] = code;
|
|
253
|
+
codeAndMessage[1] = message;
|
|
254
|
+
return codeAndMessage;
|
|
255
|
+
}
|
|
256
|
+
}
|