react-native-google-mobile-ads 5.1.1 → 6.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/__tests__/interstitial.test.ts +32 -5
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsAppOpenModule.java +2 -1
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsBannerAdViewManager.java +110 -68
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java +5 -11
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsEvent.java +3 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsInterstitialModule.java +38 -20
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsModule.java +45 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsPackage.java +1 -0
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsRewardedInterstitialModule.java +199 -0
- package/docs/ad-inspector.mdx +39 -0
- package/docs/displaying-ads-hook.mdx +1 -1
- package/docs/displaying-ads.mdx +178 -26
- package/docs/migrating-to-v6.mdx +111 -0
- package/docs.json +3 -1
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsAppOpenModule.m +1 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerViewManager.m +63 -8
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h +4 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +10 -7
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.h +2 -1
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsFullScreenContentDelegate.m +17 -2
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsInterstitialModule.m +44 -30
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsModule.m +19 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.h +25 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.m +173 -0
- package/lib/commonjs/AdEventType.js.map +1 -1
- package/lib/commonjs/GAMAdEventType.js +30 -0
- package/lib/commonjs/GAMAdEventType.js.map +1 -0
- package/lib/commonjs/MobileAds.js +9 -2
- package/lib/commonjs/MobileAds.js.map +1 -1
- package/lib/commonjs/RewardedAdEventType.js.map +1 -1
- package/lib/commonjs/TestIds.js +11 -2
- package/lib/commonjs/TestIds.js.map +1 -1
- package/lib/commonjs/ads/AppOpenAd.js +8 -53
- package/lib/commonjs/ads/AppOpenAd.js.map +1 -1
- package/lib/commonjs/ads/BannerAd.js +7 -110
- package/lib/commonjs/ads/BannerAd.js.map +1 -1
- package/lib/commonjs/ads/BaseAd.js +144 -0
- package/lib/commonjs/ads/BaseAd.js.map +1 -0
- package/lib/commonjs/ads/GAMBannerAd.js +42 -0
- package/lib/commonjs/ads/GAMBannerAd.js.map +1 -0
- package/lib/commonjs/ads/GAMInterstitialAd.js +48 -0
- package/lib/commonjs/ads/GAMInterstitialAd.js.map +1 -0
- package/lib/commonjs/ads/InterstitialAd.js +13 -64
- package/lib/commonjs/ads/InterstitialAd.js.map +1 -1
- package/lib/commonjs/ads/MobileAd.js +131 -12
- package/lib/commonjs/ads/MobileAd.js.map +1 -1
- package/lib/commonjs/ads/RewardedAd.js +23 -65
- package/lib/commonjs/ads/RewardedAd.js.map +1 -1
- package/lib/commonjs/ads/RewardedInterstitialAd.js +127 -0
- package/lib/commonjs/ads/RewardedInterstitialAd.js.map +1 -0
- package/lib/commonjs/hooks/useAppOpenAd.js.map +1 -1
- package/lib/commonjs/hooks/useFullScreenAd.js +9 -4
- package/lib/commonjs/hooks/useFullScreenAd.js.map +1 -1
- package/lib/commonjs/hooks/useInterstitialAd.js.map +1 -1
- package/lib/commonjs/hooks/useRewardedAd.js.map +1 -1
- package/lib/commonjs/hooks/useRewardedInterstitialAd.js +51 -0
- package/lib/commonjs/hooks/useRewardedInterstitialAd.js.map +1 -0
- package/lib/commonjs/index.js +80 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/AdEventsListener.js +6 -0
- package/lib/commonjs/types/AdEventsListener.js.map +1 -0
- package/lib/commonjs/types/AppEvent.js +2 -0
- package/lib/commonjs/types/AppEvent.js.map +1 -0
- package/lib/commonjs/types/index.js +149 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/validateAdRequestOptions.js +0 -38
- package/lib/commonjs/validateAdRequestOptions.js.map +1 -1
- package/lib/commonjs/version.js +2 -2
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/AdEventType.js.map +1 -1
- package/lib/module/GAMAdEventType.js +22 -0
- package/lib/module/GAMAdEventType.js.map +1 -0
- package/lib/module/MobileAds.js +9 -2
- package/lib/module/MobileAds.js.map +1 -1
- package/lib/module/RewardedAdEventType.js.map +1 -1
- package/lib/module/TestIds.js +11 -2
- package/lib/module/TestIds.js.map +1 -1
- package/lib/module/ads/AppOpenAd.js +10 -37
- package/lib/module/ads/AppOpenAd.js.map +1 -1
- package/lib/module/ads/BannerAd.js +7 -85
- package/lib/module/ads/BannerAd.js.map +1 -1
- package/lib/module/ads/BaseAd.js +124 -0
- package/lib/module/ads/BaseAd.js.map +1 -0
- package/lib/module/ads/GAMBannerAd.js +42 -0
- package/lib/module/ads/GAMBannerAd.js.map +1 -0
- package/lib/module/ads/GAMInterstitialAd.js +38 -0
- package/lib/module/ads/GAMInterstitialAd.js.map +1 -0
- package/lib/module/ads/InterstitialAd.js +15 -48
- package/lib/module/ads/InterstitialAd.js.map +1 -1
- package/lib/module/ads/MobileAd.js +128 -12
- package/lib/module/ads/MobileAd.js.map +1 -1
- package/lib/module/ads/RewardedAd.js +24 -49
- package/lib/module/ads/RewardedAd.js.map +1 -1
- package/lib/module/ads/RewardedInterstitialAd.js +130 -0
- package/lib/module/ads/RewardedInterstitialAd.js.map +1 -0
- package/lib/module/hooks/useAppOpenAd.js.map +1 -1
- package/lib/module/hooks/useFullScreenAd.js +9 -4
- package/lib/module/hooks/useFullScreenAd.js.map +1 -1
- package/lib/module/hooks/useInterstitialAd.js.map +1 -1
- package/lib/module/hooks/useRewardedAd.js.map +1 -1
- package/lib/module/hooks/useRewardedInterstitialAd.js +38 -0
- package/lib/module/hooks/useRewardedInterstitialAd.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/AdEventsListener.js +2 -0
- package/lib/module/types/AdEventsListener.js.map +1 -0
- package/lib/module/types/AppEvent.js +2 -0
- package/lib/module/types/AppEvent.js.map +1 -0
- package/lib/module/types/index.js +28 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/validateAdRequestOptions.js +1 -39
- package/lib/module/validateAdRequestOptions.js.map +1 -1
- package/lib/module/version.js +2 -2
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/AdEventType.d.ts +4 -8
- package/lib/typescript/GAMAdEventType.d.ts +20 -0
- package/lib/typescript/MobileAds.d.ts +2 -1
- package/lib/typescript/RewardedAdEventType.d.ts +7 -11
- package/lib/typescript/TestIds.d.ts +7 -0
- package/lib/typescript/ads/AppOpenAd.d.ts +6 -6
- package/lib/typescript/ads/BannerAd.d.ts +1 -1
- package/lib/typescript/ads/BaseAd.d.ts +35 -0
- package/lib/typescript/ads/GAMBannerAd.d.ts +7 -0
- package/lib/typescript/ads/GAMInterstitialAd.d.ts +33 -0
- package/lib/typescript/ads/InterstitialAd.d.ts +10 -16
- package/lib/typescript/ads/MobileAd.d.ts +35 -16
- package/lib/typescript/ads/RewardedAd.d.ts +17 -19
- package/lib/typescript/ads/RewardedInterstitialAd.d.ts +82 -0
- package/lib/typescript/hooks/useAppOpenAd.d.ts +1 -1
- package/lib/typescript/hooks/useFullScreenAd.d.ts +2 -1
- package/lib/typescript/hooks/useInterstitialAd.d.ts +1 -1
- package/lib/typescript/hooks/useRewardedAd.d.ts +1 -1
- package/lib/typescript/hooks/useRewardedInterstitialAd.d.ts +9 -0
- package/lib/typescript/index.d.ts +7 -1
- package/lib/typescript/types/AdEventListener.d.ts +5 -9
- package/lib/typescript/types/AdEventsListener.d.ts +8 -0
- package/lib/typescript/types/AppEvent.d.ts +13 -0
- package/lib/typescript/types/BannerAdProps.d.ts +81 -4
- package/lib/typescript/types/GoogleMobileAdsNativeModule.d.ts +12 -6
- package/lib/typescript/types/MobileAd.interface.d.ts +37 -12
- package/lib/typescript/types/MobileAdsModule.interface.d.ts +9 -0
- package/lib/typescript/types/RequestOptions.d.ts +0 -22
- package/lib/typescript/types/index.d.ts +11 -0
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +50 -49
- package/src/AdEventType.ts +4 -8
- package/src/GAMAdEventType.ts +37 -0
- package/src/MobileAds.ts +13 -0
- package/src/RewardedAdEventType.ts +7 -11
- package/src/TestIds.ts +9 -0
- package/src/ads/AppOpenAd.ts +11 -41
- package/src/ads/BannerAd.tsx +4 -106
- package/src/ads/BaseAd.tsx +156 -0
- package/src/ads/GAMBannerAd.tsx +37 -0
- package/src/ads/GAMInterstitialAd.ts +45 -0
- package/src/ads/InterstitialAd.ts +15 -56
- package/src/ads/MobileAd.ts +153 -30
- package/src/ads/RewardedAd.ts +29 -55
- package/src/ads/RewardedInterstitialAd.ts +143 -0
- package/src/hooks/useAppOpenAd.ts +1 -1
- package/src/hooks/useFullScreenAd.ts +9 -7
- package/src/hooks/useInterstitialAd.ts +1 -1
- package/src/hooks/useRewardedAd.ts +1 -1
- package/src/hooks/useRewardedInterstitialAd.ts +47 -0
- package/src/index.ts +6 -0
- package/src/types/AdEventListener.ts +31 -13
- package/src/types/AdEventsListener.ts +24 -0
- package/src/types/AppEvent.ts +14 -0
- package/src/types/BannerAdProps.ts +81 -4
- package/src/types/GoogleMobileAdsNativeModule.ts +16 -6
- package/src/types/MobileAd.interface.ts +56 -12
- package/src/types/MobileAdsModule.interface.ts +10 -0
- package/src/types/RequestOptions.ts +0 -24
- package/src/types/index.ts +28 -0
- package/src/validateAdRequestOptions.ts +0 -45
- package/src/version.ts +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["BaseAd.tsx"],"names":["React","useState","useEffect","requireNativeComponent","isFunction","NativeError","BannerAdSize","validateAdRequestOptions","sizeRegex","BaseAd","forwardRef","ref","unitId","sizes","requestOptions","manualImpressionsEnabled","props","dimensions","setDimensions","Error","length","every","size","test","parsedRequestOptions","JSON","stringify","e","message","onNativeEvent","nativeEvent","type","eventHandler","eventPayload","width","height","fromEvent","name","data","style","includes","FLUID","displayName","GoogleMobileAdsBannerView"],"mappings":"AAAA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,QAA2C,OAA3C;AACA,SAAwBC,sBAAxB,QAAsD,cAAtD;AACA,SAASC,UAAT,QAA2B,WAA3B;AACA,SAASC,WAAT,QAA4B,yBAA5B;AACA,SAASC,YAAT,QAA6B,iBAA7B;AACA,SAASC,wBAAT,QAAyC,6BAAzC;AAsBA,MAAMC,SAAS,GAAG,mBAAlB;AAEA,OAAO,MAAMC,MAAM,gBAAGT,KAAK,CAACU,UAAN,CACpB,OAAwEC,GAAxE,KAAgF;AAAA,MAA/E;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,KAAV;AAAiBC,IAAAA,cAAjB;AAAiCC,IAAAA,wBAAjC;AAA2D,OAAGC;AAA9D,GAA+E;AAC9E,QAAM,CAACC,UAAD,EAAaC,aAAb,IAA8BjB,QAAQ,CAAsB,CAAC,CAAD,EAAI,CAAJ,CAAtB,CAA5C;AAEAC,EAAAA,SAAS,CAAC,MAAM;AACd,QAAI,CAACU,MAAL,EAAa;AACX,YAAM,IAAIO,KAAJ,CAAU,qDAAV,CAAN;AACD;AACF,GAJQ,EAIN,CAACP,MAAD,CAJM,CAAT;AAMAV,EAAAA,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Aa,EAAEc;AAPjB,IADF;AAWD,CAzFmB,CAAf;AA2FPpB,MAAM,CAACiC,WAAP,GAAqB,QAArB;AAcA,MAAMC,yBAAyB,GAAGxC,sBAAsB,CACtD,6BADsD,CAAxD","sourcesContent":["/* eslint-disable react/prop-types */\n/*\n * Copyright (c) 2016-present Invertase Limited & Contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this library except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport React, { useState, useEffect } from 'react';\nimport { NativeMethods, requireNativeComponent } from 'react-native';\nimport { isFunction } from '../common';\nimport { NativeError } from '../internal/NativeError';\nimport { BannerAdSize } from '../BannerAdSize';\nimport { validateAdRequestOptions } from '../validateAdRequestOptions';\nimport { GAMBannerAdProps } from '../types/BannerAdProps';\nimport { RequestOptions } from '../types/RequestOptions';\n\ntype NativeEvent =\n | {\n type: 'onAdLoaded' | 'onSizeChange';\n width: number;\n height: number;\n }\n | { type: 'onAdOpened' | 'onAdClosed' }\n | {\n type: 'onAdFailedToLoad';\n code: string;\n message: string;\n }\n | {\n type: 'onAppEvent';\n name: string;\n data?: string;\n };\n\nconst sizeRegex = /([0-9]+)x([0-9]+)/;\n\nexport const BaseAd = React.forwardRef<GoogleMobileAdsBannerView, GAMBannerAdProps>(\n ({ unitId, sizes, requestOptions, manualImpressionsEnabled, ...props }, ref) => {\n const [dimensions, setDimensions] = useState<(number | string)[]>([0, 0]);\n\n useEffect(() => {\n if (!unitId) {\n throw new Error(\"BannerAd: 'unitId' expected a valid string unit ID.\");\n }\n }, [unitId]);\n\n useEffect(() => {\n if (\n sizes.length === 0 ||\n !sizes.every(size => size in BannerAdSize || sizeRegex.test(size))\n ) {\n throw new Error(\"BannerAd: 'size(s)' expected a valid BannerAdSize or custom size string.\");\n }\n }, [sizes]);\n\n const parsedRequestOptions = JSON.stringify(requestOptions);\n\n useEffect(() => {\n if (requestOptions) {\n try {\n validateAdRequestOptions(requestOptions);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`BannerAd: ${e.message}`);\n }\n }\n }\n }, [parsedRequestOptions]);\n\n function onNativeEvent({ nativeEvent }: { nativeEvent: NativeEvent }) {\n const { type } = nativeEvent;\n\n if (type !== 'onSizeChange' && isFunction(props[type])) {\n let eventHandler, eventPayload;\n switch (type) {\n case 'onAdLoaded':\n eventPayload = {\n width: nativeEvent.width,\n height: nativeEvent.height,\n };\n if ((eventHandler = props[type])) eventHandler(eventPayload);\n break;\n case 'onAdFailedToLoad':\n eventPayload = NativeError.fromEvent(nativeEvent, 'googleMobileAds');\n if ((eventHandler = props[type])) eventHandler(eventPayload);\n break;\n case 'onAppEvent':\n eventPayload = {\n name: nativeEvent.name,\n data: nativeEvent.data,\n };\n if ((eventHandler = props[type])) eventHandler(eventPayload);\n break;\n default:\n if ((eventHandler = props[type])) eventHandler();\n }\n }\n\n if (type === 'onAdLoaded' || type === 'onSizeChange') {\n const { width, height } = nativeEvent;\n if (width && height) setDimensions([width, height]);\n }\n }\n\n const style = sizes.includes(BannerAdSize.FLUID)\n ? {\n width: '100%',\n height: dimensions[1],\n }\n : {\n width: dimensions[0],\n height: dimensions[1],\n };\n\n return (\n <GoogleMobileAdsBannerView\n ref={ref}\n sizes={sizes}\n style={style}\n unitId={unitId}\n request={validateAdRequestOptions(requestOptions)}\n manualImpressionsEnabled={!!manualImpressionsEnabled}\n onNativeEvent={onNativeEvent}\n />\n );\n },\n);\nBaseAd.displayName = 'BaseAd';\n\ninterface NativeBannerProps {\n sizes: GAMBannerAdProps['sizes'];\n style: {\n width?: number | string;\n height?: number | string;\n };\n unitId: string;\n request: RequestOptions;\n manualImpressionsEnabled: boolean;\n onNativeEvent: (event: { nativeEvent: NativeEvent }) => void;\n}\n\nconst GoogleMobileAdsBannerView = requireNativeComponent<NativeBannerProps>(\n 'RNGoogleMobileAdsBannerView',\n);\nexport type GoogleMobileAdsBannerView = React.Component<NativeBannerProps> & NativeMethods;\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this library except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
import React, { createRef } from 'react';
|
|
22
|
+
import { findNodeHandle, UIManager } from 'react-native';
|
|
23
|
+
import { BaseAd } from './BaseAd';
|
|
24
|
+
export class GAMBannerAd extends React.Component {
|
|
25
|
+
constructor() {
|
|
26
|
+
super(...arguments);
|
|
27
|
+
|
|
28
|
+
_defineProperty(this, "ref", /*#__PURE__*/createRef());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
recordManualImpression() {
|
|
32
|
+
UIManager.dispatchViewManagerCommand(findNodeHandle(this.ref.current), 'recordManualImpression', undefined);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
render() {
|
|
36
|
+
return /*#__PURE__*/React.createElement(BaseAd, _extends({
|
|
37
|
+
ref: this.ref
|
|
38
|
+
}, this.props));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=GAMBannerAd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["GAMBannerAd.tsx"],"names":["React","createRef","findNodeHandle","UIManager","BaseAd","GAMBannerAd","Component","recordManualImpression","dispatchViewManagerCommand","ref","current","undefined","render","props"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,KAAP,IAAgBC,SAAhB,QAAiC,OAAjC;AACA,SAASC,cAAT,EAAyBC,SAAzB,QAA0C,cAA1C;AAEA,SAASC,MAAT,QAAkD,UAAlD;AAEA,OAAO,MAAMC,WAAN,SAA0BL,KAAK,CAACM,SAAhC,CAA4D;AAAA;AAAA;;AAAA,8CACnDL,SAAS,EAD0C;AAAA;;AAGjEM,EAAAA,sBAAsB,GAAG;AACvBJ,IAAAA,SAAS,CAACK,0BAAV,CACEN,cAAc,CAAC,KAAKO,GAAL,CAASC,OAAV,CADhB,EAEE,wBAFF,EAGEC,SAHF;AAKD;;AAEDC,EAAAA,MAAM,GAAG;AACP,wBAAO,oBAAC,MAAD;AAAQ,MAAA,GAAG,EAAE,KAAKH;AAAlB,OAA2B,KAAKI,KAAhC,EAAP;AACD;;AAbgE","sourcesContent":["/*\n * Copyright (c) 2016-present Invertase Limited & Contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this library except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport React, { createRef } from 'react';\nimport { findNodeHandle, UIManager } from 'react-native';\nimport { GAMBannerAdProps } from '../types/BannerAdProps';\nimport { BaseAd, GoogleMobileAdsBannerView } from './BaseAd';\n\nexport class GAMBannerAd extends React.Component<GAMBannerAdProps> {\n private ref = createRef<GoogleMobileAdsBannerView>();\n\n recordManualImpression() {\n UIManager.dispatchViewManagerCommand(\n findNodeHandle(this.ref.current),\n 'recordManualImpression',\n undefined,\n );\n }\n\n render() {\n return <BaseAd ref={this.ref} {...this.props} />;\n }\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { InterstitialAd } from './InterstitialAd';
|
|
2
|
+
export class GAMInterstitialAd extends InterstitialAd {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new GAMInterstitialAd instance.
|
|
5
|
+
*
|
|
6
|
+
* #### Example
|
|
7
|
+
*
|
|
8
|
+
* ```js
|
|
9
|
+
* import { GAMInterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads';
|
|
10
|
+
*
|
|
11
|
+
* const interstitialAd = await GAMInterstitialAd.createForAdRequest(TestIds.GAM_INTERSTITIAL, {
|
|
12
|
+
* requestAgent: 'CoolAds',
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* interstitialAd.addAdEventListener(AdEventType.Loaded, () => {
|
|
16
|
+
* interstitialAd.show();
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* interstitialAd.load();
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param adUnitId The Ad Unit ID for the Interstitial. You can find this on your Google Mobile Ads dashboard.
|
|
23
|
+
* @param requestOptions Optional RequestOptions used to load the ad.
|
|
24
|
+
*/
|
|
25
|
+
static createForAdRequest(adUnitId, requestOptions) {
|
|
26
|
+
return super.createForAdRequest(adUnitId, requestOptions);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
addAdEventsListener(listener) {
|
|
30
|
+
return this._addAdEventsListener(listener);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
addAdEventListener(type, listener) {
|
|
34
|
+
return this._addAdEventListener(type, listener);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=GAMInterstitialAd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["GAMInterstitialAd.ts"],"names":["InterstitialAd","GAMInterstitialAd","createForAdRequest","adUnitId","requestOptions","addAdEventsListener","listener","_addAdEventsListener","addAdEventListener","type","_addAdEventListener"],"mappings":"AAKA,SAASA,cAAT,QAA+B,kBAA/B;AAEA,OAAO,MAAMC,iBAAN,SAAgCD,cAAhC,CAA+C;AACpD;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC2B,SAAlBE,kBAAkB,CAACC,QAAD,EAAmBC,cAAnB,EAAoD;AAC3E,WAAO,MAAMF,kBAAN,CAAyBC,QAAzB,EAAmCC,cAAnC,CAAP;AACD;;AAEDC,EAAAA,mBAAmB,CAAyCC,QAAzC,EAAwE;AACzF,WAAO,KAAKC,oBAAL,CAA0BD,QAA1B,CAAP;AACD;;AAEDE,EAAAA,kBAAkB,CAChBC,IADgB,EAEhBH,QAFgB,EAGhB;AACA,WAAO,KAAKI,mBAAL,CAAyBD,IAAzB,EAA+BH,QAA/B,CAAP;AACD;;AApCmD","sourcesContent":["import { AdEventType } from '../AdEventType';\nimport { GAMAdEventType } from '../GAMAdEventType';\nimport { AdEventListener } from '../types/AdEventListener';\nimport { AdEventsListener } from '../types/AdEventsListener';\nimport { RequestOptions } from '../types/RequestOptions';\nimport { InterstitialAd } from './InterstitialAd';\n\nexport class GAMInterstitialAd extends InterstitialAd {\n /**\n * Creates a new GAMInterstitialAd instance.\n *\n * #### Example\n *\n * ```js\n * import { GAMInterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads';\n *\n * const interstitialAd = await GAMInterstitialAd.createForAdRequest(TestIds.GAM_INTERSTITIAL, {\n * requestAgent: 'CoolAds',\n * });\n *\n * interstitialAd.addAdEventListener(AdEventType.Loaded, () => {\n * interstitialAd.show();\n * });\n *\n * interstitialAd.load();\n * ```\n *\n * @param adUnitId The Ad Unit ID for the Interstitial. You can find this on your Google Mobile Ads dashboard.\n * @param requestOptions Optional RequestOptions used to load the ad.\n */\n static createForAdRequest(adUnitId: string, requestOptions?: RequestOptions) {\n return super.createForAdRequest(adUnitId, requestOptions) as GAMInterstitialAd;\n }\n\n addAdEventsListener<T extends AdEventType | GAMAdEventType>(listener: AdEventsListener<T>) {\n return this._addAdEventsListener(listener);\n }\n\n addAdEventListener<T extends AdEventType | GAMAdEventType>(\n type: T,\n listener: AdEventListener<T>,\n ) {\n return this._addAdEventListener(type, listener);\n }\n}\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
1
3
|
/*
|
|
2
4
|
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
5
|
*
|
|
@@ -14,12 +16,11 @@
|
|
|
14
16
|
* limitations under the License.
|
|
15
17
|
*
|
|
16
18
|
*/
|
|
17
|
-
import {
|
|
19
|
+
import { isString } from '../common';
|
|
18
20
|
import { MobileAds } from '../MobileAds';
|
|
19
21
|
import { validateAdRequestOptions } from '../validateAdRequestOptions';
|
|
20
|
-
import { validateAdShowOptions } from '../validateAdShowOptions';
|
|
21
22
|
import { MobileAd } from './MobileAd';
|
|
22
|
-
|
|
23
|
+
|
|
23
24
|
/**
|
|
24
25
|
* A class for interacting and showing Interstitial Ads.
|
|
25
26
|
*
|
|
@@ -49,10 +50,8 @@ let _interstitialRequest = 0;
|
|
|
49
50
|
* ```js
|
|
50
51
|
* import { AdEventType } from 'react-native-google-mobile-ads';
|
|
51
52
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* interstitial.show();
|
|
55
|
-
* }
|
|
53
|
+
* interstitialAd.addAdEventListener(AdEventType.Loaded, () => {
|
|
54
|
+
* interstitialAd.show();
|
|
56
55
|
* });
|
|
57
56
|
*
|
|
58
57
|
* interstitial.load();
|
|
@@ -61,7 +60,6 @@ let _interstitialRequest = 0;
|
|
|
61
60
|
* The advert will be presented to the user, and several more events can be triggered such as the user clicking the
|
|
62
61
|
* advert or closing it.
|
|
63
62
|
*/
|
|
64
|
-
|
|
65
63
|
export class InterstitialAd extends MobileAd {
|
|
66
64
|
/**
|
|
67
65
|
* Creates a new InterstitialAd instance.
|
|
@@ -75,12 +73,8 @@ export class InterstitialAd extends MobileAd {
|
|
|
75
73
|
* requestAgent: 'CoolAds',
|
|
76
74
|
* });
|
|
77
75
|
*
|
|
78
|
-
* interstitialAd.
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* if (type === AdEventType.LOADED) {
|
|
82
|
-
* interstitialAd.show();
|
|
83
|
-
* }
|
|
76
|
+
* interstitialAd.addAdEventListener(AdEventType.Loaded, () => {
|
|
77
|
+
* interstitialAd.show();
|
|
84
78
|
* });
|
|
85
79
|
*
|
|
86
80
|
* interstitialAd.load();
|
|
@@ -104,46 +98,19 @@ export class InterstitialAd extends MobileAd {
|
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
|
|
107
|
-
const requestId = _interstitialRequest++;
|
|
101
|
+
const requestId = InterstitialAd._interstitialRequest++;
|
|
108
102
|
return new InterstitialAd('interstitial', MobileAds(), requestId, adUnitId, options);
|
|
109
103
|
}
|
|
110
104
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (this._loaded || this._isLoadCalled) {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
this._isLoadCalled = true;
|
|
118
|
-
|
|
119
|
-
this._googleMobileAds.native.interstitialLoad(this._requestId, this._adUnitId, this._requestOptions);
|
|
105
|
+
addAdEventsListener(listener) {
|
|
106
|
+
return this._addAdEventsListener(listener);
|
|
120
107
|
}
|
|
121
108
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
throw new Error("InterstitialAd.onAdEvent(*) 'handler' expected a function.");
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return this._setAdEventHandler(handler);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
show(showOptions) {
|
|
131
|
-
if (!this._loaded) {
|
|
132
|
-
throw new Error('InterstitialAd.show() The requested InterstitialAd has not loaded and could not be shown.');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
let options;
|
|
136
|
-
|
|
137
|
-
try {
|
|
138
|
-
options = validateAdShowOptions(showOptions);
|
|
139
|
-
} catch (e) {
|
|
140
|
-
if (e instanceof Error) {
|
|
141
|
-
throw new Error(`InterstitialAd.show(*) ${e.message}.`);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return this._googleMobileAds.native.interstitialShow(this._requestId, options);
|
|
109
|
+
addAdEventListener(type, listener) {
|
|
110
|
+
return this._addAdEventListener(type, listener);
|
|
146
111
|
}
|
|
147
112
|
|
|
148
113
|
}
|
|
114
|
+
|
|
115
|
+
_defineProperty(InterstitialAd, "_interstitialRequest", 0);
|
|
149
116
|
//# sourceMappingURL=InterstitialAd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["InterstitialAd.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["InterstitialAd.ts"],"names":["isString","MobileAds","validateAdRequestOptions","MobileAd","InterstitialAd","createForAdRequest","adUnitId","requestOptions","Error","options","e","message","requestId","_interstitialRequest","addAdEventsListener","listener","_addAdEventsListener","addAdEventListener","type","_addAdEventListener"],"mappings":";;AAAA;AACA;AACA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DE,EAAAA,kBAAkB,CAAwBC,IAAxB,EAAiCH,QAAjC,EAA+D;AAC/E,WAAO,KAAKI,mBAAL,CAAyBD,IAAzB,EAA+BH,QAA/B,CAAP;AACD;;AAhD0C;;gBAAhCX,c,0BAC6B,C","sourcesContent":["/*\n * Copyright (c) 2016-present Invertase Limited & Contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this library except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport { isString } from '../common';\nimport { MobileAds } from '../MobileAds';\nimport { validateAdRequestOptions } from '../validateAdRequestOptions';\nimport { MobileAd } from './MobileAd';\nimport { AdEventType } from '../AdEventType';\nimport { AdEventListener } from '../types/AdEventListener';\nimport { AdEventsListener } from '../types/AdEventsListener';\nimport { RequestOptions } from '../types/RequestOptions';\n\n/**\n * A class for interacting and showing Interstitial Ads.\n *\n * An Interstitial advert can be pre-loaded and shown at a suitable point in your apps flow, such as at the end of a level\n * in a game. An Interstitial is a full screen advert, laid on-top of your entire application which the user can interact with.\n * Interactions are passed back via events which should be handled accordingly inside of your app.\n *\n * #### Example\n *\n * First create a new Interstitial instance, passing in your Ad Unit ID from the Google Mobile Ads configuration console, and any additional\n * request options. The example below will present a test advert, and only request a non-personalized ad.\n *\n * ```js\n * import { InterstitialAd, TestIds } from 'react-native-google-mobile-ads';\n *\n * const interstitial = InterstitialAd.createForAdRequest(TestIds.INTERSTITIAL, {\n * requestNonPersonalizedAdsOnly: true,\n * });\n * ```\n *\n * Each advert needs to be loaded from Google Mobile Ads before being shown. It is recommended this is performed before the user\n * reaches the checkpoint to show the advert, so it's ready to go. Before loading the advert, we need to setup\n * event listeners to listen for updates from Google Mobile Ads, such as advert loaded or failed to load.\n *\n * Event types match the `AdEventType` interface. Once the advert has loaded, we can trigger it to show:\n *\n * ```js\n * import { AdEventType } from 'react-native-google-mobile-ads';\n *\n * interstitialAd.addAdEventListener(AdEventType.Loaded, () => {\n * interstitialAd.show();\n * });\n *\n * interstitial.load();\n * ```\n *\n * The advert will be presented to the user, and several more events can be triggered such as the user clicking the\n * advert or closing it.\n */\nexport class InterstitialAd extends MobileAd {\n protected static _interstitialRequest = 0;\n /**\n * Creates a new InterstitialAd instance.\n *\n * #### Example\n *\n * ```js\n * import { InterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads';\n *\n * const interstitialAd = await InterstitialAd.createForAdRequest(TestIds.INTERSTITIAL, {\n * requestAgent: 'CoolAds',\n * });\n *\n * interstitialAd.addAdEventListener(AdEventType.Loaded, () => {\n * interstitialAd.show();\n * });\n *\n * interstitialAd.load();\n * ```\n *\n * @param adUnitId The Ad Unit ID for the Interstitial. You can find this on your Google Mobile Ads dashboard.\n * @param requestOptions Optional RequestOptions used to load the ad.\n */\n static createForAdRequest(adUnitId: string, requestOptions?: RequestOptions) {\n if (!isString(adUnitId)) {\n throw new Error(\"InterstitialAd.createForAdRequest(*) 'adUnitId' expected an string value.\");\n }\n\n let options = {};\n try {\n options = validateAdRequestOptions(requestOptions);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`InterstitialAd.createForAdRequest(_, *) ${e.message}.`);\n }\n }\n\n const requestId = InterstitialAd._interstitialRequest++;\n return new InterstitialAd('interstitial', MobileAds(), requestId, adUnitId, options);\n }\n\n addAdEventsListener<T extends AdEventType>(listener: AdEventsListener<T>) {\n return this._addAdEventsListener(listener);\n }\n\n addAdEventListener<T extends AdEventType>(type: T, listener: AdEventListener<T>) {\n return this._addAdEventListener(type, listener);\n }\n}\n"]}
|
|
@@ -16,9 +16,12 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
16
16
|
* limitations under the License.
|
|
17
17
|
*
|
|
18
18
|
*/
|
|
19
|
+
import { isFunction, isOneOf } from '../common';
|
|
19
20
|
import { NativeError } from '../internal/NativeError';
|
|
20
|
-
import { RewardedAdEventType } from '../RewardedAdEventType';
|
|
21
21
|
import { AdEventType } from '../AdEventType';
|
|
22
|
+
import { RewardedAdEventType } from '../RewardedAdEventType';
|
|
23
|
+
import { GAMAdEventType } from '../GAMAdEventType';
|
|
24
|
+
import { validateAdShowOptions } from '../validateAdShowOptions';
|
|
22
25
|
export class MobileAd {
|
|
23
26
|
constructor(type, googleMobileAds, requestId, adUnitId, requestOptions) {
|
|
24
27
|
_defineProperty(this, "_type", void 0);
|
|
@@ -35,7 +38,13 @@ export class MobileAd {
|
|
|
35
38
|
|
|
36
39
|
_defineProperty(this, "_isLoadCalled", void 0);
|
|
37
40
|
|
|
38
|
-
_defineProperty(this, "
|
|
41
|
+
_defineProperty(this, "_adEventsListeners", void 0);
|
|
42
|
+
|
|
43
|
+
_defineProperty(this, "_adEventListenersMap", void 0);
|
|
44
|
+
|
|
45
|
+
_defineProperty(this, "_adEventsListenerId", void 0);
|
|
46
|
+
|
|
47
|
+
_defineProperty(this, "_adEventListenerId", void 0);
|
|
39
48
|
|
|
40
49
|
_defineProperty(this, "_nativeListener", void 0);
|
|
41
50
|
|
|
@@ -46,7 +55,18 @@ export class MobileAd {
|
|
|
46
55
|
this._requestOptions = requestOptions;
|
|
47
56
|
this._loaded = false;
|
|
48
57
|
this._isLoadCalled = false;
|
|
49
|
-
this.
|
|
58
|
+
this._adEventsListeners = new Map();
|
|
59
|
+
this._adEventListenersMap = new Map();
|
|
60
|
+
Object.values({ ...AdEventType,
|
|
61
|
+
...RewardedAdEventType,
|
|
62
|
+
...GAMAdEventType,
|
|
63
|
+
_: AdEventType.LOADED // since AdEventType.LOADED is overwritten by RewardedAdEventType.LOADED
|
|
64
|
+
|
|
65
|
+
}).forEach(type => {
|
|
66
|
+
this._adEventListenersMap.set(type, new Map());
|
|
67
|
+
});
|
|
68
|
+
this._adEventListenerId = 0;
|
|
69
|
+
this._adEventsListenerId = 0;
|
|
50
70
|
this._nativeListener = googleMobileAds.emitter.addListener(`google_mobile_ads_${type}_event:${adUnitId}:${requestId}`, this._handleAdEvent.bind(this));
|
|
51
71
|
}
|
|
52
72
|
|
|
@@ -66,20 +86,116 @@ export class MobileAd {
|
|
|
66
86
|
this._isLoadCalled = false;
|
|
67
87
|
}
|
|
68
88
|
|
|
69
|
-
|
|
70
|
-
let nativeError;
|
|
89
|
+
let payload = data;
|
|
71
90
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
91
|
+
if (error) {
|
|
92
|
+
payload = NativeError.fromEvent(error, 'googleMobileAds');
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this._adEventsListeners.forEach(listener => {
|
|
96
|
+
listener({
|
|
97
|
+
type,
|
|
98
|
+
payload
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
this._getAdEventListeners(type).forEach(listener => {
|
|
103
|
+
listener(payload);
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
_addAdEventsListener(listener) {
|
|
108
|
+
if (!isFunction(listener)) {
|
|
109
|
+
throw new Error(`${this._className}.addAdEventsListener(*) 'listener' expected a function.`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const id = this._adEventsListenerId++;
|
|
113
|
+
|
|
114
|
+
this._adEventsListeners.set(id, listener);
|
|
75
115
|
|
|
76
|
-
|
|
116
|
+
return () => {
|
|
117
|
+
this._adEventsListeners.delete(id);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
_addAdEventListener(type, listener) {
|
|
122
|
+
if (!(isOneOf(type, Object.values(AdEventType)) || isOneOf(type, Object.values(RewardedAdEventType)) && this._type === 'rewarded')) {
|
|
123
|
+
throw new Error(`${this._className}.addAdEventListener(*) 'type' expected a valid event type value.`);
|
|
77
124
|
}
|
|
125
|
+
|
|
126
|
+
if (!isFunction(listener)) {
|
|
127
|
+
throw new Error(`${this._className}.addAdEventListener(_, *) 'listener' expected a function.`);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const id = this._adEventListenerId++;
|
|
131
|
+
|
|
132
|
+
this._getAdEventListeners(type).set(id, listener);
|
|
133
|
+
|
|
134
|
+
return () => {
|
|
135
|
+
this._getAdEventListeners(type).delete(id);
|
|
136
|
+
};
|
|
78
137
|
}
|
|
79
138
|
|
|
80
|
-
|
|
81
|
-
this.
|
|
82
|
-
|
|
139
|
+
_getAdEventListeners(type) {
|
|
140
|
+
return this._adEventListenersMap.get(type);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get _className() {
|
|
144
|
+
return this.constructor.name;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
get _camelCaseType() {
|
|
148
|
+
let type;
|
|
149
|
+
|
|
150
|
+
if (this._type === 'app_open') {
|
|
151
|
+
type = 'appOpen';
|
|
152
|
+
} else if (this._type === 'rewarded_interstitial') {
|
|
153
|
+
type = 'rewardedInterstitial';
|
|
154
|
+
} else {
|
|
155
|
+
type = this._type;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return type;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
load() {
|
|
162
|
+
// Prevent multiple load calls
|
|
163
|
+
if (this._loaded || this._isLoadCalled) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
this._isLoadCalled = true;
|
|
168
|
+
const load = this._googleMobileAds.native[`${this._camelCaseType}Load`];
|
|
169
|
+
load(this._requestId, this._adUnitId, this._requestOptions);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
show(showOptions) {
|
|
173
|
+
if (!this._loaded) {
|
|
174
|
+
throw new Error(`${this._className}.show() The requested ${this._className} has not loaded and could not be shown.`);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
let options;
|
|
178
|
+
|
|
179
|
+
try {
|
|
180
|
+
options = validateAdShowOptions(showOptions);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
if (e instanceof Error) {
|
|
183
|
+
throw new Error(`${this._className}.show(*) ${e.message}.`);
|
|
184
|
+
} else {
|
|
185
|
+
throw e;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const show = this._googleMobileAds.native[`${this._camelCaseType}Show`];
|
|
190
|
+
return show(this._requestId, this._adUnitId, options);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
removeAllListeners() {
|
|
194
|
+
this._adEventsListeners.clear();
|
|
195
|
+
|
|
196
|
+
this._adEventListenersMap.forEach((_, type, map) => {
|
|
197
|
+
map.set(type, new Map());
|
|
198
|
+
});
|
|
83
199
|
}
|
|
84
200
|
|
|
85
201
|
get adUnitId() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["MobileAd.ts"],"names":["NativeError","RewardedAdEventType","AdEventType","MobileAd","constructor","type","googleMobileAds","requestId","adUnitId","requestOptions","_type","_googleMobileAds","_requestId","_adUnitId","_requestOptions","_loaded","_isLoadCalled","_onAdEventHandler","_nativeListener","emitter","addListener","_handleAdEvent","bind","event","error","data","body","LOADED","CLOSED","nativeError","fromEvent","_setAdEventHandler","handler","loaded"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA,SAASA,WAAT,QAA4B,yBAA5B;AACA,SAASC,mBAAT,QAAoC,wBAApC;AACA,SAASC,WAAT,QAA4B,gBAA5B;AAMA,OAAO,MAAMC,QAAN,CAAe;AAWpBC,EAAAA,WAAW,CACTC,IADS,EAETC,eAFS,EAGTC,SAHS,EAITC,QAJS,EAKTC,cALS,EAMT;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACA,SAAKC,KAAL,GAAaL,IAAb;AACA,SAAKM,gBAAL,GAAwBL,eAAxB;AACA,SAAKM,UAAL,GAAkBL,SAAlB;AACA,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OAAZ;AACD;;AAzEmB","sourcesContent":["/*\n * Copyright (c) 2016-present Invertase Limited & Contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this library except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport { EmitterSubscription } from 'react-native';\nimport { NativeError } from '../internal/NativeError';\nimport { RewardedAdEventType } from '../RewardedAdEventType';\nimport { AdEventType } from '../AdEventType';\nimport { AdEventListener } from '../types/AdEventListener';\nimport { RequestOptions } from '../types/RequestOptions';\nimport { MobileAdsModuleInterface } from '../types/MobileAdsModule.interface';\nimport { RewardedAdReward } from '../types/RewardedAdReward';\n\nexport class MobileAd {\n _type: 'app_open' | 'interstitial' | 'rewarded';\n _googleMobileAds: MobileAdsModuleInterface;\n _requestId: number;\n _adUnitId: string;\n _requestOptions: RequestOptions;\n _loaded: boolean;\n _isLoadCalled: boolean;\n _onAdEventHandler: AdEventListener | null;\n _nativeListener: EmitterSubscription;\n\n constructor(\n type: 'app_open' | 'interstitial' | 'rewarded',\n googleMobileAds: MobileAdsModuleInterface,\n requestId: number,\n adUnitId: string,\n requestOptions: RequestOptions,\n ) {\n this._type = type;\n this._googleMobileAds = googleMobileAds;\n this._requestId = requestId;\n this._adUnitId = adUnitId;\n this._requestOptions = requestOptions;\n\n this._loaded = false;\n this._isLoadCalled = false;\n this._onAdEventHandler = null;\n\n this._nativeListener = googleMobileAds.emitter.addListener(\n `google_mobile_ads_${type}_event:${adUnitId}:${requestId}`,\n this._handleAdEvent.bind(this),\n );\n }\n\n _handleAdEvent(event: {\n body: {\n type: AdEventType | RewardedAdEventType;\n error?: { code: string; message: string };\n data?: RewardedAdReward;\n };\n }) {\n const { type, error, data } = event.body;\n\n if (type === AdEventType.LOADED || type === RewardedAdEventType.LOADED) {\n this._loaded = true;\n }\n\n if (type === AdEventType.CLOSED) {\n this._loaded = false;\n this._isLoadCalled = false;\n }\n\n if (this._onAdEventHandler) {\n let nativeError;\n if (error) {\n nativeError = NativeError.fromEvent(error, 'googleMobileAds');\n }\n\n this._onAdEventHandler(type, nativeError, data);\n }\n }\n\n _setAdEventHandler(handler: AdEventListener) {\n this._onAdEventHandler = handler;\n return () => (this._onAdEventHandler = null);\n }\n\n get adUnitId() {\n return this._adUnitId;\n }\n\n get loaded() {\n return this._loaded;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["MobileAd.ts"],"names":["isFunction","isOneOf","NativeError","AdEventType","RewardedAdEventType","GAMAdEventType","validateAdShowOptions","MobileAd","constructor","type","googleMobileAds","requestId","adUnitId","requestOptions","_type","_googleMobileAds","_requestId","_adUnitId","_requestOptions","_loaded","_isLoadCalled","_adEventsListeners","Map","_adEventListenersMap","Object","values","_","LOADED","forEach","set","_adEventListenerId","_adEventsListenerId","_nativeListener","emitter","addListener","_handleAdEvent","bind","event","error","data","body","CLOSED","payload","fromEvent","listener","_getAdEventListeners","_addAdEventsListener","Error","_className","id","delete","_addAdEventListener","get","name","_camelCaseType","load","native","show","showOptions","options","e","message","removeAllListeners","clear","map","loaded"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAGA,SAASA,UAAT,EAAqBC,OAArB,QAAoC,WAApC;AACA,SAASC,WAAT,QAA4B,yBAA5B;AACA,SAASC,WAAT,QAA4B,gBAA5B;AACA,SAASC,mBAAT,QAAoC,wBAApC;AAQA,SAASC,cAAT,QAA+B,mBAA/B;AAEA,SAASC,qBAAT,QAAsC,0BAAtC;AAIA,OAAO,MAAeC,QAAf,CAAqD;AAchDC,EAAAA,WAAW,CACnBC,IADmB,EAEnBC,eAFmB,EAGnBC,SAHmB,EAInBC,QAJmB,EA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KAAKC,eAAvC,CAAJ;AACD;;AAEMuC,EAAAA,IAAI,CAACC,WAAD,EAA8B;AACvC,QAAI,CAAC,KAAKvC,OAAV,EAAmB;AACjB,YAAM,IAAI4B,KAAJ,CACH,GAAE,KAAKC,UAAW,yBAAwB,KAAKA,UAAW,yCADvD,CAAN;AAGD;;AAED,QAAIW,OAAJ;;AACA,QAAI;AACFA,MAAAA,OAAO,GAAGrD,qBAAqB,CAACoD,WAAD,CAA/B;AACD,KAFD,CAEE,OAAOE,CAAP,EAAU;AACV,UAAIA,CAAC,YAAYb,KAAjB,EAAwB;AACtB,cAAM,IAAIA,KAAJ,CAAW,GAAE,KAAKC,UAAW,YAAWY,CAAC,CAACC,OAAQ,GAAlD,CAAN;AACD,OAFD,MAEO;AACL,cAAMD,CAAN;AACD;AACF;;AAED,UAAMH,IAAI,GAAG,KAAK1C,gBAAL,CAAsByC,MAAtB,CAA8B,GAAE,KAAKF,cAAe,MAApD,CAAb;AACA,WAAOG,IAAI,CAAC,KAAKzC,UAAN,EAAkB,KAAKC,SAAvB,EAAkC0C,OAAlC,CAAX;AACD;;AAMMG,EAAAA,kBAAkB,GAAG;AAC1B,SAAKzC,kBAAL,CAAwB0C,KAAxB;;AACA,SAAKxC,oBAAL,CAA0BK,OAA1B,CAAkC,CAACF,CAAD,EAAIjB,IAAJ,EAAUuD,GAAV,KAAkB;AAClDA,MAAAA,GAAG,CAACnC,GAAJ,CAAQpB,IAAR,EAAc,IAAIa,GAAJ,EAAd;AACD,KAFD;AAGD;;AAEkB,MAARV,QAAQ,GAAG;AACpB,WAAO,KAAKK,SAAZ;AACD;;AAEgB,MAANgD,MAAM,GAAG;AAClB,WAAO,KAAK9C,OAAZ;AACD;;AA3LyD","sourcesContent":["/*\n * Copyright (c) 2016-present Invertase Limited & Contributors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this library except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n */\n\nimport { EmitterSubscription } from 'react-native';\nimport { isFunction, isOneOf } from '../common';\nimport { NativeError } from '../internal/NativeError';\nimport { AdEventType } from '../AdEventType';\nimport { RewardedAdEventType } from '../RewardedAdEventType';\nimport { AdEventListener, AdEventPayload } from '../types/AdEventListener';\nimport { AdEventsListener } from '../types/AdEventsListener';\nimport { AdShowOptions } from '../types/AdShowOptions';\nimport { RequestOptions } from '../types/RequestOptions';\nimport { MobileAdInterface } from '../types/MobileAd.interface';\nimport { MobileAdsModuleInterface } from '../types/MobileAdsModule.interface';\nimport { RewardedAdReward } from '../types/RewardedAdReward';\nimport { GAMAdEventType } from '../GAMAdEventType';\nimport { AppEvent } from '../types/AppEvent';\nimport { validateAdShowOptions } from '../validateAdShowOptions';\n\ntype EventType = AdEventType | RewardedAdEventType | GAMAdEventType;\n\nexport abstract class MobileAd implements MobileAdInterface {\n protected _type: 'app_open' | 'interstitial' | 'rewarded' | 'rewarded_interstitial';\n protected _googleMobileAds: MobileAdsModuleInterface;\n protected _requestId: number;\n protected _adUnitId: string;\n protected _requestOptions: RequestOptions;\n protected _loaded: boolean;\n protected _isLoadCalled: boolean;\n protected _adEventsListeners: Map<number, AdEventsListener<EventType>>;\n protected _adEventListenersMap: Map<EventType, Map<number, AdEventListener<EventType>>>;\n protected _adEventsListenerId: number;\n protected _adEventListenerId: number;\n protected _nativeListener: EmitterSubscription;\n\n protected constructor(\n type: 'app_open' | 'interstitial' | 'rewarded' | 'rewarded_interstitial',\n googleMobileAds: MobileAdsModuleInterface,\n requestId: number,\n adUnitId: string,\n requestOptions: RequestOptions,\n ) {\n this._type = type;\n this._googleMobileAds = googleMobileAds;\n this._requestId = requestId;\n this._adUnitId = adUnitId;\n this._requestOptions = requestOptions;\n\n this._loaded = false;\n this._isLoadCalled = false;\n this._adEventsListeners = new Map();\n this._adEventListenersMap = new Map();\n Object.values({\n ...AdEventType,\n ...RewardedAdEventType,\n ...GAMAdEventType,\n _: AdEventType.LOADED, // since AdEventType.LOADED is overwritten by RewardedAdEventType.LOADED\n }).forEach(type => {\n this._adEventListenersMap.set(type as EventType, new Map());\n });\n this._adEventListenerId = 0;\n this._adEventsListenerId = 0;\n\n this._nativeListener = googleMobileAds.emitter.addListener(\n `google_mobile_ads_${type}_event:${adUnitId}:${requestId}`,\n this._handleAdEvent.bind(this),\n );\n }\n\n protected _handleAdEvent(event: {\n body: {\n type: EventType;\n error?: { code: string; message: string };\n data?: RewardedAdReward | AppEvent;\n };\n }) {\n const { type, error, data } = event.body;\n\n if (type === AdEventType.LOADED || type === RewardedAdEventType.LOADED) {\n this._loaded = true;\n }\n\n if (type === AdEventType.CLOSED) {\n this._loaded = false;\n this._isLoadCalled = false;\n }\n\n let payload: AdEventPayload<EventType> = data;\n if (error) {\n payload = NativeError.fromEvent(error, 'googleMobileAds');\n }\n this._adEventsListeners.forEach(listener => {\n listener({\n type,\n payload,\n });\n });\n this._getAdEventListeners(type).forEach(listener => {\n listener(payload);\n });\n }\n\n protected _addAdEventsListener<T extends EventType>(listener: AdEventsListener<T>) {\n if (!isFunction(listener)) {\n throw new Error(`${this._className}.addAdEventsListener(*) 'listener' expected a function.`);\n }\n\n const id = this._adEventsListenerId++;\n this._adEventsListeners.set(id, listener as AdEventsListener<EventType>);\n return () => {\n this._adEventsListeners.delete(id);\n };\n }\n\n protected _addAdEventListener<T extends EventType>(type: T, listener: AdEventListener<T>) {\n if (\n !(\n isOneOf(type, Object.values(AdEventType)) ||\n (isOneOf(type, Object.values(RewardedAdEventType)) && this._type === 'rewarded')\n )\n ) {\n throw new Error(\n `${this._className}.addAdEventListener(*) 'type' expected a valid event type value.`,\n );\n }\n if (!isFunction(listener)) {\n throw new Error(\n `${this._className}.addAdEventListener(_, *) 'listener' expected a function.`,\n );\n }\n\n const id = this._adEventListenerId++;\n this._getAdEventListeners(type).set(id, listener);\n return () => {\n this._getAdEventListeners(type).delete(id);\n };\n }\n\n protected _getAdEventListeners<T extends EventType>(type: T) {\n return this._adEventListenersMap.get(type) as Map<number, AdEventListener<T>>;\n }\n\n protected get _className() {\n return this.constructor.name;\n }\n\n protected get _camelCaseType() {\n let type: 'appOpen' | 'interstitial' | 'rewarded' | 'rewardedInterstitial';\n if (this._type === 'app_open') {\n type = 'appOpen';\n } else if (this._type === 'rewarded_interstitial') {\n type = 'rewardedInterstitial';\n } else {\n type = this._type;\n }\n return type;\n }\n\n public load() {\n // Prevent multiple load calls\n if (this._loaded || this._isLoadCalled) {\n return;\n }\n\n this._isLoadCalled = true;\n const load = this._googleMobileAds.native[`${this._camelCaseType}Load`];\n load(this._requestId, this._adUnitId, this._requestOptions);\n }\n\n public show(showOptions?: AdShowOptions) {\n if (!this._loaded) {\n throw new Error(\n `${this._className}.show() The requested ${this._className} has not loaded and could not be shown.`,\n );\n }\n\n let options;\n try {\n options = validateAdShowOptions(showOptions);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`${this._className}.show(*) ${e.message}.`);\n } else {\n throw e;\n }\n }\n\n const show = this._googleMobileAds.native[`${this._camelCaseType}Show`];\n return show(this._requestId, this._adUnitId, options);\n }\n\n public abstract addAdEventsListener<T extends never>(listener: AdEventsListener<T>): () => void;\n\n public abstract addAdEventListener<T extends never>(type: T, listener: AdEventListener<T>): void;\n\n public removeAllListeners() {\n this._adEventsListeners.clear();\n this._adEventListenersMap.forEach((_, type, map) => {\n map.set(type, new Map());\n });\n }\n\n public get adUnitId() {\n return this._adUnitId;\n }\n\n public get loaded() {\n return this._loaded;\n }\n}\n"]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
|
+
|
|
1
3
|
/*
|
|
2
4
|
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
5
|
*
|
|
@@ -14,12 +16,12 @@
|
|
|
14
16
|
* limitations under the License.
|
|
15
17
|
*
|
|
16
18
|
*/
|
|
17
|
-
import {
|
|
19
|
+
import { isString } from '../common';
|
|
18
20
|
import { MobileAds } from '../MobileAds';
|
|
19
21
|
import { validateAdRequestOptions } from '../validateAdRequestOptions';
|
|
20
|
-
import { validateAdShowOptions } from '../validateAdShowOptions';
|
|
21
22
|
import { MobileAd } from './MobileAd';
|
|
22
|
-
|
|
23
|
+
import { AdEventType } from '../AdEventType';
|
|
24
|
+
|
|
23
25
|
/**
|
|
24
26
|
* A class for interacting and showing Rewarded Ads.
|
|
25
27
|
*
|
|
@@ -52,13 +54,11 @@ let _rewardedRequest = 0;
|
|
|
52
54
|
* ```js
|
|
53
55
|
* import { RewardedAdEventType } from 'react-native-google-mobile-ads';
|
|
54
56
|
*
|
|
55
|
-
* rewarded.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* console.log('User earned reward of ', reward);
|
|
61
|
-
* }
|
|
57
|
+
* rewarded.addAdEventListener(RewardedAdEventType.LOADED. () => {
|
|
58
|
+
* rewarded.show();
|
|
59
|
+
* });
|
|
60
|
+
* rewarded.addAdEventListener(RewardedAdEventType.EARNED_REWARD. (reward) => {
|
|
61
|
+
* console.log('User earned reward of ', reward);
|
|
62
62
|
* });
|
|
63
63
|
*
|
|
64
64
|
* rewarded.load();
|
|
@@ -67,7 +67,6 @@ let _rewardedRequest = 0;
|
|
|
67
67
|
* The rewarded advert will be presented to the user, and several more events can be triggered such as the user clicking the
|
|
68
68
|
* advert, closing it or completing the action.
|
|
69
69
|
*/
|
|
70
|
-
|
|
71
70
|
export class RewardedAd extends MobileAd {
|
|
72
71
|
/**
|
|
73
72
|
* Creates a new RewardedAd instance.
|
|
@@ -81,12 +80,11 @@ export class RewardedAd extends MobileAd {
|
|
|
81
80
|
* requestAgent: 'CoolAds',
|
|
82
81
|
* });
|
|
83
82
|
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* }
|
|
83
|
+
* rewarded.addAdEventListener(RewardedAdEventType.LOADED. () => {
|
|
84
|
+
* rewarded.show();
|
|
85
|
+
* });
|
|
86
|
+
* rewarded.addAdEventListener(RewardedAdEventType.EARNED_REWARD. (reward) => {
|
|
87
|
+
* console.log('User earned reward of ', reward);
|
|
90
88
|
* });
|
|
91
89
|
*
|
|
92
90
|
* rewardedAd.load();
|
|
@@ -110,46 +108,23 @@ export class RewardedAd extends MobileAd {
|
|
|
110
108
|
}
|
|
111
109
|
}
|
|
112
110
|
|
|
113
|
-
const requestId = _rewardedRequest++;
|
|
111
|
+
const requestId = RewardedAd._rewardedRequest++;
|
|
114
112
|
return new RewardedAd('rewarded', MobileAds(), requestId, adUnitId, options);
|
|
115
113
|
}
|
|
116
114
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (this._loaded || this._isLoadCalled) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
this._isLoadCalled = true;
|
|
124
|
-
|
|
125
|
-
this._googleMobileAds.native.rewardedLoad(this._requestId, this._adUnitId, this._requestOptions);
|
|
115
|
+
addAdEventsListener(listener) {
|
|
116
|
+
return this._addAdEventsListener(listener);
|
|
126
117
|
}
|
|
127
118
|
|
|
128
|
-
|
|
129
|
-
if (
|
|
130
|
-
throw new Error(
|
|
119
|
+
addAdEventListener(type, listener) {
|
|
120
|
+
if (type === AdEventType.LOADED) {
|
|
121
|
+
throw new Error('RewardedAd.addAdEventListener(*) use RewardedAdEventType.LOADED instead of AdEventType.LOADED.');
|
|
131
122
|
}
|
|
132
123
|
|
|
133
|
-
return this.
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
show(showOptions) {
|
|
137
|
-
if (!this._loaded) {
|
|
138
|
-
throw new Error('RewardedAd.show() The requested RewardedAd has not loaded and could not be shown.');
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
let options;
|
|
142
|
-
|
|
143
|
-
try {
|
|
144
|
-
options = validateAdShowOptions(showOptions);
|
|
145
|
-
} catch (e) {
|
|
146
|
-
if (e instanceof Error) {
|
|
147
|
-
throw new Error(`RewardedAd.show(*) ${e.message}.`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return this._googleMobileAds.native.rewardedShow(this._requestId, this._adUnitId, options);
|
|
124
|
+
return this._addAdEventListener(type, listener);
|
|
152
125
|
}
|
|
153
126
|
|
|
154
127
|
}
|
|
128
|
+
|
|
129
|
+
_defineProperty(RewardedAd, "_rewardedRequest", 0);
|
|
155
130
|
//# sourceMappingURL=RewardedAd.js.map
|