react-native-google-mobile-ads 6.0.0 → 6.2.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/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsCommon.java +9 -3
- package/android/src/main/java/io/invertase/googlemobileads/ReactNativeGoogleMobileAdsEvent.java +2 -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/displaying-ads-hook.mdx +1 -1
- package/docs/displaying-ads.mdx +132 -1
- package/docs/european-user-consent.mdx +31 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.h +1 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsCommon.m +7 -1
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.h +25 -0
- package/ios/RNGoogleMobileAds/RNGoogleMobileAdsRewardedInterstitialModule.m +173 -0
- package/lib/commonjs/BannerAdSize.js +2 -0
- package/lib/commonjs/BannerAdSize.js.map +1 -1
- package/lib/commonjs/MobileAds.js +5 -2
- package/lib/commonjs/MobileAds.js.map +1 -1
- package/lib/commonjs/TestIds.js +6 -2
- package/lib/commonjs/TestIds.js.map +1 -1
- package/lib/commonjs/ads/MobileAd.js +16 -4
- package/lib/commonjs/ads/MobileAd.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/useFullScreenAd.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 +19 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/BannerAdSize.js +2 -0
- package/lib/module/BannerAdSize.js.map +1 -1
- package/lib/module/MobileAds.js +5 -2
- package/lib/module/MobileAds.js.map +1 -1
- package/lib/module/TestIds.js +6 -2
- package/lib/module/TestIds.js.map +1 -1
- package/lib/module/ads/MobileAd.js +16 -4
- package/lib/module/ads/MobileAd.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/useFullScreenAd.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 +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/BannerAdSize.d.ts +10 -1
- package/lib/typescript/MobileAds.d.ts +1 -1
- package/lib/typescript/TestIds.d.ts +2 -0
- package/lib/typescript/ads/MobileAd.d.ts +3 -2
- package/lib/typescript/ads/RewardedInterstitialAd.d.ts +82 -0
- package/lib/typescript/hooks/useFullScreenAd.d.ts +2 -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 +3 -1
- package/lib/typescript/types/GoogleMobileAdsNativeModule.d.ts +12 -7
- package/lib/typescript/types/MobileAdsModule.interface.d.ts +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +8 -8
- package/src/BannerAdSize.ts +12 -1
- package/src/MobileAds.ts +9 -0
- package/src/TestIds.ts +4 -0
- package/src/ads/MobileAd.ts +16 -6
- package/src/ads/RewardedInterstitialAd.ts +143 -0
- package/src/hooks/useFullScreenAd.ts +4 -3
- package/src/hooks/useRewardedAd.ts +1 -1
- package/src/hooks/useRewardedInterstitialAd.ts +47 -0
- package/src/index.ts +2 -0
- package/src/types/GoogleMobileAdsNativeModule.ts +16 -7
- package/src/types/MobileAdsModule.interface.ts +1 -1
- package/src/version.ts +1 -1
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
//
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this library except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
#import <React/RCTUtils.h>
|
|
20
|
+
|
|
21
|
+
#import "RNGoogleMobileAdsCommon.h"
|
|
22
|
+
#import "RNGoogleMobileAdsFullScreenContentDelegate.h"
|
|
23
|
+
#import "RNGoogleMobileAdsRewardedInterstitialModule.h"
|
|
24
|
+
#import "common/RNSharedUtils.h"
|
|
25
|
+
|
|
26
|
+
static __strong NSMutableDictionary *rewardedInterstitialMap;
|
|
27
|
+
static __strong NSMutableDictionary *rewardedInterstitialDelegateMap;
|
|
28
|
+
|
|
29
|
+
@implementation RNGoogleMobileAdsRewardedInterstitialModule
|
|
30
|
+
#pragma mark -
|
|
31
|
+
#pragma mark Module Setup
|
|
32
|
+
|
|
33
|
+
RCT_EXPORT_MODULE();
|
|
34
|
+
|
|
35
|
+
- (dispatch_queue_t)methodQueue {
|
|
36
|
+
return dispatch_get_main_queue();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
- (id)init {
|
|
40
|
+
self = [super init];
|
|
41
|
+
static dispatch_once_t onceToken;
|
|
42
|
+
dispatch_once(&onceToken, ^{
|
|
43
|
+
rewardedInterstitialMap = [[NSMutableDictionary alloc] init];
|
|
44
|
+
rewardedInterstitialDelegateMap = [[NSMutableDictionary alloc] init];
|
|
45
|
+
});
|
|
46
|
+
return self;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
+ (BOOL)requiresMainQueueSetup {
|
|
50
|
+
return YES;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
- (void)dealloc {
|
|
54
|
+
[self invalidate];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
- (void)invalidate {
|
|
58
|
+
for (NSNumber *id in [rewardedInterstitialMap allKeys]) {
|
|
59
|
+
[rewardedInterstitialMap removeObjectForKey:id];
|
|
60
|
+
[rewardedInterstitialDelegateMap removeObjectForKey:id];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#pragma mark -
|
|
65
|
+
#pragma mark Google Mobile Ads Methods
|
|
66
|
+
|
|
67
|
+
RCT_EXPORT_METHOD(rewardedInterstitialLoad
|
|
68
|
+
: (nonnull NSNumber *)requestId
|
|
69
|
+
: (NSString *)adUnitId
|
|
70
|
+
: (NSDictionary *)adRequestOptions) {
|
|
71
|
+
[GADRewardedInterstitialAd
|
|
72
|
+
loadWithAdUnitID:adUnitId
|
|
73
|
+
request:[RNGoogleMobileAdsCommon buildAdRequest:adRequestOptions]
|
|
74
|
+
completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
|
|
75
|
+
if (error) {
|
|
76
|
+
NSDictionary *codeAndMessage =
|
|
77
|
+
[RNGoogleMobileAdsCommon getCodeAndMessageFromAdError:error];
|
|
78
|
+
[RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
|
|
79
|
+
requestId:requestId
|
|
80
|
+
type:GOOGLE_MOBILE_ADS_EVENT_ERROR
|
|
81
|
+
adUnitId:adUnitId
|
|
82
|
+
error:codeAndMessage
|
|
83
|
+
data:nil];
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
GADRewardedInterstitialAd *rewardedInterstitialAd = ad;
|
|
87
|
+
|
|
88
|
+
NSDictionary *serverSideVerificationOptions =
|
|
89
|
+
[adRequestOptions objectForKey:@"serverSideVerificationOptions"];
|
|
90
|
+
|
|
91
|
+
if (serverSideVerificationOptions != nil) {
|
|
92
|
+
GADServerSideVerificationOptions *options =
|
|
93
|
+
[[GADServerSideVerificationOptions alloc] init];
|
|
94
|
+
|
|
95
|
+
NSString *userId = [serverSideVerificationOptions valueForKey:@"userId"];
|
|
96
|
+
|
|
97
|
+
if (userId != nil) {
|
|
98
|
+
options.userIdentifier = userId;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
NSString *customData = [serverSideVerificationOptions valueForKey:@"customData"];
|
|
102
|
+
|
|
103
|
+
if (customData != nil) {
|
|
104
|
+
options.customRewardString = customData;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
[rewardedInterstitialAd setServerSideVerificationOptions:options];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
RNGoogleMobileAdsFullScreenContentDelegate *fullScreenContentDelegate =
|
|
111
|
+
[[RNGoogleMobileAdsFullScreenContentDelegate alloc] init];
|
|
112
|
+
fullScreenContentDelegate.sendAdEvent = GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL;
|
|
113
|
+
fullScreenContentDelegate.requestId = requestId;
|
|
114
|
+
fullScreenContentDelegate.adUnitId = ad.adUnitID;
|
|
115
|
+
rewardedInterstitialAd.fullScreenContentDelegate = fullScreenContentDelegate;
|
|
116
|
+
rewardedInterstitialMap[requestId] = rewardedInterstitialAd;
|
|
117
|
+
rewardedInterstitialDelegateMap[requestId] = fullScreenContentDelegate;
|
|
118
|
+
GADAdReward *reward = rewardedInterstitialAd.adReward;
|
|
119
|
+
NSMutableDictionary *data = [NSMutableDictionary dictionary];
|
|
120
|
+
if (reward.type != nil) {
|
|
121
|
+
[data setValue:reward.type forKey:@"type"];
|
|
122
|
+
}
|
|
123
|
+
if (reward.amount != nil) {
|
|
124
|
+
[data setValue:reward.amount forKey:@"amount"];
|
|
125
|
+
}
|
|
126
|
+
[RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
|
|
127
|
+
requestId:requestId
|
|
128
|
+
type:GOOGLE_MOBILE_ADS_EVENT_REWARDED_LOADED
|
|
129
|
+
adUnitId:ad.adUnitID
|
|
130
|
+
error:nil
|
|
131
|
+
data:data];
|
|
132
|
+
}];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
RCT_EXPORT_METHOD(rewardedInterstitialShow
|
|
136
|
+
: (nonnull NSNumber *)requestId
|
|
137
|
+
: (NSString *)adUnitId
|
|
138
|
+
: (NSDictionary *)showOptions
|
|
139
|
+
: (RCTPromiseResolveBlock)resolve
|
|
140
|
+
: (RCTPromiseRejectBlock)reject) {
|
|
141
|
+
GADRewardedInterstitialAd *rewardedInterstitialAd = rewardedInterstitialMap[requestId];
|
|
142
|
+
|
|
143
|
+
if (rewardedInterstitialAd) {
|
|
144
|
+
[rewardedInterstitialAd
|
|
145
|
+
presentFromRootViewController:RCTSharedApplication().delegate.window.rootViewController
|
|
146
|
+
userDidEarnRewardHandler:^{
|
|
147
|
+
GADAdReward *reward = rewardedInterstitialAd.adReward;
|
|
148
|
+
NSMutableDictionary *data = [NSMutableDictionary dictionary];
|
|
149
|
+
if (reward.type != nil) {
|
|
150
|
+
[data setValue:reward.type forKey:@"type"];
|
|
151
|
+
}
|
|
152
|
+
if (reward.amount != nil) {
|
|
153
|
+
[data setValue:reward.amount forKey:@"amount"];
|
|
154
|
+
}
|
|
155
|
+
[RNGoogleMobileAdsCommon sendAdEvent:GOOGLE_MOBILE_ADS_EVENT_REWARDED_INTERSTITIAL
|
|
156
|
+
requestId:requestId
|
|
157
|
+
type:GOOGLE_MOBILE_ADS_EVENT_REWARDED_EARNED_REWARD
|
|
158
|
+
adUnitId:rewardedInterstitialAd.adUnitID
|
|
159
|
+
error:nil
|
|
160
|
+
data:data];
|
|
161
|
+
}];
|
|
162
|
+
} else {
|
|
163
|
+
[RNSharedUtils
|
|
164
|
+
rejectPromiseWithUserInfo:reject
|
|
165
|
+
userInfo:[@{
|
|
166
|
+
@"code" : @"not-ready",
|
|
167
|
+
@"message" :
|
|
168
|
+
@"Rewarded Interstitial ad attempted to show but was not ready.",
|
|
169
|
+
} mutableCopy]];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@end
|
|
@@ -32,6 +32,8 @@ exports.BannerAdSize = BannerAdSize;
|
|
|
32
32
|
BannerAdSize["LEADERBOARD"] = "LEADERBOARD";
|
|
33
33
|
BannerAdSize["MEDIUM_RECTANGLE"] = "MEDIUM_RECTANGLE";
|
|
34
34
|
BannerAdSize["ADAPTIVE_BANNER"] = "ADAPTIVE_BANNER";
|
|
35
|
+
BannerAdSize["ANCHORED_ADAPTIVE_BANNER"] = "ANCHORED_ADAPTIVE_BANNER";
|
|
36
|
+
BannerAdSize["INLINE_ADAPTIVE_BANNER"] = "INLINE_ADAPTIVE_BANNER";
|
|
35
37
|
BannerAdSize["FLUID"] = "FLUID";
|
|
36
38
|
BannerAdSize["WIDE_SKYSCRAPER"] = "WIDE_SKYSCRAPER";
|
|
37
39
|
})(BannerAdSize || (exports.BannerAdSize = BannerAdSize = {}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BannerAdSize.ts"],"names":["BannerAdSize"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IAEYA,Y;;;WAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;GAAAA,Y,4BAAAA,Y","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 */\n\nexport enum BannerAdSize {\n /**\n * Mobile Marketing Association (MMA) banner ad size (320x50 density-independent pixels).\n */\n BANNER = 'BANNER',\n\n /**\n * Interactive Advertising Bureau (IAB) full banner ad size (468x60 density-independent pixels).\n */\n FULL_BANNER = 'FULL_BANNER',\n\n /**\n * Large banner ad size (320x100 density-independent pixels).\n */\n LARGE_BANNER = 'LARGE_BANNER',\n\n /**\n * Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels).\n */\n LEADERBOARD = 'LEADERBOARD',\n\n /**\n * Interactive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels).\n */\n MEDIUM_RECTANGLE = 'MEDIUM_RECTANGLE',\n\n /**\n * A (next generation) dynamically sized banner that is full-width and auto-height.\n */\n
|
|
1
|
+
{"version":3,"sources":["BannerAdSize.ts"],"names":["BannerAdSize"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;IAEYA,Y;;;WAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;AAAAA,EAAAA,Y;GAAAA,Y,4BAAAA,Y","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 */\n\nexport enum BannerAdSize {\n /**\n * Mobile Marketing Association (MMA) banner ad size (320x50 density-independent pixels).\n */\n BANNER = 'BANNER',\n\n /**\n * Interactive Advertising Bureau (IAB) full banner ad size (468x60 density-independent pixels).\n */\n FULL_BANNER = 'FULL_BANNER',\n\n /**\n * Large banner ad size (320x100 density-independent pixels).\n */\n LARGE_BANNER = 'LARGE_BANNER',\n\n /**\n * Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels).\n */\n LEADERBOARD = 'LEADERBOARD',\n\n /**\n * Interactive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels).\n */\n MEDIUM_RECTANGLE = 'MEDIUM_RECTANGLE',\n\n /**\n * @deprecated Use `ANCHORED_ADAPTIVE_BANNER` instead.\n */\n ADAPTIVE_BANNER = 'ADAPTIVE_BANNER',\n\n /**\n * A (next generation) dynamically sized banner that is full-width and auto-height.\n */\n ANCHORED_ADAPTIVE_BANNER = 'ANCHORED_ADAPTIVE_BANNER',\n\n /**\n * Inline adaptive banners are larger, taller banners compared to anchored adaptive banners. They are of variable height, and can be as tall as the device screen.\n * They are intended to be placed in scrolling content.\n */\n INLINE_ADAPTIVE_BANNER = 'INLINE_ADAPTIVE_BANNER',\n\n /**\n * A dynamically sized banner that matches its parent's width and expands/contracts its height to match the ad's content after loading completes.\n */\n FLUID = 'FLUID',\n\n /**\n * IAB wide skyscraper ad size (160x600 density-independent pixels). This size is currently not supported by the Google Mobile Ads network; this is intended for mediation ad networks only.\n */\n WIDE_SKYSCRAPER = 'WIDE_SKYSCRAPER',\n}\n"]}
|
|
@@ -12,7 +12,7 @@ var _validateAdRequestConfiguration = require("./validateAdRequestConfiguration"
|
|
|
12
12
|
var _version = require("./version");
|
|
13
13
|
|
|
14
14
|
const namespace = 'google_mobile_ads';
|
|
15
|
-
const nativeModuleName = ['RNGoogleMobileAdsModule', 'RNGoogleMobileAdsAppOpenModule', 'RNGoogleMobileAdsInterstitialModule', 'RNGoogleMobileAdsRewardedModule'];
|
|
15
|
+
const nativeModuleName = ['RNGoogleMobileAdsModule', 'RNGoogleMobileAdsAppOpenModule', 'RNGoogleMobileAdsInterstitialModule', 'RNGoogleMobileAdsRewardedModule', 'RNGoogleMobileAdsRewardedInterstitialModule'];
|
|
16
16
|
|
|
17
17
|
class MobileAdsModule extends _internal.Module {
|
|
18
18
|
constructor(app, config) {
|
|
@@ -26,6 +26,9 @@ class MobileAdsModule extends _internal.Module {
|
|
|
26
26
|
this.emitter.addListener('google_mobile_ads_rewarded_event', event => {
|
|
27
27
|
this.emitter.emit(`google_mobile_ads_rewarded_event:${event.adUnitId}:${event.requestId}`, event);
|
|
28
28
|
});
|
|
29
|
+
this.emitter.addListener('google_mobile_ads_rewarded_interstitial_event', event => {
|
|
30
|
+
this.emitter.emit(`google_mobile_ads_rewarded_interstitial_event:${event.adUnitId}:${event.requestId}`, event);
|
|
31
|
+
});
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
initialize() {
|
|
@@ -58,7 +61,7 @@ const MobileAdsInstance = new MobileAdsModule({
|
|
|
58
61
|
version: _version.version,
|
|
59
62
|
namespace,
|
|
60
63
|
nativeModuleName,
|
|
61
|
-
nativeEvents: ['google_mobile_ads_app_open_event', 'google_mobile_ads_interstitial_event', 'google_mobile_ads_rewarded_event']
|
|
64
|
+
nativeEvents: ['google_mobile_ads_app_open_event', 'google_mobile_ads_interstitial_event', 'google_mobile_ads_rewarded_event', 'google_mobile_ads_rewarded_interstitial_event']
|
|
62
65
|
});
|
|
63
66
|
|
|
64
67
|
const MobileAds = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["MobileAds.ts"],"names":["namespace","nativeModuleName","MobileAdsModule","Module","constructor","app","config","emitter","addListener","event","emit","adUnitId","requestId","initialize","native","setRequestConfiguration","requestConfiguration","e","Error","message","openAdInspector","MobileAdsInstance","name","version","nativeEvents","MobileAds"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAKA,MAAMA,SAAS,GAAG,mBAAlB;AAEA,MAAMC,gBAAgB,GAAG,CACvB,yBADuB,EAEvB,gCAFuB,EAGvB,qCAHuB,EAIvB,iCAJuB,CAAzB;;
|
|
1
|
+
{"version":3,"sources":["MobileAds.ts"],"names":["namespace","nativeModuleName","MobileAdsModule","Module","constructor","app","config","emitter","addListener","event","emit","adUnitId","requestId","initialize","native","setRequestConfiguration","requestConfiguration","e","Error","message","openAdInspector","MobileAdsInstance","name","version","nativeEvents","MobileAds"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAKA,MAAMA,SAAS,GAAG,mBAAlB;AAEA,MAAMC,gBAAgB,GAAG,CACvB,yBADuB,EAEvB,gCAFuB,EAGvB,qCAHuB,EAIvB,iCAJuB,EAKvB,6CALuB,CAAzB;;AAaA,MAAMC,eAAN,SAA8BC,gBAA9B,CAAyE;AACvEC,EAAAA,WAAW,CAACC,GAAD,EAAWC,MAAX,EAA2B;AACpC,UAAMD,GAAN,EAAWC,MAAX;AAEA,SAAKC,OAAL,CAAaC,WAAb,CAAyB,kCAAzB,EAA8DC,KAAD,IAAkB;AAC7E,WAAKF,OAAL,CAAaG,IAAb,CACG,oCAAmCD,KAAK,CAACE,QAAS,IAAGF,KAAK,CAACG,SAAU,EADxE,EAEEH,KAFF;AAID,KALD;AAOA,SAAKF,OAAL,CAAaC,WAAb,CAAyB,sCAAzB,EAAkEC,KAAD,IAAkB;AACjF,WAAKF,OAAL,CAAaG,IAAb,CACG,wCAAuCD,KA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JhB,CAFwB,CAA1B;;AAeO,MAAMC,SAAS,GAAG,MAAM;AAC7B,SAAOJ,iBAAP;AACD,CAFM;;;eAIQI,S","sourcesContent":["import { Module } from './internal';\nimport { validateAdRequestConfiguration } from './validateAdRequestConfiguration';\nimport { version } from './version';\nimport { MobileAdsModuleInterface } from './types/MobileAdsModule.interface';\nimport { RequestConfiguration } from './types/RequestConfiguration';\nimport { App, Config } from './types/Module.interface';\n\nconst namespace = 'google_mobile_ads';\n\nconst nativeModuleName = [\n 'RNGoogleMobileAdsModule',\n 'RNGoogleMobileAdsAppOpenModule',\n 'RNGoogleMobileAdsInterstitialModule',\n 'RNGoogleMobileAdsRewardedModule',\n 'RNGoogleMobileAdsRewardedInterstitialModule',\n];\n\ntype Event = {\n adUnitId: string;\n requestId: number;\n};\n\nclass MobileAdsModule extends Module implements MobileAdsModuleInterface {\n constructor(app: App, config: Config) {\n super(app, config);\n\n this.emitter.addListener('google_mobile_ads_app_open_event', (event: Event) => {\n this.emitter.emit(\n `google_mobile_ads_app_open_event:${event.adUnitId}:${event.requestId}`,\n event,\n );\n });\n\n this.emitter.addListener('google_mobile_ads_interstitial_event', (event: Event) => {\n this.emitter.emit(\n `google_mobile_ads_interstitial_event:${event.adUnitId}:${event.requestId}`,\n event,\n );\n });\n\n this.emitter.addListener('google_mobile_ads_rewarded_event', (event: Event) => {\n this.emitter.emit(\n `google_mobile_ads_rewarded_event:${event.adUnitId}:${event.requestId}`,\n event,\n );\n });\n\n this.emitter.addListener('google_mobile_ads_rewarded_interstitial_event', (event: Event) => {\n this.emitter.emit(\n `google_mobile_ads_rewarded_interstitial_event:${event.adUnitId}:${event.requestId}`,\n event,\n );\n });\n }\n\n initialize() {\n return this.native.initialize();\n }\n\n setRequestConfiguration(requestConfiguration: RequestConfiguration) {\n let config;\n try {\n config = validateAdRequestConfiguration(requestConfiguration);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`googleMobileAds.setRequestConfiguration(*) ${e.message}`);\n }\n }\n\n return this.native.setRequestConfiguration(config);\n }\n\n openAdInspector() {\n return this.native.openAdInspector();\n }\n}\n\nconst MobileAdsInstance = new MobileAdsModule(\n { name: 'AppName' },\n {\n version,\n namespace,\n nativeModuleName,\n nativeEvents: [\n 'google_mobile_ads_app_open_event',\n 'google_mobile_ads_interstitial_event',\n 'google_mobile_ads_rewarded_event',\n 'google_mobile_ads_rewarded_interstitial_event',\n ],\n },\n);\n\nexport const MobileAds = () => {\n return MobileAdsInstance;\n};\n\nexport default MobileAds;\n"]}
|
package/lib/commonjs/TestIds.js
CHANGED
|
@@ -28,23 +28,27 @@ const TestIds = {
|
|
|
28
28
|
BANNER: '',
|
|
29
29
|
INTERSTITIAL: '',
|
|
30
30
|
REWARDED: '',
|
|
31
|
+
REWARDED_INTERSTITIAL: '',
|
|
31
32
|
GAM_APP_OPEN: '/6499/example/app-open',
|
|
32
33
|
GAM_BANNER: '/6499/example/banner',
|
|
33
34
|
GAM_INTERSTITIAL: '/6499/example/interstitial',
|
|
34
35
|
GAM_REWARDED: '/6499/example/rewarded',
|
|
36
|
+
GAM_REWARDED_INTERSTITIAL: '/21775744923/example/rewarded_interstitial',
|
|
35
37
|
GAM_NATIVE: '/6499/example/native',
|
|
36
38
|
..._reactNative.Platform.select({
|
|
37
39
|
android: {
|
|
38
40
|
APP_OPEN: 'ca-app-pub-3940256099942544/3419835294',
|
|
39
41
|
BANNER: 'ca-app-pub-3940256099942544/6300978111',
|
|
40
42
|
INTERSTITIAL: 'ca-app-pub-3940256099942544/1033173712',
|
|
41
|
-
REWARDED: 'ca-app-pub-3940256099942544/5224354917'
|
|
43
|
+
REWARDED: 'ca-app-pub-3940256099942544/5224354917',
|
|
44
|
+
REWARDED_INTERSTITIAL: 'ca-app-pub-3940256099942544/5354046379'
|
|
42
45
|
},
|
|
43
46
|
ios: {
|
|
44
47
|
APP_OPEN: 'ca-app-pub-3940256099942544/5662855259',
|
|
45
48
|
BANNER: 'ca-app-pub-3940256099942544/2934735716',
|
|
46
49
|
INTERSTITIAL: 'ca-app-pub-3940256099942544/4411468910',
|
|
47
|
-
REWARDED: 'ca-app-pub-3940256099942544/1712485313'
|
|
50
|
+
REWARDED: 'ca-app-pub-3940256099942544/1712485313',
|
|
51
|
+
REWARDED_INTERSTITIAL: 'ca-app-pub-3940256099942544/6978759866'
|
|
48
52
|
}
|
|
49
53
|
})
|
|
50
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["TestIds.ts"],"names":["TestIds","APP_OPEN","BANNER","INTERSTITIAL","REWARDED","GAM_APP_OPEN","GAM_BANNER","GAM_INTERSTITIAL","GAM_REWARDED","GAM_NATIVE","Platform","select","android","ios"],"mappings":";;;;;;;AAiBA;;AAjBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIO,MAAMA,OAAO,GAAG;AACrBC,EAAAA,QAAQ,EAAE,EADW;AAErBC,EAAAA,MAAM,EAAE,EAFa;AAGrBC,EAAAA,YAAY,EAAE,EAHO;AAIrBC,EAAAA,QAAQ,EAAE,EAJW;AAKrBC,EAAAA,
|
|
1
|
+
{"version":3,"sources":["TestIds.ts"],"names":["TestIds","APP_OPEN","BANNER","INTERSTITIAL","REWARDED","REWARDED_INTERSTITIAL","GAM_APP_OPEN","GAM_BANNER","GAM_INTERSTITIAL","GAM_REWARDED","GAM_REWARDED_INTERSTITIAL","GAM_NATIVE","Platform","select","android","ios"],"mappings":";;;;;;;AAiBA;;AAjBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIO,MAAMA,OAAO,GAAG;AACrBC,EAAAA,QAAQ,EAAE,EADW;AAErBC,EAAAA,MAAM,EAAE,EAFa;AAGrBC,EAAAA,YAAY,EAAE,EAHO;AAIrBC,EAAAA,QAAQ,EAAE,EAJW;AAKrBC,EAAAA,qBAAqB,EAAE,EALF;AAMrBC,EAAAA,YAAY,EAAE,wBANO;AAOrBC,EAAAA,UAAU,EAAE,sBAPS;AAQrBC,EAAAA,gBAAgB,EAAE,4BARG;AASrBC,EAAAA,YAAY,EAAE,wBATO;AAUrBC,EAAAA,yBAAyB,EAAE,4CAVN;AAWrBC,EAAAA,UAAU,EAAE,sBAXS;AAYrB,KAAGC,sBAASC,MAAT,CAAgB;AACjBC,IAAAA,OAAO,EAAE;AACPb,MAAAA,QAAQ,EAAE,wCADH;AAEPC,MAAAA,MAAM,EAAE,wCAFD;AAGPC,MAAAA,YAAY,EAAE,wCAHP;AAIPC,MAAAA,QAAQ,EAAE,wCAJH;AAKPC,MAAAA,qBAAqB,EAAE;AALhB,KADQ;AAQjBU,IAAAA,GAAG,EAAE;AACHd,MAAAA,QAAQ,EAAE,wCADP;AAEHC,MAAAA,MAAM,EAAE,wCAFL;AAGHC,MAAAA,YAAY,EAAE,wCAHX;AAIHC,MAAAA,QAAQ,EAAE,wCAJP;AAKHC,MAAAA,qBAAqB,EAAE;AALpB;AARY,GAAhB;AAZkB,CAAhB","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 { Platform } from 'react-native';\n\nexport const TestIds = {\n APP_OPEN: '',\n BANNER: '',\n INTERSTITIAL: '',\n REWARDED: '',\n REWARDED_INTERSTITIAL: '',\n GAM_APP_OPEN: '/6499/example/app-open',\n GAM_BANNER: '/6499/example/banner',\n GAM_INTERSTITIAL: '/6499/example/interstitial',\n GAM_REWARDED: '/6499/example/rewarded',\n GAM_REWARDED_INTERSTITIAL: '/21775744923/example/rewarded_interstitial',\n GAM_NATIVE: '/6499/example/native',\n ...Platform.select({\n android: {\n APP_OPEN: 'ca-app-pub-3940256099942544/3419835294',\n BANNER: 'ca-app-pub-3940256099942544/6300978111',\n INTERSTITIAL: 'ca-app-pub-3940256099942544/1033173712',\n REWARDED: 'ca-app-pub-3940256099942544/5224354917',\n REWARDED_INTERSTITIAL: 'ca-app-pub-3940256099942544/5354046379',\n },\n ios: {\n APP_OPEN: 'ca-app-pub-3940256099942544/5662855259',\n BANNER: 'ca-app-pub-3940256099942544/2934735716',\n INTERSTITIAL: 'ca-app-pub-3940256099942544/4411468910',\n REWARDED: 'ca-app-pub-3940256099942544/1712485313',\n REWARDED_INTERSTITIAL: 'ca-app-pub-3940256099942544/6978759866',\n },\n }),\n};\n"]}
|
|
@@ -141,6 +141,20 @@ class MobileAd {
|
|
|
141
141
|
return this.constructor.name;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
+
get _camelCaseType() {
|
|
145
|
+
let type;
|
|
146
|
+
|
|
147
|
+
if (this._type === 'app_open') {
|
|
148
|
+
type = 'appOpen';
|
|
149
|
+
} else if (this._type === 'rewarded_interstitial') {
|
|
150
|
+
type = 'rewardedInterstitial';
|
|
151
|
+
} else {
|
|
152
|
+
type = this._type;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return type;
|
|
156
|
+
}
|
|
157
|
+
|
|
144
158
|
load() {
|
|
145
159
|
// Prevent multiple load calls
|
|
146
160
|
if (this._loaded || this._isLoadCalled) {
|
|
@@ -148,8 +162,7 @@ class MobileAd {
|
|
|
148
162
|
}
|
|
149
163
|
|
|
150
164
|
this._isLoadCalled = true;
|
|
151
|
-
const
|
|
152
|
-
const load = this._googleMobileAds.native[`${type}Load`];
|
|
165
|
+
const load = this._googleMobileAds.native[`${this._camelCaseType}Load`];
|
|
153
166
|
load(this._requestId, this._adUnitId, this._requestOptions);
|
|
154
167
|
}
|
|
155
168
|
|
|
@@ -170,8 +183,7 @@ class MobileAd {
|
|
|
170
183
|
}
|
|
171
184
|
}
|
|
172
185
|
|
|
173
|
-
const
|
|
174
|
-
const show = this._googleMobileAds.native[`${type}Show`];
|
|
186
|
+
const show = this._googleMobileAds.native[`${this._camelCaseType}Show`];
|
|
175
187
|
return show(this._requestId, this._adUnitId, options);
|
|
176
188
|
}
|
|
177
189
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["MobileAd.ts"],"names":["MobileAd","constructor","type","googleMobileAds","requestId","adUnitId","requestOptions","_type","_googleMobileAds","_requestId","_adUnitId","_requestOptions","_loaded","_isLoadCalled","_adEventsListeners","Map","_adEventListenersMap","Object","values","AdEventType","RewardedAdEventType","GAMAdEventType","_","LOADED","forEach","set","_adEventListenerId","_adEventsListenerId","_nativeListener","emitter","addListener","_handleAdEvent","bind","event","error","data","body","CLOSED","payload","NativeError","fromEvent","listener","_getAdEventListeners","_addAdEventsListener","Error","_className","id","delete","_addAdEventListener","get","name","load","native","show","showOptions","options","e","message","removeAllListeners","clear","map","loaded"],"mappings":";;;;;;;AAkBA;;AACA;;AACA;;AACA;;AAQA;;AAEA;;;;AAIO,MAAeA,QAAf,CAAqD;AAchDC,EAAAA,WAAW,CACnBC,IADmB,EAEnBC,eAFmB,EAGnBC,SAHmB,EAInBC,QAJmB,EAKnBC,cALmB,EAMnB;AAAA;;AAAA;;AAAA;;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,SAAKM,SAAL,GAAiBL,QAAjB;AACA,SAAKM,eAAL,GAAuBL,cAAvB;AAEA,SAAKM,OAAL,GAAe,KAAf;AACA,SAAKC,aAAL,GAAqB,KAArB;AACA,SAAKC,kBAAL,GAA0B,IAAIC,GAAJ,EAA1B;AACA,SAAKC,oBAAL,GAA4B,IAAID,GAAJ,EAA5B;AACAE,IAAAA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B,EAAkC6C,OAAlC,CAAX;AACD;;AAMMG,EAAAA,kBAAkB,GAAG;AAC1B,SAAK5C,kBAAL,CAAwB6C,KAAxB;;AACA,SAAK3C,oBAAL,CAA0BQ,OAA1B,CAAkC,CAACF,CAAD,EAAIpB,IAAJ,EAAU0D,GAAV,KAAkB;AAClDA,MAAAA,GAAG,CAACnC,GAAJ,CAAQvB,IAAR,EAAc,IAAIa,GAAJ,EAAd;AACD,KAFD;AAGD;;AAEkB,MAARV,QAAQ,GAAG;AACpB,WAAO,KAAKK,SAAZ;AACD;;AAEgB,MAANmD,MAAM,GAAG;AAClB,WAAO,KAAKjD,OAAZ;AACD;;AAjLyD","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';\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',\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 public load() {\n // Prevent multiple load calls\n if (this._loaded || this._isLoadCalled) {\n return;\n }\n\n this._isLoadCalled = true;\n const type = this._type === 'app_open' ? 'appOpen' : this._type;\n const load = this._googleMobileAds.native[`${type}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 type = this._type === 'app_open' ? 'appOpen' : this._type;\n const show = this._googleMobileAds.native[`${type}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
|
+
{"version":3,"sources":["MobileAd.ts"],"names":["MobileAd","constructor","type","googleMobileAds","requestId","adUnitId","requestOptions","_type","_googleMobileAds","_requestId","_adUnitId","_requestOptions","_loaded","_isLoadCalled","_adEventsListeners","Map","_adEventListenersMap","Object","values","AdEventType","RewardedAdEventType","GAMAdEventType","_","LOADED","forEach","set","_adEventListenerId","_adEventsListenerId","_nativeListener","emitter","addListener","_handleAdEvent","bind","event","error","data","body","CLOSED","payload","NativeError","fromEvent","listener","_getAdEventListeners","_addAdEventsListener","Error","_className","id","delete","_addAdEventListener","get","name","_camelCaseType","load","native","show","showOptions","options","e","message","removeAllListeners","clear","map","loaded"],"mappings":";;;;;;;AAkBA;;AACA;;AACA;;AACA;;AAQA;;AAEA;;;;AAIO,MAAeA,QAAf,CAAqD;AAchDC,EAAAA,WAAW,CACnBC,IADmB,EAEnBC,eAFmB,EAGnBC,SAHmB,EAInBC,QAJmB,EAKnBC,cALmB,EAMnB;AAAA;;AAAA;;AAAA;;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,SAAKM,SAAL,GAAiBL,QAAjB;AACA,SAAKM,eAAL,GAAuBL,cAAvB;AAEA,SAAKM,OAAL,GAAe,KAAf;AACA,SAAKC,aAAL,GAAqB,KAArB;AACA,SAAKC,kBAAL,GAA0B,IAAIC,GAAJ,EAA1B;AACA,SAAK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AFD,MAEO;AACL,cAAMD,CAAN;AACD;AACF;;AAED,UAAMH,IAAI,GAAG,KAAK9C,gBAAL,CAAsB6C,MAAtB,CAA8B,GAAE,KAAKF,cAAe,MAApD,CAAb;AACA,WAAOG,IAAI,CAAC,KAAK7C,UAAN,EAAkB,KAAKC,SAAvB,EAAkC8C,OAAlC,CAAX;AACD;;AAMMG,EAAAA,kBAAkB,GAAG;AAC1B,SAAK7C,kBAAL,CAAwB8C,KAAxB;;AACA,SAAK5C,oBAAL,CAA0BQ,OAA1B,CAAkC,CAACF,CAAD,EAAIpB,IAAJ,EAAU2D,GAAV,KAAkB;AAClDA,MAAAA,GAAG,CAACpC,GAAJ,CAAQvB,IAAR,EAAc,IAAIa,GAAJ,EAAd;AACD,KAFD;AAGD;;AAEkB,MAARV,QAAQ,GAAG;AACpB,WAAO,KAAKK,SAAZ;AACD;;AAEgB,MAANoD,MAAM,GAAG;AAClB,WAAO,KAAKlD,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"]}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RewardedInterstitialAd = void 0;
|
|
7
|
+
|
|
8
|
+
var _common = require("../common");
|
|
9
|
+
|
|
10
|
+
var _MobileAds = require("../MobileAds");
|
|
11
|
+
|
|
12
|
+
var _validateAdRequestOptions = require("../validateAdRequestOptions");
|
|
13
|
+
|
|
14
|
+
var _MobileAd = require("./MobileAd");
|
|
15
|
+
|
|
16
|
+
var _AdEventType = require("../AdEventType");
|
|
17
|
+
|
|
18
|
+
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; }
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A class for interacting and showing Rewarded Interstitial Ads.
|
|
22
|
+
*
|
|
23
|
+
* An Rewarded Interstitial advert can be pre-loaded and shown at a suitable point in your apps flow, such as at the end of a level
|
|
24
|
+
* in a game. The content of a rewarded interstital advert can be controlled via your Google Mobile Ads dashboard. Typically users are rewarded
|
|
25
|
+
* after completing a specific advert action (e.g. watching a video or submitting an option via an interactive form).
|
|
26
|
+
* Events (such as the user earning a reward or closing a rewarded interstital advert early) are sent back for you to handle accordingly
|
|
27
|
+
* within your application.
|
|
28
|
+
*
|
|
29
|
+
* #### Example
|
|
30
|
+
*
|
|
31
|
+
* First create a new Rewarded Interstitial instance, passing in your Ad Unit ID from the Google Mobile Ads configuration console, and any additional
|
|
32
|
+
* request options. The example below will present a test advert, and only request a non-personalized ad.
|
|
33
|
+
*
|
|
34
|
+
* ```js
|
|
35
|
+
* import { RewardedInterstitialAd, TestIds } from 'react-native-google-mobile-ads';
|
|
36
|
+
*
|
|
37
|
+
* const rewardedInterstitial = RewardedInterstitialAd.createForAdRequest(TestIds.REWARDED_INTERSTITIAL, {
|
|
38
|
+
* requestNonPersonalizedAdsOnly: true,
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* Each advert needs to be loaded from Google Mobile Ads before being shown. It is recommended this is performed before the user
|
|
43
|
+
* reaches the checkpoint to show the advert, so it's ready to go. Before loading the advert, we need to setup
|
|
44
|
+
* event listeners to listen for updates from Google Mobile Ads, such as advert loaded or failed to load.
|
|
45
|
+
*
|
|
46
|
+
* Event types match the `AdEventType` or `RewardedAdEventType` interface. The potential user reward for rewarded interstitial
|
|
47
|
+
* adverts are passed back to the event handler on advert load and when the user earns the reward.
|
|
48
|
+
*
|
|
49
|
+
* ```js
|
|
50
|
+
* import { RewardedAdEventType } from 'react-native-google-mobile-ads';
|
|
51
|
+
*
|
|
52
|
+
* rewardedInterstitial.addAdEventListener(RewardedAdEventType.LOADED. () => {
|
|
53
|
+
* rewarded.show();
|
|
54
|
+
* });
|
|
55
|
+
* rewardedInterstitial.addAdEventListener(RewardedAdEventType.EARNED_REWARD. (reward) => {
|
|
56
|
+
* console.log('User earned reward of ', reward);
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* rewardedInterstitial.load();
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* The rewarded interstitial advert will be presented to the user, and several more events can be triggered such as the user clicking the
|
|
63
|
+
* advert, closing it or completing the action.
|
|
64
|
+
*/
|
|
65
|
+
class RewardedInterstitialAd extends _MobileAd.MobileAd {
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new RewardedInterstitialAd instance.
|
|
68
|
+
*
|
|
69
|
+
* #### Example
|
|
70
|
+
*
|
|
71
|
+
* ```js
|
|
72
|
+
* import { RewardedInterstitialAd, RewardedAdEventType, TestIds } from 'react-native-google-mobile-ads';
|
|
73
|
+
*
|
|
74
|
+
* const rewardedInterstitialAd = await RewardedInterstitialAd.createForAdRequest(TestIds.REWARDED_INTERSTITIAL, {
|
|
75
|
+
* requestAgent: 'CoolAds',
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* rewardedInterstitialAd.addAdEventListener(RewardedAdEventType.LOADED. () => {
|
|
79
|
+
* rewardedInterstitialAd.show();
|
|
80
|
+
* });
|
|
81
|
+
* rewardedInterstitialAd.addAdEventListener(RewardedAdEventType.EARNED_REWARD. (reward) => {
|
|
82
|
+
* console.log('User earned reward of ', reward);
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* rewardedInterstitialAd.load();
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @param adUnitId The Ad Unit ID for the Rewarded Interstitial Ad. You can find this on your Google Mobile Ads dashboard.
|
|
89
|
+
* @param requestOptions Optional RequestOptions used to load the ad.
|
|
90
|
+
*/
|
|
91
|
+
static createForAdRequest(adUnitId, requestOptions) {
|
|
92
|
+
if (!(0, _common.isString)(adUnitId)) {
|
|
93
|
+
throw new Error("RewardedInterstitialAd.createForAdRequest(*) 'adUnitId' expected an string value.");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let options = {};
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
options = (0, _validateAdRequestOptions.validateAdRequestOptions)(requestOptions);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
if (e instanceof Error) {
|
|
102
|
+
throw new Error(`RewardedInterstitialAd.createForAdRequest(_, *) ${e.message}.`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const requestId = RewardedInterstitialAd._rewardedInterstitialRequest++;
|
|
107
|
+
return new RewardedInterstitialAd('rewarded_interstitial', (0, _MobileAds.MobileAds)(), requestId, adUnitId, options);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
addAdEventsListener(listener) {
|
|
111
|
+
return this._addAdEventsListener(listener);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
addAdEventListener(type, listener) {
|
|
115
|
+
if (type === _AdEventType.AdEventType.LOADED) {
|
|
116
|
+
throw new Error('RewardedInterstitialAd.addAdEventListener(*) use RewardedAdEventType.LOADED instead of AdEventType.LOADED.');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return this._addAdEventListener(type, listener);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
exports.RewardedInterstitialAd = RewardedInterstitialAd;
|
|
125
|
+
|
|
126
|
+
_defineProperty(RewardedInterstitialAd, "_rewardedInterstitialRequest", 0);
|
|
127
|
+
//# sourceMappingURL=RewardedInterstitialAd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["RewardedInterstitialAd.ts"],"names":["RewardedInterstitialAd","MobileAd","createForAdRequest","adUnitId","requestOptions","Error","options","e","message","requestId","_rewardedInterstitialRequest","addAdEventsListener","listener","_addAdEventsListener","addAdEventListener","type","AdEventType","LOADED","_addAdEventListener"],"mappings":";;;;;;;AAiBA;;AACA;;AACA;;AACA;;AACA;;;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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CZ,sB,kCACqC,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 { RewardedAdEventType } from '../RewardedAdEventType';\nimport { AdEventListener } from '../types/AdEventListener';\nimport { AdEventsListener } from '../types/AdEventsListener';\nimport { RequestOptions } from '../types/RequestOptions';\n\n/**\n * A class for interacting and showing Rewarded Interstitial Ads.\n *\n * An Rewarded 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. The content of a rewarded interstital advert can be controlled via your Google Mobile Ads dashboard. Typically users are rewarded\n * after completing a specific advert action (e.g. watching a video or submitting an option via an interactive form).\n * Events (such as the user earning a reward or closing a rewarded interstital advert early) are sent back for you to handle accordingly\n * within your application.\n *\n * #### Example\n *\n * First create a new Rewarded 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 { RewardedInterstitialAd, TestIds } from 'react-native-google-mobile-ads';\n *\n * const rewardedInterstitial = RewardedInterstitialAd.createForAdRequest(TestIds.REWARDED_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` or `RewardedAdEventType` interface. The potential user reward for rewarded interstitial\n * adverts are passed back to the event handler on advert load and when the user earns the reward.\n *\n * ```js\n * import { RewardedAdEventType } from 'react-native-google-mobile-ads';\n *\n * rewardedInterstitial.addAdEventListener(RewardedAdEventType.LOADED. () => {\n * rewarded.show();\n * });\n * rewardedInterstitial.addAdEventListener(RewardedAdEventType.EARNED_REWARD. (reward) => {\n * console.log('User earned reward of ', reward);\n * });\n *\n * rewardedInterstitial.load();\n * ```\n *\n * The rewarded interstitial advert will be presented to the user, and several more events can be triggered such as the user clicking the\n * advert, closing it or completing the action.\n */\nexport class RewardedInterstitialAd extends MobileAd {\n protected static _rewardedInterstitialRequest = 0;\n /**\n * Creates a new RewardedInterstitialAd instance.\n *\n * #### Example\n *\n * ```js\n * import { RewardedInterstitialAd, RewardedAdEventType, TestIds } from 'react-native-google-mobile-ads';\n *\n * const rewardedInterstitialAd = await RewardedInterstitialAd.createForAdRequest(TestIds.REWARDED_INTERSTITIAL, {\n * requestAgent: 'CoolAds',\n * });\n *\n * rewardedInterstitialAd.addAdEventListener(RewardedAdEventType.LOADED. () => {\n * rewardedInterstitialAd.show();\n * });\n * rewardedInterstitialAd.addAdEventListener(RewardedAdEventType.EARNED_REWARD. (reward) => {\n * console.log('User earned reward of ', reward);\n * });\n *\n * rewardedInterstitialAd.load();\n * ```\n *\n * @param adUnitId The Ad Unit ID for the Rewarded Interstitial Ad. 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(\n \"RewardedInterstitialAd.createForAdRequest(*) 'adUnitId' expected an string value.\",\n );\n }\n\n let options = {};\n try {\n options = validateAdRequestOptions(requestOptions);\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`RewardedInterstitialAd.createForAdRequest(_, *) ${e.message}.`);\n }\n }\n\n const requestId = RewardedInterstitialAd._rewardedInterstitialRequest++;\n return new RewardedInterstitialAd(\n 'rewarded_interstitial',\n MobileAds(),\n requestId,\n adUnitId,\n options,\n );\n }\n\n addAdEventsListener<T extends AdEventType | RewardedAdEventType>(\n listener: AdEventsListener<T>,\n ): () => void {\n return this._addAdEventsListener(listener);\n }\n\n addAdEventListener<T extends AdEventType | RewardedAdEventType>(\n type: T,\n listener: AdEventListener<T>,\n ) {\n if (type === AdEventType.LOADED) {\n throw new Error(\n 'RewardedInterstitialAd.addAdEventListener(*) use RewardedAdEventType.LOADED instead of AdEventType.LOADED.',\n );\n }\n return this._addAdEventListener(type, listener);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useFullScreenAd.ts"],"names":["initialState","isLoaded","isOpened","isClicked","isClosed","error","undefined","reward","isEarnedReward","useFullScreenAd","ad","state","setState","prevState","newState","isShowing","load","show","showOptions","unsubscribe","addAdEventsListener","type","payload","AdEventType","LOADED","OPENED","CLOSED","CLICKED","ERROR","RewardedAdEventType","EARNED_REWARD"],"mappings":";;;;;;;AAiBA;;AAEA;;
|
|
1
|
+
{"version":3,"sources":["useFullScreenAd.ts"],"names":["initialState","isLoaded","isOpened","isClicked","isClosed","error","undefined","reward","isEarnedReward","useFullScreenAd","ad","state","setState","prevState","newState","isShowing","load","show","showOptions","unsubscribe","addAdEventsListener","type","payload","AdEventType","LOADED","OPENED","CLOSED","CLICKED","ERROR","RewardedAdEventType","EARNED_REWARD"],"mappings":";;;;;;;AAiBA;;AAEA;;AAKA;;AAxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAcA,MAAMA,YAAsB,GAAG;AAC7BC,EAAAA,QAAQ,EAAE,KADmB;AAE7BC,EAAAA,QAAQ,EAAE,KAFmB;AAG7BC,EAAAA,SAAS,EAAE,KAHkB;AAI7BC,EAAAA,QAAQ,EAAE,KAJmB;AAK7BC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,CAAC;AAAER,YAAAA,QAAQ,EAAE;AAAZ,WAAD,CAAR;AACA;;AACF,aAAKmB,yBAAYI,OAAjB;AACEf,UAAAA,QAAQ,CAAC;AAAET,YAAAA,SAAS,EAAE;AAAb,WAAD,CAAR;AACA;;AACF,aAAKoB,yBAAYK,KAAjB;AACEhB,UAAAA,QAAQ,CAAC;AAAEP,YAAAA,KAAK,EAAEiB;AAAT,WAAD,CAAR;AACA;;AACF,aAAKO,yCAAoBL,MAAzB;AACEZ,UAAAA,QAAQ,CAAC;AAAEX,YAAAA,QAAQ,EAAE,IAAZ;AAAkBM,YAAAA,MAAM,EAAEe;AAA1B,WAAD,CAAR;AACA;;AACF,aAAKO,yCAAoBC,aAAzB;AACElB,UAAAA,QAAQ,CAAC;AAAEJ,YAAAA,cAAc,EAAE,IAAlB;AAAwBD,YAAAA,MAAM,EAAEe;AAAhC,WAAD,CAAR;AACA;AArBJ;AAuBD,KAxBmB,CAApB;AAyBA,WAAO,MAAM;AACXH,MAAAA,WAAW;AACZ,KAFD;AAGD,GAjCD,EAiCG,CAACT,EAAD,CAjCH;AAmCA,SAAO,EACL,GAAGC,KADE;AAELI,IAAAA,SAFK;AAGLC,IAAAA,IAHK;AAILC,IAAAA;AAJK,GAAP;AAMD","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 { Reducer, useCallback, useEffect, useReducer } from 'react';\n\nimport { AdEventType } from '../AdEventType';\nimport { AppOpenAd } from '../ads/AppOpenAd';\nimport { InterstitialAd } from '../ads/InterstitialAd';\nimport { RewardedAd } from '../ads/RewardedAd';\nimport { RewardedInterstitialAd } from '../ads/RewardedInterstitialAd';\nimport { RewardedAdEventType } from '../RewardedAdEventType';\nimport { AdStates, AdHookReturns } from '../types/AdStates';\nimport { AdShowOptions } from '../types/AdShowOptions';\nimport { RewardedAdReward } from '../types/RewardedAdReward';\n\nconst initialState: AdStates = {\n isLoaded: false,\n isOpened: false,\n isClicked: false,\n isClosed: false,\n error: undefined,\n reward: undefined,\n isEarnedReward: false,\n};\n\nexport function useFullScreenAd<\n T extends AppOpenAd | InterstitialAd | RewardedAd | RewardedInterstitialAd | null,\n>(ad: T): AdHookReturns {\n const [state, setState] = useReducer<Reducer<AdStates, Partial<AdStates>>>(\n (prevState, newState) => ({ ...prevState, ...newState }),\n initialState,\n );\n const isShowing = state.isOpened && !state.isClosed;\n\n const load = useCallback(() => {\n if (ad) {\n setState(initialState);\n ad.load();\n }\n }, [ad]);\n\n const show = useCallback(\n (showOptions?: AdShowOptions) => {\n if (ad) {\n ad.show(showOptions);\n }\n },\n [ad],\n );\n\n useEffect(() => {\n setState(initialState);\n if (!ad) {\n return;\n }\n const unsubscribe = (ad as RewardedAd).addAdEventsListener(({ type, payload }) => {\n switch (type) {\n case AdEventType.LOADED:\n setState({ isLoaded: true });\n break;\n case AdEventType.OPENED:\n setState({ isOpened: true });\n break;\n case AdEventType.CLOSED:\n setState({ isClosed: true });\n break;\n case AdEventType.CLICKED:\n setState({ isClicked: true });\n break;\n case AdEventType.ERROR:\n setState({ error: payload as Error });\n break;\n case RewardedAdEventType.LOADED:\n setState({ isLoaded: true, reward: payload as RewardedAdReward });\n break;\n case RewardedAdEventType.EARNED_REWARD:\n setState({ isEarnedReward: true, reward: payload as RewardedAdReward });\n break;\n }\n });\n return () => {\n unsubscribe();\n };\n }, [ad]);\n\n return {\n ...state,\n isShowing,\n load,\n show,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useRewardedAd.ts"],"names":["useRewardedAd","adUnitId","requestOptions","rewardedAd","setRewardedAd","RewardedAd","createForAdRequest"],"mappings":";;;;;;;AAiBA;;AACA;;AAEA;;AAIA;;;;AAxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAT,CACLC,QADK,
|
|
1
|
+
{"version":3,"sources":["useRewardedAd.ts"],"names":["useRewardedAd","adUnitId","requestOptions","rewardedAd","setRewardedAd","RewardedAd","createForAdRequest"],"mappings":";;;;;;;AAiBA;;AACA;;AAEA;;AAIA;;;;AAxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAWA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,aAAT,CACLC,QADK,EAGU;AAAA,MADfC,cACe,uEADkB,EAClB;AACf,QAAM,CAACC,UAAD,EAAaC,aAAb,IAA8B,qBAA4B,IAA5B,CAApC;AAEA,qCAAqB,MAAM;AACzBA,IAAAA,aAAa,CAAC,MAAM;AAClB,aAAOH,QAAQ,GAAGI,uBAAWC,kBAAX,CAA8BL,QAA9B,EAAwCC,cAAxC,CAAH,GAA6D,IAA5E;AACD,KAFY,CAAb;AAGD,GAJD,EAIG,CAACD,QAAD,EAAWC,cAAX,CAJH;AAMA,SAAO,sCAAgBC,UAAhB,CAAP;AACD","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 { useState } from 'react';\nimport useDeepCompareEffect from 'use-deep-compare-effect';\n\nimport { RewardedAd } from '../ads/RewardedAd';\nimport { AdHookReturns } from '../types/AdStates';\nimport { RequestOptions } from '../types/RequestOptions';\n\nimport { useFullScreenAd } from './useFullScreenAd';\n\n/**\n * React Hook for Rewarded Ad.\n *\n * @param adUnitId The Ad Unit ID for the Rewarded Ad. You can find this on your Google Mobile Ads dashboard. You can destroy ad instance by setting this value to null.\n * @param requestOptions Optional RequestOptions used to load the ad.\n */\nexport function useRewardedAd(\n adUnitId: string | null,\n requestOptions: RequestOptions = {},\n): AdHookReturns {\n const [rewardedAd, setRewardedAd] = useState<RewardedAd | null>(null);\n\n useDeepCompareEffect(() => {\n setRewardedAd(() => {\n return adUnitId ? RewardedAd.createForAdRequest(adUnitId, requestOptions) : null;\n });\n }, [adUnitId, requestOptions]);\n\n return useFullScreenAd(rewardedAd);\n}\n"]}
|