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,114 @@
|
|
|
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
|
+
/**
|
|
19
|
+
* Returns the next parent of the path e.g. /foo/bar/car -> /foo/bar
|
|
20
|
+
*/
|
|
21
|
+
export function pathParent(path: string) {
|
|
22
|
+
if (path.length === 0) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const index = path.lastIndexOf('/');
|
|
27
|
+
if (index <= 0) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return path.slice(0, index);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Joins a parent and a child path
|
|
36
|
+
*/
|
|
37
|
+
export function pathChild(path: string, childPath: string) {
|
|
38
|
+
const canonicalChildPath = pathPieces(childPath).join('/');
|
|
39
|
+
|
|
40
|
+
if (path.length === 0) {
|
|
41
|
+
return canonicalChildPath;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return `${path}/${canonicalChildPath}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Returns the last component of a path, e.g /foo/bar.jpeg -> bar.jpeg
|
|
49
|
+
*/
|
|
50
|
+
export function pathLastComponent(path: string) {
|
|
51
|
+
const index = path.lastIndexOf('/', path.length - 2);
|
|
52
|
+
if (index === -1) {
|
|
53
|
+
return path;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return path.slice(index + 1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns all none empty pieces of the path
|
|
61
|
+
* @param path
|
|
62
|
+
* @returns {*}
|
|
63
|
+
*/
|
|
64
|
+
export function pathPieces(path: string) {
|
|
65
|
+
return path.split('/').filter($ => $.length > 0);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Returns whether a given path is empty
|
|
70
|
+
* @param path
|
|
71
|
+
* @returns {boolean}
|
|
72
|
+
*/
|
|
73
|
+
export function pathIsEmpty(path: string) {
|
|
74
|
+
return !pathPieces(path).length;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Converts a given path to a URL encoded string
|
|
79
|
+
* @param path
|
|
80
|
+
* @returns {string|string}
|
|
81
|
+
*/
|
|
82
|
+
export function pathToUrlEncodedString(path: string) {
|
|
83
|
+
const pieces = pathPieces(path);
|
|
84
|
+
let pathString = '';
|
|
85
|
+
for (let i = 0; i < pieces.length; i++) {
|
|
86
|
+
pathString += `/${encodeURIComponent(String(pieces[i]))}`;
|
|
87
|
+
}
|
|
88
|
+
return pathString || '/';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// eslint-disable-next-line no-control-regex
|
|
92
|
+
export const INVALID_PATH_REGEX = /[[\].#$\u0000-\u001F\u007F]/;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Ensures a given path is a valid Firebase path
|
|
96
|
+
* @param path
|
|
97
|
+
* @returns {boolean}
|
|
98
|
+
*/
|
|
99
|
+
export function isValidPath(path: unknown) {
|
|
100
|
+
return typeof path === 'string' && path.length !== 0 && !INVALID_PATH_REGEX.test(path);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Converts a file path to a standardized string path
|
|
105
|
+
* @param path
|
|
106
|
+
* @returns {*}
|
|
107
|
+
*/
|
|
108
|
+
export function toFilePath(path: string) {
|
|
109
|
+
let _filePath = path.replace('file://', '');
|
|
110
|
+
if (_filePath.includes('%')) {
|
|
111
|
+
_filePath = decodeURIComponent(_filePath);
|
|
112
|
+
}
|
|
113
|
+
return _filePath;
|
|
114
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 } from './validate';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
export function promiseDefer() {
|
|
24
|
+
const deferred: {
|
|
25
|
+
promise: Promise<unknown> | null;
|
|
26
|
+
resolve: (value: unknown) => void;
|
|
27
|
+
reject: (value: unknown) => void;
|
|
28
|
+
} = { promise: null, resolve: () => {}, reject: () => {} };
|
|
29
|
+
|
|
30
|
+
deferred.promise = new Promise((resolve, reject) => {
|
|
31
|
+
deferred.resolve = resolve;
|
|
32
|
+
deferred.reject = reject;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return deferred;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param promise
|
|
40
|
+
* @param callback
|
|
41
|
+
*/
|
|
42
|
+
export function promiseWithOptionalCallback(
|
|
43
|
+
promise: Promise<unknown>,
|
|
44
|
+
callback: (a: unknown, b?: unknown) => void,
|
|
45
|
+
) {
|
|
46
|
+
if (!isFunction(callback)) {
|
|
47
|
+
return promise;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return promise
|
|
51
|
+
.then(result => {
|
|
52
|
+
if (callback && callback.length === 1) {
|
|
53
|
+
callback(null);
|
|
54
|
+
} else if (callback) {
|
|
55
|
+
callback(null, result);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return result;
|
|
59
|
+
})
|
|
60
|
+
.catch(error => {
|
|
61
|
+
if (callback) {
|
|
62
|
+
callback(error);
|
|
63
|
+
}
|
|
64
|
+
return Promise.reject(error);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { tryJSONParse, tryJSONStringify } from './index';
|
|
19
|
+
import { isObject } from './validate';
|
|
20
|
+
|
|
21
|
+
export function serializeType(value: unknown) {
|
|
22
|
+
if (isObject(value)) {
|
|
23
|
+
return {
|
|
24
|
+
type: 'object',
|
|
25
|
+
value: serializeObject(value),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
type: typeof value,
|
|
31
|
+
value,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function serializeObject(object: unknown) {
|
|
36
|
+
if (!isObject(object)) {
|
|
37
|
+
return object;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// json stringify then parse it calls toString on Objects / Classes
|
|
41
|
+
// that support it i.e new Date() becomes a ISO string.
|
|
42
|
+
return tryJSONParse(tryJSONStringify(object) || '');
|
|
43
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
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
|
+
const AlphaNumericUnderscore = /^[a-zA-Z0-9_]+$/;
|
|
21
|
+
|
|
22
|
+
export function objectKeyValuesAreStrings(object: Record<string, unknown>) {
|
|
23
|
+
if (!isObject(object)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const entries = Object.entries(object);
|
|
28
|
+
|
|
29
|
+
for (let i = 0; i < entries.length; i++) {
|
|
30
|
+
const [key, value] = entries[i];
|
|
31
|
+
if (!isString(key) || !isString(value)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Simple is null check.
|
|
41
|
+
*
|
|
42
|
+
* @param value
|
|
43
|
+
* @returns {boolean}
|
|
44
|
+
*/
|
|
45
|
+
export function isNull(value: unknown) {
|
|
46
|
+
return value === null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Simple is object check.
|
|
51
|
+
*
|
|
52
|
+
* @param value
|
|
53
|
+
* @returns {boolean}
|
|
54
|
+
*/
|
|
55
|
+
export function isObject(value: unknown) {
|
|
56
|
+
return value ? typeof value === 'object' && !Array.isArray(value) && !isNull(value) : false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Simple is date check
|
|
61
|
+
* https://stackoverflow.com/a/44198641
|
|
62
|
+
* @param value
|
|
63
|
+
* @returns {boolean}
|
|
64
|
+
*/
|
|
65
|
+
export function isDate(value: number) {
|
|
66
|
+
// use the global isNaN() and not Number.isNaN() since it will validate an Invalid Date
|
|
67
|
+
return value && Object.prototype.toString.call(value) === '[object Date]' && !isNaN(value);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Simple is function check
|
|
72
|
+
*
|
|
73
|
+
* @param value
|
|
74
|
+
* @returns {*|boolean}
|
|
75
|
+
*/
|
|
76
|
+
export function isFunction(value: unknown) {
|
|
77
|
+
return value ? typeof value === 'function' : false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Simple is string check
|
|
82
|
+
* @param value
|
|
83
|
+
* @return {boolean}
|
|
84
|
+
*/
|
|
85
|
+
export function isString(value: unknown) {
|
|
86
|
+
return typeof value === 'string';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Simple is number check
|
|
91
|
+
* @param value
|
|
92
|
+
* @return {boolean}
|
|
93
|
+
*/
|
|
94
|
+
export function isNumber(value: unknown): value is number {
|
|
95
|
+
return typeof value === 'number';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Simple finite check
|
|
100
|
+
* @param value
|
|
101
|
+
* @returns {boolean}
|
|
102
|
+
*/
|
|
103
|
+
export function isFinite(value: unknown) {
|
|
104
|
+
return Number.isFinite(value);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Simple integer check
|
|
109
|
+
* @param value
|
|
110
|
+
* @returns {boolean}
|
|
111
|
+
*/
|
|
112
|
+
export function isInteger(value: unknown) {
|
|
113
|
+
return Number.isInteger(value);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Simple is boolean check
|
|
118
|
+
*
|
|
119
|
+
* @param value
|
|
120
|
+
* @return {boolean}
|
|
121
|
+
*/
|
|
122
|
+
export function isBoolean(value: unknown) {
|
|
123
|
+
return typeof value === 'boolean';
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
*
|
|
128
|
+
* @param value
|
|
129
|
+
* @returns {arg is Array<unknown>}
|
|
130
|
+
*/
|
|
131
|
+
export function isArray(value: unknown) {
|
|
132
|
+
return Array.isArray(value);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
*
|
|
137
|
+
* @param value
|
|
138
|
+
* @returns {boolean}
|
|
139
|
+
*/
|
|
140
|
+
export function isUndefined(value: unknown): value is undefined {
|
|
141
|
+
return typeof value === 'undefined';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* /^[a-zA-Z0-9_]+$/
|
|
146
|
+
*
|
|
147
|
+
* @param value
|
|
148
|
+
* @returns {boolean}
|
|
149
|
+
*/
|
|
150
|
+
export function isAlphaNumericUnderscore(value: string) {
|
|
151
|
+
return AlphaNumericUnderscore.test(value);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* URL test
|
|
156
|
+
* @param url
|
|
157
|
+
* @returns {boolean}
|
|
158
|
+
*/
|
|
159
|
+
const IS_VALID_URL_REGEX = /^(http|https):\/\/[^ "]+$/;
|
|
160
|
+
export function isValidUrl(url: string) {
|
|
161
|
+
return IS_VALID_URL_REGEX.test(url);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Array includes
|
|
166
|
+
*
|
|
167
|
+
* @param value
|
|
168
|
+
* @param oneOf
|
|
169
|
+
* @returns {boolean}
|
|
170
|
+
*/
|
|
171
|
+
export function isOneOf(value: unknown, oneOf: unknown[] = []) {
|
|
172
|
+
if (!isArray(oneOf)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
return oneOf.includes(value);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export function noop() {
|
|
179
|
+
// noop-🐈
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function validateOptionalNativeDependencyExists(
|
|
183
|
+
firebaseJsonKey: string,
|
|
184
|
+
apiName: string,
|
|
185
|
+
nativeFnExists: boolean,
|
|
186
|
+
) {
|
|
187
|
+
if (nativeFnExists) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
let errorMessage =
|
|
191
|
+
"You attempted to use an optional API that's not enabled natively. \n\n To enable ";
|
|
192
|
+
|
|
193
|
+
errorMessage += apiName;
|
|
194
|
+
errorMessage += ` please set the 'react-native' -> '${firebaseJsonKey}' key to true in your firebase.json file`;
|
|
195
|
+
|
|
196
|
+
if (Platform.OS === 'android') {
|
|
197
|
+
errorMessage += ' and rebuild your Android app.';
|
|
198
|
+
} else {
|
|
199
|
+
errorMessage +=
|
|
200
|
+
', re-run pod install and rebuild your iOS app. ' +
|
|
201
|
+
"If you're not using Pods then make sure you've have downloaded the necessary Firebase iOS SDK dependencies for this API.";
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
throw new Error(errorMessage);
|
|
205
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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 { version } from './version';
|
|
19
|
+
|
|
20
|
+
// import { SDK_VERSION } from 'react-native-google-mobile-ads';
|
|
21
|
+
export const SDK_VERSION = version;
|
|
22
|
+
|
|
23
|
+
export { default, MobileAds } from './MobileAds';
|
|
24
|
+
export { AdsConsentDebugGeography } from './AdsConsentDebugGeography';
|
|
25
|
+
export { AdsConsentStatus } from './AdsConsentStatus';
|
|
26
|
+
export { MaxAdContentRating } from './MaxAdContentRating';
|
|
27
|
+
export { TestIds } from './TestIds';
|
|
28
|
+
export { AdEventType } from './AdEventType';
|
|
29
|
+
export { BannerAdSize } from './BannerAdSize';
|
|
30
|
+
export { RewardedAdEventType } from './RewardedAdEventType';
|
|
31
|
+
export { AdsConsent } from './AdsConsent';
|
|
32
|
+
export { AppOpenAd } from './ads/AppOpenAd';
|
|
33
|
+
export { InterstitialAd } from './ads/InterstitialAd';
|
|
34
|
+
export { RewardedAd } from './ads/RewardedAd';
|
|
35
|
+
export { BannerAd } from './ads/BannerAd';
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { NativeEventEmitter, NativeModules, EmitterSubscription } from 'react-native';
|
|
19
|
+
|
|
20
|
+
const { RNAppModule } = NativeModules;
|
|
21
|
+
|
|
22
|
+
class GANativeEventEmitter extends NativeEventEmitter {
|
|
23
|
+
ready: boolean;
|
|
24
|
+
|
|
25
|
+
constructor() {
|
|
26
|
+
super(RNAppModule);
|
|
27
|
+
this.ready = false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
addListener(
|
|
31
|
+
eventType: string,
|
|
32
|
+
listener: (event: { appName?: string }) => void,
|
|
33
|
+
context?: Record<string, unknown>,
|
|
34
|
+
) {
|
|
35
|
+
if (!this.ready) {
|
|
36
|
+
RNAppModule.eventsNotifyReady(true);
|
|
37
|
+
this.ready = true;
|
|
38
|
+
}
|
|
39
|
+
RNAppModule.eventsAddListener(eventType);
|
|
40
|
+
|
|
41
|
+
const subscription = super.addListener(`rnapp_${eventType}`, listener, context);
|
|
42
|
+
|
|
43
|
+
// React Native 0.65+ altered EventEmitter:
|
|
44
|
+
// - removeSubscription is gone
|
|
45
|
+
// - addListener returns an unsubscriber instead of a more complex object with eventType etc
|
|
46
|
+
|
|
47
|
+
// make sure eventType for backwards compatibility just in case
|
|
48
|
+
subscription.eventType = `rnapp_${eventType}`;
|
|
49
|
+
|
|
50
|
+
// New style is to return a remove function on the object, just in csae people call that,
|
|
51
|
+
// we will modify it to do our native unsubscription then call the original
|
|
52
|
+
const originalRemove = subscription.remove;
|
|
53
|
+
const newRemove = () => {
|
|
54
|
+
RNAppModule.eventsRemoveListener(eventType, false);
|
|
55
|
+
if (super.removeSubscription != null) {
|
|
56
|
+
// This is for RN <= 0.64 - 65 and greater no longer have removeSubscription
|
|
57
|
+
super.removeSubscription(subscription);
|
|
58
|
+
} else if (originalRemove != null) {
|
|
59
|
+
// This is for RN >= 0.65
|
|
60
|
+
originalRemove();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
subscription.remove = newRemove;
|
|
64
|
+
return subscription;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
removeAllListeners(eventType: string) {
|
|
68
|
+
RNAppModule.eventsRemoveListener(eventType, true);
|
|
69
|
+
super.removeAllListeners(`rnapp_${eventType}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// This is likely no longer ever called, but it is here for backwards compatibility with RN <= 0.64
|
|
73
|
+
removeSubscription(subscription: EmitterSubscription) {
|
|
74
|
+
RNAppModule.eventsRemoveListener(subscription.eventType.replace('rnapp_', ''), false);
|
|
75
|
+
if (super.removeSubscription != null) {
|
|
76
|
+
super.removeSubscription(subscription);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const GoogleMobileAdsNativeEventEmitter = new GANativeEventEmitter();
|
|
@@ -0,0 +1,58 @@
|
|
|
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 { getNativeModule } from './registry/nativeModule';
|
|
19
|
+
import { SharedEventEmitter } from './SharedEventEmitter';
|
|
20
|
+
import { App, Config } from '../types/Module.interface';
|
|
21
|
+
import { GoogleMobileAdsNativeModule } from '../types/GoogleMobileAdsNativeModule';
|
|
22
|
+
|
|
23
|
+
export class AppModule {
|
|
24
|
+
_app: App;
|
|
25
|
+
_nativeModule: unknown;
|
|
26
|
+
_config: Config;
|
|
27
|
+
|
|
28
|
+
static __extended__ = {};
|
|
29
|
+
|
|
30
|
+
constructor(app: App, config: Config) {
|
|
31
|
+
this._app = app;
|
|
32
|
+
this._nativeModule = null;
|
|
33
|
+
this._config = Object.assign({}, config);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get app() {
|
|
37
|
+
return this._app;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get emitter() {
|
|
41
|
+
return SharedEventEmitter;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
eventNameForApp(...args: string[]) {
|
|
45
|
+
return `${this.app.name}-${args.join('-')}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get native() {
|
|
49
|
+
if (this._nativeModule) {
|
|
50
|
+
return this._nativeModule as GoogleMobileAdsNativeModule;
|
|
51
|
+
}
|
|
52
|
+
this._nativeModule = getNativeModule(this);
|
|
53
|
+
return this._nativeModule as GoogleMobileAdsNativeModule;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Instance of checks don't work once compiled
|
|
58
|
+
AppModule.__extended__ = {};
|
|
@@ -0,0 +1,56 @@
|
|
|
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 class NativeError extends Error {
|
|
19
|
+
namespace: string;
|
|
20
|
+
code: string;
|
|
21
|
+
message: string;
|
|
22
|
+
jsStack: string;
|
|
23
|
+
userInfo: { code: string; message: string };
|
|
24
|
+
|
|
25
|
+
static fromEvent(
|
|
26
|
+
errorEvent: { code: string; message: string },
|
|
27
|
+
namespace: string,
|
|
28
|
+
stack?: string,
|
|
29
|
+
) {
|
|
30
|
+
return new NativeError({ userInfo: errorEvent }, stack || new Error().stack || '', namespace);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
constructor(
|
|
34
|
+
nativeError: { userInfo: { code: string; message: string } },
|
|
35
|
+
jsStack: string,
|
|
36
|
+
namespace: string,
|
|
37
|
+
) {
|
|
38
|
+
super();
|
|
39
|
+
const { userInfo } = nativeError;
|
|
40
|
+
this.namespace = namespace;
|
|
41
|
+
this.code = `${this.namespace}/${userInfo.code || 'unknown'}`;
|
|
42
|
+
this.message = `[${this.code}] ${userInfo.message}`;
|
|
43
|
+
this.jsStack = jsStack;
|
|
44
|
+
this.userInfo = userInfo;
|
|
45
|
+
this.stack = NativeError.getStackWithMessage(`NativeError: ${this.message}`, this.jsStack);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Build a stack trace that includes JS stack prior to calling the native method.
|
|
50
|
+
*
|
|
51
|
+
* @returns {string}
|
|
52
|
+
*/
|
|
53
|
+
static getStackWithMessage(message: string, jsStack: string) {
|
|
54
|
+
return [message, ...jsStack.split('\n').slice(2, 13)].join('\n');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
// @ts-ignore: Could not find a declaration file
|
|
19
|
+
import Emitter from 'react-native/Libraries/vendor/emitter/EventEmitter';
|
|
20
|
+
import { EventEmitter } from 'react-native';
|
|
21
|
+
|
|
22
|
+
export const SharedEventEmitter: EventEmitter = new Emitter();
|