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.
Files changed (373) hide show
  1. package/LICENSE +32 -0
  2. package/README.md +65 -0
  3. package/RNGoogleMobileAds.podspec +42 -0
  4. package/__tests__/consent.test.ts +25 -0
  5. package/__tests__/googleMobileAds.test.ts +63 -0
  6. package/__tests__/interstitial.test.ts +53 -0
  7. package/__tests__/requestOptions.test.tsx +4 -0
  8. package/__tests__/rewarded.test.tsx +4 -0
  9. package/__tests__/showOptions.test.tsx +4 -0
  10. package/android/.editorconfig +10 -0
  11. package/android/app-json.gradle +69 -0
  12. package/android/build.gradle +98 -0
  13. package/android/lint.xml +5 -0
  14. package/android/settings.gradle +1 -0
  15. package/android/src/main/AndroidManifest.xml +17 -0
  16. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeAppModule.java +169 -0
  17. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.java +161 -0
  18. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java +209 -0
  19. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java +256 -0
  20. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsConsentModule.java +226 -0
  21. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsEvent.java +72 -0
  22. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.java +159 -0
  23. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +143 -0
  24. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.java +48 -0
  25. package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedModule.java +177 -0
  26. package/android/src/main/java/io/invertase/googlemobileads/common/RCTConvert.java +111 -0
  27. package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeApp.java +34 -0
  28. package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeEvent.java +41 -0
  29. package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeEventEmitter.java +150 -0
  30. package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeInitProvider.java +77 -0
  31. package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeJSON.java +107 -0
  32. package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeMeta.java +92 -0
  33. package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativeModule.java +96 -0
  34. package/android/src/main/java/io/invertase/googlemobileads/common/ReactNativePreferences.java +86 -0
  35. package/android/src/main/java/io/invertase/googlemobileads/common/SharedUtils.java +427 -0
  36. package/android/src/main/java/io/invertase/googlemobileads/common/TaskExecutorService.java +124 -0
  37. package/android/src/main/java/io/invertase/googlemobileads/interfaces/ContextProvider.java +30 -0
  38. package/android/src/main/java/io/invertase/googlemobileads/interfaces/NativeError.java +28 -0
  39. package/android/src/main/java/io/invertase/googlemobileads/interfaces/NativeEvent.java +26 -0
  40. package/babel.config.js +18 -0
  41. package/docs/displaying-ads.mdx +319 -0
  42. package/docs/european-user-consent.mdx +258 -0
  43. package/docs/img/logo_admob_192px.svg +19 -0
  44. package/docs/index.mdx +168 -0
  45. package/docs.json +9 -0
  46. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.h +29 -0
  47. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m +98 -0
  48. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.h +23 -0
  49. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.m +153 -0
  50. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h +60 -0
  51. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +201 -0
  52. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.h +26 -0
  53. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.m +179 -0
  54. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.h +32 -0
  55. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.m +57 -0
  56. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.h +25 -0
  57. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m +124 -0
  58. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.h +24 -0
  59. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.m +104 -0
  60. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.h +25 -0
  61. package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedModule.m +173 -0
  62. package/ios/RNGoogleMobileAds/common/RNAppModule.h +24 -0
  63. package/ios/RNGoogleMobileAds/common/RNAppModule.m +158 -0
  64. package/ios/RNGoogleMobileAds/common/RNJSON.h +34 -0
  65. package/ios/RNGoogleMobileAds/common/RNJSON.m +93 -0
  66. package/ios/RNGoogleMobileAds/common/RNMeta.h +30 -0
  67. package/ios/RNGoogleMobileAds/common/RNMeta.m +61 -0
  68. package/ios/RNGoogleMobileAds/common/RNPreferences.h +44 -0
  69. package/ios/RNGoogleMobileAds/common/RNPreferences.m +94 -0
  70. package/ios/RNGoogleMobileAds/common/RNRCTEventEmitter.h +73 -0
  71. package/ios/RNGoogleMobileAds/common/RNRCTEventEmitter.m +150 -0
  72. package/ios/RNGoogleMobileAds/common/RNSharedUtils.h +48 -0
  73. package/ios/RNGoogleMobileAds/common/RNSharedUtils.m +56 -0
  74. package/ios/RNGoogleMobileAds.xcodeproj/project.pbxproj +377 -0
  75. package/ios/RNGoogleMobileAds.xcodeproj/xcshareddata/IDETemplateMacros.plist +24 -0
  76. package/ios_config.sh +140 -0
  77. package/jest.config.js +6 -0
  78. package/jest.setup.ts +29 -0
  79. package/lib/commonjs/AdEventType.js +34 -0
  80. package/lib/commonjs/AdEventType.js.map +1 -0
  81. package/lib/commonjs/AdsConsent.js +160 -0
  82. package/lib/commonjs/AdsConsent.js.map +1 -0
  83. package/lib/commonjs/AdsConsentDebugGeography.js +38 -0
  84. package/lib/commonjs/AdsConsentDebugGeography.js.map +1 -0
  85. package/lib/commonjs/AdsConsentStatus.js +36 -0
  86. package/lib/commonjs/AdsConsentStatus.js.map +1 -0
  87. package/lib/commonjs/BannerAdSize.js +38 -0
  88. package/lib/commonjs/BannerAdSize.js.map +1 -0
  89. package/lib/commonjs/MaxAdContentRating.js +33 -0
  90. package/lib/commonjs/MaxAdContentRating.js.map +1 -0
  91. package/lib/commonjs/MobileAds.js +67 -0
  92. package/lib/commonjs/MobileAds.js.map +1 -0
  93. package/lib/commonjs/RewardedAdEventType.js +31 -0
  94. package/lib/commonjs/RewardedAdEventType.js.map +1 -0
  95. package/lib/commonjs/TestIds.js +47 -0
  96. package/lib/commonjs/TestIds.js.map +1 -0
  97. package/lib/commonjs/ads/AppOpenAd.js +96 -0
  98. package/lib/commonjs/ads/AppOpenAd.js.map +1 -0
  99. package/lib/commonjs/ads/BannerAd.js +128 -0
  100. package/lib/commonjs/ads/BannerAd.js.map +1 -0
  101. package/lib/commonjs/ads/InterstitialAd.js +163 -0
  102. package/lib/commonjs/ads/InterstitialAd.js.map +1 -0
  103. package/lib/commonjs/ads/MobileAd.js +90 -0
  104. package/lib/commonjs/ads/MobileAd.js.map +1 -0
  105. package/lib/commonjs/ads/RewardedAd.js +169 -0
  106. package/lib/commonjs/ads/RewardedAd.js.map +1 -0
  107. package/lib/commonjs/common/Base64.js +121 -0
  108. package/lib/commonjs/common/Base64.js.map +1 -0
  109. package/lib/commonjs/common/MutatableParams.js +46 -0
  110. package/lib/commonjs/common/MutatableParams.js.map +1 -0
  111. package/lib/commonjs/common/ReferenceBase.js +59 -0
  112. package/lib/commonjs/common/ReferenceBase.js.map +1 -0
  113. package/lib/commonjs/common/deeps.js +101 -0
  114. package/lib/commonjs/common/deeps.js.map +1 -0
  115. package/lib/commonjs/common/id.js +82 -0
  116. package/lib/commonjs/common/id.js.map +1 -0
  117. package/lib/commonjs/common/index.js +212 -0
  118. package/lib/commonjs/common/index.js.map +1 -0
  119. package/lib/commonjs/common/path.js +144 -0
  120. package/lib/commonjs/common/path.js.map +1 -0
  121. package/lib/commonjs/common/promise.js +70 -0
  122. package/lib/commonjs/common/promise.js.map +1 -0
  123. package/lib/commonjs/common/serialize.js +52 -0
  124. package/lib/commonjs/common/serialize.js.map +1 -0
  125. package/lib/commonjs/common/validate.js +239 -0
  126. package/lib/commonjs/common/validate.js.map +1 -0
  127. package/lib/commonjs/declarations.d.js +2 -0
  128. package/lib/commonjs/declarations.d.js.map +1 -0
  129. package/lib/commonjs/index.js +143 -0
  130. package/lib/commonjs/index.js.map +1 -0
  131. package/lib/commonjs/internal/GoogleMobileAdsNativeEventEmitter.js +76 -0
  132. package/lib/commonjs/internal/GoogleMobileAdsNativeEventEmitter.js.map +1 -0
  133. package/lib/commonjs/internal/Module.js +60 -0
  134. package/lib/commonjs/internal/Module.js.map +1 -0
  135. package/lib/commonjs/internal/NativeError.js +70 -0
  136. package/lib/commonjs/internal/NativeError.js.map +1 -0
  137. package/lib/commonjs/internal/SharedEventEmitter.js +31 -0
  138. package/lib/commonjs/internal/SharedEventEmitter.js.map +1 -0
  139. package/lib/commonjs/internal/constants.js +30 -0
  140. package/lib/commonjs/internal/constants.js.map +1 -0
  141. package/lib/commonjs/internal/index.js +49 -0
  142. package/lib/commonjs/internal/index.js.map +1 -0
  143. package/lib/commonjs/internal/registry/nativeModule.js +231 -0
  144. package/lib/commonjs/internal/registry/nativeModule.js.map +1 -0
  145. package/lib/commonjs/types/AdEventListener.js +6 -0
  146. package/lib/commonjs/types/AdEventListener.js.map +1 -0
  147. package/lib/commonjs/types/AdShowOptions.js +2 -0
  148. package/lib/commonjs/types/AdShowOptions.js.map +1 -0
  149. package/lib/commonjs/types/AdapterStatus.js +18 -0
  150. package/lib/commonjs/types/AdapterStatus.js.map +1 -0
  151. package/lib/commonjs/types/AdsConsent.interface.js +6 -0
  152. package/lib/commonjs/types/AdsConsent.interface.js.map +1 -0
  153. package/lib/commonjs/types/BannerAdProps.js +6 -0
  154. package/lib/commonjs/types/BannerAdProps.js.map +1 -0
  155. package/lib/commonjs/types/GoogleMobileAdsNativeModule.js +6 -0
  156. package/lib/commonjs/types/GoogleMobileAdsNativeModule.js.map +1 -0
  157. package/lib/commonjs/types/MobileAd.interface.js +6 -0
  158. package/lib/commonjs/types/MobileAd.interface.js.map +1 -0
  159. package/lib/commonjs/types/MobileAdsModule.interface.js +6 -0
  160. package/lib/commonjs/types/MobileAdsModule.interface.js.map +1 -0
  161. package/lib/commonjs/types/Module.interface.js +2 -0
  162. package/lib/commonjs/types/Module.interface.js.map +1 -0
  163. package/lib/commonjs/types/RequestConfiguration.js +6 -0
  164. package/lib/commonjs/types/RequestConfiguration.js.map +1 -0
  165. package/lib/commonjs/types/RequestOptions.js +2 -0
  166. package/lib/commonjs/types/RequestOptions.js.map +1 -0
  167. package/lib/commonjs/types/RewardedAdReward.js +2 -0
  168. package/lib/commonjs/types/RewardedAdReward.js.map +1 -0
  169. package/lib/commonjs/validateAdRequestConfiguration.js +69 -0
  170. package/lib/commonjs/validateAdRequestConfiguration.js.map +1 -0
  171. package/lib/commonjs/validateAdRequestOptions.js +158 -0
  172. package/lib/commonjs/validateAdRequestOptions.js.map +1 -0
  173. package/lib/commonjs/validateAdShowOptions.js +47 -0
  174. package/lib/commonjs/validateAdShowOptions.js.map +1 -0
  175. package/lib/commonjs/version.js +10 -0
  176. package/lib/commonjs/version.js.map +1 -0
  177. package/lib/module/AdEventType.js +26 -0
  178. package/lib/module/AdEventType.js.map +1 -0
  179. package/lib/module/AdsConsent.js +148 -0
  180. package/lib/module/AdsConsent.js.map +1 -0
  181. package/lib/module/AdsConsentDebugGeography.js +30 -0
  182. package/lib/module/AdsConsentDebugGeography.js.map +1 -0
  183. package/lib/module/AdsConsentStatus.js +28 -0
  184. package/lib/module/AdsConsentStatus.js.map +1 -0
  185. package/lib/module/BannerAdSize.js +30 -0
  186. package/lib/module/BannerAdSize.js.map +1 -0
  187. package/lib/module/MaxAdContentRating.js +25 -0
  188. package/lib/module/MaxAdContentRating.js.map +1 -0
  189. package/lib/module/MobileAds.js +53 -0
  190. package/lib/module/MobileAds.js.map +1 -0
  191. package/lib/module/RewardedAdEventType.js +23 -0
  192. package/lib/module/RewardedAdEventType.js.map +1 -0
  193. package/lib/module/TestIds.js +38 -0
  194. package/lib/module/TestIds.js.map +1 -0
  195. package/lib/module/ads/AppOpenAd.js +81 -0
  196. package/lib/module/ads/AppOpenAd.js.map +1 -0
  197. package/lib/module/ads/BannerAd.js +108 -0
  198. package/lib/module/ads/BannerAd.js.map +1 -0
  199. package/lib/module/ads/InterstitialAd.js +149 -0
  200. package/lib/module/ads/InterstitialAd.js.map +1 -0
  201. package/lib/module/ads/MobileAd.js +94 -0
  202. package/lib/module/ads/MobileAd.js.map +1 -0
  203. package/lib/module/ads/RewardedAd.js +155 -0
  204. package/lib/module/ads/RewardedAd.js.map +1 -0
  205. package/lib/module/common/Base64.js +106 -0
  206. package/lib/module/common/Base64.js.map +1 -0
  207. package/lib/module/common/MutatableParams.js +52 -0
  208. package/lib/module/common/MutatableParams.js.map +1 -0
  209. package/lib/module/common/ReferenceBase.js +50 -0
  210. package/lib/module/common/ReferenceBase.js.map +1 -0
  211. package/lib/module/common/deeps.js +91 -0
  212. package/lib/module/common/deeps.js.map +1 -0
  213. package/lib/module/common/id.js +74 -0
  214. package/lib/module/common/id.js.map +1 -0
  215. package/lib/module/common/index.js +109 -0
  216. package/lib/module/common/index.js.map +1 -0
  217. package/lib/module/common/path.js +120 -0
  218. package/lib/module/common/path.js.map +1 -0
  219. package/lib/module/common/promise.js +60 -0
  220. package/lib/module/common/promise.js.map +1 -0
  221. package/lib/module/common/serialize.js +41 -0
  222. package/lib/module/common/serialize.js.map +1 -0
  223. package/lib/module/common/validate.js +197 -0
  224. package/lib/module/common/validate.js.map +1 -0
  225. package/lib/module/declarations.d.js +2 -0
  226. package/lib/module/declarations.d.js.map +1 -0
  227. package/lib/module/index.js +33 -0
  228. package/lib/module/index.js.map +1 -0
  229. package/lib/module/internal/GoogleMobileAdsNativeEventEmitter.js +83 -0
  230. package/lib/module/internal/GoogleMobileAdsNativeEventEmitter.js.map +1 -0
  231. package/lib/module/internal/Module.js +64 -0
  232. package/lib/module/internal/Module.js.map +1 -0
  233. package/lib/module/internal/NativeError.js +61 -0
  234. package/lib/module/internal/NativeError.js.map +1 -0
  235. package/lib/module/internal/SharedEventEmitter.js +20 -0
  236. package/lib/module/internal/SharedEventEmitter.js.map +1 -0
  237. package/lib/module/internal/constants.js +20 -0
  238. package/lib/module/internal/constants.js.map +1 -0
  239. package/lib/module/internal/index.js +21 -0
  240. package/lib/module/internal/index.js.map +1 -0
  241. package/lib/module/internal/registry/nativeModule.js +215 -0
  242. package/lib/module/internal/registry/nativeModule.js.map +1 -0
  243. package/lib/module/types/AdEventListener.js +2 -0
  244. package/lib/module/types/AdEventListener.js.map +1 -0
  245. package/lib/module/types/AdShowOptions.js +2 -0
  246. package/lib/module/types/AdShowOptions.js.map +1 -0
  247. package/lib/module/types/AdapterStatus.js +10 -0
  248. package/lib/module/types/AdapterStatus.js.map +1 -0
  249. package/lib/module/types/AdsConsent.interface.js +2 -0
  250. package/lib/module/types/AdsConsent.interface.js.map +1 -0
  251. package/lib/module/types/BannerAdProps.js +2 -0
  252. package/lib/module/types/BannerAdProps.js.map +1 -0
  253. package/lib/module/types/GoogleMobileAdsNativeModule.js +2 -0
  254. package/lib/module/types/GoogleMobileAdsNativeModule.js.map +1 -0
  255. package/lib/module/types/MobileAd.interface.js +2 -0
  256. package/lib/module/types/MobileAd.interface.js.map +1 -0
  257. package/lib/module/types/MobileAdsModule.interface.js +2 -0
  258. package/lib/module/types/MobileAdsModule.interface.js.map +1 -0
  259. package/lib/module/types/Module.interface.js +2 -0
  260. package/lib/module/types/Module.interface.js.map +1 -0
  261. package/lib/module/types/RequestConfiguration.js +2 -0
  262. package/lib/module/types/RequestConfiguration.js.map +1 -0
  263. package/lib/module/types/RequestOptions.js +2 -0
  264. package/lib/module/types/RequestOptions.js.map +1 -0
  265. package/lib/module/types/RewardedAdReward.js +2 -0
  266. package/lib/module/types/RewardedAdReward.js.map +1 -0
  267. package/lib/module/validateAdRequestConfiguration.js +60 -0
  268. package/lib/module/validateAdRequestConfiguration.js.map +1 -0
  269. package/lib/module/validateAdRequestOptions.js +150 -0
  270. package/lib/module/validateAdRequestOptions.js.map +1 -0
  271. package/lib/module/validateAdShowOptions.js +39 -0
  272. package/lib/module/validateAdShowOptions.js.map +1 -0
  273. package/lib/module/version.js +3 -0
  274. package/lib/module/version.js.map +1 -0
  275. package/lib/typescript/AdEventType.d.ts +47 -0
  276. package/lib/typescript/AdsConsent.d.ts +2 -0
  277. package/lib/typescript/AdsConsentDebugGeography.d.ts +19 -0
  278. package/lib/typescript/AdsConsentStatus.d.ts +17 -0
  279. package/lib/typescript/BannerAdSize.d.ts +34 -0
  280. package/lib/typescript/MaxAdContentRating.d.ts +18 -0
  281. package/lib/typescript/MobileAds.d.ts +11 -0
  282. package/lib/typescript/RewardedAdEventType.d.ts +46 -0
  283. package/lib/typescript/TestIds.d.ts +6 -0
  284. package/lib/typescript/ads/AppOpenAd.d.ts +11 -0
  285. package/lib/typescript/ads/BannerAd.d.ts +3 -0
  286. package/lib/typescript/ads/InterstitialAd.d.ts +78 -0
  287. package/lib/typescript/ads/MobileAd.d.ts +32 -0
  288. package/lib/typescript/ads/RewardedAd.d.ts +84 -0
  289. package/lib/typescript/common/Base64.d.ts +14 -0
  290. package/lib/typescript/common/MutatableParams.d.ts +9 -0
  291. package/lib/typescript/common/ReferenceBase.d.ts +11 -0
  292. package/lib/typescript/common/deeps.d.ts +18 -0
  293. package/lib/typescript/common/id.d.ts +11 -0
  294. package/lib/typescript/common/index.d.ts +28 -0
  295. package/lib/typescript/common/path.d.ts +43 -0
  296. package/lib/typescript/common/promise.d.ts +13 -0
  297. package/lib/typescript/common/serialize.d.ts +5 -0
  298. package/lib/typescript/common/validate.d.ts +90 -0
  299. package/lib/typescript/index.d.ts +14 -0
  300. package/lib/typescript/internal/GoogleMobileAdsNativeEventEmitter.d.ts +12 -0
  301. package/lib/typescript/internal/Module.d.ts +13 -0
  302. package/lib/typescript/internal/NativeError.d.ts +26 -0
  303. package/lib/typescript/internal/SharedEventEmitter.d.ts +2 -0
  304. package/lib/typescript/internal/constants.d.ts +3 -0
  305. package/lib/typescript/internal/index.d.ts +4 -0
  306. package/lib/typescript/internal/registry/nativeModule.d.ts +15 -0
  307. package/lib/typescript/types/AdEventListener.d.ts +11 -0
  308. package/lib/typescript/types/AdShowOptions.d.ts +12 -0
  309. package/lib/typescript/types/AdapterStatus.d.ts +18 -0
  310. package/lib/typescript/types/AdsConsent.interface.d.ts +286 -0
  311. package/lib/typescript/types/BannerAdProps.d.ts +66 -0
  312. package/lib/typescript/types/GoogleMobileAdsNativeModule.d.ts +14 -0
  313. package/lib/typescript/types/MobileAd.interface.d.ts +64 -0
  314. package/lib/typescript/types/MobileAdsModule.interface.d.ts +38 -0
  315. package/lib/typescript/types/Module.interface.d.ts +14 -0
  316. package/lib/typescript/types/RequestConfiguration.d.ts +36 -0
  317. package/lib/typescript/types/RequestOptions.d.ts +106 -0
  318. package/lib/typescript/types/RewardedAdReward.d.ts +13 -0
  319. package/lib/typescript/validateAdRequestConfiguration.d.ts +2 -0
  320. package/lib/typescript/validateAdRequestOptions.d.ts +2 -0
  321. package/lib/typescript/validateAdShowOptions.d.ts +2 -0
  322. package/lib/typescript/version.d.ts +1 -0
  323. package/package.json +143 -0
  324. package/react-native.config.js +19 -0
  325. package/src/AdEventType.ts +68 -0
  326. package/src/AdsConsent.ts +191 -0
  327. package/src/AdsConsentDebugGeography.ts +38 -0
  328. package/src/AdsConsentStatus.ts +36 -0
  329. package/src/BannerAdSize.ts +59 -0
  330. package/src/MaxAdContentRating.ts +38 -0
  331. package/src/MobileAds.ts +84 -0
  332. package/src/RewardedAdEventType.ts +64 -0
  333. package/src/TestIds.ts +39 -0
  334. package/src/ads/AppOpenAd.ts +85 -0
  335. package/src/ads/BannerAd.tsx +126 -0
  336. package/src/ads/InterstitialAd.ts +156 -0
  337. package/src/ads/MobileAd.ts +101 -0
  338. package/src/ads/RewardedAd.ts +161 -0
  339. package/src/common/Base64.ts +114 -0
  340. package/src/common/MutatableParams.ts +50 -0
  341. package/src/common/ReferenceBase.ts +45 -0
  342. package/src/common/deeps.ts +88 -0
  343. package/src/common/id.ts +74 -0
  344. package/src/common/index.ts +103 -0
  345. package/src/common/path.ts +114 -0
  346. package/src/common/promise.ts +66 -0
  347. package/src/common/serialize.ts +43 -0
  348. package/src/common/validate.ts +205 -0
  349. package/src/declarations.d.ts +3 -0
  350. package/src/index.ts +35 -0
  351. package/src/internal/GoogleMobileAdsNativeEventEmitter.ts +81 -0
  352. package/src/internal/Module.ts +58 -0
  353. package/src/internal/NativeError.ts +56 -0
  354. package/src/internal/SharedEventEmitter.ts +22 -0
  355. package/src/internal/constants.ts +43 -0
  356. package/src/internal/index.ts +21 -0
  357. package/src/internal/registry/nativeModule.ts +226 -0
  358. package/src/types/AdEventListener.ts +16 -0
  359. package/src/types/AdShowOptions.ts +12 -0
  360. package/src/types/AdapterStatus.ts +20 -0
  361. package/src/types/AdsConsent.interface.ts +306 -0
  362. package/src/types/BannerAdProps.ts +73 -0
  363. package/src/types/GoogleMobileAdsNativeModule.ts +15 -0
  364. package/src/types/MobileAd.interface.ts +69 -0
  365. package/src/types/MobileAdsModule.interface.ts +43 -0
  366. package/src/types/Module.interface.ts +16 -0
  367. package/src/types/RequestConfiguration.ts +40 -0
  368. package/src/types/RequestOptions.ts +113 -0
  369. package/src/types/RewardedAdReward.ts +14 -0
  370. package/src/validateAdRequestConfiguration.ts +71 -0
  371. package/src/validateAdRequestOptions.ts +168 -0
  372. package/src/validateAdShowOptions.ts +41 -0
  373. package/src/version.ts +2 -0
@@ -0,0 +1,226 @@
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 com.facebook.react.bridge.Arguments;
21
+ import com.facebook.react.bridge.Promise;
22
+ import com.facebook.react.bridge.ReactApplicationContext;
23
+ import com.facebook.react.bridge.ReactMethod;
24
+ import com.facebook.react.bridge.ReadableArray;
25
+ import com.facebook.react.bridge.ReadableMap;
26
+ import com.facebook.react.bridge.WritableArray;
27
+ import com.facebook.react.bridge.WritableMap;
28
+ import com.google.ads.consent.AdProvider;
29
+ import com.google.ads.consent.ConsentForm;
30
+ import com.google.ads.consent.ConsentFormListener;
31
+ import com.google.ads.consent.ConsentInfoUpdateListener;
32
+ import com.google.ads.consent.ConsentInformation;
33
+ import com.google.ads.consent.ConsentStatus;
34
+ import com.google.ads.consent.DebugGeography;
35
+ import io.invertase.googlemobileads.common.ReactNativeModule;
36
+ import java.net.MalformedURLException;
37
+ import java.net.URL;
38
+ import java.util.List;
39
+
40
+ public class ReactNativeGoogleMobileAdsConsentModule extends ReactNativeModule {
41
+ private static final String TAG = "RNGoogleMobileAdsConsentModule";
42
+ private ConsentInformation consentInformation;
43
+ private ConsentForm consentForm;
44
+
45
+ public ReactNativeGoogleMobileAdsConsentModule(ReactApplicationContext reactContext) {
46
+ super(reactContext, TAG);
47
+ consentInformation = ConsentInformation.getInstance(reactContext);
48
+ }
49
+
50
+ private int getConsentStatusInt(ConsentStatus consentStatus) {
51
+ switch (consentStatus) {
52
+ case NON_PERSONALIZED:
53
+ return 1;
54
+ case PERSONALIZED:
55
+ return 2;
56
+ case UNKNOWN:
57
+ default:
58
+ return 0;
59
+ }
60
+ }
61
+
62
+ @ReactMethod
63
+ public void requestInfoUpdate(ReadableArray publisherIds, Promise promise) {
64
+ @SuppressWarnings("SuspiciousToArrayCall")
65
+ String[] publisherIdsArray = publisherIds.toArrayList().toArray(new String[0]);
66
+
67
+ consentInformation.requestConsentInfoUpdate(
68
+ publisherIdsArray,
69
+ new ConsentInfoUpdateListener() {
70
+ @Override
71
+ public void onConsentInfoUpdated(ConsentStatus consentStatus) {
72
+ WritableMap requestInfoMap = Arguments.createMap();
73
+ requestInfoMap.putInt("status", getConsentStatusInt(consentStatus));
74
+ requestInfoMap.putBoolean(
75
+ "isRequestLocationInEeaOrUnknown",
76
+ consentInformation.isRequestLocationInEeaOrUnknown());
77
+ promise.resolve(requestInfoMap);
78
+ }
79
+
80
+ @Override
81
+ public void onFailedToUpdateConsentInfo(String reason) {
82
+ rejectPromiseWithCodeAndMessage(promise, "consent-update-failed", reason);
83
+ }
84
+ });
85
+ }
86
+
87
+ @ReactMethod
88
+ public void showForm(ReadableMap options, Promise promise) {
89
+ if (getCurrentActivity() == null) {
90
+ rejectPromiseWithCodeAndMessage(
91
+ promise,
92
+ "null-activity",
93
+ "Consent form attempted to show but the current Activity was null.");
94
+ return;
95
+ }
96
+ getCurrentActivity()
97
+ .runOnUiThread(
98
+ () -> {
99
+ URL privacyUrl = null;
100
+
101
+ try {
102
+ privacyUrl = new URL(options.getString("privacyPolicy"));
103
+ } catch (MalformedURLException e) {
104
+ // Validated in JS land
105
+ }
106
+
107
+ ConsentFormListener listener =
108
+ new ConsentFormListener() {
109
+ @Override
110
+ public void onConsentFormLoaded() {
111
+ try {
112
+ consentForm.show();
113
+ } catch (Exception e) {
114
+ rejectPromiseWithCodeAndMessage(
115
+ promise, "consent-form-error", e.toString());
116
+ }
117
+ }
118
+
119
+ @Override
120
+ public void onConsentFormClosed(
121
+ ConsentStatus consentStatus, Boolean userPrefersAdFree) {
122
+ WritableMap consentFormMap = Arguments.createMap();
123
+ consentFormMap.putInt("status", getConsentStatusInt(consentStatus));
124
+ consentFormMap.putBoolean("userPrefersAdFree", userPrefersAdFree);
125
+ promise.resolve(consentFormMap);
126
+ }
127
+
128
+ @Override
129
+ public void onConsentFormError(String reason) {
130
+ rejectPromiseWithCodeAndMessage(promise, "consent-form-error", reason);
131
+ }
132
+ };
133
+
134
+ ConsentForm.Builder builder =
135
+ new ConsentForm.Builder(getCurrentActivity(), privacyUrl).withListener(listener);
136
+
137
+ if (options.hasKey("withPersonalizedAds")
138
+ && options.getBoolean("withPersonalizedAds")) {
139
+ builder = builder.withPersonalizedAdsOption();
140
+ }
141
+
142
+ if (options.hasKey("withNonPersonalizedAds")
143
+ && options.getBoolean("withNonPersonalizedAds")) {
144
+ builder = builder.withNonPersonalizedAdsOption();
145
+ }
146
+
147
+ if (options.hasKey("withAdFree") && options.getBoolean("withAdFree")) {
148
+ builder = builder.withAdFreeOption();
149
+ }
150
+
151
+ consentForm = builder.build();
152
+ consentForm.load();
153
+ });
154
+ }
155
+
156
+ @ReactMethod
157
+ public void getStatus(Promise promise) {
158
+ ConsentStatus status = consentInformation.getConsentStatus();
159
+ promise.resolve(getConsentStatusInt(status));
160
+ }
161
+
162
+ @ReactMethod
163
+ public void setStatus(int status, Promise promise) {
164
+ ConsentStatus consentStatus = ConsentStatus.UNKNOWN;
165
+
166
+ switch (status) {
167
+ case 0:
168
+ consentStatus = ConsentStatus.UNKNOWN;
169
+ break;
170
+ case 1:
171
+ consentStatus = ConsentStatus.NON_PERSONALIZED;
172
+ break;
173
+ case 2:
174
+ consentStatus = ConsentStatus.PERSONALIZED;
175
+ break;
176
+ }
177
+
178
+ consentInformation.setConsentStatus(consentStatus);
179
+ promise.resolve(null);
180
+ }
181
+
182
+ @ReactMethod
183
+ public void getAdProviders(Promise promise) {
184
+ List<AdProvider> providers = consentInformation.getAdProviders();
185
+
186
+ WritableArray formattedAdProviders = Arguments.createArray();
187
+
188
+ for (AdProvider provider : providers) {
189
+ WritableMap formattedProvider = Arguments.createMap();
190
+ formattedProvider.putString("companyName", provider.getName());
191
+ formattedProvider.putString("companyId", provider.getId());
192
+ formattedProvider.putString("privacyPolicyUrl", provider.getPrivacyPolicyUrlString());
193
+ formattedAdProviders.pushMap(formattedProvider);
194
+ }
195
+
196
+ promise.resolve(formattedAdProviders);
197
+ }
198
+
199
+ @ReactMethod
200
+ public void setTagForUnderAgeOfConsent(boolean tag, Promise promise) {
201
+ consentInformation.setTagForUnderAgeOfConsent(tag);
202
+ promise.resolve(null);
203
+ }
204
+
205
+ @ReactMethod
206
+ public void setDebugGeography(int geography, Promise promise) {
207
+ if (geography == 0) {
208
+ consentInformation.setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_DISABLED);
209
+ } else if (geography == 1) {
210
+ consentInformation.setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_EEA);
211
+ } else if (geography == 2) {
212
+ consentInformation.setDebugGeography(DebugGeography.DEBUG_GEOGRAPHY_NOT_EEA);
213
+ }
214
+
215
+ promise.resolve(null);
216
+ }
217
+
218
+ @ReactMethod
219
+ public void addTestDevices(ReadableArray deviceIds, Promise promise) {
220
+ List<Object> devices = deviceIds.toArrayList();
221
+ for (Object device : devices) {
222
+ consentInformation.addTestDevice((String) device);
223
+ }
224
+ promise.resolve(null);
225
+ }
226
+ }
@@ -0,0 +1,72 @@
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 com.facebook.react.bridge.Arguments;
21
+ import com.facebook.react.bridge.WritableMap;
22
+ import io.invertase.googlemobileads.interfaces.NativeEvent;
23
+
24
+ public class ReactNativeGoogleMobileAdsEvent implements NativeEvent {
25
+ public static final String GOOGLE_MOBILE_ADS_EVENT_APP_OPEN = "google_mobile_ads_app_open_event";
26
+ public static final String GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL =
27
+ "google_mobile_ads_interstitial_event";
28
+ public static final String GOOGLE_MOBILE_ADS_EVENT_REWARDED = "google_mobile_ads_rewarded_event";
29
+
30
+ public static final String GOOGLE_MOBILE_ADS_EVENT_LOADED = "loaded";
31
+ public static final String GOOGLE_MOBILE_ADS_EVENT_ERROR = "error";
32
+ public static final String GOOGLE_MOBILE_ADS_EVENT_OPENED = "opened";
33
+ public static final String GOOGLE_MOBILE_ADS_EVENT_CLICKED = "clicked";
34
+ public static final String GOOGLE_MOBILE_ADS_EVENT_CLOSED = "closed";
35
+
36
+ public static final String GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED = "rewarded_loaded";
37
+ public static final String GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD =
38
+ "rewarded_earned_reward";
39
+
40
+ private static final String KEY_BODY = "body";
41
+ private static final String KEY_REQUEST_ID = "requestId";
42
+ private static final String KEY_GOOGLE_MOBILE_ADS_EVENT_UNIT_ID = "adUnitId";
43
+ private static final String KEY_EVENT_NAME = "eventName";
44
+
45
+ private String eventName;
46
+ private int requestId;
47
+ private String adUnitId;
48
+ private WritableMap eventBody;
49
+
50
+ public ReactNativeGoogleMobileAdsEvent(
51
+ String eventName, int requestId, String adUnitId, WritableMap eventBody) {
52
+ this.eventName = eventName;
53
+ this.requestId = requestId;
54
+ this.adUnitId = adUnitId;
55
+ this.eventBody = eventBody;
56
+ }
57
+
58
+ @Override
59
+ public String getEventName() {
60
+ return eventName;
61
+ }
62
+
63
+ @Override
64
+ public WritableMap getEventBody() {
65
+ WritableMap event = Arguments.createMap();
66
+ event.putMap(KEY_BODY, eventBody);
67
+ event.putInt(KEY_REQUEST_ID, requestId);
68
+ event.putString(KEY_GOOGLE_MOBILE_ADS_EVENT_UNIT_ID, adUnitId);
69
+ event.putString(KEY_EVENT_NAME, eventName);
70
+ return event;
71
+ }
72
+ }
@@ -0,0 +1,159 @@
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_CLICKED;
23
+ import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_CLOSED;
24
+ import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_ERROR;
25
+ import static io.invertase.googlemobileads.ReactNativeGoogleMobileAdsEvent.GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL;
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 android.util.SparseArray;
31
+ import androidx.annotation.NonNull;
32
+ import com.facebook.react.bridge.Arguments;
33
+ import com.facebook.react.bridge.Promise;
34
+ import com.facebook.react.bridge.ReactApplicationContext;
35
+ import com.facebook.react.bridge.ReactMethod;
36
+ import com.facebook.react.bridge.ReadableMap;
37
+ import com.facebook.react.bridge.WritableMap;
38
+ import com.google.android.gms.ads.AdRequest;
39
+ import com.google.android.gms.ads.FullScreenContentCallback;
40
+ import com.google.android.gms.ads.LoadAdError;
41
+ import com.google.android.gms.ads.interstitial.InterstitialAd;
42
+ import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
43
+ import io.invertase.googlemobileads.common.ReactNativeModule;
44
+ import javax.annotation.Nullable;
45
+
46
+ public class ReactNativeGoogleMobileAdsInterstitialModule extends ReactNativeModule {
47
+ private static final String SERVICE = "RNGoogleMobileAdsInterstitialModule";
48
+ private static SparseArray<InterstitialAd> interstitialAdArray = new SparseArray<>();
49
+
50
+ public ReactNativeGoogleMobileAdsInterstitialModule(ReactApplicationContext reactContext) {
51
+ super(reactContext, SERVICE);
52
+ }
53
+
54
+ private void sendInterstitialEvent(
55
+ String type, int requestId, String adUnitId, @Nullable WritableMap error) {
56
+ sendAdEvent(GOOGLE_MOBILE_ADS_EVENT_INTERSTITIAL, requestId, type, adUnitId, error);
57
+ }
58
+
59
+ @ReactMethod
60
+ public void interstitialLoad(int requestId, String adUnitId, ReadableMap adRequestOptions) {
61
+ Activity currentActivity = getCurrentActivity();
62
+ if (currentActivity == null) {
63
+ WritableMap error = Arguments.createMap();
64
+ error.putString("code", "null-activity");
65
+ error.putString(
66
+ "message", "Interstitial ad attempted to load but the current Activity was null.");
67
+ sendInterstitialEvent(GOOGLE_MOBILE_ADS_EVENT_ERROR, requestId, adUnitId, error);
68
+ return;
69
+ }
70
+ currentActivity.runOnUiThread(
71
+ () -> {
72
+ AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
73
+ AdRequest adRequest = adRequestBuilder.build();
74
+
75
+ InterstitialAdLoadCallback interstitialAdLoadCallback =
76
+ new InterstitialAdLoadCallback() {
77
+
78
+ @Override
79
+ public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
80
+
81
+ interstitialAd.setFullScreenContentCallback(
82
+ new FullScreenContentCallback() {
83
+ @Override
84
+ public void onAdDismissedFullScreenContent() {
85
+ sendInterstitialEvent(
86
+ GOOGLE_MOBILE_ADS_EVENT_CLOSED, requestId, adUnitId, null);
87
+ interstitialAdArray.put(requestId, null);
88
+ }
89
+
90
+ @Override
91
+ public void onAdClicked() {
92
+ sendInterstitialEvent(
93
+ GOOGLE_MOBILE_ADS_EVENT_CLICKED, requestId, adUnitId, null);
94
+ }
95
+
96
+ @Override
97
+ public void onAdShowedFullScreenContent() {
98
+ sendInterstitialEvent(
99
+ GOOGLE_MOBILE_ADS_EVENT_OPENED, requestId, adUnitId, null);
100
+ }
101
+ });
102
+
103
+ interstitialAdArray.put(requestId, interstitialAd);
104
+ sendInterstitialEvent(GOOGLE_MOBILE_ADS_EVENT_LOADED, requestId, adUnitId, null);
105
+ }
106
+
107
+ @Override
108
+ public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
109
+ WritableMap error = Arguments.createMap();
110
+ String[] codeAndMessage = getCodeAndMessageFromAdError(loadAdError);
111
+ error.putString("code", codeAndMessage[0]);
112
+ error.putString("message", codeAndMessage[1]);
113
+ sendInterstitialEvent(GOOGLE_MOBILE_ADS_EVENT_ERROR, requestId, adUnitId, error);
114
+ }
115
+ };
116
+
117
+ InterstitialAd.load(currentActivity, adUnitId, adRequest, interstitialAdLoadCallback);
118
+ });
119
+ }
120
+
121
+ @ReactMethod
122
+ public void interstitialShow(int requestId, ReadableMap showOptions, Promise promise) {
123
+ if (getCurrentActivity() == null) {
124
+ rejectPromiseWithCodeAndMessage(
125
+ promise,
126
+ "null-activity",
127
+ "Interstitial ad attempted to show but the current Activity was null.");
128
+ return;
129
+ }
130
+ getCurrentActivity()
131
+ .runOnUiThread(
132
+ () -> {
133
+ InterstitialAd interstitialAd = interstitialAdArray.get(requestId);
134
+ if (interstitialAd == null) {
135
+ rejectPromiseWithCodeAndMessage(
136
+ promise,
137
+ "null-interstitialAd",
138
+ "Interstitial ad attempted to show but its object was null.");
139
+ return;
140
+ }
141
+
142
+ if (showOptions.hasKey("immersiveModeEnabled")) {
143
+ interstitialAd.setImmersiveMode(showOptions.getBoolean("immersiveModeEnabled"));
144
+ } else {
145
+ interstitialAd.setImmersiveMode(false);
146
+ }
147
+
148
+ String a = String.valueOf(requestId);
149
+
150
+ if (interstitialAd != null) {
151
+ interstitialAd.show(getCurrentActivity());
152
+ promise.resolve(null);
153
+ } else {
154
+ rejectPromiseWithCodeAndMessage(
155
+ promise, "not-ready", "Interstitial ad attempted to show but was not ready.");
156
+ }
157
+ });
158
+ }
159
+ }
@@ -0,0 +1,143 @@
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 com.facebook.react.bridge.Arguments;
21
+ import com.facebook.react.bridge.Promise;
22
+ import com.facebook.react.bridge.ReactApplicationContext;
23
+ import com.facebook.react.bridge.ReactMethod;
24
+ import com.facebook.react.bridge.ReadableMap;
25
+ import com.facebook.react.bridge.WritableArray;
26
+ import com.facebook.react.bridge.WritableMap;
27
+ import com.google.android.gms.ads.AdRequest;
28
+ import com.google.android.gms.ads.MobileAds;
29
+ import com.google.android.gms.ads.RequestConfiguration;
30
+ import com.google.android.gms.ads.initialization.AdapterStatus;
31
+ import com.google.android.gms.ads.initialization.InitializationStatus;
32
+ import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
33
+ import io.invertase.googlemobileads.common.ReactNativeModule;
34
+ import java.util.ArrayList;
35
+ import java.util.List;
36
+ import java.util.Map;
37
+ import java.util.Objects;
38
+
39
+ public class ReactNativeGoogleMobileAdsModule extends ReactNativeModule {
40
+ private static final String SERVICE = "RNGoogleMobileAdsModule";
41
+
42
+ ReactNativeGoogleMobileAdsModule(ReactApplicationContext reactContext) {
43
+ super(reactContext, SERVICE);
44
+ }
45
+
46
+ private RequestConfiguration buildRequestConfiguration(ReadableMap requestConfiguration) {
47
+ RequestConfiguration.Builder builder = new RequestConfiguration.Builder();
48
+
49
+ if (requestConfiguration.hasKey("testDeviceIdentifiers")) {
50
+ ArrayList<Object> devices =
51
+ Objects.requireNonNull(requestConfiguration.getArray("testDeviceIdentifiers"))
52
+ .toArrayList();
53
+
54
+ List<String> testDeviceIds = new ArrayList<>();
55
+
56
+ for (Object device : devices) {
57
+ String id = (String) device;
58
+
59
+ if (id.equals("EMULATOR")) {
60
+ testDeviceIds.add(AdRequest.DEVICE_ID_EMULATOR);
61
+ } else {
62
+ testDeviceIds.add(id);
63
+ }
64
+ }
65
+ builder.setTestDeviceIds(testDeviceIds);
66
+ }
67
+
68
+ if (requestConfiguration.hasKey("maxAdContentRating")) {
69
+ String rating = requestConfiguration.getString("maxAdContentRating");
70
+
71
+ switch (Objects.requireNonNull(rating)) {
72
+ case "G":
73
+ builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_G);
74
+ break;
75
+ case "PG":
76
+ builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_PG);
77
+ break;
78
+ case "T":
79
+ builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_T);
80
+ break;
81
+ case "MA":
82
+ builder.setMaxAdContentRating(RequestConfiguration.MAX_AD_CONTENT_RATING_MA);
83
+ break;
84
+ }
85
+ }
86
+
87
+ if (requestConfiguration.hasKey("tagForChildDirectedTreatment")) {
88
+ boolean tagForChildDirectedTreatment =
89
+ requestConfiguration.getBoolean("tagForChildDirectedTreatment");
90
+ if (tagForChildDirectedTreatment) {
91
+ builder.setTagForChildDirectedTreatment(
92
+ RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE);
93
+ } else {
94
+ builder.setTagForChildDirectedTreatment(
95
+ RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE);
96
+ }
97
+ } else {
98
+ builder.setTagForChildDirectedTreatment(
99
+ RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_UNSPECIFIED);
100
+ }
101
+
102
+ if (requestConfiguration.hasKey("tagForUnderAgeOfConsent")) {
103
+ boolean tagForUnderAgeOfConsent = requestConfiguration.getBoolean("tagForUnderAgeOfConsent");
104
+ if (tagForUnderAgeOfConsent) {
105
+ builder.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE);
106
+ } else {
107
+ builder.setTagForUnderAgeOfConsent(RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE);
108
+ }
109
+ } else {
110
+ builder.setTagForUnderAgeOfConsent(
111
+ RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_UNSPECIFIED);
112
+ }
113
+
114
+ return builder.build();
115
+ }
116
+
117
+ @ReactMethod
118
+ public void initialize(Promise promise) {
119
+ MobileAds.initialize(
120
+ getContext(),
121
+ new OnInitializationCompleteListener() {
122
+ @Override
123
+ public void onInitializationComplete(InitializationStatus initializationStatus) {
124
+ WritableArray result = Arguments.createArray();
125
+ for (Map.Entry<String, AdapterStatus> entry :
126
+ initializationStatus.getAdapterStatusMap().entrySet()) {
127
+ WritableMap info = Arguments.createMap();
128
+ info.putString("name", entry.getKey());
129
+ info.putInt("state", entry.getValue().getInitializationState().ordinal());
130
+ info.putString("description", entry.getValue().getDescription());
131
+ result.pushMap(info);
132
+ }
133
+ promise.resolve(result);
134
+ }
135
+ });
136
+ }
137
+
138
+ @ReactMethod
139
+ public void setRequestConfiguration(ReadableMap requestConfiguration, Promise promise) {
140
+ MobileAds.setRequestConfiguration(buildRequestConfiguration(requestConfiguration));
141
+ promise.resolve(null);
142
+ }
143
+ }
@@ -0,0 +1,48 @@
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 com.facebook.react.ReactPackage;
21
+ import com.facebook.react.bridge.NativeModule;
22
+ import com.facebook.react.bridge.ReactApplicationContext;
23
+ import com.facebook.react.uimanager.ViewManager;
24
+ import java.util.ArrayList;
25
+ import java.util.Arrays;
26
+ import java.util.List;
27
+ import javax.annotation.Nonnull;
28
+
29
+ @SuppressWarnings("unused")
30
+ public class ReactNativeGoogleMobileAdsPackage implements ReactPackage {
31
+ @Override
32
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
33
+ List<NativeModule> modules = new ArrayList<>();
34
+ modules.add(new ReactNativeAppModule(reactContext));
35
+ modules.add(new ReactNativeGoogleMobileAdsModule(reactContext));
36
+ modules.add(new ReactNativeGoogleMobileAdsConsentModule(reactContext));
37
+ modules.add(new ReactNativeGoogleMobileAdsAppOpenModule(reactContext));
38
+ modules.add(new ReactNativeGoogleMobileAdsInterstitialModule(reactContext));
39
+ modules.add(new ReactNativeGoogleMobileAdsRewardedModule(reactContext));
40
+ return modules;
41
+ }
42
+
43
+ @Nonnull
44
+ @Override
45
+ public List<ViewManager> createViewManagers(@Nonnull ReactApplicationContext reactContext) {
46
+ return Arrays.asList(new ReactNativeGoogleMobileAdsBannerAdViewManager());
47
+ }
48
+ }